OpenZeppelinOwnable.sol
1 // SPDX-License-Identifier: MIT 2 // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) 3 4 pragma solidity ^0.6.0; 5 6 import "./OpenZeppelinOwnableContext.sol"; 7 8 /** 9 * @dev Contract module which provides a basic access control mechanism, where 10 * there is an account (an owner) that can be granted exclusive access to 11 * specific functions. 12 * 13 * By default, the owner account will be the one that deploys the contract. This 14 * can later be changed with {transferOwnership}. 15 * 16 * This module is used through inheritance. It will make available the modifier 17 * `onlyOwner`, which can be applied to your functions to restrict their use to 18 * the owner. 19 */ 20 abstract contract OpenZeppelinOwnable is OpenZeppelinOwnableContext { 21 address private _owner; 22 23 event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 24 25 /** 26 * @dev Initializes the contract setting the deployer as the initial owner. 27 */ 28 constructor() public { 29 _transferOwnership(_msgSender()); 30 } 31 32 /** 33 * @dev Throws if called by any account other than the owner. 34 */ 35 modifier onlyOwner() { 36 _checkOwner(); 37 _; 38 } 39 40 /** 41 * @dev Returns the address of the current owner. 42 */ 43 function owner() public view virtual returns (address) { 44 return _owner; 45 } 46 47 /** 48 * @dev Throws if the sender is not the owner. 49 */ 50 function _checkOwner() internal view virtual { 51 require(owner() == _msgSender(), "Ownable: caller is not the owner"); 52 } 53 54 /** 55 * @dev Leaves the contract without owner. It will not be possible to call 56 * `onlyOwner` functions anymore. Can only be called by the current owner. 57 * 58 * NOTE: Renouncing ownership will leave the contract without an owner, 59 * thereby removing any functionality that is only available to the owner. 60 */ 61 function renounceOwnership() public virtual onlyOwner { 62 _transferOwnership(address(0)); 63 } 64 65 /** 66 * @dev Transfers ownership of the contract to a new account (`newOwner`). 67 * Can only be called by the current owner. 68 */ 69 function transferOwnership(address newOwner) public virtual onlyOwner { 70 require(newOwner != address(0), "Ownable: new owner is the zero address"); 71 _transferOwnership(newOwner); 72 } 73 74 /** 75 * @dev Transfers ownership of the contract to a new account (`newOwner`). 76 * Internal function without access restriction. 77 */ 78 function _transferOwnership(address newOwner) internal virtual { 79 address oldOwner = _owner; 80 _owner = newOwner; 81 emit OwnershipTransferred(oldOwner, newOwner); 82 } 83 }