-
Notifications
You must be signed in to change notification settings - Fork 4
/
Authority.sol
114 lines (90 loc) · 3.36 KB
/
Authority.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
pragma solidity ^0.4.0;
contract Authority {
function canCall(address callerAddress,
address codeAddress,
bytes4 sig) constant returns (bool);
}
contract AuthorizedInterface {
address public owner;
Authority public authority;
modifier auth {
if (!isAuthorized()) throw;
_;
}
event OwnerUpdate(address indexed oldOwner, address indexed newOwner);
event AuthorityUpdate(address indexed oldAuthority, address indexed newAuthority);
function setOwner(address newOwner) public auth returns (bool);
function setAuthority(Authority newAuthority) public auth returns (bool);
function isAuthorized() internal returns (bool);
}
contract Authorized is AuthorizedInterface {
function Authorized() {
owner = msg.sender;
OwnerUpdate(0x0, owner);
}
function setOwner(address newOwner) public auth returns (bool) {
OwnerUpdate(owner, newOwner);
owner = newOwner;
return true;
}
function setAuthority(Authority newAuthority) public auth returns (bool) {
AuthorityUpdate(authority, newAuthority);
authority = newAuthority;
return true;
}
function isAuthorized() internal returns (bool) {
if (msg.sender == owner) {
return true;
} else if (address(authority) == (0)) {
return false;
} else {
return authority.canCall(msg.sender, this, msg.sig);
}
}
}
contract WhitelistAuthorityInterface is Authority, AuthorizedInterface {
event SetCanCall(address indexed callerAddress,
address indexed codeAddress,
bytes4 indexed sig,
bool can);
event SetAnyoneCanCall(address indexed codeAddress,
bytes4 indexed sig,
bool can);
function setCanCall(address callerAddress,
address codeAddress,
bytes4 sig,
bool can) auth public returns (bool);
function setAnyoneCanCall(address codeAddress,
bytes4 sig,
bool can) auth public returns (bool);
}
contract WhitelistAuthority is WhitelistAuthorityInterface, Authorized {
mapping (address =>
mapping (address =>
mapping (bytes4 => bool))) _canCall;
mapping (address => mapping (bytes4 => bool)) _anyoneCanCall;
function canCall(address callerAddress,
address codeAddress,
bytes4 sig) constant returns (bool) {
if (_anyoneCanCall[codeAddress][sig]) {
return true;
} else {
return _canCall[callerAddress][codeAddress][sig];
}
}
function setCanCall(address callerAddress,
address codeAddress,
bytes4 sig,
bool can) auth public returns (bool) {
_canCall[callerAddress][codeAddress][sig] = can;
SetCanCall(callerAddress, codeAddress, sig, can);
return true;
}
function setAnyoneCanCall(address codeAddress,
bytes4 sig,
bool can) auth public returns (bool) {
_anyoneCanCall[codeAddress][sig] = can;
SetAnyoneCanCall(codeAddress, sig, can);
return true;
}
}