@latticexyz/world-modules 2.0.12-type-resolutions-effc7ab1 → 2.0.12-type-resolutions-8538f80e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cache/solidity-files-cache.json +1 -1
- package/package.json +9 -8
- package/src/index.sol +25 -0
- package/src/interfaces/IBaseWorld.sol +16 -0
- package/src/interfaces/IERC20System.sol +33 -0
- package/src/interfaces/IERC721System.sol +43 -0
- package/src/interfaces/IPuppetFactorySystem.sol +15 -0
- package/src/interfaces/IUniqueEntitySystem.sol +13 -0
- package/src/interfaces/IUnstable_CallWithSignatureSystem.sol +20 -0
- package/src/modules/callwithsignature/ECDSA.sol +174 -0
- package/src/modules/callwithsignature/IERC1271.sol +17 -0
- package/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol +9 -0
- package/src/modules/callwithsignature/SignatureChecker.sol +50 -0
- package/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol +48 -0
- package/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol +36 -0
- package/src/modules/callwithsignature/constants.sol +10 -0
- package/src/modules/callwithsignature/getSignedMessageHash.sol +54 -0
- package/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol +199 -0
- package/src/modules/callwithsignature/validateCallWithSignature.sol +31 -0
- package/src/modules/erc20-puppet/ERC20Module.sol +88 -0
- package/src/modules/erc20-puppet/ERC20System.sol +286 -0
- package/src/modules/erc20-puppet/IERC20.sol +94 -0
- package/src/modules/erc20-puppet/IERC20Errors.sol +49 -0
- package/src/modules/erc20-puppet/IERC20Events.sol +18 -0
- package/src/modules/erc20-puppet/IERC20Mintable.sol +25 -0
- package/src/modules/erc20-puppet/constants.sol +20 -0
- package/src/modules/erc20-puppet/registerERC20.sol +35 -0
- package/src/modules/erc20-puppet/tables/Allowances.sol +208 -0
- package/src/modules/erc20-puppet/tables/ERC20Metadata.sol +604 -0
- package/src/modules/erc20-puppet/tables/ERC20Registry.sol +199 -0
- package/src/modules/erc20-puppet/tables/TotalSupply.sol +184 -0
- package/src/modules/erc20-puppet/utils.sol +30 -0
- package/src/modules/erc721-puppet/ERC721Module.sol +95 -0
- package/src/modules/erc721-puppet/ERC721System.sol +531 -0
- package/src/modules/erc721-puppet/IERC721.sol +120 -0
- package/src/modules/erc721-puppet/IERC721Errors.sol +61 -0
- package/src/modules/erc721-puppet/IERC721Events.sol +23 -0
- package/src/modules/erc721-puppet/IERC721Metadata.sol +27 -0
- package/src/modules/erc721-puppet/IERC721Mintable.sol +53 -0
- package/src/modules/erc721-puppet/IERC721Receiver.sol +28 -0
- package/src/modules/erc721-puppet/constants.sol +23 -0
- package/src/modules/erc721-puppet/libraries/LibString.sol +77 -0
- package/src/modules/erc721-puppet/registerERC721.sol +37 -0
- package/src/modules/erc721-puppet/tables/ERC721Metadata.sol +703 -0
- package/src/modules/erc721-puppet/tables/ERC721Registry.sol +199 -0
- package/src/modules/erc721-puppet/tables/OperatorApproval.sol +220 -0
- package/src/modules/erc721-puppet/tables/Owners.sol +196 -0
- package/src/modules/erc721-puppet/tables/TokenApproval.sol +196 -0
- package/src/modules/erc721-puppet/tables/TokenURI.sol +450 -0
- package/src/modules/erc721-puppet/utils.sol +38 -0
- package/src/modules/keysintable/KeysInTableHook.sol +141 -0
- package/src/modules/keysintable/KeysInTableModule.sol +110 -0
- package/src/modules/keysintable/constants.sol +7 -0
- package/src/modules/keysintable/getKeysInTable.sol +81 -0
- package/src/modules/keysintable/hasKey.sol +28 -0
- package/src/modules/keysintable/query.sol +200 -0
- package/src/modules/keysintable/tables/KeysInTable.sol +1638 -0
- package/src/modules/keysintable/tables/UsedKeysIndex.sol +414 -0
- package/src/modules/keyswithvalue/KeysWithValueHook.sol +158 -0
- package/src/modules/keyswithvalue/KeysWithValueModule.sol +103 -0
- package/src/modules/keyswithvalue/constants.sol +7 -0
- package/src/modules/keyswithvalue/getKeysWithValue.sol +58 -0
- package/src/modules/keyswithvalue/getTargetTableId.sol +32 -0
- package/src/modules/keyswithvalue/tables/KeysWithValue.sol +668 -0
- package/src/modules/puppet/Puppet.sol +80 -0
- package/src/modules/puppet/PuppetDelegationControl.sol +17 -0
- package/src/modules/puppet/PuppetFactorySystem.sol +25 -0
- package/src/modules/puppet/PuppetMaster.sol +19 -0
- package/src/modules/puppet/PuppetModule.sol +64 -0
- package/src/modules/puppet/constants.sol +23 -0
- package/src/modules/puppet/createPuppet.sol +24 -0
- package/src/modules/puppet/tables/PuppetRegistry.sol +199 -0
- package/src/modules/puppet/utils.sol +10 -0
- package/src/modules/std-delegations/CallboundDelegationControl.sol +64 -0
- package/src/modules/std-delegations/StandardDelegationsModule.sol +55 -0
- package/src/modules/std-delegations/SystemboundDelegationControl.sol +54 -0
- package/src/modules/std-delegations/TimeboundDelegationControl.sol +27 -0
- package/src/modules/std-delegations/constants.sol +21 -0
- package/src/modules/std-delegations/tables/CallboundDelegations.sol +287 -0
- package/src/modules/std-delegations/tables/SystemboundDelegations.sol +256 -0
- package/src/modules/std-delegations/tables/TimeboundDelegations.sol +211 -0
- package/src/modules/tokens/tables/Balances.sol +196 -0
- package/src/modules/uniqueentity/UniqueEntityModule.sol +73 -0
- package/src/modules/uniqueentity/UniqueEntitySystem.sol +18 -0
- package/src/modules/uniqueentity/constants.sol +13 -0
- package/src/modules/uniqueentity/getUniqueEntity.sol +26 -0
- package/src/modules/uniqueentity/tables/UniqueEntity.sol +238 -0
- package/src/modules/utils/ArrayLib.sol +55 -0
- package/src/utils/AccessControlLib.sol +55 -0
- package/src/utils/SystemSwitch.sol +80 -0
@@ -0,0 +1,668 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
5
|
+
|
6
|
+
// Import store internals
|
7
|
+
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
8
|
+
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
9
|
+
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
10
|
+
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
11
|
+
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
12
|
+
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
13
|
+
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
14
|
+
import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
|
15
|
+
import { Schema } from "@latticexyz/store/src/Schema.sol";
|
16
|
+
import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
|
17
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
18
|
+
|
19
|
+
library KeysWithValue {
|
20
|
+
FieldLayout constant _fieldLayout =
|
21
|
+
FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000);
|
22
|
+
|
23
|
+
// Hex-encoded key schema of (bytes32)
|
24
|
+
Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000);
|
25
|
+
// Hex-encoded value schema of (bytes32[])
|
26
|
+
Schema constant _valueSchema = Schema.wrap(0x00000001c1000000000000000000000000000000000000000000000000000000);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @notice Get the table's key field names.
|
30
|
+
* @return keyNames An array of strings with the names of key fields.
|
31
|
+
*/
|
32
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
33
|
+
keyNames = new string[](1);
|
34
|
+
keyNames[0] = "valueHash";
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @notice Get the table's value field names.
|
39
|
+
* @return fieldNames An array of strings with the names of value fields.
|
40
|
+
*/
|
41
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
42
|
+
fieldNames = new string[](1);
|
43
|
+
fieldNames[0] = "keysWithValue";
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @notice Register the table with its config.
|
48
|
+
*/
|
49
|
+
function register(ResourceId _tableId) internal {
|
50
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @notice Register the table with its config.
|
55
|
+
*/
|
56
|
+
function _register(ResourceId _tableId) internal {
|
57
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @notice Register the table with its config (using the specified store).
|
62
|
+
*/
|
63
|
+
function register(IStore _store, ResourceId _tableId) internal {
|
64
|
+
_store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @notice Get keysWithValue.
|
69
|
+
*/
|
70
|
+
function getKeysWithValue(
|
71
|
+
ResourceId _tableId,
|
72
|
+
bytes32 valueHash
|
73
|
+
) internal view returns (bytes32[] memory keysWithValue) {
|
74
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
75
|
+
_keyTuple[0] = valueHash;
|
76
|
+
|
77
|
+
bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0);
|
78
|
+
return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32());
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* @notice Get keysWithValue.
|
83
|
+
*/
|
84
|
+
function _getKeysWithValue(
|
85
|
+
ResourceId _tableId,
|
86
|
+
bytes32 valueHash
|
87
|
+
) internal view returns (bytes32[] memory keysWithValue) {
|
88
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
89
|
+
_keyTuple[0] = valueHash;
|
90
|
+
|
91
|
+
bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0);
|
92
|
+
return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32());
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* @notice Get keysWithValue (using the specified store).
|
97
|
+
*/
|
98
|
+
function getKeysWithValue(
|
99
|
+
IStore _store,
|
100
|
+
ResourceId _tableId,
|
101
|
+
bytes32 valueHash
|
102
|
+
) internal view returns (bytes32[] memory keysWithValue) {
|
103
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
104
|
+
_keyTuple[0] = valueHash;
|
105
|
+
|
106
|
+
bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0);
|
107
|
+
return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32());
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* @notice Get keysWithValue.
|
112
|
+
*/
|
113
|
+
function get(ResourceId _tableId, bytes32 valueHash) internal view returns (bytes32[] memory keysWithValue) {
|
114
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
115
|
+
_keyTuple[0] = valueHash;
|
116
|
+
|
117
|
+
bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0);
|
118
|
+
return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32());
|
119
|
+
}
|
120
|
+
|
121
|
+
/**
|
122
|
+
* @notice Get keysWithValue.
|
123
|
+
*/
|
124
|
+
function _get(ResourceId _tableId, bytes32 valueHash) internal view returns (bytes32[] memory keysWithValue) {
|
125
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
126
|
+
_keyTuple[0] = valueHash;
|
127
|
+
|
128
|
+
bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0);
|
129
|
+
return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32());
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* @notice Get keysWithValue (using the specified store).
|
134
|
+
*/
|
135
|
+
function get(
|
136
|
+
IStore _store,
|
137
|
+
ResourceId _tableId,
|
138
|
+
bytes32 valueHash
|
139
|
+
) internal view returns (bytes32[] memory keysWithValue) {
|
140
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
141
|
+
_keyTuple[0] = valueHash;
|
142
|
+
|
143
|
+
bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0);
|
144
|
+
return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32());
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* @notice Set keysWithValue.
|
149
|
+
*/
|
150
|
+
function setKeysWithValue(ResourceId _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal {
|
151
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
152
|
+
_keyTuple[0] = valueHash;
|
153
|
+
|
154
|
+
StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)));
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @notice Set keysWithValue.
|
159
|
+
*/
|
160
|
+
function _setKeysWithValue(ResourceId _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal {
|
161
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
162
|
+
_keyTuple[0] = valueHash;
|
163
|
+
|
164
|
+
StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)));
|
165
|
+
}
|
166
|
+
|
167
|
+
/**
|
168
|
+
* @notice Set keysWithValue (using the specified store).
|
169
|
+
*/
|
170
|
+
function setKeysWithValue(
|
171
|
+
IStore _store,
|
172
|
+
ResourceId _tableId,
|
173
|
+
bytes32 valueHash,
|
174
|
+
bytes32[] memory keysWithValue
|
175
|
+
) internal {
|
176
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
177
|
+
_keyTuple[0] = valueHash;
|
178
|
+
|
179
|
+
_store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)));
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* @notice Set keysWithValue.
|
184
|
+
*/
|
185
|
+
function set(ResourceId _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal {
|
186
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
187
|
+
_keyTuple[0] = valueHash;
|
188
|
+
|
189
|
+
StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)));
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* @notice Set keysWithValue.
|
194
|
+
*/
|
195
|
+
function _set(ResourceId _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal {
|
196
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
197
|
+
_keyTuple[0] = valueHash;
|
198
|
+
|
199
|
+
StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)));
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* @notice Set keysWithValue (using the specified store).
|
204
|
+
*/
|
205
|
+
function set(IStore _store, ResourceId _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal {
|
206
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
207
|
+
_keyTuple[0] = valueHash;
|
208
|
+
|
209
|
+
_store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)));
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* @notice Get the length of keysWithValue.
|
214
|
+
*/
|
215
|
+
function lengthKeysWithValue(ResourceId _tableId, bytes32 valueHash) internal view returns (uint256) {
|
216
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
217
|
+
_keyTuple[0] = valueHash;
|
218
|
+
|
219
|
+
uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
220
|
+
unchecked {
|
221
|
+
return _byteLength / 32;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* @notice Get the length of keysWithValue.
|
227
|
+
*/
|
228
|
+
function _lengthKeysWithValue(ResourceId _tableId, bytes32 valueHash) internal view returns (uint256) {
|
229
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
230
|
+
_keyTuple[0] = valueHash;
|
231
|
+
|
232
|
+
uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
233
|
+
unchecked {
|
234
|
+
return _byteLength / 32;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* @notice Get the length of keysWithValue (using the specified store).
|
240
|
+
*/
|
241
|
+
function lengthKeysWithValue(IStore _store, ResourceId _tableId, bytes32 valueHash) internal view returns (uint256) {
|
242
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
243
|
+
_keyTuple[0] = valueHash;
|
244
|
+
|
245
|
+
uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
246
|
+
unchecked {
|
247
|
+
return _byteLength / 32;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* @notice Get the length of keysWithValue.
|
253
|
+
*/
|
254
|
+
function length(ResourceId _tableId, bytes32 valueHash) internal view returns (uint256) {
|
255
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
256
|
+
_keyTuple[0] = valueHash;
|
257
|
+
|
258
|
+
uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
259
|
+
unchecked {
|
260
|
+
return _byteLength / 32;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
/**
|
265
|
+
* @notice Get the length of keysWithValue.
|
266
|
+
*/
|
267
|
+
function _length(ResourceId _tableId, bytes32 valueHash) internal view returns (uint256) {
|
268
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
269
|
+
_keyTuple[0] = valueHash;
|
270
|
+
|
271
|
+
uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
272
|
+
unchecked {
|
273
|
+
return _byteLength / 32;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
* @notice Get the length of keysWithValue (using the specified store).
|
279
|
+
*/
|
280
|
+
function length(IStore _store, ResourceId _tableId, bytes32 valueHash) internal view returns (uint256) {
|
281
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
282
|
+
_keyTuple[0] = valueHash;
|
283
|
+
|
284
|
+
uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
285
|
+
unchecked {
|
286
|
+
return _byteLength / 32;
|
287
|
+
}
|
288
|
+
}
|
289
|
+
|
290
|
+
/**
|
291
|
+
* @notice Get an item of keysWithValue.
|
292
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
293
|
+
*/
|
294
|
+
function getItemKeysWithValue(
|
295
|
+
ResourceId _tableId,
|
296
|
+
bytes32 valueHash,
|
297
|
+
uint256 _index
|
298
|
+
) internal view returns (bytes32) {
|
299
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
300
|
+
_keyTuple[0] = valueHash;
|
301
|
+
|
302
|
+
unchecked {
|
303
|
+
bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32);
|
304
|
+
return (bytes32(_blob));
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
/**
|
309
|
+
* @notice Get an item of keysWithValue.
|
310
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
311
|
+
*/
|
312
|
+
function _getItemKeysWithValue(
|
313
|
+
ResourceId _tableId,
|
314
|
+
bytes32 valueHash,
|
315
|
+
uint256 _index
|
316
|
+
) internal view returns (bytes32) {
|
317
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
318
|
+
_keyTuple[0] = valueHash;
|
319
|
+
|
320
|
+
unchecked {
|
321
|
+
bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32);
|
322
|
+
return (bytes32(_blob));
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
/**
|
327
|
+
* @notice Get an item of keysWithValue (using the specified store).
|
328
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
329
|
+
*/
|
330
|
+
function getItemKeysWithValue(
|
331
|
+
IStore _store,
|
332
|
+
ResourceId _tableId,
|
333
|
+
bytes32 valueHash,
|
334
|
+
uint256 _index
|
335
|
+
) internal view returns (bytes32) {
|
336
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
337
|
+
_keyTuple[0] = valueHash;
|
338
|
+
|
339
|
+
unchecked {
|
340
|
+
bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32);
|
341
|
+
return (bytes32(_blob));
|
342
|
+
}
|
343
|
+
}
|
344
|
+
|
345
|
+
/**
|
346
|
+
* @notice Get an item of keysWithValue.
|
347
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
348
|
+
*/
|
349
|
+
function getItem(ResourceId _tableId, bytes32 valueHash, uint256 _index) internal view returns (bytes32) {
|
350
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
351
|
+
_keyTuple[0] = valueHash;
|
352
|
+
|
353
|
+
unchecked {
|
354
|
+
bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32);
|
355
|
+
return (bytes32(_blob));
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
/**
|
360
|
+
* @notice Get an item of keysWithValue.
|
361
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
362
|
+
*/
|
363
|
+
function _getItem(ResourceId _tableId, bytes32 valueHash, uint256 _index) internal view returns (bytes32) {
|
364
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
365
|
+
_keyTuple[0] = valueHash;
|
366
|
+
|
367
|
+
unchecked {
|
368
|
+
bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32);
|
369
|
+
return (bytes32(_blob));
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
/**
|
374
|
+
* @notice Get an item of keysWithValue (using the specified store).
|
375
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
376
|
+
*/
|
377
|
+
function getItem(
|
378
|
+
IStore _store,
|
379
|
+
ResourceId _tableId,
|
380
|
+
bytes32 valueHash,
|
381
|
+
uint256 _index
|
382
|
+
) internal view returns (bytes32) {
|
383
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
384
|
+
_keyTuple[0] = valueHash;
|
385
|
+
|
386
|
+
unchecked {
|
387
|
+
bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32);
|
388
|
+
return (bytes32(_blob));
|
389
|
+
}
|
390
|
+
}
|
391
|
+
|
392
|
+
/**
|
393
|
+
* @notice Push an element to keysWithValue.
|
394
|
+
*/
|
395
|
+
function pushKeysWithValue(ResourceId _tableId, bytes32 valueHash, bytes32 _element) internal {
|
396
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
397
|
+
_keyTuple[0] = valueHash;
|
398
|
+
|
399
|
+
StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element)));
|
400
|
+
}
|
401
|
+
|
402
|
+
/**
|
403
|
+
* @notice Push an element to keysWithValue.
|
404
|
+
*/
|
405
|
+
function _pushKeysWithValue(ResourceId _tableId, bytes32 valueHash, bytes32 _element) internal {
|
406
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
407
|
+
_keyTuple[0] = valueHash;
|
408
|
+
|
409
|
+
StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element)));
|
410
|
+
}
|
411
|
+
|
412
|
+
/**
|
413
|
+
* @notice Push an element to keysWithValue (using the specified store).
|
414
|
+
*/
|
415
|
+
function pushKeysWithValue(IStore _store, ResourceId _tableId, bytes32 valueHash, bytes32 _element) internal {
|
416
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
417
|
+
_keyTuple[0] = valueHash;
|
418
|
+
|
419
|
+
_store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element)));
|
420
|
+
}
|
421
|
+
|
422
|
+
/**
|
423
|
+
* @notice Push an element to keysWithValue.
|
424
|
+
*/
|
425
|
+
function push(ResourceId _tableId, bytes32 valueHash, bytes32 _element) internal {
|
426
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
427
|
+
_keyTuple[0] = valueHash;
|
428
|
+
|
429
|
+
StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element)));
|
430
|
+
}
|
431
|
+
|
432
|
+
/**
|
433
|
+
* @notice Push an element to keysWithValue.
|
434
|
+
*/
|
435
|
+
function _push(ResourceId _tableId, bytes32 valueHash, bytes32 _element) internal {
|
436
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
437
|
+
_keyTuple[0] = valueHash;
|
438
|
+
|
439
|
+
StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element)));
|
440
|
+
}
|
441
|
+
|
442
|
+
/**
|
443
|
+
* @notice Push an element to keysWithValue (using the specified store).
|
444
|
+
*/
|
445
|
+
function push(IStore _store, ResourceId _tableId, bytes32 valueHash, bytes32 _element) internal {
|
446
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
447
|
+
_keyTuple[0] = valueHash;
|
448
|
+
|
449
|
+
_store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element)));
|
450
|
+
}
|
451
|
+
|
452
|
+
/**
|
453
|
+
* @notice Pop an element from keysWithValue.
|
454
|
+
*/
|
455
|
+
function popKeysWithValue(ResourceId _tableId, bytes32 valueHash) internal {
|
456
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
457
|
+
_keyTuple[0] = valueHash;
|
458
|
+
|
459
|
+
StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 32);
|
460
|
+
}
|
461
|
+
|
462
|
+
/**
|
463
|
+
* @notice Pop an element from keysWithValue.
|
464
|
+
*/
|
465
|
+
function _popKeysWithValue(ResourceId _tableId, bytes32 valueHash) internal {
|
466
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
467
|
+
_keyTuple[0] = valueHash;
|
468
|
+
|
469
|
+
StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 32);
|
470
|
+
}
|
471
|
+
|
472
|
+
/**
|
473
|
+
* @notice Pop an element from keysWithValue (using the specified store).
|
474
|
+
*/
|
475
|
+
function popKeysWithValue(IStore _store, ResourceId _tableId, bytes32 valueHash) internal {
|
476
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
477
|
+
_keyTuple[0] = valueHash;
|
478
|
+
|
479
|
+
_store.popFromDynamicField(_tableId, _keyTuple, 0, 32);
|
480
|
+
}
|
481
|
+
|
482
|
+
/**
|
483
|
+
* @notice Pop an element from keysWithValue.
|
484
|
+
*/
|
485
|
+
function pop(ResourceId _tableId, bytes32 valueHash) internal {
|
486
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
487
|
+
_keyTuple[0] = valueHash;
|
488
|
+
|
489
|
+
StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 32);
|
490
|
+
}
|
491
|
+
|
492
|
+
/**
|
493
|
+
* @notice Pop an element from keysWithValue.
|
494
|
+
*/
|
495
|
+
function _pop(ResourceId _tableId, bytes32 valueHash) internal {
|
496
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
497
|
+
_keyTuple[0] = valueHash;
|
498
|
+
|
499
|
+
StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 32);
|
500
|
+
}
|
501
|
+
|
502
|
+
/**
|
503
|
+
* @notice Pop an element from keysWithValue (using the specified store).
|
504
|
+
*/
|
505
|
+
function pop(IStore _store, ResourceId _tableId, bytes32 valueHash) internal {
|
506
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
507
|
+
_keyTuple[0] = valueHash;
|
508
|
+
|
509
|
+
_store.popFromDynamicField(_tableId, _keyTuple, 0, 32);
|
510
|
+
}
|
511
|
+
|
512
|
+
/**
|
513
|
+
* @notice Update an element of keysWithValue at `_index`.
|
514
|
+
*/
|
515
|
+
function updateKeysWithValue(ResourceId _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal {
|
516
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
517
|
+
_keyTuple[0] = valueHash;
|
518
|
+
|
519
|
+
unchecked {
|
520
|
+
bytes memory _encoded = abi.encodePacked((_element));
|
521
|
+
StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded);
|
522
|
+
}
|
523
|
+
}
|
524
|
+
|
525
|
+
/**
|
526
|
+
* @notice Update an element of keysWithValue at `_index`.
|
527
|
+
*/
|
528
|
+
function _updateKeysWithValue(ResourceId _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal {
|
529
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
530
|
+
_keyTuple[0] = valueHash;
|
531
|
+
|
532
|
+
unchecked {
|
533
|
+
bytes memory _encoded = abi.encodePacked((_element));
|
534
|
+
StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded);
|
535
|
+
}
|
536
|
+
}
|
537
|
+
|
538
|
+
/**
|
539
|
+
* @notice Update an element of keysWithValue (using the specified store) at `_index`.
|
540
|
+
*/
|
541
|
+
function updateKeysWithValue(
|
542
|
+
IStore _store,
|
543
|
+
ResourceId _tableId,
|
544
|
+
bytes32 valueHash,
|
545
|
+
uint256 _index,
|
546
|
+
bytes32 _element
|
547
|
+
) internal {
|
548
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
549
|
+
_keyTuple[0] = valueHash;
|
550
|
+
|
551
|
+
unchecked {
|
552
|
+
bytes memory _encoded = abi.encodePacked((_element));
|
553
|
+
_store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded);
|
554
|
+
}
|
555
|
+
}
|
556
|
+
|
557
|
+
/**
|
558
|
+
* @notice Update an element of keysWithValue at `_index`.
|
559
|
+
*/
|
560
|
+
function update(ResourceId _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal {
|
561
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
562
|
+
_keyTuple[0] = valueHash;
|
563
|
+
|
564
|
+
unchecked {
|
565
|
+
bytes memory _encoded = abi.encodePacked((_element));
|
566
|
+
StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded);
|
567
|
+
}
|
568
|
+
}
|
569
|
+
|
570
|
+
/**
|
571
|
+
* @notice Update an element of keysWithValue at `_index`.
|
572
|
+
*/
|
573
|
+
function _update(ResourceId _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal {
|
574
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
575
|
+
_keyTuple[0] = valueHash;
|
576
|
+
|
577
|
+
unchecked {
|
578
|
+
bytes memory _encoded = abi.encodePacked((_element));
|
579
|
+
StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded);
|
580
|
+
}
|
581
|
+
}
|
582
|
+
|
583
|
+
/**
|
584
|
+
* @notice Update an element of keysWithValue (using the specified store) at `_index`.
|
585
|
+
*/
|
586
|
+
function update(IStore _store, ResourceId _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal {
|
587
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
588
|
+
_keyTuple[0] = valueHash;
|
589
|
+
|
590
|
+
unchecked {
|
591
|
+
bytes memory _encoded = abi.encodePacked((_element));
|
592
|
+
_store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded);
|
593
|
+
}
|
594
|
+
}
|
595
|
+
|
596
|
+
/**
|
597
|
+
* @notice Delete all data for given keys.
|
598
|
+
*/
|
599
|
+
function deleteRecord(ResourceId _tableId, bytes32 valueHash) internal {
|
600
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
601
|
+
_keyTuple[0] = valueHash;
|
602
|
+
|
603
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
604
|
+
}
|
605
|
+
|
606
|
+
/**
|
607
|
+
* @notice Delete all data for given keys.
|
608
|
+
*/
|
609
|
+
function _deleteRecord(ResourceId _tableId, bytes32 valueHash) internal {
|
610
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
611
|
+
_keyTuple[0] = valueHash;
|
612
|
+
|
613
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
614
|
+
}
|
615
|
+
|
616
|
+
/**
|
617
|
+
* @notice Delete all data for given keys (using the specified store).
|
618
|
+
*/
|
619
|
+
function deleteRecord(IStore _store, ResourceId _tableId, bytes32 valueHash) internal {
|
620
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
621
|
+
_keyTuple[0] = valueHash;
|
622
|
+
|
623
|
+
_store.deleteRecord(_tableId, _keyTuple);
|
624
|
+
}
|
625
|
+
|
626
|
+
/**
|
627
|
+
* @notice Tightly pack dynamic data lengths using this table's schema.
|
628
|
+
* @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value).
|
629
|
+
*/
|
630
|
+
function encodeLengths(bytes32[] memory keysWithValue) internal pure returns (EncodedLengths _encodedLengths) {
|
631
|
+
// Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits
|
632
|
+
unchecked {
|
633
|
+
_encodedLengths = EncodedLengthsLib.pack(keysWithValue.length * 32);
|
634
|
+
}
|
635
|
+
}
|
636
|
+
|
637
|
+
/**
|
638
|
+
* @notice Tightly pack dynamic (variable length) data using this table's schema.
|
639
|
+
* @return The dynamic data, encoded into a sequence of bytes.
|
640
|
+
*/
|
641
|
+
function encodeDynamic(bytes32[] memory keysWithValue) internal pure returns (bytes memory) {
|
642
|
+
return abi.encodePacked(EncodeArray.encode((keysWithValue)));
|
643
|
+
}
|
644
|
+
|
645
|
+
/**
|
646
|
+
* @notice Encode all of a record's fields.
|
647
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
648
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
649
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
650
|
+
*/
|
651
|
+
function encode(bytes32[] memory keysWithValue) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
652
|
+
bytes memory _staticData;
|
653
|
+
EncodedLengths _encodedLengths = encodeLengths(keysWithValue);
|
654
|
+
bytes memory _dynamicData = encodeDynamic(keysWithValue);
|
655
|
+
|
656
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
657
|
+
}
|
658
|
+
|
659
|
+
/**
|
660
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
661
|
+
*/
|
662
|
+
function encodeKeyTuple(bytes32 valueHash) internal pure returns (bytes32[] memory) {
|
663
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
664
|
+
_keyTuple[0] = valueHash;
|
665
|
+
|
666
|
+
return _keyTuple;
|
667
|
+
}
|
668
|
+
}
|