1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // SPDX-License-Identifier: MIT
- // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)
- pragma solidity ^0.8.19;
- import {Ownable} from "./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.
- *
- * The initial owner is specified at deployment time in the constructor for `Ownable`. 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();
- if (pendingOwner() != sender) {
- revert OwnableUnauthorizedAccount(sender);
- }
- _transferOwnership(sender);
- }
- }
|