Ownable.sol 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. _owner = _msgSender();
  20. emit OwnershipTransferred(address(0), _owner);
  21. }
  22. /**
  23. * @dev Returns the address of the current owner.
  24. */
  25. function owner() public view returns (address) {
  26. return _owner;
  27. }
  28. /**
  29. * @dev Throws if called by any account other than the owner.
  30. */
  31. modifier onlyOwner() {
  32. require(isOwner(), "Ownable: caller is not the owner");
  33. _;
  34. }
  35. /**
  36. * @dev Returns true if the caller is the current owner.
  37. */
  38. function isOwner() public view returns (bool) {
  39. return _msgSender() == _owner;
  40. }
  41. /**
  42. * @dev Leaves the contract without owner. It will not be possible to call
  43. * `onlyOwner` functions anymore. Can only be called by the current owner.
  44. *
  45. * NOTE: Renouncing ownership will leave the contract without an owner,
  46. * thereby removing any functionality that is only available to the owner.
  47. */
  48. function renounceOwnership() public onlyOwner {
  49. emit OwnershipTransferred(_owner, address(0));
  50. _owner = address(0);
  51. }
  52. /**
  53. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  54. * Can only be called by the current owner.
  55. */
  56. function transferOwnership(address newOwner) public onlyOwner {
  57. _transferOwnership(newOwner);
  58. }
  59. /**
  60. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  61. */
  62. function _transferOwnership(address newOwner) internal {
  63. require(newOwner != address(0), "Ownable: new owner is the zero address");
  64. emit OwnershipTransferred(_owner, newOwner);
  65. _owner = newOwner;
  66. }
  67. }