Ownable.sol 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.6.0;
  3. import "../GSN/Context.sol";
  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. * By default, the owner account will be the one that deploys the contract. This
  10. * can later be changed with {transferOwnership}.
  11. *
  12. * This module is used through inheritance. It will make available the modifier
  13. * `onlyOwner`, which can be applied to your functions to restrict their use to
  14. * the owner.
  15. */
  16. contract Ownable is Context {
  17. address private _owner;
  18. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  19. /**
  20. * @dev Initializes the contract setting the deployer as the initial owner.
  21. */
  22. constructor () internal {
  23. address msgSender = _msgSender();
  24. _owner = msgSender;
  25. emit OwnershipTransferred(address(0), msgSender);
  26. }
  27. /**
  28. * @dev Returns the address of the current owner.
  29. */
  30. function owner() public view returns (address) {
  31. return _owner;
  32. }
  33. /**
  34. * @dev Throws if called by any account other than the owner.
  35. */
  36. modifier onlyOwner() {
  37. require(_owner == _msgSender(), "Ownable: caller is not the owner");
  38. _;
  39. }
  40. /**
  41. * @dev Leaves the contract without owner. It will not be possible to call
  42. * `onlyOwner` functions anymore. Can only be called by the current owner.
  43. *
  44. * NOTE: Renouncing ownership will leave the contract without an owner,
  45. * thereby removing any functionality that is only available to the owner.
  46. */
  47. function renounceOwnership() public virtual onlyOwner {
  48. emit OwnershipTransferred(_owner, address(0));
  49. _owner = address(0);
  50. }
  51. /**
  52. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  53. * Can only be called by the current owner.
  54. */
  55. function transferOwnership(address newOwner) public virtual onlyOwner {
  56. require(newOwner != address(0), "Ownable: new owner is the zero address");
  57. emit OwnershipTransferred(_owner, newOwner);
  58. _owner = newOwner;
  59. }
  60. }