-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(world): add InstalledModules table to store installed modules
- Loading branch information
Showing
10 changed files
with
199 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
(test/World.t.sol) | Delete record [world.deleteRecord(namespace, file, singletonKey)]: 16038 | ||
(test/World.t.sol) | Push data to the table [world.pushToField(namespace, file, keyTuple, 0, encodedData)]: 96409 | ||
(test/World.t.sol) | Register a fallback system [bytes4 funcSelector1 = world.registerFunctionSelector(namespace, file, "", "")]: 80937 | ||
(test/World.t.sol) | Register a root fallback system [bytes4 funcSelector2 = world.registerRootFunctionSelector(namespace, file, worldFunc, 0)]: 72163 | ||
(test/World.t.sol) | Register a function selector [bytes4 functionSelector = world.registerFunctionSelector(namespace, file, "msgSender", "()")]: 101534 | ||
(test/World.t.sol) | Register a new namespace [world.registerNamespace("test")]: 151628 | ||
(test/World.t.sol) | Register a root function selector [bytes4 functionSelector = world.registerRootFunctionSelector(namespace, file, worldFunc, sysFunc)]: 96069 | ||
(test/World.t.sol) | Register a new table in the namespace [bytes32 tableSelector = world.registerTable(namespace, table, schema, defaultKeySchema)]: 252155 | ||
(test/World.t.sol) | Write data to a table field [world.setField(namespace, file, singletonKey, 0, abi.encodePacked(true))]: 44726 | ||
(test/World.t.sol) | Set metadata [world.setMetadata(namespace, file, tableName, fieldNames)]: 277162 | ||
(test/World.t.sol) | Delete record [world.deleteRecord(namespace, file, singletonKey)]: 16026 | ||
(test/World.t.sol) | Push data to the table [world.pushToField(namespace, file, keyTuple, 0, encodedData)]: 96397 | ||
(test/World.t.sol) | Register a fallback system [bytes4 funcSelector1 = world.registerFunctionSelector(namespace, file, "", "")]: 80940 | ||
(test/World.t.sol) | Register a root fallback system [bytes4 funcSelector2 = world.registerRootFunctionSelector(namespace, file, worldFunc, 0)]: 72166 | ||
(test/World.t.sol) | Register a function selector [bytes4 functionSelector = world.registerFunctionSelector(namespace, file, "msgSender", "()")]: 101537 | ||
(test/World.t.sol) | Register a new namespace [world.registerNamespace("test")]: 151631 | ||
(test/World.t.sol) | Register a root function selector [bytes4 functionSelector = world.registerRootFunctionSelector(namespace, file, worldFunc, sysFunc)]: 96072 | ||
(test/World.t.sol) | Register a new table in the namespace [bytes32 tableSelector = world.registerTable(namespace, table, schema, defaultKeySchema)]: 252158 | ||
(test/World.t.sol) | Write data to a table field [world.setField(namespace, file, singletonKey, 0, abi.encodePacked(true))]: 44714 | ||
(test/World.t.sol) | Set metadata [world.setMetadata(namespace, file, tableName, fieldNames)]: 277165 | ||
(test/World.t.sol) | Write data to the table [Bool.set(tableId, world, true)]: 42598 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
/* Autogenerated file. Do not edit manually. */ | ||
|
||
// Import schema type | ||
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; | ||
|
||
// Import store internals | ||
import { IStore } from "@latticexyz/store/src/IStore.sol"; | ||
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; | ||
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; | ||
import { Bytes } from "@latticexyz/store/src/Bytes.sol"; | ||
import { SliceLib } from "@latticexyz/store/src/Slice.sol"; | ||
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; | ||
import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; | ||
import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; | ||
|
||
uint256 constant _tableId = uint256(bytes32(abi.encodePacked(bytes16(""), bytes16("InstalledModules")))); | ||
uint256 constant InstalledModulesTableId = _tableId; | ||
|
||
struct InstalledModulesData { | ||
address moduleAddress; | ||
} | ||
|
||
library InstalledModules { | ||
/** Get the table's schema */ | ||
function getSchema() internal pure returns (Schema) { | ||
SchemaType[] memory _schema = new SchemaType[](1); | ||
_schema[0] = SchemaType.ADDRESS; | ||
|
||
return SchemaLib.encode(_schema); | ||
} | ||
|
||
function getKeySchema() internal pure returns (Schema) { | ||
SchemaType[] memory _schema = new SchemaType[](2); | ||
_schema[0] = SchemaType.BYTES16; | ||
_schema[1] = SchemaType.BYTES16; | ||
|
||
return SchemaLib.encode(_schema); | ||
} | ||
|
||
/** Get the table's metadata */ | ||
function getMetadata() internal pure returns (string memory, string[] memory) { | ||
string[] memory _fieldNames = new string[](1); | ||
_fieldNames[0] = "moduleAddress"; | ||
return ("InstalledModules", _fieldNames); | ||
} | ||
|
||
/** Register the table's schema */ | ||
function registerSchema() internal { | ||
StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); | ||
} | ||
|
||
/** Set the table's metadata */ | ||
function setMetadata() internal { | ||
(string memory _tableName, string[] memory _fieldNames) = getMetadata(); | ||
StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); | ||
} | ||
|
||
/** Get moduleAddress */ | ||
function getModuleAddress(bytes16 namespace, bytes16 mdouleName) internal view returns (address moduleAddress) { | ||
bytes32[] memory _primaryKeys = new bytes32[](2); | ||
_primaryKeys[0] = bytes32((namespace)); | ||
_primaryKeys[1] = bytes32((mdouleName)); | ||
|
||
bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); | ||
return (address(Bytes.slice20(_blob, 0))); | ||
} | ||
|
||
/** Set moduleAddress */ | ||
function setModuleAddress(bytes16 namespace, bytes16 mdouleName, address moduleAddress) internal { | ||
bytes32[] memory _primaryKeys = new bytes32[](2); | ||
_primaryKeys[0] = bytes32((namespace)); | ||
_primaryKeys[1] = bytes32((mdouleName)); | ||
|
||
StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((moduleAddress))); | ||
} | ||
|
||
/** Get the full data */ | ||
function get(bytes16 namespace, bytes16 mdouleName) internal view returns (InstalledModulesData memory _table) { | ||
bytes32[] memory _primaryKeys = new bytes32[](2); | ||
_primaryKeys[0] = bytes32((namespace)); | ||
_primaryKeys[1] = bytes32((mdouleName)); | ||
|
||
bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); | ||
return decode(_blob); | ||
} | ||
|
||
/** Set the full data using individual values */ | ||
function set(bytes16 namespace, bytes16 mdouleName, address moduleAddress) internal { | ||
bytes memory _data = abi.encodePacked(moduleAddress); | ||
|
||
bytes32[] memory _primaryKeys = new bytes32[](2); | ||
_primaryKeys[0] = bytes32((namespace)); | ||
_primaryKeys[1] = bytes32((mdouleName)); | ||
|
||
StoreSwitch.setRecord(_tableId, _primaryKeys, _data); | ||
} | ||
|
||
/** Set the full data using the data struct */ | ||
function set(bytes16 namespace, bytes16 mdouleName, InstalledModulesData memory _table) internal { | ||
set(namespace, mdouleName, _table.moduleAddress); | ||
} | ||
|
||
/** Decode the tightly packed blob using this table's schema */ | ||
function decode(bytes memory _blob) internal pure returns (InstalledModulesData memory _table) { | ||
_table.moduleAddress = (address(Bytes.slice20(_blob, 0))); | ||
} | ||
|
||
/* Delete all data for given keys */ | ||
function deleteRecord(bytes16 namespace, bytes16 mdouleName) internal { | ||
bytes32[] memory _primaryKeys = new bytes32[](2); | ||
_primaryKeys[0] = bytes32((namespace)); | ||
_primaryKeys[1] = bytes32((mdouleName)); | ||
|
||
StoreSwitch.deleteRecord(_tableId, _primaryKeys); | ||
} | ||
} |