@@ -3,24 +3,56 @@ pragma solidity 0.4.24;
33import "./IssuesRegistry.sol " ;
44
55
6- contract KillSwitch {
6+ contract KillSwitch is AragonApp {
7+ bytes32 constant public SET_ISSUES_REGISTRY_ROLE = keccak256 ("SET_ISSUES_REGISTRY_ROLE " );
78 bytes32 constant public SET_CONTRACT_ACTION_ROLE = keccak256 ("SET_CONTRACT_ACTION_ROLE " );
9+ bytes32 constant public SET_LOWEST_ALLOWED_SEVERITY_ROLE = keccak256 ("SET_LOWEST_ALLOWED_SEVERITY_ROLE " );
810
911 enum ContractAction { Check, Ignore, Deny }
1012
1113 IssuesRegistry public issuesRegistry;
1214 mapping (address => ContractAction) internal contractActions;
15+ mapping (address => IssuesRegistry.Severity) internal lowestAllowedSeverityByContract;
1316
1417 event IssuesRegistrySet (address issuesRegistry , address sender );
1518 event ContractActionSet (address contractAddress , ContractAction action );
19+ event LowestAllowedSeveritySet (address indexed _contract , IssuesRegistry.Severity severity );
1620
17- function setContractAction (address _contract , ContractAction _action ) external ;
21+ function initialize (IssuesRegistry _issuesRegistry ) external onlyInit {
22+ initialized ();
23+ _setIssuesRegistry (_issuesRegistry);
24+ }
25+
26+ function setContractAction (address _contract , ContractAction _action )
27+ external
28+ authP (SET_CONTRACT_ACTION_ROLE, arr (_contract, msg .sender ))
29+ {
30+ contractActions[_contract] = _action;
31+ emit ContractActionSet (_contract, _action);
32+ }
33+
34+ function setLowestAllowedSeverity (address _contract , IssuesRegistry.Severity _severity )
35+ external
36+ authP (SET_LOWEST_ALLOWED_SEVERITY_ROLE, arr (_contract, msg .sender ))
37+ {
38+ lowestAllowedSeverityByContract[_contract] = _severity;
39+ emit LowestAllowedSeveritySet (_contract, _severity);
40+ }
41+
42+ function setIssuesRegistry (IssuesRegistry _issuesRegistry )
43+ external
44+ authP (SET_ISSUES_REGISTRY_ROLE, arr (msg .sender ))
45+ {
46+ _setIssuesRegistry (_issuesRegistry);
47+ }
1848
1949 function getContractAction (address _contract ) public view returns (ContractAction) {
2050 return contractActions[_contract];
2151 }
2252
23- function isSeverityIgnored (address _contract , IssuesRegistry.Severity _severity ) public view returns (bool );
53+ function getLowestAllowedSeverity (address _contract ) public view returns (IssuesRegistry.Severity) {
54+ return lowestAllowedSeverityByContract[_contract];
55+ }
2456
2557 function isContractIgnored (address _contract ) public view returns (bool ) {
2658 return getContractAction (_contract) == ContractAction.Ignore;
@@ -30,6 +62,12 @@ contract KillSwitch {
3062 return getContractAction (_contract) == ContractAction.Deny;
3163 }
3264
65+ function isSeverityIgnored (address _contract ) public view returns (bool ) {
66+ IssuesRegistry.Severity severityFound = issuesRegistry.getSeverityFor (_contract);
67+ IssuesRegistry.Severity lowestAllowedSeverity = getLowestAllowedSeverity (_contract);
68+ return lowestAllowedSeverity >= severityFound;
69+ }
70+
3371 function shouldDenyCallingContract (address _base , address _instance , address _sender , bytes _data , uint256 _value ) public returns (bool ) {
3472 // if the call should not be evaluated, then allow given call
3573 if (! _shouldEvaluateCall (_base, _instance, _sender, _data, _value)) {
@@ -52,15 +90,19 @@ contract KillSwitch {
5290 }
5391
5492 // if the contract severity found is ignored, then allow given call
55- IssuesRegistry.Severity _severityFound = issuesRegistry.getSeverityFor (_base);
56- if (isSeverityIgnored (_base, _severityFound)) {
93+ if (isSeverityIgnored (_base)) {
5794 return false ;
5895 }
5996
6097 // if none of the conditions above were met, then deny given call
6198 return true ;
6299 }
63100
101+ function _setIssuesRegistry (IssuesRegistry _issuesRegistry ) internal {
102+ issuesRegistry = _issuesRegistry;
103+ emit IssuesRegistrySet (_issuesRegistry, msg .sender );
104+ }
105+
64106 /**
65107 * @dev This function allows different kill-switch implementations to provide a custom logic to tell whether a
66108 * certain call should be denied or not. This is important to ensure recoverability. For example, custom
@@ -71,14 +113,4 @@ contract KillSwitch {
71113 function _shouldEvaluateCall (address , address , address , bytes , uint256 ) internal returns (bool ) {
72114 return true ;
73115 }
74-
75- function _setIssuesRegistry (IssuesRegistry _issuesRegistry ) internal {
76- issuesRegistry = _issuesRegistry;
77- emit IssuesRegistrySet (_issuesRegistry, msg .sender );
78- }
79-
80- function _setContractAction (address _contract , ContractAction _action ) internal {
81- contractActions[_contract] = _action;
82- emit ContractActionSet (_contract, _action);
83- }
84116}
0 commit comments