OwnableUpgradeable.sol 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. __Context_init_unchained();
  26. __Ownable_init_unchained();
  27. }
  28. function __Ownable_init_unchained() internal onlyInitializing {
  29. _transferOwnership(_msgSender());
  30. }
  31. /**
  32. * @dev Returns the address of the current owner.
  33. */
  34. function owner() public view virtual returns (address) {
  35. return _owner;
  36. }
  37. /**
  38. * @dev Throws if called by any account other than the owner.
  39. */
  40. modifier onlyOwner() {
  41. require(owner() == _msgSender(), "Ownable: caller is not the owner");
  42. _;
  43. }
  44. /**
  45. * @dev Leaves the contract without owner. It will not be possible to call
  46. * `onlyOwner` functions anymore. Can only be called by the current owner.
  47. *
  48. * NOTE: Renouncing ownership will leave the contract without an owner,
  49. * thereby removing any functionality that is only available to the owner.
  50. */
  51. function renounceOwnership() public virtual onlyOwner {
  52. _transferOwnership(address(0));
  53. }
  54. /**
  55. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  56. * Can only be called by the current owner.
  57. */
  58. function transferOwnership(address newOwner) public virtual onlyOwner {
  59. require(newOwner != address(0), "Ownable: new owner is the zero address");
  60. _transferOwnership(newOwner);
  61. }
  62. /**
  63. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  64. * Internal function without access restriction.
  65. */
  66. function _transferOwnership(address newOwner) internal virtual {
  67. address oldOwner = _owner;
  68. _owner = newOwner;
  69. emit OwnershipTransferred(oldOwner, newOwner);
  70. }
  71. uint256[49] private __gap;
  72. }