-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAccountRules.sol
118 lines (97 loc) · 3.39 KB
/
AccountRules.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
pragma solidity 0.5.9;
import "./AccountRulesProxy.sol";
import "./AccountRulesList.sol";
import "./AccountIngress.sol";
import "./Admin.sol";
import "./AccountStorage.sol";
contract AccountRules is AccountRulesProxy, AccountRulesList {
// in read-only mode rules can't be added/removed
// this will be used to protect data when upgrading contracts
bool private readOnlyMode = false;
// version of this contract: semver like 1.2.14 represented like 001002014
uint private version = 3000000;
AccountIngress private ingressContract;
modifier onlyOnEditMode() {
require(!readOnlyMode, "In read only mode: rules cannot be modified");
_;
}
modifier onlyAdmin() {
address adminContractAddress = ingressContract.getContractAddress(ingressContract.ADMIN_CONTRACT());
require(adminContractAddress != address(0), "Ingress contract must have Admin contract registered");
require(Admin(adminContractAddress).isAuthorized(msg.sender), "Sender not authorized");
_;
}
constructor (AccountIngress _ingressContract, AccountStorage _storage) public {
setStorage(_storage);
ingressContract = _ingressContract;
}
// VERSION
function getContractVersion() external view returns (uint) {
return version;
}
// READ ONLY MODE
function isReadOnly() external view returns (bool) {
return readOnlyMode;
}
function enterReadOnly() external onlyAdmin returns (bool) {
require(readOnlyMode == false, "Already in read only mode");
readOnlyMode = true;
return true;
}
function exitReadOnly() external onlyAdmin returns (bool) {
require(readOnlyMode == true, "Not in read only mode");
readOnlyMode = false;
return true;
}
function transactionAllowed(
address sender,
address target, // target
uint256, // value
uint256, // gasPrice
uint256, // gasLimit
bytes calldata // payload
) external view returns (bool) {
if (
accountPermitted (sender)
) {
if (target == address(0)) {
// contract creation
return getCanCreateContracts(sender);
}
return true;
} else {
return false;
}
}
function accountPermitted(
address _account
) public view returns (bool) {
return exists(_account);
}
function addAccount(
address account
) external onlyAdmin onlyOnEditMode returns (bool) {
bool added = add(account);
emit AccountAdded(added, account);
return added;
}
function removeAccount(
address account
) external onlyAdmin onlyOnEditMode returns (bool) {
bool removed = remove(account);
emit AccountRemoved(removed, account);
return removed;
}
function setCreateContractPermission(address _account, bool _allowed) public onlyAdmin returns (bool){
return setCanCreateContracts(_account, _allowed);
}
function getCreateContractPermission(address _account) public onlyAdmin returns (bool){
return getCanCreateContracts(_account);
}
function getSize() external view returns (uint) {
return size();
}
function addAccounts(address[] calldata accounts) external onlyAdmin returns (bool) {
return addAll(accounts);
}
}