github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/permission/v2/contract/PermissionsInterface.sol (about) 1 pragma solidity ^0.5.3; 2 3 import "./PermissionsImplementation.sol"; 4 import "./PermissionsUpgradable.sol"; 5 6 /** @title Permissions Interface Contract 7 * @notice This contract is the interface for permissions implementation 8 contract. for any call, it forwards the call to the implementation 9 contract 10 */ 11 contract PermissionsInterface { 12 PermissionsImplementation private permImplementation; 13 PermissionsUpgradable private permUpgradable; 14 address private permImplUpgradeable; 15 16 /** @notice constructor 17 * @param _permImplUpgradeable permissions upgradable contract address 18 */ 19 constructor(address _permImplUpgradeable) public { 20 permImplUpgradeable = _permImplUpgradeable; 21 } 22 23 /** @notice confirms that the caller is the address of upgradable 24 contract 25 */ 26 modifier onlyUpgradeable { 27 require(msg.sender == permImplUpgradeable, "invalid caller"); 28 _; 29 } 30 31 /** @notice interface for setting the permissions policy in implementation 32 * @param _nwAdminOrg network admin organization id 33 * @param _nwAdminRole default network admin role id 34 * @param _oAdminRole default organization admin role id 35 */ 36 function setPolicy(string calldata _nwAdminOrg, string calldata _nwAdminRole, 37 string calldata _oAdminRole) external { 38 permImplementation.setPolicy(_nwAdminOrg, _nwAdminRole, _oAdminRole); 39 } 40 41 /** @notice interface to initializes the breadth and depth values for 42 sub organization management 43 * @param _breadth controls the number of sub org a parent org can have 44 * @param _depth controls the depth of nesting allowed for sub orgs 45 */ 46 function init(uint256 _breadth, uint256 _depth) external { 47 permImplementation.init(_breadth, _depth); 48 } 49 50 /** @notice interface to add new node to an admin organization 51 * @param _enodeId enode id of the node to be added 52 * @param _ip IP of node 53 * @param _port tcp port of node 54 * @param _raftport raft port of node 55 */ 56 function addAdminNode(string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport) public { 57 permImplementation.addAdminNode(_enodeId, _ip, _port, _raftport); 58 } 59 60 /** @notice interface to add accounts to an admin organization 61 * @param _acct account address to be added 62 */ 63 function addAdminAccount(address _acct) external { 64 permImplementation.addAdminAccount(_acct); 65 } 66 67 /** @notice interface to update network boot up status 68 * @return bool true or false 69 */ 70 function updateNetworkBootStatus() external 71 returns (bool) 72 { 73 return permImplementation.updateNetworkBootStatus(); 74 } 75 76 /** @notice interface to fetch network boot status 77 * @return bool network boot status 78 */ 79 function getNetworkBootStatus() external view returns (bool){ 80 return permImplementation.getNetworkBootStatus(); 81 } 82 83 /** @notice interface to add a new organization to the network 84 * @param _orgId unique organization id 85 * @param _enodeId enode id linked to the organization 86 * @param _ip IP of node 87 * @param _port tcp port of node 88 * @param _raftport raft port of node 89 * @param _account account id. this will have the org admin privileges 90 */ 91 function addOrg(string memory _orgId, string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport, 92 address _account) public { 93 permImplementation.addOrg(_orgId, _enodeId, _ip, _port, _raftport, _account, msg.sender); 94 } 95 96 /** @notice interface to approve a newly added organization 97 * @param _orgId unique organization id 98 * @param _enodeId enode id linked to the organization 99 * @param _ip IP of node 100 * @param _port tcp port of node 101 * @param _raftport raft port of node 102 * @param _account account id this will have the org admin privileges 103 */ 104 function approveOrg(string memory _orgId, string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport, 105 address _account) public { 106 permImplementation.approveOrg(_orgId, _enodeId, _ip, _port, _raftport, _account, msg.sender); 107 } 108 109 /** @notice interface to add sub org under an org 110 * @param _pOrgId parent org id under which the sub org is being added 111 * @param _orgId unique id for the sub organization 112 * @param _enodeId enode id linked to the sjb organization 113 * @param _ip IP of node 114 * @param _port tcp port of node 115 * @param _raftport raft port of node 116 */ 117 function addSubOrg(string memory _pOrgId, string memory _orgId, 118 string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport) public { 119 permImplementation.addSubOrg(_pOrgId, _orgId, _enodeId, _ip, _port, _raftport, msg.sender); 120 } 121 122 /** @notice interface to update the org status 123 * @param _orgId unique id of the organization 124 * @param _action 1 for suspending an org and 2 for revoke of suspension 125 */ 126 function updateOrgStatus(string calldata _orgId, uint256 _action) external { 127 permImplementation.updateOrgStatus(_orgId, _action, msg.sender); 128 } 129 130 /** @notice interface to approve org status change 131 * @param _orgId unique id for the sub organization 132 * @param _action 1 for suspending an org and 2 for revoke of suspension 133 */ 134 function approveOrgStatus(string calldata _orgId, uint256 _action) external { 135 permImplementation.approveOrgStatus(_orgId, _action, msg.sender); 136 } 137 138 /** @notice interface to add a new role definition to an organization 139 * @param _roleId unique id for the role 140 * @param _orgId unique id of the organization to which the role belongs 141 * @param _access account access type for the role 142 * @param _voter bool indicates if the role is voter role or not 143 * @param _admin bool indicates if the role is an admin role 144 * @dev account access type can have of the following four values: 145 0 - Read only 146 1 - Transact access 147 2 - Contract deployment access. Can transact as well 148 3 - Full access 149 */ 150 function addNewRole(string calldata _roleId, string calldata _orgId, 151 uint256 _access, bool _voter, bool _admin) external { 152 permImplementation.addNewRole(_roleId, _orgId, _access, _voter, _admin, msg.sender); 153 } 154 155 /** @notice interface to remove a role definition from an organization 156 * @param _roleId unique id for the role 157 * @param _orgId unique id of the organization to which the role belongs 158 */ 159 function removeRole(string calldata _roleId, string calldata _orgId) external { 160 permImplementation.removeRole(_roleId, _orgId, msg.sender); 161 } 162 163 /** @notice interface to assign network admin/org admin role to an account 164 this can be executed by network admin accounts only 165 * @param _orgId unique id of the organization to which the account belongs 166 * @param _account account id 167 * @param _roleId role id to be assigned to the account 168 */ 169 function assignAdminRole(string calldata _orgId, address _account, 170 string calldata _roleId) external { 171 permImplementation.assignAdminRole(_orgId, _account, _roleId, msg.sender); 172 173 } 174 /** @notice interface to approve network admin/org admin role assigment 175 this can be executed by network admin accounts only 176 * @param _orgId unique id of the organization to which the account belongs 177 * @param _account account id 178 */ 179 function approveAdminRole(string calldata _orgId, address _account) external { 180 permImplementation.approveAdminRole(_orgId, _account, msg.sender); 181 182 } 183 184 /** @notice interface to update account status 185 this can be executed by org admin accounts only 186 * @param _orgId unique id of the organization to which the account belongs 187 * @param _account account id 188 * @param _action 1-suspending 2-activating back 3-blacklisting 189 */ 190 function updateAccountStatus(string calldata _orgId, address _account, 191 uint256 _action) external { 192 permImplementation.updateAccountStatus(_orgId, _account, _action, msg.sender); 193 } 194 195 /** @notice interface to add a new node to the organization 196 * @param _orgId unique id of the organization to which the account belongs 197 * @param _enodeId enode id being dded to the org 198 * @param _ip IP of node 199 * @param _port tcp port of node 200 * @param _raftport raft port of node 201 */ 202 function addNode(string memory _orgId, string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport) public { 203 permImplementation.addNode(_orgId, _enodeId, _ip, _port, _raftport, msg.sender); 204 205 } 206 207 /** @notice interface to update node status 208 * @param _orgId unique id of the organization to which the account belongs 209 * @param _enodeId enode id being dded to the org 210 * @param _ip IP of node 211 * @param _port tcp port of node 212 * @param _raftport raft port of node 213 * @param _action 1-deactivate, 2-activate back, 3-blacklist the node 214 */ 215 function updateNodeStatus(string memory _orgId, string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport, 216 uint256 _action) public { 217 permImplementation.updateNodeStatus(_orgId, _enodeId, _ip, _port, _raftport, _action, msg.sender); 218 } 219 220 /** @notice interface to initiate blacklisted node recovery 221 * @param _orgId unique id of the organization to which the account belongs 222 * @param _enodeId enode id being recovered 223 * @param _ip IP of node 224 * @param _port tcp port of node 225 * @param _raftport raft port of node 226 */ 227 function startBlacklistedNodeRecovery(string memory _orgId, string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport) 228 public { 229 permImplementation.startBlacklistedNodeRecovery(_orgId, _enodeId, _ip, _port, _raftport, msg.sender); 230 } 231 232 /** @notice interface to approve blacklisted node recoevry 233 * @param _orgId unique id of the organization to which the account belongs 234 * @param _enodeId enode id being recovered 235 * @param _ip IP of node 236 * @param _port tcp port of node 237 * @param _raftport raft port of node 238 */ 239 function approveBlacklistedNodeRecovery(string memory _orgId, string memory _enodeId, string memory _ip, uint16 _port, uint16 _raftport) 240 public { 241 permImplementation.approveBlacklistedNodeRecovery(_orgId, _enodeId, _ip, _port, _raftport, msg.sender); 242 } 243 244 /** @notice interface to initiate blacklisted account recovery 245 * @param _orgId unique id of the organization to which the account belongs 246 * @param _account account id being recovered 247 */ 248 function startBlacklistedAccountRecovery(string calldata _orgId, address _account) 249 external { 250 permImplementation.startBlacklistedAccountRecovery(_orgId, _account, msg.sender); 251 } 252 253 /** @notice interface to approve blacklisted node recovery 254 * @param _orgId unique id of the organization to which the account belongs 255 * @param _account account id being recovered 256 */ 257 function approveBlacklistedAccountRecovery(string calldata _orgId, address _account) 258 external { 259 permImplementation.approveBlacklistedAccountRecovery(_orgId, _account, msg.sender); 260 } 261 262 /** @notice interface to fetch detail of any pending approval activities 263 for network admin organization 264 * @param _orgId unique id of the organization to which the account belongs 265 */ 266 function getPendingOp(string calldata _orgId) external view 267 returns (string memory, string memory, address, uint256) { 268 return permImplementation.getPendingOp(_orgId); 269 } 270 271 /** @notice sets the permissions implementation contract address 272 can be called from upgradable contract only 273 * @param _permImplementation permissions implementation contract address 274 */ 275 function setPermImplementation(address _permImplementation) external 276 onlyUpgradeable { 277 permImplementation = PermissionsImplementation(_permImplementation); 278 } 279 280 /** @notice returns the address of permissions implementation contract 281 * @return permissions implementation contract address 282 */ 283 function getPermissionsImpl() external view returns (address) { 284 return address(permImplementation); 285 } 286 287 /** @notice interface to assigns a role id to the account give 288 * @param _account account id 289 * @param _orgId organization id to which the account belongs 290 * @param _roleId role id to be assigned to the account 291 */ 292 function assignAccountRole(address _account, string calldata _orgId, 293 string calldata _roleId) external { 294 permImplementation.assignAccountRole(_account, _orgId, _roleId, msg.sender); 295 296 } 297 298 /** @notice interface to check if passed account is an network admin account 299 * @param _account account id 300 * @return true/false 301 */ 302 function isNetworkAdmin(address _account) external view returns (bool) { 303 return permImplementation.isNetworkAdmin(_account); 304 } 305 306 /** @notice interface to check if passed account is an org admin account 307 * @param _account account id 308 * @param _orgId organization id 309 * @return true/false 310 */ 311 function isOrgAdmin(address _account, string calldata _orgId) 312 external view returns (bool) { 313 return permImplementation.isOrgAdmin(_account, _orgId); 314 } 315 316 /** @notice interface to validate the account for access change operation 317 * @param _account account id 318 * @param _orgId organization id 319 * @return true/false 320 */ 321 function validateAccount(address _account, string calldata _orgId) 322 external view returns (bool) { 323 return permImplementation.validateAccount(_account, _orgId); 324 } 325 326 /** @notice checks if the node is allowed to connect or not 327 * @param _enodeId enode id 328 * @param _ip IP of node 329 * @param _port tcp port of node 330 * @return bool indicating if the node is allowed to connect or not 331 */ 332 function connectionAllowed(string calldata _enodeId, string calldata _ip, uint16 _port) external view returns (bool) { 333 return permImplementation.connectionAllowed(_enodeId, _ip, _port); 334 } 335 336 337 /** @notice checks if the account is allowed to transact or not 338 * @param _sender source account 339 * @param _target target account 340 * @param _value value being transferred 341 * @param _gasPrice gas price 342 * @param _gasLimit gas limit 343 * @param _payload payload for transactions on contracts 344 * @return bool indicating if the account is allowed to transact or not 345 */ 346 function transactionAllowed(address _sender, address _target, uint256 _value, uint256 _gasPrice, uint256 _gasLimit, bytes calldata _payload) 347 external view returns (bool) { 348 return permImplementation.transactionAllowed(_sender, _target, _value, _gasPrice, _gasLimit, _payload); 349 } 350 351 }