github.com/klaytn/klaytn@v1.12.1/contracts/kip103/Ownable.sol (about) 1 // SPDX-License-Identifier: GPL-3.0 2 pragma solidity ^0.8.0; 3 4 /** 5 * @dev Contract module which provides a basic access control mechanism, where 6 * there is an account (an owner) that can be granted exclusive access to 7 * specific functions. 8 * 9 * This module is used through inheritance. It will make available the modifier 10 * `onlyOwner`, which can be aplied to your functions to restrict their use to 11 * the owner. 12 */ 13 contract Ownable { 14 address private _owner; 15 16 event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 17 18 /** 19 * @dev Initializes the contract setting the deployer as the initial owner. 20 */ 21 constructor () { 22 _owner = msg.sender; 23 emit OwnershipTransferred(address(0), _owner); 24 } 25 26 /** 27 * @dev Returns the address of the current owner. 28 */ 29 function owner() public view returns (address) { 30 return _owner; 31 } 32 33 /** 34 * @dev Throws if called by any account other than the owner. 35 */ 36 modifier onlyOwner() { 37 require(isOwner(), "Ownable: caller is not the owner"); 38 _; 39 } 40 41 /** 42 * @dev Returns true if the caller is the current owner. 43 */ 44 function isOwner() public view returns (bool) { 45 return msg.sender == _owner; 46 } 47 48 /** 49 * @dev Leaves the contract without owner. It will not be possible to call 50 * `onlyOwner` functions anymore. Can only be called by the current owner. 51 * 52 * > Note: Renouncing ownership will leave the contract without an owner, 53 * thereby removing any functionality that is only available to the owner. 54 */ 55 function renounceOwnership() public onlyOwner { 56 emit OwnershipTransferred(_owner, address(0)); 57 _owner = address(0); 58 } 59 60 /** 61 * @dev Transfers ownership of the contract to a new account (`newOwner`). 62 * Can only be called by the current owner. 63 */ 64 function transferOwnership(address newOwner) public onlyOwner { 65 _transferOwnership(newOwner); 66 } 67 68 /** 69 * @dev Transfers ownership of the contract to a new account (`newOwner`). 70 */ 71 function _transferOwnership(address newOwner) internal { 72 require(newOwner != address(0), "Ownable: new owner is the zero address"); 73 emit OwnershipTransferred(_owner, newOwner); 74 _owner = newOwner; 75 } 76 }