Ownable.sol 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. pragma solidity ^0.4.24;
  2. /**
  3. * @title Ownable
  4. * @dev The Ownable contract has an owner address, and provides basic authorization control
  5. * functions, this simplifies the implementation of "user permissions".
  6. */
  7. contract Ownable {
  8. address private _owner;
  9. event OwnershipRenounced(address indexed previousOwner);
  10. event OwnershipTransferred(
  11. address indexed previousOwner,
  12. address indexed newOwner
  13. );
  14. /**
  15. * @dev The Ownable constructor sets the original `owner` of the contract to the sender
  16. * account.
  17. */
  18. constructor() public {
  19. _owner = msg.sender;
  20. }
  21. /**
  22. * @return the address of the 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());
  32. _;
  33. }
  34. /**
  35. * @return true if `msg.sender` is the owner of the contract.
  36. */
  37. function isOwner() public view returns(bool) {
  38. return msg.sender == _owner;
  39. }
  40. /**
  41. * @dev Allows the current owner to relinquish control of the contract.
  42. * @notice Renouncing to ownership will leave the contract without an owner.
  43. * It will not be possible to call the functions with the `onlyOwner`
  44. * modifier anymore.
  45. */
  46. function renounceOwnership() public onlyOwner {
  47. emit OwnershipRenounced(_owner);
  48. _owner = address(0);
  49. }
  50. /**
  51. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  52. * @param newOwner The address to transfer ownership to.
  53. */
  54. function transferOwnership(address newOwner) public onlyOwner {
  55. _transferOwnership(newOwner);
  56. }
  57. /**
  58. * @dev Transfers control of the contract to a newOwner.
  59. * @param newOwner The address to transfer ownership to.
  60. */
  61. function _transferOwnership(address newOwner) internal {
  62. require(newOwner != address(0));
  63. emit OwnershipTransferred(_owner, newOwner);
  64. _owner = newOwner;
  65. }
  66. }