2019-03-14 23:41:04 -07:00
|
|
|
pragma solidity ^0.5.3;
|
|
|
|
|
|
|
|
import "./PermissionsInterface.sol";
|
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @title Permissions Upgradable Contract
|
|
|
|
* @notice This contract holds the address of current permissions implementation
|
|
|
|
contract. The contract is owned by a guardian account. Only the
|
|
|
|
guardian account can change the implementation contract address as
|
|
|
|
business needs.
|
|
|
|
*/
|
2019-03-19 02:15:51 -07:00
|
|
|
contract PermissionsUpgradable {
|
2019-03-14 23:41:04 -07:00
|
|
|
|
2019-07-09 19:10:43 -07:00
|
|
|
address private guardian;
|
2019-03-14 23:41:04 -07:00
|
|
|
address private permImpl;
|
2019-03-15 02:26:57 -07:00
|
|
|
address private permInterface;
|
2019-07-19 01:48:42 -07:00
|
|
|
// initDone ensures that init can be called only once
|
2019-07-19 01:16:50 -07:00
|
|
|
bool private initDone;
|
2019-03-14 23:41:04 -07:00
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice constructor
|
|
|
|
* @param _guardian account address
|
|
|
|
*/
|
2019-07-17 03:26:39 -07:00
|
|
|
constructor (address _guardian) public{
|
2019-07-09 19:10:43 -07:00
|
|
|
guardian = _guardian;
|
2019-07-19 01:16:50 -07:00
|
|
|
initDone = false;
|
2019-03-14 23:41:04 -07:00
|
|
|
}
|
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice confirms that the caller is the guardian account
|
|
|
|
*/
|
2019-07-17 03:26:39 -07:00
|
|
|
modifier onlyGuardian {
|
2019-07-21 20:17:39 -07:00
|
|
|
require(msg.sender == guardian, "invalid caller");
|
2019-03-14 23:41:04 -07:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice executed by guardian. Links interface and implementation contract
|
|
|
|
addresses. Can be executed by guardian account only
|
|
|
|
* @param _permInterface permissions interface contract address
|
|
|
|
* @param _permImpl implementation contract address
|
|
|
|
*/
|
2019-05-08 20:07:54 -07:00
|
|
|
function init(address _permInterface, address _permImpl) external
|
2019-07-17 03:26:39 -07:00
|
|
|
onlyGuardian {
|
2019-07-19 01:16:50 -07:00
|
|
|
require(!initDone, "can be executed only once");
|
2019-03-15 02:26:57 -07:00
|
|
|
permImpl = _permImpl;
|
|
|
|
permInterface = _permInterface;
|
2019-07-17 03:26:39 -07:00
|
|
|
_setImpl(permImpl);
|
2019-07-19 01:16:50 -07:00
|
|
|
initDone = true;
|
2019-03-15 02:26:57 -07:00
|
|
|
}
|
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice changes the implementation contract address to the new address
|
|
|
|
address passed. Can be executed by guardian account only
|
|
|
|
* @param _proposedImpl address of the new permissions implementation contract
|
|
|
|
*/
|
2019-03-15 02:26:57 -07:00
|
|
|
function confirmImplChange(address _proposedImpl) public
|
2019-07-17 03:26:39 -07:00
|
|
|
onlyGuardian {
|
|
|
|
// The policy details needs to be carried forward from existing
|
|
|
|
// implementation to new. So first these are read from existing
|
|
|
|
// implementation and then updated in new implementation
|
2019-06-03 00:24:31 -07:00
|
|
|
(string memory adminOrg, string memory adminRole, string memory orgAdminRole, bool bootStatus) = PermissionsImplementation(permImpl).getPolicyDetails();
|
2019-07-17 03:26:39 -07:00
|
|
|
_setPolicy(_proposedImpl, adminOrg, adminRole, orgAdminRole, bootStatus);
|
2019-03-14 23:41:04 -07:00
|
|
|
permImpl = _proposedImpl;
|
2019-07-17 03:26:39 -07:00
|
|
|
_setImpl(permImpl);
|
2019-03-14 23:41:04 -07:00
|
|
|
}
|
2019-07-30 01:56:44 -07:00
|
|
|
|
|
|
|
/** @notice function to fetch the guardian account address
|
|
|
|
* @return _guardian guardian account address
|
|
|
|
*/
|
2019-07-17 03:26:39 -07:00
|
|
|
function getGuardian() public view returns (address) {
|
2019-07-09 19:10:43 -07:00
|
|
|
return guardian;
|
2019-03-14 23:41:04 -07:00
|
|
|
}
|
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice function to fetch the current implementation address
|
|
|
|
* @return permissions implementation contract address
|
|
|
|
*/
|
2019-07-17 03:26:39 -07:00
|
|
|
function getPermImpl() public view returns (address) {
|
2019-03-14 23:41:04 -07:00
|
|
|
return permImpl;
|
|
|
|
}
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice function to fetch the interface address
|
|
|
|
* @return permissions interface contract address
|
|
|
|
*/
|
2019-07-17 03:26:39 -07:00
|
|
|
function getPermInterface() public view returns (address) {
|
2019-03-15 02:26:57 -07:00
|
|
|
return permInterface;
|
|
|
|
}
|
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice function to set the permissions policy details in the
|
|
|
|
permissions implementation contract
|
|
|
|
* @param _permImpl permissions implementation contract address
|
|
|
|
* @param _adminOrg name of admin organization
|
|
|
|
* @param _adminRole name of the admin role
|
|
|
|
* @param _orgAdminRole name of default organization admin role
|
|
|
|
* @param _bootStatus network boot status
|
|
|
|
*/
|
2019-07-17 03:26:39 -07:00
|
|
|
function _setPolicy(address _permImpl, string memory _adminOrg, string memory _adminRole, string memory _orgAdminRole, bool _bootStatus) private {
|
2019-06-03 00:24:31 -07:00
|
|
|
PermissionsImplementation(_permImpl).setMigrationPolicy(_adminOrg, _adminRole, _orgAdminRole, _bootStatus);
|
|
|
|
}
|
|
|
|
|
2019-07-30 01:56:44 -07:00
|
|
|
/** @notice function to set the permissions implementation contract address
|
|
|
|
in the permissions interface contract
|
|
|
|
* @param _permImpl permissions implementation contract address
|
|
|
|
*/
|
2019-07-17 03:26:39 -07:00
|
|
|
function _setImpl(address _permImpl) private {
|
2019-03-15 02:26:57 -07:00
|
|
|
PermissionsInterface(permInterface).setPermImplementation(_permImpl);
|
2019-03-14 23:41:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|