-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOwnable.sol
More file actions
69 lines (60 loc) · 1.95 KB
/
Ownable.sol
File metadata and controls
69 lines (60 loc) · 1.95 KB
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
// SPDX-License-Identifier: MIT
pragma solidity 0.6.11;
/**
* Based on OpenZeppelin's Ownable contract:
* https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol
*
* @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.
*
* 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 {
bytes32 private constant KEY_OWNER = keccak256("key.ownable.owner");
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
_setOwner(msg.sender);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == getOwner(), "Ownable:: access denied");
_;
}
/**
* @notice Set address of the owner.
* @param _owner Address of the owner.
* */
function _setOwner(address _owner) internal {
require(_owner != address(0), "Ownable::setOwner: invalid address");
emit OwnershipTransferred(getOwner(), _owner);
bytes32 key = KEY_OWNER;
assembly {
sstore(key, _owner)
}
}
/**
* @notice Set address of the owner (only owner can call this function)
* @param _owner Address of the owner.
* */
function setOwner(address _owner) public onlyOwner {
_setOwner(_owner);
}
/**
* @notice Return address of the owner.
* @return _owner Address of the owner.
* */
function getOwner() public view returns (address _owner) {
bytes32 key = KEY_OWNER;
assembly {
_owner := sload(key)
}
}
}