@latticexyz/world 1.40.0 → 1.41.0
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/LICENSE +21 -0
- package/abi/AddressArraySchemaLib.json +718 -869
- package/abi/BoolSchemaLib.json +401 -401
- package/abi/Bytes.json +1162 -1162
- package/abi/CommonBase.json +125 -125
- package/abi/DSTest.json +2630 -2630
- package/abi/DecodeSlice.json +3883 -3883
- package/abi/EncodeArray.json +3336 -3336
- package/abi/Hooks.json +1491 -785
- package/abi/IMulticall3.json +283 -283
- package/abi/IStore.json +623 -421
- package/abi/IStoreHook.json +567 -421
- package/abi/ISystemHook.json +19 -19
- package/abi/Memory.json +131 -131
- package/abi/PackedCounterLib.json +683 -683
- package/abi/RouteAccess.json +2209 -1159
- package/abi/RouteOwnerSchemaLib.json +349 -349
- package/abi/RouteOwnerTable.json +297 -297
- package/abi/RouteSchemaLib.json +433 -433
- package/abi/RouteTable.json +336 -336
- package/abi/SchemaLib.json +1211 -1211
- package/abi/ScriptBase.json +125 -125
- package/abi/SliceInstance.json +429 -429
- package/abi/SliceLib.json +429 -429
- package/abi/StdAssertions.json +2135 -2135
- package/abi/StdChains.json +1051 -1051
- package/abi/StdCheats.json +3257 -3257
- package/abi/StdCheatsSafe.json +3257 -3257
- package/abi/StdInvariant.json +337 -337
- package/abi/StdUtils.json +1122 -1122
- package/abi/Storage.json +491 -491
- package/abi/Store.json +374 -209
- package/abi/StoreCore.json +10665 -7865
- package/abi/StoreCoreExtended.json +10443 -7722
- package/abi/StoreCoreInternal.json +10482 -7638
- package/abi/StoreMetadata.json +3719 -2417
- package/abi/StoreSwitch.json +1692 -783
- package/abi/System.json +16 -16
- package/abi/SystemRouteSchemaLib.json +402 -402
- package/abi/SystemRouteTable.json +336 -336
- package/abi/SystemTable.json +8544 -651
- package/abi/SystemTest.json +287 -303
- package/abi/Test.json +124 -124
- package/abi/TestBase.json +125 -125
- package/abi/TestSystem.json +287 -303
- package/abi/TightCoder.json +272 -272
- package/abi/Utils.json +67 -67
- package/abi/Vm.json +1850 -1850
- package/abi/VmSafe.json +1850 -1850
- package/abi/World.json +5183 -3374
- package/abi/WorldTest.json +9983 -10520
- package/abi/WorldTestSystem.json +9992 -10503
- package/abi/WorldTestTableHook.json +9978 -10511
- package/abi/console.json +11417 -11417
- package/abi/console2.json +11459 -11459
- package/abi/stdError.json +79 -79
- package/abi/stdJson.json +1016 -1016
- package/abi/stdMath.json +218 -218
- package/abi/stdStorage.json +2400 -2400
- package/abi/stdStorageSafe.json +2400 -2400
- package/package.json +8 -8
- package/src/World.sol +78 -32
- package/src/schemas/AddressArray.sol +5 -19
- package/src/tables/RouteAccess.sol +35 -30
- package/src/tables/SystemTable.sol +142 -23
- package/types/ethers-contracts/IStore.ts +49 -0
- package/types/ethers-contracts/Store.ts +49 -0
- package/types/ethers-contracts/World.ts +94 -0
- package/types/ethers-contracts/WorldTest.ts +27 -0
- package/types/ethers-contracts/factories/IStore__factory.ts +28 -0
- package/types/ethers-contracts/factories/StoreCore__factory.ts +2 -23
- package/types/ethers-contracts/factories/StoreSwitch__factory.ts +1 -1
- package/types/ethers-contracts/factories/Store__factory.ts +81 -0
- package/types/ethers-contracts/factories/SystemTest__factory.ts +1 -1
- package/types/ethers-contracts/factories/TestSystem__factory.ts +1 -1
- package/types/ethers-contracts/factories/WorldTestSystem__factory.ts +12 -1
- package/types/ethers-contracts/factories/WorldTestTableHook__factory.ts +1 -1
- package/types/ethers-contracts/factories/WorldTest__factory.ts +11 -34
- package/types/ethers-contracts/factories/World__factory.ts +70 -30
- package/types/ethers-contracts/index.ts +0 -2
- package/abi/SystemSchemaLib.json +0 -3704
- package/src/schemas/SystemSchema.sol +0 -78
- package/types/ethers-contracts/StoreCoreExtended.ts +0 -141
- package/types/ethers-contracts/factories/StoreCoreExtended__factory.ts +0 -123
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/world",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.41.0",
|
|
5
5
|
"description": "World framework",
|
|
6
6
|
"types": "./types/ethers-contracts/",
|
|
7
7
|
"repository": {
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
"lint": "yarn prettier && yarn solhint",
|
|
23
23
|
"link": "yarn link",
|
|
24
24
|
"docs": "rimraf API && hardhat docgen && echo 'label: API\norder: 50' > API/index.yml",
|
|
25
|
-
"release": "npm publish
|
|
25
|
+
"release": "npm publish --access=public",
|
|
26
26
|
"gas-report": "mud gas-report --path test/** --save gas-report.txt"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@latticexyz/cli": "^1.
|
|
30
|
-
"@latticexyz/schema-type": "^1.
|
|
31
|
-
"@latticexyz/store": "^1.
|
|
29
|
+
"@latticexyz/cli": "^1.41.0",
|
|
30
|
+
"@latticexyz/schema-type": "^1.41.0",
|
|
31
|
+
"@latticexyz/store": "^1.41.0",
|
|
32
32
|
"@typechain/ethers-v5": "^9.0.0",
|
|
33
33
|
"@types/mocha": "^9.1.1",
|
|
34
34
|
"ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084",
|
|
35
35
|
"forge-std": "https://github.com/foundry-rs/forge-std.git#f36dab24d63d1c1945a05ed375ce341d3c1a49ed",
|
|
36
36
|
"hardhat": "^2.10.1",
|
|
37
|
-
"prettier": "^2.
|
|
38
|
-
"prettier-plugin-solidity": "^1.
|
|
37
|
+
"prettier": "^2.8.4",
|
|
38
|
+
"prettier-plugin-solidity": "^1.1.2",
|
|
39
39
|
"rimraf": "^3.0.2",
|
|
40
40
|
"solhint": "^3.3.7",
|
|
41
41
|
"solidity-docgen": "^0.6.0-beta.22",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084",
|
|
49
49
|
"forge-std": "https://github.com/foundry-rs/forge-std.git#f36dab24d63d1c1945a05ed375ce341d3c1a49ed"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ecac84146f0288e3a129d1d3dbfaf373db86b1ab"
|
|
52
52
|
}
|
package/src/World.sol
CHANGED
|
@@ -45,7 +45,7 @@ contract World is Store {
|
|
|
45
45
|
/**
|
|
46
46
|
* Register a new route by extending an existing route
|
|
47
47
|
*/
|
|
48
|
-
function registerRoute(string calldata baseRoute, string calldata subRoute) public returns (uint256 routeId) {
|
|
48
|
+
function registerRoute(string calldata baseRoute, string calldata subRoute) public virtual returns (uint256 routeId) {
|
|
49
49
|
// Require subroute to be a valid route fragment (start with `/` and don't contain any further `/`)
|
|
50
50
|
if (!_isSingleLevelRoute(subRoute)) revert RouteInvalid(subRoute);
|
|
51
51
|
|
|
@@ -53,6 +53,9 @@ contract World is Store {
|
|
|
53
53
|
uint256 baseRouteId = _toRouteId(baseRoute);
|
|
54
54
|
if (!(baseRouteId == ROOT_ROUTE_ID || RouteTable.has(baseRouteId))) revert RouteInvalid(baseRoute);
|
|
55
55
|
|
|
56
|
+
// Require subRoute to not be empty
|
|
57
|
+
if (bytes(subRoute).length == 0) revert RouteInvalid(subRoute);
|
|
58
|
+
|
|
56
59
|
// Construct the new route
|
|
57
60
|
string memory route = string(abi.encodePacked(baseRoute, subRoute));
|
|
58
61
|
routeId = _toRouteId(route);
|
|
@@ -77,7 +80,7 @@ contract World is Store {
|
|
|
77
80
|
string calldata baseRoute,
|
|
78
81
|
string calldata tableRoute,
|
|
79
82
|
Schema schema
|
|
80
|
-
) public returns (uint256 tableRouteId) {
|
|
83
|
+
) public virtual returns (uint256 tableRouteId) {
|
|
81
84
|
// Register table route
|
|
82
85
|
tableRouteId = uint256(registerRoute(baseRoute, tableRoute));
|
|
83
86
|
|
|
@@ -90,7 +93,7 @@ contract World is Store {
|
|
|
90
93
|
* This overload exists to conform to the Store interface,
|
|
91
94
|
* but it requires the caller to register a route using `registerRoute` first
|
|
92
95
|
*/
|
|
93
|
-
function registerSchema(uint256 tableId, Schema schema) public override {
|
|
96
|
+
function registerSchema(uint256 tableId, Schema schema) public virtual override {
|
|
94
97
|
// Require caller to own the given tableId
|
|
95
98
|
if (RouteOwnerTable.get(tableId) != msg.sender) revert RouteAccessDenied(RouteTable.get(tableId), msg.sender);
|
|
96
99
|
|
|
@@ -105,18 +108,14 @@ contract World is Store {
|
|
|
105
108
|
string calldata tableRoute,
|
|
106
109
|
string calldata tableName,
|
|
107
110
|
string[] calldata fieldNames
|
|
108
|
-
) public {
|
|
111
|
+
) public virtual {
|
|
109
112
|
setMetadata(_toRouteId(tableRoute), tableName, fieldNames);
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
/**
|
|
113
116
|
* Register metadata (tableName, fieldNames) for a given table via its id
|
|
114
117
|
*/
|
|
115
|
-
function setMetadata(
|
|
116
|
-
uint256 tableId,
|
|
117
|
-
string calldata tableName,
|
|
118
|
-
string[] calldata fieldNames
|
|
119
|
-
) public {
|
|
118
|
+
function setMetadata(uint256 tableId, string calldata tableName, string[] calldata fieldNames) public virtual {
|
|
120
119
|
// Require caller to own the given tableId
|
|
121
120
|
if (RouteOwnerTable.get(tableId) != msg.sender) revert RouteAccessDenied(RouteTable.get(tableId), msg.sender);
|
|
122
121
|
|
|
@@ -127,7 +126,7 @@ contract World is Store {
|
|
|
127
126
|
/**
|
|
128
127
|
* Register a hook for a given table route
|
|
129
128
|
*/
|
|
130
|
-
function registerTableHook(string calldata tableRoute, IStoreHook hook) public {
|
|
129
|
+
function registerTableHook(string calldata tableRoute, IStoreHook hook) public virtual {
|
|
131
130
|
registerStoreHook(_toRouteId(tableRoute), hook);
|
|
132
131
|
}
|
|
133
132
|
|
|
@@ -135,7 +134,7 @@ contract World is Store {
|
|
|
135
134
|
* Register a hook for a given table route id
|
|
136
135
|
* This overload exists to conform with the `IStore` interface.
|
|
137
136
|
*/
|
|
138
|
-
function registerStoreHook(uint256 tableId, IStoreHook hook) public override {
|
|
137
|
+
function registerStoreHook(uint256 tableId, IStoreHook hook) public virtual override {
|
|
139
138
|
// Require caller to own the given tableId
|
|
140
139
|
if (RouteOwnerTable.get(tableId) != msg.sender) revert RouteAccessDenied(RouteTable.get(tableId), msg.sender);
|
|
141
140
|
|
|
@@ -146,7 +145,7 @@ contract World is Store {
|
|
|
146
145
|
/**
|
|
147
146
|
* Register a hook for a given system route
|
|
148
147
|
*/
|
|
149
|
-
function registerSystemHook(string calldata systemRoute, ISystemHook hook) public {
|
|
148
|
+
function registerSystemHook(string calldata systemRoute, ISystemHook hook) public virtual {
|
|
150
149
|
// TODO implement (see https://github.com/latticexyz/mud/issues/444)
|
|
151
150
|
}
|
|
152
151
|
|
|
@@ -158,7 +157,7 @@ contract World is Store {
|
|
|
158
157
|
string calldata systemRoute,
|
|
159
158
|
System system,
|
|
160
159
|
bool publicAccess
|
|
161
|
-
) public returns (uint256 systemRouteId) {
|
|
160
|
+
) public virtual returns (uint256 systemRouteId) {
|
|
162
161
|
// Require the system to not exist yet
|
|
163
162
|
if (SystemRouteTable.has(address(system))) revert SystemExists(address(system));
|
|
164
163
|
|
|
@@ -182,7 +181,7 @@ contract World is Store {
|
|
|
182
181
|
/**
|
|
183
182
|
* Grant access to a given route
|
|
184
183
|
*/
|
|
185
|
-
function grantAccess(string calldata route, address grantee) public {
|
|
184
|
+
function grantAccess(string calldata route, address grantee) public virtual {
|
|
186
185
|
// Require the caller to own the route
|
|
187
186
|
uint256 routeId = _toRouteId(route);
|
|
188
187
|
if (RouteOwnerTable.get(routeId) != msg.sender) revert RouteAccessDenied(route, msg.sender);
|
|
@@ -194,7 +193,7 @@ contract World is Store {
|
|
|
194
193
|
/**
|
|
195
194
|
* Retract access to a given route
|
|
196
195
|
*/
|
|
197
|
-
function retractAccess(string calldata route, address grantee) public {
|
|
196
|
+
function retractAccess(string calldata route, address grantee) public virtual {
|
|
198
197
|
// Require the caller to own the route
|
|
199
198
|
uint256 routeId = _toRouteId(route);
|
|
200
199
|
if (RouteOwnerTable.get(routeId) != msg.sender) revert RouteAccessDenied(route, msg.sender);
|
|
@@ -219,7 +218,7 @@ contract World is Store {
|
|
|
219
218
|
string calldata subRoute,
|
|
220
219
|
bytes32[] calldata key,
|
|
221
220
|
bytes calldata data
|
|
222
|
-
) public {
|
|
221
|
+
) public virtual {
|
|
223
222
|
// Require access to accessRoute
|
|
224
223
|
if (!_hasAccess(accessRoute, msg.sender)) revert RouteAccessDenied(accessRoute, msg.sender);
|
|
225
224
|
|
|
@@ -237,11 +236,7 @@ contract World is Store {
|
|
|
237
236
|
* Write a record in a table based on access right to the table route id.
|
|
238
237
|
* This overload exists to conform with the `IStore` interface.
|
|
239
238
|
*/
|
|
240
|
-
function setRecord(
|
|
241
|
-
uint256 tableRouteId,
|
|
242
|
-
bytes32[] calldata key,
|
|
243
|
-
bytes calldata data
|
|
244
|
-
) public {
|
|
239
|
+
function setRecord(uint256 tableRouteId, bytes32[] calldata key, bytes calldata data) public virtual {
|
|
245
240
|
// Check access based on the tableRoute
|
|
246
241
|
if (!_hasAccess(tableRouteId, msg.sender)) revert RouteAccessDenied(RouteTable.get(tableRouteId), msg.sender);
|
|
247
242
|
|
|
@@ -260,7 +255,7 @@ contract World is Store {
|
|
|
260
255
|
bytes32[] calldata key,
|
|
261
256
|
uint8 schemaIndex,
|
|
262
257
|
bytes calldata data
|
|
263
|
-
) public {
|
|
258
|
+
) public virtual {
|
|
264
259
|
// Require access to accessRoute
|
|
265
260
|
if (!_hasAccess(accessRoute, msg.sender)) revert RouteAccessDenied(accessRoute, msg.sender);
|
|
266
261
|
|
|
@@ -283,7 +278,7 @@ contract World is Store {
|
|
|
283
278
|
bytes32[] calldata key,
|
|
284
279
|
uint8 schemaIndex,
|
|
285
280
|
bytes calldata data
|
|
286
|
-
) public override {
|
|
281
|
+
) public virtual override {
|
|
287
282
|
// Check access based on the tableRoute
|
|
288
283
|
if (!_hasAccess(tableRouteId, msg.sender)) revert RouteAccessDenied(RouteTable.get(tableRouteId), msg.sender);
|
|
289
284
|
|
|
@@ -292,15 +287,47 @@ contract World is Store {
|
|
|
292
287
|
}
|
|
293
288
|
|
|
294
289
|
/**
|
|
295
|
-
*
|
|
290
|
+
* Push data to the end of a field in a table based on a parent route access right.
|
|
296
291
|
* We check for access based on `accessRoute`, and write to `accessRoute/subRoute`
|
|
297
292
|
* because access to a route also grants access to all sub routes.
|
|
298
293
|
*/
|
|
299
|
-
function
|
|
294
|
+
function pushToField(
|
|
300
295
|
string calldata accessRoute,
|
|
301
296
|
string calldata subRoute,
|
|
302
|
-
bytes32[] calldata key
|
|
297
|
+
bytes32[] calldata key,
|
|
298
|
+
uint8 schemaIndex,
|
|
299
|
+
bytes calldata dataToPush
|
|
303
300
|
) public {
|
|
301
|
+
// Check access based on accessRoute
|
|
302
|
+
uint256 tableRouteId = _verifiedTableRouteId(accessRoute, subRoute);
|
|
303
|
+
|
|
304
|
+
// Push to the field
|
|
305
|
+
StoreCore.pushToField(tableRouteId, key, schemaIndex, dataToPush);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Push data to the end of a field in a table based on specific access rights.
|
|
310
|
+
* This overload exists to conform with the `IStore` interface.
|
|
311
|
+
*/
|
|
312
|
+
function pushToField(
|
|
313
|
+
uint256 tableRouteId,
|
|
314
|
+
bytes32[] calldata key,
|
|
315
|
+
uint8 schemaIndex,
|
|
316
|
+
bytes calldata dataToPush
|
|
317
|
+
) public override {
|
|
318
|
+
// Check access based on the tableRoute
|
|
319
|
+
if (!_hasAccess(tableRouteId, msg.sender)) revert RouteAccessDenied(RouteTable.get(tableRouteId), msg.sender);
|
|
320
|
+
|
|
321
|
+
// Push to the field
|
|
322
|
+
StoreCore.pushToField(tableRouteId, key, schemaIndex, dataToPush);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Delete a record in a table based on a parent route access right.
|
|
327
|
+
* We check for access based on `accessRoute`, and write to `accessRoute/subRoute`
|
|
328
|
+
* because access to a route also grants access to all sub routes.
|
|
329
|
+
*/
|
|
330
|
+
function deleteRecord(string calldata accessRoute, string calldata subRoute, bytes32[] calldata key) public virtual {
|
|
304
331
|
// Require access to accessRoute
|
|
305
332
|
if (!_hasAccess(accessRoute, msg.sender)) revert RouteAccessDenied(accessRoute, msg.sender);
|
|
306
333
|
|
|
@@ -318,7 +345,7 @@ contract World is Store {
|
|
|
318
345
|
* Delete a record in a table based on specific access rights.
|
|
319
346
|
* This overload exists to conform with the `IStore` interface.
|
|
320
347
|
*/
|
|
321
|
-
function deleteRecord(uint256 tableRouteId, bytes32[] calldata key) public override {
|
|
348
|
+
function deleteRecord(uint256 tableRouteId, bytes32[] calldata key) public virtual override {
|
|
322
349
|
// Check access based on the tableRoute
|
|
323
350
|
if (!_hasAccess(tableRouteId, msg.sender)) revert RouteAccessDenied(RouteTable.get(tableRouteId), msg.sender);
|
|
324
351
|
|
|
@@ -326,6 +353,25 @@ contract World is Store {
|
|
|
326
353
|
StoreCore.deleteRecord(tableRouteId, key);
|
|
327
354
|
}
|
|
328
355
|
|
|
356
|
+
/**
|
|
357
|
+
* Check for access based on `accessRoute`
|
|
358
|
+
* and return `tableRouteId` for `accessRoute/subRoute`
|
|
359
|
+
* because access to a route also grants access to all sub routes.
|
|
360
|
+
*/
|
|
361
|
+
function _verifiedTableRouteId(
|
|
362
|
+
string calldata accessRoute,
|
|
363
|
+
string calldata subRoute
|
|
364
|
+
) internal view returns (uint256 tableRouteId) {
|
|
365
|
+
// Require access to accessRoute
|
|
366
|
+
if (!_hasAccess(accessRoute, msg.sender)) revert RouteAccessDenied(accessRoute, msg.sender);
|
|
367
|
+
|
|
368
|
+
// Require a valid subRoute
|
|
369
|
+
if (!_isRoute(subRoute)) revert RouteInvalid(subRoute);
|
|
370
|
+
|
|
371
|
+
// Construct the table route id by concatenating accessRoute and tableRoute
|
|
372
|
+
tableRouteId = uint256(keccak256(abi.encodePacked(accessRoute, subRoute)));
|
|
373
|
+
}
|
|
374
|
+
|
|
329
375
|
/************************************************************************
|
|
330
376
|
*
|
|
331
377
|
* SYSTEM CALLS
|
|
@@ -341,13 +387,13 @@ contract World is Store {
|
|
|
341
387
|
string calldata accessRoute,
|
|
342
388
|
string memory subRoute,
|
|
343
389
|
bytes calldata funcSelectorAndArgs
|
|
344
|
-
) public returns (bytes memory) {
|
|
345
|
-
// Check if the system is a public system and get its address
|
|
390
|
+
) public virtual returns (bytes memory) {
|
|
391
|
+
// Check if the system is a public virtual system and get its address
|
|
346
392
|
string memory systemRoute = string(abi.encodePacked(accessRoute, subRoute));
|
|
347
393
|
uint256 systemRouteId = _toRouteId(systemRoute);
|
|
348
394
|
(address systemAddress, bool publicAccess) = SystemTable.get(systemRouteId);
|
|
349
395
|
|
|
350
|
-
// If the system is not public, check for individual access
|
|
396
|
+
// If the system is not public virtual, check for individual access
|
|
351
397
|
if (!publicAccess) {
|
|
352
398
|
// Require access to accessRoute
|
|
353
399
|
if (!_hasAccess(accessRoute, msg.sender)) revert RouteAccessDenied(accessRoute, msg.sender);
|
|
@@ -367,9 +413,9 @@ contract World is Store {
|
|
|
367
413
|
}
|
|
368
414
|
|
|
369
415
|
/**
|
|
370
|
-
* Overload for the function above to check access based on the full system route instead of a parent route (better devex for public systems)
|
|
416
|
+
* Overload for the function above to check access based on the full system route instead of a parent route (better devex for public virtual systems)
|
|
371
417
|
*/
|
|
372
|
-
function call(string calldata systemRoute, bytes calldata funcSelectorAndArgs) public returns (bytes memory) {
|
|
418
|
+
function call(string calldata systemRoute, bytes calldata funcSelectorAndArgs) public virtual returns (bytes memory) {
|
|
373
419
|
return call(systemRoute, "", funcSelectorAndArgs);
|
|
374
420
|
}
|
|
375
421
|
|
|
@@ -36,11 +36,7 @@ library AddressArraySchemaLib {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** Set the table's data */
|
|
39
|
-
function set(
|
|
40
|
-
uint256 tableId,
|
|
41
|
-
bytes32 key,
|
|
42
|
-
address[] memory addresses
|
|
43
|
-
) internal {
|
|
39
|
+
function set(uint256 tableId, bytes32 key, address[] memory addresses) internal {
|
|
44
40
|
bytes memory data = EncodeArray.encode(addresses);
|
|
45
41
|
bytes32[] memory keyTuple = new bytes32[](1);
|
|
46
42
|
keyTuple[0] = key;
|
|
@@ -49,17 +45,11 @@ library AddressArraySchemaLib {
|
|
|
49
45
|
|
|
50
46
|
/**
|
|
51
47
|
* Push an element to the addresses array
|
|
52
|
-
* TODO: this is super inefficient right now, need to add support for pushing to arrays to the store core library to avoid reading/writing the entire array
|
|
53
48
|
*/
|
|
54
|
-
function push(
|
|
55
|
-
uint256 tableId,
|
|
56
|
-
bytes32 key,
|
|
57
|
-
address addr
|
|
58
|
-
) internal {
|
|
49
|
+
function push(uint256 tableId, bytes32 key, address addr) internal {
|
|
59
50
|
bytes32[] memory keyTuple = new bytes32[](1);
|
|
60
51
|
keyTuple[0] = key;
|
|
61
|
-
|
|
62
|
-
StoreSwitch.setField(tableId, keyTuple, 0, addresses);
|
|
52
|
+
StoreSwitch.pushToField(tableId, keyTuple, 0, abi.encodePacked(addr));
|
|
63
53
|
}
|
|
64
54
|
|
|
65
55
|
/** Get the table's data */
|
|
@@ -70,11 +60,7 @@ library AddressArraySchemaLib {
|
|
|
70
60
|
return decode(blob);
|
|
71
61
|
}
|
|
72
62
|
|
|
73
|
-
function get(
|
|
74
|
-
uint256 tableId,
|
|
75
|
-
IStore store,
|
|
76
|
-
bytes32 key
|
|
77
|
-
) internal view returns (address[] memory addresses) {
|
|
63
|
+
function get(uint256 tableId, IStore store, bytes32 key) internal view returns (address[] memory addresses) {
|
|
78
64
|
bytes32[] memory keyTuple = new bytes32[](1);
|
|
79
65
|
keyTuple[0] = key;
|
|
80
66
|
bytes memory blob = store.getRecord(tableId, keyTuple);
|
|
@@ -83,6 +69,6 @@ library AddressArraySchemaLib {
|
|
|
83
69
|
|
|
84
70
|
function decode(bytes memory blob) internal pure returns (address[] memory addresses) {
|
|
85
71
|
if (blob.length == 0) return new address[](0);
|
|
86
|
-
SliceLib.getSubslice(blob, 32).decodeArray_address();
|
|
72
|
+
return SliceLib.getSubslice(blob, 32).decodeArray_address();
|
|
87
73
|
}
|
|
88
74
|
}
|
|
@@ -3,8 +3,10 @@ pragma solidity >=0.8.0;
|
|
|
3
3
|
|
|
4
4
|
/* Autogenerated file. Do not edit manually. */
|
|
5
5
|
|
|
6
|
+
// Import schema type
|
|
6
7
|
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol";
|
|
7
8
|
|
|
9
|
+
// Import store internals
|
|
8
10
|
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
9
11
|
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
10
12
|
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
|
@@ -14,7 +16,7 @@ import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
|
|
14
16
|
import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol";
|
|
15
17
|
import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol";
|
|
16
18
|
|
|
17
|
-
uint256 constant _tableId = uint256(keccak256("/
|
|
19
|
+
uint256 constant _tableId = uint256(keccak256("/RouteAccess"));
|
|
18
20
|
uint256 constant RouteAccessTableId = _tableId;
|
|
19
21
|
|
|
20
22
|
library RouteAccess {
|
|
@@ -26,66 +28,69 @@ library RouteAccess {
|
|
|
26
28
|
return SchemaLib.encode(_schema);
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
/** Get the table's metadata */
|
|
32
|
+
function getMetadata() internal pure returns (string memory, string[] memory) {
|
|
33
|
+
string[] memory _fieldNames = new string[](1);
|
|
34
|
+
_fieldNames[0] = "value";
|
|
35
|
+
return ("RouteAccess", _fieldNames);
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
/** Register the table's schema */
|
|
30
39
|
function registerSchema() internal {
|
|
31
40
|
StoreSwitch.registerSchema(_tableId, getSchema());
|
|
32
41
|
}
|
|
33
42
|
|
|
43
|
+
/** Set the table's metadata */
|
|
44
|
+
function setMetadata() internal {
|
|
45
|
+
(string memory _tableName, string[] memory _fieldNames) = getMetadata();
|
|
46
|
+
StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames);
|
|
47
|
+
}
|
|
48
|
+
|
|
34
49
|
/** Register the table's schema for the specified store */
|
|
35
50
|
function registerSchema(IStore _store) internal {
|
|
36
51
|
_store.registerSchema(_tableId, getSchema());
|
|
37
52
|
}
|
|
38
53
|
|
|
54
|
+
/** Set the table's metadata for the specified store */
|
|
55
|
+
function setMetadata(IStore _store) internal {
|
|
56
|
+
(string memory _tableName, string[] memory _fieldNames) = getMetadata();
|
|
57
|
+
_store.setMetadata(_tableId, _tableName, _fieldNames);
|
|
58
|
+
}
|
|
59
|
+
|
|
39
60
|
/** Get value */
|
|
40
61
|
function get(uint256 routeId, address caller) internal view returns (bool value) {
|
|
41
62
|
bytes32[] memory _primaryKeys = new bytes32[](2);
|
|
42
|
-
|
|
43
|
-
_primaryKeys[
|
|
44
|
-
|
|
45
|
-
_primaryKeys[1] = bytes32(bytes20(caller));
|
|
63
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
64
|
+
_primaryKeys[1] = bytes32(bytes20((caller)));
|
|
46
65
|
|
|
47
66
|
bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0);
|
|
48
|
-
return _toBool(uint8(Bytes.slice1(_blob, 0)));
|
|
67
|
+
return (_toBool(uint8(Bytes.slice1(_blob, 0))));
|
|
49
68
|
}
|
|
50
69
|
|
|
51
70
|
/** Get value from the specified store */
|
|
52
|
-
function get(
|
|
53
|
-
IStore _store,
|
|
54
|
-
uint256 routeId,
|
|
55
|
-
address caller
|
|
56
|
-
) internal view returns (bool value) {
|
|
71
|
+
function get(IStore _store, uint256 routeId, address caller) internal view returns (bool value) {
|
|
57
72
|
bytes32[] memory _primaryKeys = new bytes32[](2);
|
|
58
|
-
|
|
59
|
-
_primaryKeys[
|
|
60
|
-
|
|
61
|
-
_primaryKeys[1] = bytes32(bytes20(caller));
|
|
73
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
74
|
+
_primaryKeys[1] = bytes32(bytes20((caller)));
|
|
62
75
|
|
|
63
76
|
bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0);
|
|
64
|
-
return _toBool(uint8(Bytes.slice1(_blob, 0)));
|
|
77
|
+
return (_toBool(uint8(Bytes.slice1(_blob, 0))));
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
/** Set value */
|
|
68
|
-
function set(
|
|
69
|
-
uint256 routeId,
|
|
70
|
-
address caller,
|
|
71
|
-
bool value
|
|
72
|
-
) internal {
|
|
81
|
+
function set(uint256 routeId, address caller, bool value) internal {
|
|
73
82
|
bytes32[] memory _primaryKeys = new bytes32[](2);
|
|
83
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
84
|
+
_primaryKeys[1] = bytes32(bytes20((caller)));
|
|
74
85
|
|
|
75
|
-
_primaryKeys
|
|
76
|
-
|
|
77
|
-
_primaryKeys[1] = bytes32(bytes20(caller));
|
|
78
|
-
|
|
79
|
-
StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked(value));
|
|
86
|
+
StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value)));
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
/* Delete all data for given keys */
|
|
83
90
|
function deleteRecord(uint256 routeId, address caller) internal {
|
|
84
91
|
bytes32[] memory _primaryKeys = new bytes32[](2);
|
|
85
|
-
|
|
86
|
-
_primaryKeys[
|
|
87
|
-
|
|
88
|
-
_primaryKeys[1] = bytes32(bytes20(caller));
|
|
92
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
93
|
+
_primaryKeys[1] = bytes32(bytes20((caller)));
|
|
89
94
|
|
|
90
95
|
StoreSwitch.deleteRecord(_tableId, _primaryKeys);
|
|
91
96
|
}
|
|
@@ -1,43 +1,162 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity >=0.8.0;
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
|
5
|
+
|
|
6
|
+
// Import schema type
|
|
5
7
|
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol";
|
|
6
|
-
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
7
|
-
import { Schema } from "@latticexyz/store/src/Schema.sol";
|
|
8
|
-
import { SystemSchemaLib as SchemaLib } from "../schemas/SystemSchema.sol";
|
|
9
8
|
|
|
10
|
-
//
|
|
11
|
-
|
|
9
|
+
// Import store internals
|
|
10
|
+
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
11
|
+
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
12
|
+
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
|
13
|
+
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
|
14
|
+
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
|
15
|
+
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
|
16
|
+
import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol";
|
|
17
|
+
import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol";
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
uint256 constant _tableId = uint256(keccak256("/SystemTable"));
|
|
20
|
+
uint256 constant SystemTableTableId = _tableId;
|
|
15
21
|
|
|
16
22
|
library SystemTable {
|
|
23
|
+
/** Get the table's schema */
|
|
24
|
+
function getSchema() internal pure returns (Schema) {
|
|
25
|
+
SchemaType[] memory _schema = new SchemaType[](2);
|
|
26
|
+
_schema[0] = SchemaType.ADDRESS;
|
|
27
|
+
_schema[1] = SchemaType.BOOL;
|
|
28
|
+
|
|
29
|
+
return SchemaLib.encode(_schema);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Get the table's metadata */
|
|
33
|
+
function getMetadata() internal pure returns (string memory, string[] memory) {
|
|
34
|
+
string[] memory _fieldNames = new string[](2);
|
|
35
|
+
_fieldNames[0] = "system";
|
|
36
|
+
_fieldNames[1] = "publicAccess";
|
|
37
|
+
return ("SystemTable", _fieldNames);
|
|
38
|
+
}
|
|
39
|
+
|
|
17
40
|
/** Register the table's schema */
|
|
18
41
|
function registerSchema() internal {
|
|
19
|
-
|
|
42
|
+
StoreSwitch.registerSchema(_tableId, getSchema());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Set the table's metadata */
|
|
46
|
+
function setMetadata() internal {
|
|
47
|
+
(string memory _tableName, string[] memory _fieldNames) = getMetadata();
|
|
48
|
+
StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Register the table's schema for the specified store */
|
|
52
|
+
function registerSchema(IStore _store) internal {
|
|
53
|
+
_store.registerSchema(_tableId, getSchema());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Set the table's metadata for the specified store */
|
|
57
|
+
function setMetadata(IStore _store) internal {
|
|
58
|
+
(string memory _tableName, string[] memory _fieldNames) = getMetadata();
|
|
59
|
+
_store.setMetadata(_tableId, _tableName, _fieldNames);
|
|
20
60
|
}
|
|
21
61
|
|
|
22
|
-
|
|
23
|
-
|
|
62
|
+
/** Get system */
|
|
63
|
+
function getSystem(uint256 routeId) internal view returns (address system) {
|
|
64
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
65
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
66
|
+
|
|
67
|
+
bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0);
|
|
68
|
+
return (address(Bytes.slice20(_blob, 0)));
|
|
24
69
|
}
|
|
25
70
|
|
|
26
|
-
/**
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
71
|
+
/** Get system from the specified store */
|
|
72
|
+
function getSystem(IStore _store, uint256 routeId) internal view returns (address system) {
|
|
73
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
74
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
75
|
+
|
|
76
|
+
bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0);
|
|
77
|
+
return (address(Bytes.slice20(_blob, 0)));
|
|
33
78
|
}
|
|
34
79
|
|
|
35
|
-
/**
|
|
36
|
-
function
|
|
37
|
-
|
|
80
|
+
/** Set system */
|
|
81
|
+
function setSystem(uint256 routeId, address system) internal {
|
|
82
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
83
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
84
|
+
|
|
85
|
+
StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((system)));
|
|
38
86
|
}
|
|
39
87
|
|
|
40
|
-
|
|
41
|
-
|
|
88
|
+
/** Get publicAccess */
|
|
89
|
+
function getPublicAccess(uint256 routeId) internal view returns (bool publicAccess) {
|
|
90
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
91
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
92
|
+
|
|
93
|
+
bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1);
|
|
94
|
+
return (_toBool(uint8(Bytes.slice1(_blob, 0))));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Get publicAccess from the specified store */
|
|
98
|
+
function getPublicAccess(IStore _store, uint256 routeId) internal view returns (bool publicAccess) {
|
|
99
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
100
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
101
|
+
|
|
102
|
+
bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1);
|
|
103
|
+
return (_toBool(uint8(Bytes.slice1(_blob, 0))));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Set publicAccess */
|
|
107
|
+
function setPublicAccess(uint256 routeId, bool publicAccess) internal {
|
|
108
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
109
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
110
|
+
|
|
111
|
+
StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((publicAccess)));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Get the full data */
|
|
115
|
+
function get(uint256 routeId) internal view returns (address system, bool publicAccess) {
|
|
116
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
117
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
118
|
+
|
|
119
|
+
bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema());
|
|
120
|
+
return decode(_blob);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Get the full data from the specified store */
|
|
124
|
+
function get(IStore _store, uint256 routeId) internal view returns (address system, bool publicAccess) {
|
|
125
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
126
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
127
|
+
|
|
128
|
+
bytes memory _blob = _store.getRecord(_tableId, _primaryKeys);
|
|
129
|
+
return decode(_blob);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Set the full data using individual values */
|
|
133
|
+
function set(uint256 routeId, address system, bool publicAccess) internal {
|
|
134
|
+
bytes memory _data = abi.encodePacked(system, publicAccess);
|
|
135
|
+
|
|
136
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
137
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
138
|
+
|
|
139
|
+
StoreSwitch.setRecord(_tableId, _primaryKeys, _data);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Decode the tightly packed blob using this table's schema */
|
|
143
|
+
function decode(bytes memory _blob) internal pure returns (address system, bool publicAccess) {
|
|
144
|
+
system = (address(Bytes.slice20(_blob, 0)));
|
|
145
|
+
|
|
146
|
+
publicAccess = (_toBool(uint8(Bytes.slice1(_blob, 20))));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Delete all data for given keys */
|
|
150
|
+
function deleteRecord(uint256 routeId) internal {
|
|
151
|
+
bytes32[] memory _primaryKeys = new bytes32[](1);
|
|
152
|
+
_primaryKeys[0] = bytes32(uint256((routeId)));
|
|
153
|
+
|
|
154
|
+
StoreSwitch.deleteRecord(_tableId, _primaryKeys);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function _toBool(uint8 value) pure returns (bool result) {
|
|
159
|
+
assembly {
|
|
160
|
+
result := value
|
|
42
161
|
}
|
|
43
162
|
}
|