OwnableUpgradeable.sol 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
  3. pragma solidity ^0.8.0;
  4. import "../utils/ContextUpgradeable.sol";
  5. import "../proxy/utils/Initializable.sol";
  6. /**
  7. * @dev Contract module which provides a basic access control mechanism, where
  8. * there is an account (an owner) that can be granted exclusive access to
  9. * specific functions.
  10. *
  11. * By default, the owner account will be the one that deploys the contract. This
  12. * can later be changed with {transferOwnership}.
  13. *
  14. * This module is used through inheritance. It will make available the modifier
  15. * `onlyOwner`, which can be applied to your functions to restrict their use to
  16. * the owner.
  17. */
  18. abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
  19. address private _owner;
  20. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  21. /**
  22. * @dev Initializes the contract setting the deployer as the initial owner.
  23. */
  24. function __Ownable_init() internal onlyInitializing {
  25. __Ownable_init_unchained();
  26. }
  27. function __Ownable_init_unchained() internal onlyInitializing {
  28. _transferOwnership(_msgSender());
  29. }
  30. /**
  31. * @dev Returns the address of the current owner.
  32. */
  33. function owner() public view virtual returns (address) {
  34. return _owner;
  35. }
  36. /**
  37. * @dev Throws if called by any account other than the owner.
  38. */
  39. modifier onlyOwner() {
  40. require(owner() == _msgSender(), "Ownable: caller is not the owner");
  41. _;
  42. }
  43. /**
  44. * @dev Leaves the contract without owner. It will not be possible to call
  45. * `onlyOwner` functions anymore. Can only be called by the current owner.
  46. *
  47. * NOTE: Renouncing ownership will leave the contract without an owner,
  48. * thereby removing any functionality that is only available to the owner.
  49. */
  50. function renounceOwnership() public virtual onlyOwner {
  51. _transferOwnership(address(0));
  52. }
  53. /**
  54. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  55. * Can only be called by the current owner.
  56. */
  57. function transferOwnership(address newOwner) public virtual onlyOwner {
  58. require(newOwner != address(0), "Ownable: new owner is the zero address");
  59. _transferOwnership(newOwner);
  60. }
  61. /**
  62. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  63. * Internal function without access restriction.
  64. */
  65. function _transferOwnership(address newOwner) internal virtual {
  66. address oldOwner = _owner;
  67. _owner = newOwner;
  68. emit OwnershipTransferred(oldOwner, newOwner);
  69. }
  70. /**
  71. * @dev This empty reserved space is put in place to allow future versions to add new
  72. * variables without shifting down storage in the inheritance chain.
  73. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  74. */
  75. uint256[49] private __gap;
  76. }