-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOwnable.sol
74 lines (60 loc) · 1.92 KB
/
Ownable.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable {
address payable public owner;
address payable public newOwner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() internal {
_trasnferOwnership(msg.sender);
}
function _trasnferOwnership(address payable _whom) internal {
emit OwnershipTransferred(owner,_whom);
owner = _whom;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner == msg.sender, "ERR_AUTHORIZED_ADDRESS_ONLY");
_;
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address payable _newOwner)
external
virtual
onlyOwner
{
require(_newOwner != address(0),"ERR_ZERO_ADDRESS");
newOwner = _newOwner;
}
function acceptOwnership() external
virtual
returns (bool){
require(msg.sender == newOwner,"ERR_ONLY_NEW_OWNER");
owner = newOwner;
emit OwnershipTransferred(owner, newOwner);
newOwner = address(0);
return true;
}
}