forked from m10io/tokeninc-smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokenIOStorage.sol
259 lines (219 loc) · 9.77 KB
/
TokenIOStorage.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
pragma solidity 0.4.24;
import "./Ownable.sol";
/**
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 TokenIOStorage - Serves as derived contract for TokenIO contract and
is used to upgrade interfaces in the event of deprecating the main contract.
@author Ryan Tate <[email protected]>, Sean Pollock <[email protected]>
@notice Storage contract
@dev In the event that the main contract becomes deprecated, the upgraded contract
will be set as the owner of this contract, and use this contract's storage to
maintain data consistency between contract.
@notice NOTE: This contract is based on the RocketPool Storage Contract,
found here: https://github.com/rocket-pool/rocketpool/blob/master/contracts/RocketStorage.sol
And this medium article: https://medium.com/rocket-pool/upgradable-solidity-contract-design-54789205276d
Changes:
- setting primitive mapping view to internal;
- setting method views to public;
@dev NOTE: When deprecating the main TokenIO contract, the upgraded contract
must take ownership of the TokenIO contract, it will require using the public methods
to update changes to the underlying data. The updated contract must use a
standard call to original TokenIO contract such that the request is made from
the upgraded contract and not the transaction origin (tx.origin) of the signing
account.
@dev NOTE: The reasoning for using the storage contract is to abstract the interface
from the data of the contract on chain, limiting the need to migrate data to
new contracts.
*/
contract TokenIOStorage is Ownable {
/// @dev mapping for Primitive Data Types;
/// @notice primitive data mappings have `internal` view;
/// @dev only the derived contract can use the internal methods;
/// @dev key == `keccak256(param1, param2...)`
/// @dev Nested mapping can be achieved using multiple params in keccak256 hash;
mapping(bytes32 => uint256) internal uIntStorage;
mapping(bytes32 => string) internal stringStorage;
mapping(bytes32 => address) internal addressStorage;
mapping(bytes32 => bytes) internal bytesStorage;
mapping(bytes32 => bool) internal boolStorage;
mapping(bytes32 => int256) internal intStorage;
constructor() public {
/// @notice owner is set to msg.sender by default
/// @dev consider removing in favor of setting ownership in inherited
/// contract
owner[msg.sender] = true;
}
/// @dev Set Key Methods
/**
* @notice Set value for Address associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @param _value The Address value to be set
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function setAddress(bytes32 _key, address _value) public onlyOwner returns (bool success) {
addressStorage[_key] = _value;
return true;
}
/**
* @notice Set value for Uint associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @param _value The Uint value to be set
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function setUint(bytes32 _key, uint _value) public onlyOwner returns (bool success) {
uIntStorage[_key] = _value;
return true;
}
/**
* @notice Set value for String associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @param _value The String value to be set
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function setString(bytes32 _key, string _value) public onlyOwner returns (bool success) {
stringStorage[_key] = _value;
return true;
}
/**
* @notice Set value for Bytes associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @param _value The Bytes value to be set
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function setBytes(bytes32 _key, bytes _value) public onlyOwner returns (bool success) {
bytesStorage[_key] = _value;
return true;
}
/**
* @notice Set value for Bool associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @param _value The Bool value to be set
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function setBool(bytes32 _key, bool _value) public onlyOwner returns (bool success) {
boolStorage[_key] = _value;
return true;
}
/**
* @notice Set value for Int associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @param _value The Int value to be set
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function setInt(bytes32 _key, int _value) public onlyOwner returns (bool success) {
intStorage[_key] = _value;
return true;
}
/// @dev Delete Key Methods
/// @dev delete methods may be unnecessary; Use set methods to set values
/// to default?
/**
* @notice Delete value for Address associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function deleteAddress(bytes32 _key) public onlyOwner returns (bool success) {
delete addressStorage[_key];
return true;
}
/**
* @notice Delete value for Uint associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function deleteUint(bytes32 _key) public onlyOwner returns (bool success) {
delete uIntStorage[_key];
return true;
}
/**
* @notice Delete value for String associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function deleteString(bytes32 _key) public onlyOwner returns (bool success) {
delete stringStorage[_key];
return true;
}
/**
* @notice Delete value for Bytes associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function deleteBytes(bytes32 _key) public onlyOwner returns (bool success) {
delete bytesStorage[_key];
return true;
}
/**
* @notice Delete value for Bool associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function deleteBool(bytes32 _key) public onlyOwner returns (bool success) {
delete boolStorage[_key];
return true;
}
/**
* @notice Delete value for Int associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "success" : "Returns true when successfully called from another contract" }
*/
function deleteInt(bytes32 _key) public onlyOwner returns (bool success) {
delete intStorage[_key];
return true;
}
/// @dev Get Key Methods
/**
* @notice Get value for Address associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "_value" : "Returns the Address value associated with the id key" }
*/
function getAddress(bytes32 _key) public view returns (address _value) {
return addressStorage[_key];
}
/**
* @notice Get value for Uint associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "_value" : "Returns the Uint value associated with the id key" }
*/
function getUint(bytes32 _key) public view returns (uint _value) {
return uIntStorage[_key];
}
/**
* @notice Get value for String associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "_value" : "Returns the String value associated with the id key" }
*/
function getString(bytes32 _key) public view returns (string _value) {
return stringStorage[_key];
}
/**
* @notice Get value for Bytes associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "_value" : "Returns the Bytes value associated with the id key" }
*/
function getBytes(bytes32 _key) public view returns (bytes _value) {
return bytesStorage[_key];
}
/**
* @notice Get value for Bool associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "_value" : "Returns the Bool value associated with the id key" }
*/
function getBool(bytes32 _key) public view returns (bool _value) {
return boolStorage[_key];
}
/**
* @notice Get value for Int associated with bytes32 id key
* @param _key Pointer identifier for value in storage
* @return { "_value" : "Returns the Int value associated with the id key" }
*/
function getInt(bytes32 _key) public view returns (int _value) {
return intStorage[_key];
}
}