forked from m10io/tokeninc-smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokenIOAuthority.sol
145 lines (124 loc) · 5.57 KB
/
TokenIOAuthority.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pragma solidity 0.4.24;
/*
COPYRIGHT 2018 Token, Inc.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
@title TokenIOAuthority - Authority Smart Contract for Token, Inc.
@author Ryan Tate <[email protected]>, Sean Pollock <[email protected]>
@notice Contract uses generalized storage contract, `TokenIOStorage`, for
upgradeability of interface contract.
*/
import "./Ownable.sol";
import "./TokenIOStorage.sol";
import "./TokenIOLib.sol";
contract TokenIOAuthority is Ownable {
/// @dev Set reference to TokenIOLib interface which proxies to TokenIOStorage
using TokenIOLib for TokenIOLib.Data;
TokenIOLib.Data lib;
/**
* @notice Constructor method for Authority contract
* @param _storageContract Ethereum Address of TokenIOStorage contract
*/
constructor(address _storageContract) public {
/*
* @notice Set the storage contract for the interface
* @dev This contract will be unable to use the storage constract until
* @dev contract address is authorized with the storage contract
* @dev Once authorized, you can setRegisteredFirm and setRegisteredAuthority
*/
lib.Storage = TokenIOStorage(_storageContract);
/// @dev set owner to contract initiator
owner[msg.sender] = true;
}
/**
* @notice Registers a firm as authorized true/false
* @param firmName Name of firm
* @param _authorized Authorization status
* @return {"success" : "Returns true if lib.setRegisteredFirm succeeds"}
*/
function setRegisteredFirm(string firmName, bool _authorized) public onlyAuthority(firmName, msg.sender) returns (bool success) {
/// @notice set firm registration status
require(
lib.setRegisteredFirm(firmName, _authorized),
"Error: Failed to register firm with storage contract! Please check your arguments."
);
return true;
}
/**
* @notice Registers an authority asoociated with the given firm as true/false
* @param firmName Name of firm
* @param authority Address of authority account
* @param _authorized Authorization status
* @return {"success" : "Returns true if lib.setRegisteredAuthority succeeds"}
*/
function setRegisteredAuthority(string firmName, address authority, bool _authorized) public onlyAuthority(firmName, msg.sender) returns (bool success) {
/// @notice set authority of firm to given status
require(
lib.setRegisteredAuthority(firmName, authority, _authorized),
"Error: Failed to register authority for issuer firm with storage contract! Please check your arguments and ensure firmName is registered before allowing an authority of said firm"
);
return true;
}
/**
* @notice Gets firm asoociated with an authority address
* @param authority Address of authority account
* @return {"firm" : "name of firm"}
*/
function getFirmFromAuthority(address authority) public view returns (string firm) {
return lib.getFirmFromAuthority(authority);
}
/**
* @notice Gets status of firm registration
* @param firmName Name of firm
* @return {"status" : "Returns status of firm registration"}
*/
function isRegisteredFirm(string firmName) public view returns (bool status) {
/// @notice check firm's registration status
return lib.isRegisteredFirm(firmName);
}
/**
* @notice Checks if an authority account is registered to a given firm
* @param firmName Name of firm
* @param authority Address of authority account
* @return {"registered" : "Returns status of account registration to firm"}
*/
function isRegisteredToFirm(string firmName, address authority) public view returns (bool registered) {
/// @notice check if registered to firm
return lib.isRegisteredToFirm(firmName, authority);
}
/**
* @notice Gets status of authority registration
* @param authority Address of authority account
* @return { "registered" : "Returns true if account is a registered authority" }
*/
function isRegisteredAuthority(address authority) public view returns (bool registered) {
/// @notice check if registered authority
return lib.isRegisteredAuthority(authority);
}
/**
* @notice Sets contract which specifies fee parameters
* @param feeContract Address of the fee contract
* @return { "success" : "Returns true if lib.setMasterFeeContract succeeds" }
*/
function setMasterFeeContract(address feeContract) public onlyOwner returns (bool success) {
/// @notice set master fee contract
require(
lib.setMasterFeeContract(feeContract),
"Error: Unable to set master fee contract. Please ensure fee contract has the correct parameters."
);
return true;
}
modifier onlyAuthority(string firmName, address authority) {
/// @notice throws if not an owner authority or not registered to the given firm
require(owner[authority] || lib.isRegisteredToFirm(firmName, authority),
"Error: Transaction sender does not have permission for this operation!"
);
_;
}
}