github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/permission/v1/contract/PermissionsUpgradable.sol (about)

     1  pragma solidity ^0.5.3;
     2  
     3  import "./PermissionsInterface.sol";
     4  
     5  /** @title Permissions Upgradable Contract
     6    * @notice This contract holds the address of current permissions implementation
     7      contract. The contract is owned by a guardian account. Only the
     8      guardian account can change the implementation contract address as
     9      business needs.
    10    */
    11  contract PermissionsUpgradable {
    12  
    13      address private guardian;
    14      address private permImpl;
    15      address private permInterface;
    16      // initDone ensures that init can be called only once
    17      bool private initDone;
    18  
    19      /** @notice constructor
    20        * @param _guardian account address
    21        */
    22      constructor (address _guardian) public{
    23          guardian = _guardian;
    24          initDone = false;
    25      }
    26  
    27      /** @notice confirms that the caller is the guardian account
    28      */
    29      modifier onlyGuardian {
    30          require(msg.sender == guardian, "invalid caller");
    31          _;
    32      }
    33  
    34      /** @notice executed by guardian. Links interface and implementation contract
    35          addresses. Can be executed by guardian account only
    36        * @param _permInterface permissions interface contract address
    37        * @param _permImpl implementation contract address
    38        */
    39      function init(address _permInterface, address _permImpl) external
    40      onlyGuardian {
    41          require(!initDone, "can be executed only once");
    42          permImpl = _permImpl;
    43          permInterface = _permInterface;
    44          _setImpl(permImpl);
    45          initDone = true;
    46      }
    47  
    48      /** @notice changes the implementation contract address to the new address
    49          address passed. Can be executed by guardian account only
    50        * @param _proposedImpl address of the new permissions implementation contract
    51        */
    52      function confirmImplChange(address _proposedImpl) public
    53      onlyGuardian {
    54          // The policy details needs to be carried forward from existing
    55          // implementation to new. So first these are read from existing
    56          // implementation and then updated in new implementation
    57          (string memory adminOrg, string memory adminRole, string memory orgAdminRole, bool bootStatus) = PermissionsImplementation(permImpl).getPolicyDetails();
    58          _setPolicy(_proposedImpl, adminOrg, adminRole, orgAdminRole, bootStatus);
    59          permImpl = _proposedImpl;
    60          _setImpl(permImpl);
    61      }
    62  
    63      /** @notice function to fetch the guardian account address
    64        * @return _guardian guardian account address
    65        */
    66      function getGuardian() public view returns (address) {
    67          return guardian;
    68      }
    69  
    70      /** @notice function to fetch the current implementation address
    71        * @return permissions implementation contract address
    72        */
    73      function getPermImpl() public view returns (address) {
    74          return permImpl;
    75      }
    76      /** @notice function to fetch the interface address
    77        * @return permissions interface contract address
    78        */
    79      function getPermInterface() public view returns (address) {
    80          return permInterface;
    81      }
    82  
    83      /** @notice function to set the permissions policy details in the
    84          permissions implementation contract
    85        * @param _permImpl permissions implementation contract address
    86        * @param _adminOrg name of admin organization
    87        * @param _adminRole name of the admin role
    88        * @param _orgAdminRole name of default organization admin role
    89        * @param _bootStatus network boot status
    90        */
    91      function _setPolicy(address _permImpl, string memory _adminOrg, string memory _adminRole, string memory _orgAdminRole, bool _bootStatus) private {
    92          PermissionsImplementation(_permImpl).setMigrationPolicy(_adminOrg, _adminRole, _orgAdminRole, _bootStatus);
    93      }
    94  
    95      /** @notice function to set the permissions implementation contract address
    96          in the permissions interface contract
    97        * @param _permImpl permissions implementation contract address
    98        */
    99      function _setImpl(address _permImpl) private {
   100          PermissionsInterface(permInterface).setPermImplementation(_permImpl);
   101      }
   102  
   103  }