Ownable.sol 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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(), "Ownable: caller is not the owner");
  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. * It will not be possible to call the functions with the `onlyOwner`
  40. * modifier anymore.
  41. * @notice Renouncing ownership will leave the contract without an owner,
  42. * thereby removing any functionality that is only available to the owner.
  43. */
  44. function renounceOwnership() public onlyOwner {
  45. emit OwnershipTransferred(_owner, address(0));
  46. _owner = address(0);
  47. }
  48. /**
  49. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  50. * @param newOwner The address to transfer ownership to.
  51. */
  52. function transferOwnership(address newOwner) public onlyOwner {
  53. _transferOwnership(newOwner);
  54. }
  55. /**
  56. * @dev Transfers control of the contract to a newOwner.
  57. * @param newOwner The address to transfer ownership to.
  58. */
  59. function _transferOwnership(address newOwner) internal {
  60. require(newOwner != address(0), "Ownable: new owner is the zero address");
  61. emit OwnershipTransferred(_owner, newOwner);
  62. _owner = newOwner;
  63. }
  64. }