Ownable.sol 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. pragma solidity ^0.5.0;
  2. /**
  3. * @dev Contract module which provides a basic access control mechanism, where
  4. * there is an account (an owner) that can be granted exclusive access to
  5. * specific functions.
  6. *
  7. * This module is used through inheritance. It will make available the modifier
  8. * `onlyOwner`, which can be applied to your functions to restrict their use to
  9. * the owner.
  10. */
  11. contract Ownable {
  12. address private _owner;
  13. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  14. /**
  15. * @dev Initializes the contract setting the deployer as the initial owner.
  16. */
  17. constructor () internal {
  18. _owner = msg.sender;
  19. emit OwnershipTransferred(address(0), _owner);
  20. }
  21. /**
  22. * @dev Returns the address of the current owner.
  23. */
  24. function owner() public view returns (address) {
  25. return _owner;
  26. }
  27. /**
  28. * @dev Throws if called by any account other than the owner.
  29. */
  30. modifier onlyOwner() {
  31. require(isOwner(), "Ownable: caller is not the owner");
  32. _;
  33. }
  34. /**
  35. * @dev Returns true if the caller is the current owner.
  36. */
  37. function isOwner() public view returns (bool) {
  38. return msg.sender == _owner;
  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 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 onlyOwner {
  56. _transferOwnership(newOwner);
  57. }
  58. /**
  59. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  60. */
  61. function _transferOwnership(address newOwner) internal {
  62. require(newOwner != address(0), "Ownable: new owner is the zero address");
  63. emit OwnershipTransferred(_owner, newOwner);
  64. _owner = newOwner;
  65. }
  66. }