github.com/klaytn/klaytn@v1.12.1/contracts/system_contracts/lib/OwnableUpgradeable.sol (about)

     1  // Copyright 2023 The klaytn Authors
     2  // This file is part of the klaytn library.
     3  //
     4  // The klaytn library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The klaytn library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.
    16  //
    17  // This flattened solidity file is from openzeppelin-upgradeable/access/OwnableUpgradeable.sol
    18  // Sources flattened with hardhat v2.13.0 https://hardhat.org
    19  
    20  // SPDX-License-Identifier: MIT
    21  
    22  // Manually import this to avoid identifier collision.
    23  import "./Initializable.sol";
    24  
    25  // File @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol@v4.9.3
    26  
    27  // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
    28  
    29  pragma solidity ^0.8.0;
    30  
    31  /**
    32   * @dev Provides information about the current execution context, including the
    33   * sender of the transaction and its data. While these are generally available
    34   * via msg.sender and msg.data, they should not be accessed in such a direct
    35   * manner, since when dealing with meta-transactions the account sending and
    36   * paying for execution may not be the actual sender (as far as an application
    37   * is concerned).
    38   *
    39   * This contract is only required for intermediate, library-like contracts.
    40   */
    41  abstract contract ContextUpgradeable is Initializable {
    42      function __Context_init() internal onlyInitializing {}
    43  
    44      function __Context_init_unchained() internal onlyInitializing {}
    45  
    46      function _msgSender() internal view virtual returns (address) {
    47          return msg.sender;
    48      }
    49  
    50      function _msgData() internal view virtual returns (bytes calldata) {
    51          return msg.data;
    52      }
    53  
    54      /**
    55       * @dev This empty reserved space is put in place to allow future versions to add new
    56       * variables without shifting down storage in the inheritance chain.
    57       * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
    58       */
    59      uint256[50] private __gap;
    60  }
    61  
    62  // File @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol@v4.9.3
    63  
    64  // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
    65  
    66  pragma solidity ^0.8.0;
    67  
    68  /**
    69   * @dev Contract module which provides a basic access control mechanism, where
    70   * there is an account (an owner) that can be granted exclusive access to
    71   * specific functions.
    72   *
    73   * By default, the owner account will be the one that deploys the contract. This
    74   * can later be changed with {transferOwnership}.
    75   *
    76   * This module is used through inheritance. It will make available the modifier
    77   * `onlyOwner`, which can be applied to your functions to restrict their use to
    78   * the owner.
    79   */
    80  abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    81      address private _owner;
    82  
    83      event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    84  
    85      /**
    86       * @dev Initializes the contract setting the deployer as the initial owner.
    87       */
    88      function __Ownable_init() internal onlyInitializing {
    89          __Ownable_init_unchained();
    90      }
    91  
    92      function __Ownable_init_unchained() internal onlyInitializing {
    93          _transferOwnership(_msgSender());
    94      }
    95  
    96      /**
    97       * @dev Throws if called by any account other than the owner.
    98       */
    99      modifier onlyOwner() {
   100          _checkOwner();
   101          _;
   102      }
   103  
   104      /**
   105       * @dev Returns the address of the current owner.
   106       */
   107      function owner() public view virtual returns (address) {
   108          return _owner;
   109      }
   110  
   111      /**
   112       * @dev Throws if the sender is not the owner.
   113       */
   114      function _checkOwner() internal view virtual {
   115          require(owner() == _msgSender(), "Ownable: caller is not the owner");
   116      }
   117  
   118      /**
   119       * @dev Leaves the contract without owner. It will not be possible to call
   120       * `onlyOwner` functions. Can only be called by the current owner.
   121       *
   122       * NOTE: Renouncing ownership will leave the contract without an owner,
   123       * thereby disabling any functionality that is only available to the owner.
   124       */
   125      function renounceOwnership() public virtual onlyOwner {
   126          _transferOwnership(address(0));
   127      }
   128  
   129      /**
   130       * @dev Transfers ownership of the contract to a new account (`newOwner`).
   131       * Can only be called by the current owner.
   132       */
   133      function transferOwnership(address newOwner) public virtual onlyOwner {
   134          require(newOwner != address(0), "Ownable: new owner is the zero address");
   135          _transferOwnership(newOwner);
   136      }
   137  
   138      /**
   139       * @dev Transfers ownership of the contract to a new account (`newOwner`).
   140       * Internal function without access restriction.
   141       */
   142      function _transferOwnership(address newOwner) internal virtual {
   143          address oldOwner = _owner;
   144          _owner = newOwner;
   145          emit OwnershipTransferred(oldOwner, newOwner);
   146      }
   147  
   148      /**
   149       * @dev This empty reserved space is put in place to allow future versions to add new
   150       * variables without shifting down storage in the inheritance chain.
   151       * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
   152       */
   153      uint256[49] private __gap;
   154  }