Ownable.sol 2.1 KB

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