This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Store.sol
254 lines (190 loc) · 6.5 KB
/
Store.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
// Neptune Mutual Protocol (https://neptunemutual.com)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.0;
import "./StoreBase.sol";
contract Store is StoreBase {
function setAddress(bytes32 k, address v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
addressStorage[k] = v;
}
function setAddressBoolean(
bytes32 k,
address a,
bool v
) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
addressBooleanStorage[k][a] = v;
}
function setUint(bytes32 k, uint256 v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
uintStorage[k] = v;
}
function addUint(bytes32 k, uint256 v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
uint256 existing = uintStorage[k];
uintStorage[k] = existing + v;
}
function subtractUint(bytes32 k, uint256 v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
uint256 existing = uintStorage[k];
uintStorage[k] = existing - v;
}
function setUints(bytes32 k, uint256[] memory v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
uintsStorage[k] = v;
}
function setString(bytes32 k, string calldata v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
stringStorage[k] = v;
}
function setBytes(bytes32 k, bytes calldata v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
bytesStorage[k] = v;
}
function setBool(bytes32 k, bool v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
if (v) {
boolStorage[k] = v;
}
}
function setInt(bytes32 k, int256 v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
intStorage[k] = v;
}
function setBytes32(bytes32 k, bytes32 v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
bytes32Storage[k] = v;
}
function setAddressArrayItem(bytes32 k, address v) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
if (addressArrayAddressPositionMap[k][v] == 0) {
addressArrayStorage[k].push(v);
addressArrayAddressPositionMap[k][v] = addressArrayStorage[k].length;
}
}
function deleteAddress(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete addressStorage[k];
}
function deleteUint(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete uintStorage[k];
}
function deleteUints(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete uintsStorage[k];
}
function deleteString(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete stringStorage[k];
}
function deleteBytes(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete bytesStorage[k];
}
function deleteBool(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete boolStorage[k];
}
function deleteInt(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete intStorage[k];
}
function deleteBytes32(bytes32 k) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
delete bytes32Storage[k];
}
function deleteAddressArrayItem(bytes32 k, address v) public override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
require(addressArrayAddressPositionMap[k][v] > 0, "Not found");
uint256 i = addressArrayAddressPositionMap[k][v] - 1;
uint256 count = addressArrayStorage[k].length;
if (i + 1 != count) {
addressArrayStorage[k][i] = addressArrayStorage[k][count - 1];
address theThenLastAddress = addressArrayStorage[k][i];
addressArrayAddressPositionMap[k][theThenLastAddress] = i + 1;
}
addressArrayStorage[k].pop();
delete addressArrayAddressPositionMap[k][v];
}
function deleteAddressArrayItemByIndex(bytes32 k, uint256 i) external override {
_throwIfPaused();
_throwIfSenderNotProtocolMember();
require(i < addressArrayStorage[k].length, "Invalid key");
address v = addressArrayStorage[k][i];
deleteAddressArrayItem(k, v);
}
function getAddressValues(bytes32[] memory keys) external view override returns (address[] memory values) {
values = new address[](keys.length + 1);
for (uint256 i = 0; i < keys.length; i++) {
values[i] = addressStorage[keys[i]];
}
}
function getAddress(bytes32 k) external view override returns (address) {
return addressStorage[k];
}
function getAddressBoolean(bytes32 k, address a) external view override returns (bool) {
return addressBooleanStorage[k][a];
}
function getUintValues(bytes32[] memory keys) external view override returns (uint256[] memory values) {
values = new uint256[](keys.length + 1);
for (uint256 i = 0; i < keys.length; i++) {
values[i] = uintStorage[keys[i]];
}
}
function getUint(bytes32 k) external view override returns (uint256) {
return uintStorage[k];
}
function getUints(bytes32 k) external view override returns (uint256[] memory) {
return uintsStorage[k];
}
function getString(bytes32 k) external view override returns (string memory) {
return stringStorage[k];
}
function getBytes(bytes32 k) external view override returns (bytes memory) {
return bytesStorage[k];
}
function getBool(bytes32 k) external view override returns (bool) {
return boolStorage[k];
}
function getInt(bytes32 k) external view override returns (int256) {
return intStorage[k];
}
function getBytes32(bytes32 k) external view override returns (bytes32) {
return bytes32Storage[k];
}
function getAddressArray(bytes32 k) external view override returns (address[] memory) {
return addressArrayStorage[k];
}
function getAddressArrayItemPosition(bytes32 k, address toFind) external view override returns (uint256) {
return addressArrayAddressPositionMap[k][toFind];
}
function getAddressArrayItemByIndex(bytes32 k, uint256 i) external view override returns (address) {
require(addressArrayStorage[k].length > i, "Invalid index");
return addressArrayStorage[k][i];
}
function countAddressArrayItems(bytes32 k) external view override returns (uint256) {
return addressArrayStorage[k].length;
}
}