-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ownable.sol
59 lines (46 loc) · 1.47 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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.6.12;
/**
* @notice A contract with helpers for safe contract ownership.
*/
contract Ownable {
address private ownerAddr;
address private pendingOwnerAddr;
event OwnershipTransferRequested(address indexed from, address indexed to);
event OwnershipTransferred(address indexed from, address indexed to);
constructor() public {
ownerAddr = msg.sender;
}
/**
* @notice Allows an owner to begin transferring ownership to a new address,
* pending.
*/
function transferOwnership(address to) external onlyOwner() {
require(to != msg.sender, "Cannot transfer to self");
pendingOwnerAddr = to;
emit OwnershipTransferRequested(ownerAddr, to);
}
/**
* @notice Allows an ownership transfer to be completed by the recipient.
*/
function acceptOwnership() external {
require(msg.sender == pendingOwnerAddr, "Must be proposed owner");
address oldOwner = ownerAddr;
ownerAddr = msg.sender;
pendingOwnerAddr = address(0);
emit OwnershipTransferred(oldOwner, msg.sender);
}
/**
* @notice Get the current owner
*/
function owner() public view returns (address) {
return ownerAddr;
}
/**
* @notice Reverts if called by anyone other than the contract owner.
*/
modifier onlyOwner() {
require(msg.sender == ownerAddr, "Only callable by owner");
_;
}
}