Created
September 8, 2023 12:34
-
-
Save Luke-Rogerson/4e19c4d88f5845589d0013d8976a0f16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @dev Taken from OpenZeppelin Contracts (access/Ownable.sol). | |
* Represents the project owner entity of a given project. | |
* Names have been changed, but otherwise the code is identical. | |
*/ | |
abstract contract ProjectRole is Context { | |
address private _projectOwner; | |
event ProjectOwnershipTransferred(address indexed previousProjectOwner, address indexed newProjectOwner); | |
/** | |
* @dev Initializes the contract setting the deployer as the initial project owner. | |
*/ | |
constructor() { | |
_transferOwnership(_msgSender()); | |
} | |
/** | |
* @dev Throws if called by any account other than the project owner. | |
*/ | |
modifier onlyProjectOwner() { | |
_checkProjectOwner(); | |
_; | |
} | |
/** | |
* @dev Returns the address of the current project owner. | |
*/ | |
function projectOwner() public view virtual returns (address) { | |
return _projectOwner; | |
} | |
/** | |
* @dev Throws if the sender is not the project owner. | |
*/ | |
function _checkProjectOwner() internal view virtual { | |
require(projectOwner() == _msgSender(), "ProjectRole: caller is not the owner"); | |
} | |
/** | |
* @dev Transfers project ownership to a new account (`newProjectOwner`). | |
* Can only be called by the current project owner. | |
*/ | |
function transferOwnership(address newProjectOwner) public virtual onlyProjectOwner { | |
require(newProjectOwner != address(0), "ProjectRole: new owner is the zero address"); | |
_transferOwnership(newProjectOwner); | |
} | |
/** | |
* @dev Transfers project ownership of the contract to a new account (`newProjectOwner`). | |
* Internal function without access restriction. | |
*/ | |
function _transferOwnership(address newProjectOwner) internal virtual { | |
address oldProjectOwner = _projectOwner; | |
_projectOwner = newProjectOwner; | |
emit ProjectOwnershipTransferred(oldProjectOwner, newProjectOwner); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment