Ownable.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. pragma solidity ^0.4.23;
  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. */
  31. function renounceOwnership() public onlyOwner {
  32. emit OwnershipRenounced(owner);
  33. owner = address(0);
  34. }
  35. /**
  36. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  37. * @param _newOwner The address to transfer ownership to.
  38. */
  39. function transferOwnership(address _newOwner) public onlyOwner {
  40. _transferOwnership(_newOwner);
  41. }
  42. /**
  43. * @dev Transfers control of the contract to a newOwner.
  44. * @param _newOwner The address to transfer ownership to.
  45. */
  46. function _transferOwnership(address _newOwner) internal {
  47. require(_newOwner != address(0));
  48. emit OwnershipTransferred(owner, _newOwner);
  49. owner = _newOwner;
  50. }
  51. }