-
Notifications
You must be signed in to change notification settings - Fork 4
/
Ownable.sol
49 lines (40 loc) · 1.43 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
pragma solidity ^0.4.24;
/// Provides basic authorization control
contract Ownable {
address private origOwner;
// Define an Event
event TransferOwnership(address indexed oldOwner, address indexed newOwner);
/// Assign the contract to an owner
constructor () internal {
origOwner = msg.sender;
emit TransferOwnership(address(0), origOwner);
}
/// Look up the address of the owner
function owner() public view returns (address) {
return origOwner;
}
/// Define a function modifier 'onlyOwner'
modifier onlyOwner() {
require(isOwner(), "sender is not the owner");
_;
}
/// Check if the calling address is the owner of the contract
function isOwner() public view returns (bool) {
return msg.sender == origOwner;
}
/// Define a function to renounce ownerhip
function renounceOwnership() public onlyOwner {
emit TransferOwnership(origOwner, address(0));
origOwner = address(0);
}
/// Define a public function to transfer ownership
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/// Define an internal function to transfer ownership
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "the account cannot be zero");
emit TransferOwnership(origOwner, newOwner);
origOwner = newOwner;
}
}