Ownable.sol 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 public 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. * @dev Throws if called by any account other than the owner.
  23. */
  24. modifier onlyOwner() {
  25. require(msg.sender == owner);
  26. _;
  27. }
  28. /**
  29. * @dev Allows the current owner to relinquish control of the contract.
  30. * @notice Renouncing to ownership will leave the contract without an owner.
  31. * It will not be possible to call the functions with the `onlyOwner`
  32. * modifier anymore.
  33. */
  34. function renounceOwnership() public onlyOwner {
  35. emit OwnershipRenounced(owner);
  36. owner = address(0);
  37. }
  38. /**
  39. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  40. * @param _newOwner The address to transfer ownership to.
  41. */
  42. function transferOwnership(address _newOwner) public onlyOwner {
  43. _transferOwnership(_newOwner);
  44. }
  45. /**
  46. * @dev Transfers control of the contract to a newOwner.
  47. * @param _newOwner The address to transfer ownership to.
  48. */
  49. function _transferOwnership(address _newOwner) internal {
  50. require(_newOwner != address(0));
  51. emit OwnershipTransferred(owner, _newOwner);
  52. owner = _newOwner;
  53. }
  54. }