You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.9 KiB
Solidity
58 lines
1.9 KiB
Solidity
2 years ago
|
// SPDX-License-Identifier: MIT
|
||
|
// OpenZeppelin Contracts (last updated v4.8.0) (access/Ownable2Step.sol)
|
||
|
|
||
|
pragma solidity ^0.8.0;
|
||
|
|
||
|
import "./Ownable.sol";
|
||
|
|
||
|
/**
|
||
|
* @dev Contract module which provides 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} and {acceptOwnership}.
|
||
|
*
|
||
|
* This module is used through inheritance. It will make available all functions
|
||
|
* from parent (Ownable).
|
||
|
*/
|
||
|
abstract contract Ownable2Step is Ownable {
|
||
|
address private _pendingOwner;
|
||
|
|
||
|
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
|
||
|
|
||
|
/**
|
||
|
* @dev Returns the address of the pending owner.
|
||
|
*/
|
||
|
function pendingOwner() public view virtual returns (address) {
|
||
|
return _pendingOwner;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
|
||
|
* Can only be called by the current owner.
|
||
|
*/
|
||
|
function transferOwnership(address newOwner) public virtual override onlyOwner {
|
||
|
_pendingOwner = newOwner;
|
||
|
emit OwnershipTransferStarted(owner(), newOwner);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
|
||
|
* Internal function without access restriction.
|
||
|
*/
|
||
|
function _transferOwnership(address newOwner) internal virtual override {
|
||
|
delete _pendingOwner;
|
||
|
super._transferOwnership(newOwner);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dev The new owner accepts the ownership transfer.
|
||
|
*/
|
||
|
function acceptOwnership() public virtual {
|
||
|
address sender = _msgSender();
|
||
|
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
|
||
|
_transferOwnership(sender);
|
||
|
}
|
||
|
}
|