|
| 1 | +pragma solidity 0.5.17; |
| 2 | +pragma experimental ABIEncoderV2; |
| 3 | + |
| 4 | +import "./SchemeConstraints.sol"; |
| 5 | + |
| 6 | +//a simple genericSchemeMultiCall constraint which put constraints only on white listed contracts to call. |
| 7 | + |
| 8 | +contract SimpleSchemeConstraints is SchemeConstraints { |
| 9 | + |
| 10 | + mapping(address=>bool) public contractsWhiteListMap; |
| 11 | + bool public initialized; |
| 12 | + |
| 13 | + /* @dev initialize |
| 14 | + * @param _contractsWhiteList the contracts the scheme is allowed to interact with |
| 15 | + * @param _descriptionHash can be used to add detalis description of the constraints. |
| 16 | + */ |
| 17 | + function initialize( |
| 18 | + address[] calldata _contractsWhiteList, |
| 19 | + string calldata _descriptionHash |
| 20 | + ) |
| 21 | + external { |
| 22 | + require(!initialized, "cannot initialize twice"); |
| 23 | + initialized = true; |
| 24 | + for (uint i = 0; i < _contractsWhiteList.length; i++) { |
| 25 | + contractsWhiteListMap[_contractsWhiteList[i]] = true; |
| 26 | + } |
| 27 | + contractsWhiteList = _contractsWhiteList; |
| 28 | + descriptionHash = _descriptionHash; |
| 29 | + } |
| 30 | + |
| 31 | + /* |
| 32 | + * @dev isAllowedToCall should be called upon a proposal execution. |
| 33 | + * @param _contractsToCall the contracts to be called |
| 34 | + * @return bool value true-allowed false not allowed |
| 35 | + */ |
| 36 | + function isAllowedToCall( |
| 37 | + address[] calldata _contractsToCall, |
| 38 | + bytes[] calldata, |
| 39 | + uint256[] calldata, |
| 40 | + Avatar |
| 41 | + ) |
| 42 | + external |
| 43 | + returns(bool) |
| 44 | + { |
| 45 | + for (uint i = 0; i < _contractsToCall.length; i++) { |
| 46 | + require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted"); |
| 47 | + } |
| 48 | + return true; |
| 49 | + } |
| 50 | + |
| 51 | + /* |
| 52 | + * @dev isAllowedToPropose should be called upon a proposal submition. |
| 53 | + * @param _contractsToCall the contracts to be called |
| 54 | + * @return bool value true-allowed false not allowed |
| 55 | + */ |
| 56 | + function isAllowedToPropose( |
| 57 | + address[] calldata _contractsToCall, |
| 58 | + bytes[] calldata, |
| 59 | + uint256[] calldata, |
| 60 | + Avatar) |
| 61 | + external |
| 62 | + returns(bool) |
| 63 | + { |
| 64 | + for (uint i = 0; i < _contractsToCall.length; i++) { |
| 65 | + require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted"); |
| 66 | + } |
| 67 | + return true; |
| 68 | + } |
| 69 | +} |
0 commit comments