Ownable.sol 2.3 KB

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