Ownable.sol 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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(msg.sender == owner_);
  32. _;
  33. }
  34. /**
  35. * @dev Allows the current owner to relinquish control of the contract.
  36. * @notice Renouncing to ownership will leave the contract without an owner.
  37. * It will not be possible to call the functions with the `onlyOwner`
  38. * modifier anymore.
  39. */
  40. function renounceOwnership() public onlyOwner {
  41. emit OwnershipRenounced(owner_);
  42. owner_ = address(0);
  43. }
  44. /**
  45. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  46. * @param _newOwner The address to transfer ownership to.
  47. */
  48. function transferOwnership(address _newOwner) public onlyOwner {
  49. _transferOwnership(_newOwner);
  50. }
  51. /**
  52. * @dev Transfers control of the contract to a newOwner.
  53. * @param _newOwner The address to transfer ownership to.
  54. */
  55. function _transferOwnership(address _newOwner) internal {
  56. require(_newOwner != address(0));
  57. emit OwnershipTransferred(owner_, _newOwner);
  58. owner_ = _newOwner;
  59. }
  60. }