Ownable.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. pragma solidity ^0.5.0;
  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 OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  10. /**
  11. * @dev The Ownable constructor sets the original `owner` of the contract to the sender
  12. * account.
  13. */
  14. constructor () internal {
  15. _owner = msg.sender;
  16. emit OwnershipTransferred(address(0), _owner);
  17. }
  18. /**
  19. * @return the address of the owner.
  20. */
  21. function owner() public view returns (address) {
  22. return _owner;
  23. }
  24. /**
  25. * @dev Throws if called by any account other than the owner.
  26. */
  27. modifier onlyOwner() {
  28. require(isOwner());
  29. _;
  30. }
  31. /**
  32. * @return true if `msg.sender` is the owner of the contract.
  33. */
  34. function isOwner() public view returns (bool) {
  35. return msg.sender == _owner;
  36. }
  37. /**
  38. * @dev Allows the current owner to relinquish control of the contract.
  39. * @notice Renouncing to ownership will leave the contract without an owner.
  40. * It will not be possible to call the functions with the `onlyOwner`
  41. * modifier anymore.
  42. */
  43. function renounceOwnership() public onlyOwner {
  44. emit OwnershipTransferred(_owner, address(0));
  45. _owner = address(0);
  46. }
  47. /**
  48. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  49. * @param newOwner The address to transfer ownership to.
  50. */
  51. function transferOwnership(address newOwner) public onlyOwner {
  52. _transferOwnership(newOwner);
  53. }
  54. /**
  55. * @dev Transfers control of the contract to a newOwner.
  56. * @param newOwner The address to transfer ownership to.
  57. */
  58. function _transferOwnership(address newOwner) internal {
  59. require(newOwner != address(0));
  60. emit OwnershipTransferred(_owner, newOwner);
  61. _owner = newOwner;
  62. }
  63. }