diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index 8b6741473b..1b24600f46 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -5,6 +5,7 @@ import { StoreRead } from "@latticexyz/store/src/StoreRead.sol"; import { IStoreData } from "@latticexyz/store/src/IStore.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { System } from "./System.sol"; import { ResourceSelector } from "./ResourceSelector.sol"; @@ -68,12 +69,18 @@ contract World is StoreRead, IStoreData, IWorldKernel { * Write a record in the table at the given namespace and name. * Requires the caller to have access to the namespace or name. */ - function setRecord(bytes16 namespace, bytes16 name, bytes32[] calldata key, bytes calldata data) public virtual { + function setRecord( + bytes16 namespace, + bytes16 name, + bytes32[] calldata key, + bytes calldata data, + Schema valueSchema + ) public virtual { // Require access to the namespace or name bytes32 resourceSelector = AccessControl.requireAccess(namespace, name, msg.sender); // Set the record - StoreCore.setRecord(resourceSelector, key, data); + StoreCore.setRecord(resourceSelector, key, data, valueSchema); } /** @@ -85,13 +92,14 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes16 name, bytes32[] calldata key, uint8 schemaIndex, - bytes calldata data + bytes calldata data, + Schema valueSchema ) public virtual { // Require access to namespace or name bytes32 resourceSelector = AccessControl.requireAccess(namespace, name, msg.sender); // Set the field - StoreCore.setField(resourceSelector, key, schemaIndex, data); + StoreCore.setField(resourceSelector, key, schemaIndex, data, valueSchema); } /** @@ -103,13 +111,14 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes16 name, bytes32[] calldata key, uint8 schemaIndex, - bytes calldata dataToPush + bytes calldata dataToPush, + Schema valueSchema ) public virtual { // Require access to namespace or name bytes32 resourceSelector = AccessControl.requireAccess(namespace, name, msg.sender); // Push to the field - StoreCore.pushToField(resourceSelector, key, schemaIndex, dataToPush); + StoreCore.pushToField(resourceSelector, key, schemaIndex, dataToPush, valueSchema); } /** @@ -121,13 +130,14 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes16 name, bytes32[] calldata key, uint8 schemaIndex, - uint256 byteLengthToPop + uint256 byteLengthToPop, + Schema valueSchema ) public virtual { // Require access to namespace or name bytes32 resourceSelector = AccessControl.requireAccess(namespace, name, msg.sender); // Push to the field - StoreCore.popFromField(resourceSelector, key, schemaIndex, byteLengthToPop); + StoreCore.popFromField(resourceSelector, key, schemaIndex, byteLengthToPop, valueSchema); } /** @@ -140,25 +150,26 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32[] calldata key, uint8 schemaIndex, uint256 startByteIndex, - bytes calldata dataToSet + bytes calldata dataToSet, + Schema valueSchema ) public virtual { // Require access to namespace or name bytes32 resourceSelector = AccessControl.requireAccess(namespace, name, msg.sender); // Update data in the field - StoreCore.updateInField(resourceSelector, key, schemaIndex, startByteIndex, dataToSet); + StoreCore.updateInField(resourceSelector, key, schemaIndex, startByteIndex, dataToSet, valueSchema); } /** * Delete a record in the table at the given namespace and name. * Requires the caller to have access to the namespace or name. */ - function deleteRecord(bytes16 namespace, bytes16 name, bytes32[] calldata key) public virtual { + function deleteRecord(bytes16 namespace, bytes16 name, bytes32[] calldata key, Schema valueSchema) public virtual { // Require access to namespace or name bytes32 resourceSelector = AccessControl.requireAccess(namespace, name, msg.sender); // Delete the record - StoreCore.deleteRecord(resourceSelector, key); + StoreCore.deleteRecord(resourceSelector, key, valueSchema); } /************************************************************************ @@ -172,8 +183,8 @@ contract World is StoreRead, IStoreData, IWorldKernel { * This overload exists to conform with the `IStore` interface. * Access is checked based on the namespace or name (encoded in the tableId). */ - function setRecord(bytes32 tableId, bytes32[] calldata key, bytes calldata data) public virtual { - setRecord(tableId.getNamespace(), tableId.getName(), key, data); + function setRecord(bytes32 tableId, bytes32[] calldata key, bytes calldata data, Schema valueSchema) public virtual { + setRecord(tableId.getNamespace(), tableId.getName(), key, data, valueSchema); } /** @@ -185,9 +196,10 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32 tableId, bytes32[] calldata key, uint8 schemaIndex, - bytes calldata data + bytes calldata data, + Schema valueSchema ) public virtual override { - setField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, data); + setField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, data, valueSchema); } /** @@ -199,9 +211,10 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32 tableId, bytes32[] calldata key, uint8 schemaIndex, - bytes calldata dataToPush + bytes calldata dataToPush, + Schema valueSchema ) public override { - pushToField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, dataToPush); + pushToField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, dataToPush, valueSchema); } /** @@ -213,9 +226,10 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32 tableId, bytes32[] calldata key, uint8 schemaIndex, - uint256 byteLengthToPop + uint256 byteLengthToPop, + Schema valueSchema ) public override { - popFromField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, byteLengthToPop); + popFromField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, byteLengthToPop, valueSchema); } /** @@ -228,9 +242,10 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32[] calldata key, uint8 schemaIndex, uint256 startByteIndex, - bytes calldata dataToSet + bytes calldata dataToSet, + Schema valueSchema ) public virtual { - updateInField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, startByteIndex, dataToSet); + updateInField(tableId.getNamespace(), tableId.getName(), key, schemaIndex, startByteIndex, dataToSet, valueSchema); } /** @@ -238,8 +253,8 @@ contract World is StoreRead, IStoreData, IWorldKernel { * This overload exists to conform with the `IStore` interface. * Access is checked based on the namespace or name (encoded in the tableId). */ - function deleteRecord(bytes32 tableId, bytes32[] calldata key) public virtual override { - deleteRecord(tableId.getNamespace(), tableId.getName(), key); + function deleteRecord(bytes32 tableId, bytes32[] calldata key, Schema valueSchema) public virtual override { + deleteRecord(tableId.getNamespace(), tableId.getName(), key, valueSchema); } /************************************************************************ diff --git a/packages/world/src/interfaces/IWorldEphemeral.sol b/packages/world/src/interfaces/IWorldEphemeral.sol index a1d36fe676..7616962411 100644 --- a/packages/world/src/interfaces/IWorldEphemeral.sol +++ b/packages/world/src/interfaces/IWorldEphemeral.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; +import { Schema } from "@latticexyz/store/src/Schema.sol"; + /** * Necessary in addition to `IStoreEphemeral` * because 2 functions with the same name need 2 separate interfaces to allow referencing their selector @@ -10,5 +12,11 @@ interface IWorldEphemeral { * Emit the ephemeral event without modifying storage at the given namespace and name. * Requires the caller to have access to the namespace or name. */ - function emitEphemeralRecord(bytes16 namespace, bytes16 name, bytes32[] calldata key, bytes calldata data) external; + function emitEphemeralRecord( + bytes16 namespace, + bytes16 name, + bytes32[] calldata key, + bytes calldata data, + Schema valueSchema + ) external; } diff --git a/packages/world/src/interfaces/IWorldKernel.sol b/packages/world/src/interfaces/IWorldKernel.sol index 03c3258431..7890c7bfd1 100644 --- a/packages/world/src/interfaces/IWorldKernel.sol +++ b/packages/world/src/interfaces/IWorldKernel.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { IWorldErrors } from "./IWorldErrors.sol"; import { IModule } from "./IModule.sol"; @@ -14,7 +15,13 @@ interface IWorldData { * Write a record in the table at the given namespace and name. * Requires the caller to have access to the namespace or name. */ - function setRecord(bytes16 namespace, bytes16 name, bytes32[] calldata key, bytes calldata data) external; + function setRecord( + bytes16 namespace, + bytes16 name, + bytes32[] calldata key, + bytes calldata data, + Schema valueSchema + ) external; /** * Write a field in the table at the given namespace and name. @@ -25,7 +32,8 @@ interface IWorldData { bytes16 name, bytes32[] calldata key, uint8 schemaIndex, - bytes calldata data + bytes calldata data, + Schema valueSchema ) external; /** @@ -37,7 +45,8 @@ interface IWorldData { bytes16 name, bytes32[] calldata key, uint8 schemaIndex, - bytes calldata dataToPush + bytes calldata dataToPush, + Schema valueSchema ) external; /** @@ -49,7 +58,8 @@ interface IWorldData { bytes16 name, bytes32[] calldata key, uint8 schemaIndex, - uint256 byteLengthToPop + uint256 byteLengthToPop, + Schema valueSchema ) external; /** @@ -62,14 +72,15 @@ interface IWorldData { bytes32[] calldata key, uint8 schemaIndex, uint256 startByteIndex, - bytes calldata dataToSet + bytes calldata dataToSet, + Schema valueSchema ) external; /** * Delete a record in the table at the given namespace and name. * Requires the caller to have access to the namespace or name. */ - function deleteRecord(bytes16 namespace, bytes16 name, bytes32[] calldata key) external; + function deleteRecord(bytes16 namespace, bytes16 name, bytes32[] calldata key, Schema valueSchema) external; } interface IWorldModuleInstallation { diff --git a/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol b/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol index 77156edb4f..b20fe81f57 100644 --- a/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol +++ b/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol @@ -2,6 +2,7 @@ pragma solidity >=0.8.0; import { IStoreEphemeral } from "@latticexyz/store/src/IStore.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { IModule } from "../../../interfaces/IModule.sol"; import { IWorldEphemeral } from "../../../interfaces/IWorldEphemeral.sol"; import { System } from "../../../System.sol"; @@ -23,13 +24,14 @@ contract EphemeralRecordSystem is IStoreEphemeral, IWorldEphemeral, System { bytes16 namespace, bytes16 name, bytes32[] calldata key, - bytes calldata data + bytes calldata data, + Schema valueSchema ) public virtual { // Require access to the namespace or name bytes32 resourceSelector = AccessControl.requireAccess(namespace, name, msg.sender); // Set the record - StoreCore.emitEphemeralRecord(resourceSelector, key, data); + StoreCore.emitEphemeralRecord(resourceSelector, key, data, valueSchema); } /** @@ -37,7 +39,12 @@ contract EphemeralRecordSystem is IStoreEphemeral, IWorldEphemeral, System { * This overload exists to conform with the `IStore` interface. * Access is checked based on the namespace or name (encoded in the tableId). */ - function emitEphemeralRecord(bytes32 tableId, bytes32[] calldata key, bytes calldata data) public virtual { - emitEphemeralRecord(tableId.getNamespace(), tableId.getName(), key, data); + function emitEphemeralRecord( + bytes32 tableId, + bytes32[] calldata key, + bytes calldata data, + Schema valueSchema + ) public virtual { + emitEphemeralRecord(tableId.getNamespace(), tableId.getName(), key, data, valueSchema); } } diff --git a/packages/world/src/modules/core/tables/FunctionSelectors.sol b/packages/world/src/modules/core/tables/FunctionSelectors.sol index 618cc9ab0c..530fd6a5fd 100644 --- a/packages/world/src/modules/core/tables/FunctionSelectors.sol +++ b/packages/world/src/modules/core/tables/FunctionSelectors.sol @@ -74,7 +74,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (Bytes.slice16(_blob, 0)); } @@ -83,7 +83,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (Bytes.slice16(_blob, 0)); } @@ -92,7 +92,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((namespace))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((namespace)), getSchema()); } /** Set namespace (using the specified store) */ @@ -100,7 +100,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((namespace))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((namespace)), getSchema()); } /** Get name */ @@ -108,7 +108,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getSchema()); return (Bytes.slice16(_blob, 0)); } @@ -117,7 +117,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getSchema()); return (Bytes.slice16(_blob, 0)); } @@ -126,7 +126,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((name))); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((name)), getSchema()); } /** Set name (using the specified store) */ @@ -134,7 +134,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((name))); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((name)), getSchema()); } /** Get systemFunctionSelector */ @@ -142,7 +142,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getSchema()); return (Bytes.slice4(_blob, 0)); } @@ -154,7 +154,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getSchema()); return (Bytes.slice4(_blob, 0)); } @@ -163,7 +163,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((systemFunctionSelector))); + StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((systemFunctionSelector)), getSchema()); } /** Set systemFunctionSelector (using the specified store) */ @@ -171,7 +171,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((systemFunctionSelector))); + _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((systemFunctionSelector)), getSchema()); } /** Get the full data */ @@ -204,7 +204,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.setRecord(_tableId, _keyTuple, _data); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Set the full data using individual values (using the specified store) */ @@ -220,7 +220,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.setRecord(_tableId, _keyTuple, _data); + _store.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Decode the tightly packed blob using this table's schema */ @@ -250,7 +250,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -258,6 +258,6 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/core/tables/ResourceType.sol b/packages/world/src/modules/core/tables/ResourceType.sol index 3d33df38a1..1a850fc38b 100644 --- a/packages/world/src/modules/core/tables/ResourceType.sol +++ b/packages/world/src/modules/core/tables/ResourceType.sol @@ -73,7 +73,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return Resource(uint8(Bytes.slice1(_blob, 0))); } @@ -82,7 +82,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return Resource(uint8(Bytes.slice1(_blob, 0))); } @@ -91,7 +91,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), getSchema()); } /** Set resourceType (using the specified store) */ @@ -99,7 +99,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -118,7 +118,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -126,6 +126,6 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/core/tables/SystemHooks.sol b/packages/world/src/modules/core/tables/SystemHooks.sol index 8b2300a63d..cdbe5e6c54 100644 --- a/packages/world/src/modules/core/tables/SystemHooks.sol +++ b/packages/world/src/modules/core/tables/SystemHooks.sol @@ -70,7 +70,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -79,7 +79,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -88,7 +88,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getSchema()); } /** Set value (using the specified store) */ @@ -96,7 +96,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getSchema()); } /** Get the length of value */ @@ -140,7 +140,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Push an element to value (using the specified store) */ @@ -148,7 +148,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Pop an element from value */ @@ -156,7 +156,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 20); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 20, getSchema()); } /** Pop an element from value (using the specified store) */ @@ -164,7 +164,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.popFromField(_tableId, _keyTuple, 0, 20); + _store.popFromField(_tableId, _keyTuple, 0, 20, getSchema()); } /** Update an element of value at `_index` */ @@ -172,7 +172,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getSchema()); } /** Update an element of value (using the specified store) at `_index` */ @@ -180,7 +180,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -203,7 +203,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -211,6 +211,6 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/core/tables/SystemRegistry.sol b/packages/world/src/modules/core/tables/SystemRegistry.sol index 1dd6e9bcad..6c90b48353 100644 --- a/packages/world/src/modules/core/tables/SystemRegistry.sol +++ b/packages/world/src/modules/core/tables/SystemRegistry.sol @@ -70,7 +70,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (Bytes.slice32(_blob, 0)); } @@ -79,7 +79,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (Bytes.slice32(_blob, 0)); } @@ -88,7 +88,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getSchema()); } /** Set resourceSelector (using the specified store) */ @@ -96,7 +96,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -115,7 +115,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -123,6 +123,6 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/core/tables/Systems.sol b/packages/world/src/modules/core/tables/Systems.sol index 16a250d86e..c8fbf75dba 100644 --- a/packages/world/src/modules/core/tables/Systems.sol +++ b/packages/world/src/modules/core/tables/Systems.sol @@ -72,7 +72,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (address(Bytes.slice20(_blob, 0))); } @@ -81,7 +81,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (address(Bytes.slice20(_blob, 0))); } @@ -90,7 +90,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((system))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((system)), getSchema()); } /** Set system (using the specified store) */ @@ -98,7 +98,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((system))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((system)), getSchema()); } /** Get publicAccess */ @@ -106,7 +106,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -115,7 +115,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -124,7 +124,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess))); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), getSchema()); } /** Set publicAccess (using the specified store) */ @@ -132,7 +132,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess))); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), getSchema()); } /** Get the full data */ @@ -160,7 +160,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setRecord(_tableId, _keyTuple, _data); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Set the full data using individual values (using the specified store) */ @@ -170,7 +170,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setRecord(_tableId, _keyTuple, _data); + _store.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Decode the tightly packed blob using this table's schema */ @@ -196,7 +196,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -204,7 +204,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/keysintable/KeysInTableHook.sol b/packages/world/src/modules/keysintable/KeysInTableHook.sol index 747b5a709b..f2c4522de5 100644 --- a/packages/world/src/modules/keysintable/KeysInTableHook.sol +++ b/packages/world/src/modules/keysintable/KeysInTableHook.sol @@ -2,6 +2,7 @@ pragma solidity >=0.8.0; import { IStoreHook } from "@latticexyz/store/src/IStore.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { KeysInTable } from "./tables/KeysInTable.sol"; import { UsedKeysIndex } from "./tables/UsedKeysIndex.sol"; @@ -39,17 +40,17 @@ contract KeysInTableHook is IStoreHook { } } - function onSetRecord(bytes32 table, bytes32[] memory key, bytes memory) public { + function onSetRecord(bytes32 table, bytes32[] memory key, bytes memory, Schema) public { handleSet(table, key); } - function onBeforeSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory) public {} + function onBeforeSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory, Schema) public {} - function onAfterSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory) public { + function onAfterSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory, Schema) public { handleSet(table, key); } - function onDeleteRecord(bytes32 tableId, bytes32[] memory key) public { + function onDeleteRecord(bytes32 tableId, bytes32[] memory key, Schema) public { bytes32 keysHash = keccak256(abi.encode(key)); (bool has, uint40 index) = UsedKeysIndex.get(tableId, keysHash); diff --git a/packages/world/src/modules/keysintable/tables/KeysInTable.sol b/packages/world/src/modules/keysintable/tables/KeysInTable.sol index 274a4b14aa..fbfabc0017 100644 --- a/packages/world/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world/src/modules/keysintable/tables/KeysInTable.sol @@ -86,7 +86,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -95,7 +95,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -104,7 +104,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0))); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0)), getSchema()); } /** Set keys0 (using the specified store) */ @@ -112,7 +112,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0))); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0)), getSchema()); } /** Get the length of keys0 */ @@ -156,7 +156,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Push an element to keys0 (using the specified store) */ @@ -164,7 +164,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Pop an element from keys0 */ @@ -172,7 +172,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getSchema()); } /** Pop an element from keys0 (using the specified store) */ @@ -180,7 +180,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 0, 32); + _store.popFromField(_tableId, _keyTuple, 0, 32, getSchema()); } /** Update an element of keys0 at `_index` */ @@ -188,7 +188,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Update an element of keys0 (using the specified store) at `_index` */ @@ -196,7 +196,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Get keys1 */ @@ -204,7 +204,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -213,7 +213,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -222,7 +222,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1))); + StoreSwitch.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1)), getSchema()); } /** Set keys1 (using the specified store) */ @@ -230,7 +230,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1))); + _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1)), getSchema()); } /** Get the length of keys1 */ @@ -274,7 +274,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getSchema()); } /** Push an element to keys1 (using the specified store) */ @@ -282,7 +282,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getSchema()); } /** Pop an element from keys1 */ @@ -290,7 +290,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 1, 32); + StoreSwitch.popFromField(_tableId, _keyTuple, 1, 32, getSchema()); } /** Pop an element from keys1 (using the specified store) */ @@ -298,7 +298,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 1, 32); + _store.popFromField(_tableId, _keyTuple, 1, 32, getSchema()); } /** Update an element of keys1 at `_index` */ @@ -306,7 +306,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Update an element of keys1 (using the specified store) at `_index` */ @@ -314,7 +314,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Get keys2 */ @@ -322,7 +322,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -331,7 +331,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -340,7 +340,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2))); + StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2)), getSchema()); } /** Set keys2 (using the specified store) */ @@ -348,7 +348,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2))); + _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2)), getSchema()); } /** Get the length of keys2 */ @@ -392,7 +392,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getSchema()); } /** Push an element to keys2 (using the specified store) */ @@ -400,7 +400,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getSchema()); } /** Pop an element from keys2 */ @@ -408,7 +408,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 2, 32); + StoreSwitch.popFromField(_tableId, _keyTuple, 2, 32, getSchema()); } /** Pop an element from keys2 (using the specified store) */ @@ -416,7 +416,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 2, 32); + _store.popFromField(_tableId, _keyTuple, 2, 32, getSchema()); } /** Update an element of keys2 at `_index` */ @@ -424,7 +424,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Update an element of keys2 (using the specified store) at `_index` */ @@ -432,7 +432,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Get keys3 */ @@ -440,7 +440,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -449,7 +449,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -458,7 +458,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3))); + StoreSwitch.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3)), getSchema()); } /** Set keys3 (using the specified store) */ @@ -466,7 +466,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3))); + _store.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3)), getSchema()); } /** Get the length of keys3 */ @@ -510,7 +510,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getSchema()); } /** Push an element to keys3 (using the specified store) */ @@ -518,7 +518,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getSchema()); } /** Pop an element from keys3 */ @@ -526,7 +526,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 3, 32); + StoreSwitch.popFromField(_tableId, _keyTuple, 3, 32, getSchema()); } /** Pop an element from keys3 (using the specified store) */ @@ -534,7 +534,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 3, 32); + _store.popFromField(_tableId, _keyTuple, 3, 32, getSchema()); } /** Update an element of keys3 at `_index` */ @@ -542,7 +542,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Update an element of keys3 (using the specified store) at `_index` */ @@ -550,7 +550,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Get keys4 */ @@ -558,7 +558,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -567,7 +567,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -576,7 +576,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4))); + StoreSwitch.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4)), getSchema()); } /** Set keys4 (using the specified store) */ @@ -584,7 +584,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4))); + _store.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4)), getSchema()); } /** Get the length of keys4 */ @@ -628,7 +628,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getSchema()); } /** Push an element to keys4 (using the specified store) */ @@ -636,7 +636,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getSchema()); } /** Pop an element from keys4 */ @@ -644,7 +644,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 4, 32); + StoreSwitch.popFromField(_tableId, _keyTuple, 4, 32, getSchema()); } /** Pop an element from keys4 (using the specified store) */ @@ -652,7 +652,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 4, 32); + _store.popFromField(_tableId, _keyTuple, 4, 32, getSchema()); } /** Update an element of keys4 at `_index` */ @@ -660,7 +660,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Update an element of keys4 (using the specified store) at `_index` */ @@ -668,7 +668,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Get the full data */ @@ -703,7 +703,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setRecord(_tableId, _keyTuple, _data); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Set the full data using individual values (using the specified store) */ @@ -721,7 +721,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setRecord(_tableId, _keyTuple, _data); + _store.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Set the full data using the data struct */ @@ -805,7 +805,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -813,6 +813,6 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol index 8378c830cb..84cddae279 100644 --- a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol +++ b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol @@ -74,7 +74,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -84,7 +84,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -94,7 +94,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((has))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((has)), getSchema()); } /** Set has (using the specified store) */ @@ -103,7 +103,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((has))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((has)), getSchema()); } /** Get index */ @@ -112,7 +112,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getSchema()); return (uint40(Bytes.slice5(_blob, 0))); } @@ -122,7 +122,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getSchema()); return (uint40(Bytes.slice5(_blob, 0))); } @@ -132,7 +132,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((index))); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((index)), getSchema()); } /** Set index (using the specified store) */ @@ -141,7 +141,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((index))); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((index)), getSchema()); } /** Get the full data */ @@ -172,7 +172,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.setRecord(_tableId, _keyTuple, _data); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Set the full data using individual values (using the specified store) */ @@ -183,7 +183,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.setRecord(_tableId, _keyTuple, _data); + _store.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Decode the tightly packed blob using this table's schema */ @@ -211,7 +211,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -220,7 +220,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol b/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol index 82d931d6ce..ce53f7792f 100644 --- a/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol +++ b/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol @@ -3,6 +3,7 @@ pragma solidity >=0.8.0; import { IStoreHook } from "@latticexyz/store/src/IStore.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; @@ -29,11 +30,11 @@ contract KeysWithValueHook is IStoreHook { return IBaseWorld(StoreSwitch.getStoreAddress()); } - function onSetRecord(bytes32 sourceTableId, bytes32[] memory key, bytes memory data) public { + function onSetRecord(bytes32 sourceTableId, bytes32[] memory key, bytes memory data, Schema valueSchema) public { bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); // Get the previous value - bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key)); + bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); // Remove the key from the list of keys with the previous value _removeKeyFromList(targetTableId, key[0], previousValue); @@ -42,23 +43,35 @@ contract KeysWithValueHook is IStoreHook { KeysWithValue.push(targetTableId, keccak256(data), key[0]); } - function onBeforeSetField(bytes32 sourceTableId, bytes32[] memory key, uint8, bytes memory) public { + function onBeforeSetField( + bytes32 sourceTableId, + bytes32[] memory key, + uint8, + bytes memory, + Schema valueSchema + ) public { // Remove the key from the list of keys with the previous value - bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key)); + bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); _removeKeyFromList(targetTableId, key[0], previousValue); } - function onAfterSetField(bytes32 sourceTableId, bytes32[] memory key, uint8, bytes memory) public { + function onAfterSetField( + bytes32 sourceTableId, + bytes32[] memory key, + uint8, + bytes memory, + Schema valueSchema + ) public { // Add the key to the list of keys with the new value - bytes32 newValue = keccak256(_world().getRecord(sourceTableId, key)); + bytes32 newValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); KeysWithValue.push(targetTableId, newValue, key[0]); } - function onDeleteRecord(bytes32 sourceTableId, bytes32[] memory key) public { + function onDeleteRecord(bytes32 sourceTableId, bytes32[] memory key, Schema valueSchema) public { // Remove the key from the list of keys with the previous value - bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key)); + bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); _removeKeyFromList(targetTableId, key[0], previousValue); } diff --git a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol index 209ef4ee8d..ca318fe214 100644 --- a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -67,7 +67,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -80,7 +80,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -89,7 +89,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue))); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), getSchema()); } /** Set keysWithValue (using the specified store) */ @@ -97,7 +97,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue))); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), getSchema()); } /** Get the length of keysWithValue */ @@ -141,7 +141,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Push an element to keysWithValue (using the specified store) */ @@ -149,7 +149,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Pop an element from keysWithValue */ @@ -157,7 +157,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getSchema()); } /** Pop an element from keysWithValue (using the specified store) */ @@ -165,7 +165,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.popFromField(_tableId, _keyTuple, 0, 32); + _store.popFromField(_tableId, _keyTuple, 0, 32, getSchema()); } /** Update an element of keysWithValue at `_index` */ @@ -173,7 +173,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Update an element of keysWithValue (using the specified store) at `_index` */ @@ -181,7 +181,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -204,7 +204,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -212,6 +212,6 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/modules/snapsync/SnapSyncSystem.sol b/packages/world/src/modules/snapsync/SnapSyncSystem.sol index 4657e4060e..720095d4cb 100644 --- a/packages/world/src/modules/snapsync/SnapSyncSystem.sol +++ b/packages/world/src/modules/snapsync/SnapSyncSystem.sol @@ -18,8 +18,8 @@ contract SnapSyncSystem is System { ) public view virtual returns (SyncRecord[] memory records) { records = new SyncRecord[](limit); - Schema schema = StoreSwitch.getKeySchema(tableId); - uint256 numFields = schema.numFields(); + Schema keySchema = StoreSwitch.getKeySchema(tableId); + uint256 numFields = keySchema.numFields(); for (uint256 i = offset; i < limit + offset; i++) { bytes32[] memory keyTuple = new bytes32[](numFields); @@ -40,7 +40,8 @@ contract SnapSyncSystem is System { } } - bytes memory value = StoreSwitch.getRecord(tableId, keyTuple); + Schema valueSchema = StoreSwitch.getSchema(tableId); + bytes memory value = StoreSwitch.getRecord(tableId, keyTuple, valueSchema); records[i] = SyncRecord({ tableId: tableId, keyTuple: keyTuple, value: value }); } } diff --git a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol index d094fad3bc..b346e586e9 100644 --- a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -65,7 +65,7 @@ library UniqueEntity { function get(bytes32 _tableId) internal view returns (uint256 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -73,7 +73,7 @@ library UniqueEntity { function get(IStore _store, bytes32 _tableId) internal view returns (uint256 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -81,14 +81,14 @@ library UniqueEntity { function set(bytes32 _tableId, uint256 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getSchema()); } /** Set value (using the specified store) */ function set(IStore _store, bytes32 _tableId, uint256 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -105,13 +105,13 @@ library UniqueEntity { function deleteRecord(bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store, bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/tables/InstalledModules.sol b/packages/world/src/tables/InstalledModules.sol index 136d4e6909..6595d0f7fa 100644 --- a/packages/world/src/tables/InstalledModules.sol +++ b/packages/world/src/tables/InstalledModules.sol @@ -76,7 +76,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (address(Bytes.slice20(_blob, 0))); } @@ -90,7 +90,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (address(Bytes.slice20(_blob, 0))); } @@ -100,7 +100,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), getSchema()); } /** Set moduleAddress (using the specified store) */ @@ -109,7 +109,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), getSchema()); } /** Get the full data */ @@ -144,7 +144,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - StoreSwitch.setRecord(_tableId, _keyTuple, _data); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Set the full data using individual values (using the specified store) */ @@ -155,7 +155,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - _store.setRecord(_tableId, _keyTuple, _data); + _store.setRecord(_tableId, _keyTuple, _data, getSchema()); } /** Set the full data using the data struct */ @@ -194,7 +194,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -203,6 +203,6 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/tables/NamespaceOwner.sol b/packages/world/src/tables/NamespaceOwner.sol index 9e5a75ed00..2f7dfea5fe 100644 --- a/packages/world/src/tables/NamespaceOwner.sol +++ b/packages/world/src/tables/NamespaceOwner.sol @@ -70,7 +70,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (address(Bytes.slice20(_blob, 0))); } @@ -79,7 +79,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (address(Bytes.slice20(_blob, 0))); } @@ -88,7 +88,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), getSchema()); } /** Set owner (using the specified store) */ @@ -96,7 +96,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -115,7 +115,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -123,6 +123,6 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/src/tables/ResourceAccess.sol b/packages/world/src/tables/ResourceAccess.sol index 294106c30e..936f5e9f9a 100644 --- a/packages/world/src/tables/ResourceAccess.sol +++ b/packages/world/src/tables/ResourceAccess.sol @@ -72,7 +72,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -82,7 +82,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -92,7 +92,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((access))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), getSchema()); } /** Set access (using the specified store) */ @@ -101,7 +101,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((access))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -122,7 +122,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -131,7 +131,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/test/KeysInTableModule.t.sol b/packages/world/test/KeysInTableModule.t.sol index dd6b057bc5..b330eaaa0c 100644 --- a/packages/world/test/KeysInTableModule.t.sol +++ b/packages/world/test/KeysInTableModule.t.sol @@ -86,7 +86,7 @@ contract KeysInTableModuleTest is Test, GasReporter { bytes32[] memory keyTuple = new bytes32[](0); - world.setRecord(namespace, singletonName, keyTuple, abi.encodePacked(val1)); + world.setRecord(namespace, singletonName, keyTuple, abi.encodePacked(val1), tableSchema); // Get the list of keys in this target table bytes32[][] memory keysInTable = getKeysInTable(world, singletonTableId); @@ -103,7 +103,7 @@ contract KeysInTableModuleTest is Test, GasReporter { keyTuple[1] = "two"; keyTuple[2] = "three"; - world.setRecord(namespace, compositeName, keyTuple, abi.encodePacked(val1)); + world.setRecord(namespace, compositeName, keyTuple, abi.encodePacked(val1), tableSchema); // Get the list of keys in this target table bytes32[][] memory keysInTable = getKeysInTable(world, compositeTableId); @@ -128,7 +128,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed"); - world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value)); + world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value), tableSchema); endGasReport(); // Get the list of keys in this target table @@ -147,7 +147,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed (first)"); - world.setRecord(namespace, name, keyTuple, abi.encodePacked(value1)); + world.setRecord(namespace, name, keyTuple, abi.encodePacked(value1), tableSchema); endGasReport(); // Get the list of keys in the first target table @@ -167,7 +167,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed (second)"); - world.setRecord(namespace, sourceFile2, keyTuple, abi.encodePacked(value2)); + world.setRecord(namespace, sourceFile2, keyTuple, abi.encodePacked(value2), tableSchema); endGasReport(); // Get the list of keys in the second target table @@ -187,7 +187,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table - world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value1)); + world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value1), tableSchema); // Get the list of keys in the target table bytes32[][] memory keysInTable = getKeysInTable(world, tableId); @@ -197,7 +197,7 @@ contract KeysInTableModuleTest is Test, GasReporter { assertEq(keysInTable[0][0], key1, "2"); // Set another key with the same value - world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value1)); + world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value1), tableSchema); // Get the list of keys in the target table keysInTable = getKeysInTable(world, tableId); @@ -209,7 +209,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Change the value of the first key startGasReport("change a record on a table with keysInTableModule installed"); - world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value2)); + world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value2), tableSchema); endGasReport(); // Get the list of keys in the target table @@ -222,7 +222,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Delete the first key startGasReport("delete a record on a table with keysInTableModule installed"); - world.deleteRecord(namespace, name, keyTuple1); + world.deleteRecord(namespace, name, keyTuple1, tableSchema); endGasReport(); // Get the list of keys in the target table @@ -252,7 +252,7 @@ contract KeysInTableModuleTest is Test, GasReporter { keyTupleB[2] = "charlie"; // Set a value in the source table - world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value1)); + world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value1), tableSchema); // Get the list of keys in the target table bytes32[][] memory keysInTable = getKeysInTable(world, compositeTableId); @@ -264,7 +264,7 @@ contract KeysInTableModuleTest is Test, GasReporter { } // Set another key with the same value - world.setRecord(namespace, compositeName, keyTupleB, abi.encodePacked(value1)); + world.setRecord(namespace, compositeName, keyTupleB, abi.encodePacked(value1), tableSchema); // Get the list of keys in the target table keysInTable = getKeysInTable(world, compositeTableId); @@ -280,7 +280,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Change the value of the first key startGasReport("change a composite record on a table with keysInTableModule installed"); - world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value2)); + world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value2), tableSchema); endGasReport(); // Get the list of keys in the target table @@ -297,7 +297,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Delete the first key startGasReport("delete a composite record on a table with keysInTableModule installed"); - world.deleteRecord(namespace, compositeName, keyTupleA); + world.deleteRecord(namespace, compositeName, keyTupleA, tableSchema); endGasReport(); // Get the list of keys in the target table @@ -315,7 +315,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a field on a table with keysInTableModule installed"); - world.setField(namespace, name, keyTuple1, 0, abi.encodePacked(value1)); + world.setField(namespace, name, keyTuple1, 0, abi.encodePacked(value1), tableSchema); endGasReport(); // Get the list of keys in the target table @@ -327,7 +327,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Change the value using setField startGasReport("change a field on a table with keysInTableModule installed"); - world.setField(namespace, name, keyTuple1, 0, abi.encodePacked(value2)); + world.setField(namespace, name, keyTuple1, 0, abi.encodePacked(value2), tableSchema); endGasReport(); // Get the list of keys in the target table @@ -342,7 +342,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table - world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value1)); + world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value1), tableSchema); startGasReport("Get list of keys in a given table"); bytes32[][] memory keysInTable = getKeysInTable(world, tableId); @@ -353,7 +353,7 @@ contract KeysInTableModuleTest is Test, GasReporter { assertEq(keysInTable[0][0], key1); // Set another key with a different value - world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value2)); + world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value2), tableSchema); // Get the list of keys in the target table keysInTable = getKeysInTable(world, tableId); @@ -368,14 +368,14 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Add 3 values - world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value)); - world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value)); - world.setRecord(namespace, name, keyTuple3, abi.encodePacked(value)); + world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value), tableSchema); + world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value), tableSchema); + world.setRecord(namespace, name, keyTuple3, abi.encodePacked(value), tableSchema); // Remove 2, starting from the middle // This tests that KeysInTable correctly tracks swaps indexes - world.deleteRecord(namespace, name, keyTuple2); - world.deleteRecord(namespace, name, keyTuple3); + world.deleteRecord(namespace, name, keyTuple2, tableSchema); + world.deleteRecord(namespace, name, keyTuple3, tableSchema); // Get the list of keys in the target table bytes32[][] memory keysInTable = getKeysInTable(world, tableId); diff --git a/packages/world/test/KeysWithValueModule.t.sol b/packages/world/test/KeysWithValueModule.t.sol index 0a063c41ac..5ab148ca00 100644 --- a/packages/world/test/KeysWithValueModule.t.sol +++ b/packages/world/test/KeysWithValueModule.t.sol @@ -68,7 +68,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value = 1; startGasReport("set a record on a table with KeysWithValueModule installed"); - world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value)); + world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value), sourceTableSchema); endGasReport(); // Get the list of entities with this value from the target table @@ -85,7 +85,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { // Set a value in the source table uint256 value1 = 1; - world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value1)); + world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value1), sourceTableSchema); // Get the list of entities with value1 from the target table bytes32[] memory keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encode(value1))); @@ -95,7 +95,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { assertEq(keysWithValue[0], key1, "2"); // Set a another key with the same value - world.setRecord(namespace, sourceName, keyTuple2, abi.encodePacked(value1)); + world.setRecord(namespace, sourceName, keyTuple2, abi.encodePacked(value1), sourceTableSchema); // Get the list of entities with value2 from the target table keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encode(value1))); @@ -109,7 +109,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value2 = 2; startGasReport("change a record on a table with KeysWithValueModule installed"); - world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value2)); + world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value2), sourceTableSchema); endGasReport(); // Get the list of entities with value1 from the target table @@ -128,7 +128,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { // Delete the first key startGasReport("delete a record on a table with KeysWithValueModule installed"); - world.deleteRecord(namespace, sourceName, keyTuple1); + world.deleteRecord(namespace, sourceName, keyTuple1, sourceTableSchema); endGasReport(); // Get the list of entities with value2 from the target table @@ -145,7 +145,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value1 = 1; startGasReport("set a field on a table with KeysWithValueModule installed"); - world.setField(namespace, sourceName, keyTuple1, 0, abi.encodePacked(value1)); + world.setField(namespace, sourceName, keyTuple1, 0, abi.encodePacked(value1), sourceTableSchema); endGasReport(); // Get the list of entities with value1 from the target table @@ -159,7 +159,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { // Change the value using setField startGasReport("change a field on a table with KeysWithValueModule installed"); - world.setField(namespace, sourceName, keyTuple1, 0, abi.encodePacked(value2)); + world.setField(namespace, sourceName, keyTuple1, 0, abi.encodePacked(value2), sourceTableSchema); endGasReport(); // Get the list of entities with value1 from the target table @@ -200,7 +200,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { _installKeysWithValueModule(); // Set a value in the source table - world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value)); + world.setRecord(namespace, sourceName, keyTuple1, abi.encodePacked(value), sourceTableSchema); startGasReport("Get list of keys with a given value"); bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value)); @@ -211,7 +211,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { assertEq(keysWithValue[0], key1); // Set a another key with the same value - world.setRecord(namespace, sourceName, keyTuple2, abi.encodePacked(value)); + world.setRecord(namespace, sourceName, keyTuple2, abi.encodePacked(value), sourceTableSchema); // Get the list of keys with value from the target table keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value)); diff --git a/packages/world/test/SnapSyncModule.t.sol b/packages/world/test/SnapSyncModule.t.sol index 4af7739520..1980062a3d 100644 --- a/packages/world/test/SnapSyncModule.t.sol +++ b/packages/world/test/SnapSyncModule.t.sol @@ -88,7 +88,7 @@ contract SnapSyncModuleTest is Test, GasReporter { _installModules(); // Set a value in the source table - world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value1)); + world.setRecord(namespace, name, keyTuple1, abi.encodePacked(value1), tableSchema); uint256 limit = ISnapSyncSystem(address(world)).snapSync_system_getNumKeysInTable(tableId); @@ -102,7 +102,7 @@ contract SnapSyncModuleTest is Test, GasReporter { assertEq(records[0].value, abi.encodePacked(value1)); // Set another key with a different value - world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value2)); + world.setRecord(namespace, name, keyTuple2, abi.encodePacked(value2), tableSchema); limit = ISnapSyncSystem(address(world)).snapSync_system_getNumKeysInTable(tableId); @@ -137,7 +137,7 @@ contract SnapSyncModuleTest is Test, GasReporter { ISnapSyncSystem syncSystem = ISnapSyncSystem(address(world)); // Set a value in the source table - world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value1)); + world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value1), tableSchema); uint256 limit = syncSystem.snapSync_system_getNumKeysInTable(compositeTableId); @@ -153,7 +153,7 @@ contract SnapSyncModuleTest is Test, GasReporter { assertEq(records[0].value, abi.encodePacked(value1)); // Set another key with a different value - world.setRecord(namespace, compositeName, keyTupleB, abi.encodePacked(value2)); + world.setRecord(namespace, compositeName, keyTupleB, abi.encodePacked(value2), tableSchema); limit = syncSystem.snapSync_system_getNumKeysInTable(compositeTableId); @@ -184,7 +184,7 @@ contract SnapSyncModuleTest is Test, GasReporter { keyTupleB[2] = "B3"; // Set a value in the source table - world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value1)); + world.setRecord(namespace, compositeName, keyTupleA, abi.encodePacked(value1), tableSchema); ISnapSyncSystem syncSystem = ISnapSyncSystem(address(world)); @@ -202,7 +202,7 @@ contract SnapSyncModuleTest is Test, GasReporter { assertEq(records[0].value, abi.encodePacked(value1)); // Set another key with a different value - world.setRecord(namespace, compositeName, keyTupleB, abi.encodePacked(value2)); + world.setRecord(namespace, compositeName, keyTupleB, abi.encodePacked(value2), tableSchema); limit = syncSystem.snapSync_system_getNumKeysInTable(compositeTableId); diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index c34aacb87f..d43fd029c5 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -76,12 +76,13 @@ contract WorldTestSystem is System { function writeData(bytes16 namespace, bytes16 name, bool data) public { bytes32[] memory key = new bytes32[](0); + bytes32 tableId = ResourceSelector.from(namespace, name); + Schema valueSchema = StoreSwitch.getSchema(tableId); if (StoreSwitch.getStoreAddress() == address(this)) { - bytes32 tableId = ResourceSelector.from(namespace, name); - StoreCore.setRecord(tableId, key, abi.encodePacked(data)); + StoreCore.setRecord(tableId, key, abi.encodePacked(data), valueSchema); } else { - IBaseWorld(msg.sender).setRecord(namespace, name, key, abi.encodePacked(data)); + IBaseWorld(msg.sender).setRecord(namespace, name, key, abi.encodePacked(data), valueSchema); } } @@ -107,20 +108,32 @@ contract PayableFallbackSystem is System { contract WorldTestTableHook is IStoreHook { event HookCalled(bytes data); - function onSetRecord(bytes32 table, bytes32[] memory key, bytes memory data) public { - emit HookCalled(abi.encode(table, key, data)); + function onSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) public { + emit HookCalled(abi.encode(table, key, data, valueSchema)); } - function onBeforeSetField(bytes32 table, bytes32[] memory key, uint8 schemaIndex, bytes memory data) public { - emit HookCalled(abi.encode(table, key, schemaIndex, data)); + function onBeforeSetField( + bytes32 table, + bytes32[] memory key, + uint8 schemaIndex, + bytes memory data, + Schema valueSchema + ) public { + emit HookCalled(abi.encode(table, key, schemaIndex, data, valueSchema)); } - function onAfterSetField(bytes32 table, bytes32[] memory key, uint8 schemaIndex, bytes memory data) public { - emit HookCalled(abi.encode(table, key, schemaIndex, data)); + function onAfterSetField( + bytes32 table, + bytes32[] memory key, + uint8 schemaIndex, + bytes memory data, + Schema valueSchema + ) public { + emit HookCalled(abi.encode(table, key, schemaIndex, data, valueSchema)); } - function onDeleteRecord(bytes32 table, bytes32[] memory key) public { - emit HookCalled(abi.encode(table, key)); + function onDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) public { + emit HookCalled(abi.encode(table, key, valueSchema)); } } @@ -180,7 +193,11 @@ contract WorldTest is Test, GasReporter { bytes32[] memory schemaKey = new bytes32[](1); schemaKey[0] = StoreCoreInternal.SCHEMA_TABLE; - bytes memory value = world.getRecord(StoreCoreInternal.SCHEMA_TABLE, schemaKey); + bytes memory value = world.getRecord( + StoreCoreInternal.SCHEMA_TABLE, + schemaKey, + SchemaLib.encode(SchemaType.BYTES32, SchemaType.BYTES32) + ); assertEq( value, abi.encodePacked( @@ -405,42 +422,44 @@ contract WorldTest is Test, GasReporter { function testSetField() public { bytes16 namespace = "testSetField"; bytes16 name = "testTable"; + Schema schema = Bool.getSchema(); // Register a new table - bytes32 tableId = world.registerTable(namespace, name, Bool.getSchema(), defaultKeySchema); + bytes32 tableId = world.registerTable(namespace, name, schema, defaultKeySchema); startGasReport("Write data to a table field"); - world.setField(namespace, name, singletonKey, 0, abi.encodePacked(true)); + world.setField(namespace, name, singletonKey, 0, abi.encodePacked(true), schema); endGasReport(); // Expect the data to be written assertTrue(Bool.get(world, tableId)); // Write data to the table via its tableId - world.setField(tableId, singletonKey, 0, abi.encodePacked(false)); + world.setField(tableId, singletonKey, 0, abi.encodePacked(false), schema); // Expect the data to be written assertFalse(Bool.get(world, tableId)); // Expect an error when trying to write from an address that doesn't have access when calling via the namespace _expectAccessDenied(address(0x01), "testSetField", "testTable"); - world.setField("testSetField", "testTable", singletonKey, 0, abi.encodePacked(true)); + world.setField("testSetField", "testTable", singletonKey, 0, abi.encodePacked(true), schema); // Expect an error when trying to write from an address that doesn't have access when calling via the tableId _expectAccessDenied(address(0x01), "testSetField", "testTable"); - world.setField(tableId, singletonKey, 0, abi.encodePacked(true)); + world.setField(tableId, singletonKey, 0, abi.encodePacked(true), schema); // Expect the World to have access vm.prank(address(world)); - world.setField("testSetField", "testTable", singletonKey, 0, abi.encodePacked(true)); + world.setField("testSetField", "testTable", singletonKey, 0, abi.encodePacked(true), schema); } function testPushToField() public { bytes16 namespace = "testPushToField"; bytes16 name = "testTable"; + Schema schema = AddressArray.getSchema(); // Register a new table - bytes32 tableId = world.registerTable(namespace, name, AddressArray.getSchema(), defaultKeySchema); + bytes32 tableId = world.registerTable(namespace, name, schema, defaultKeySchema); // Create data address[] memory dataToPush = new address[](3); @@ -450,75 +469,76 @@ contract WorldTest is Test, GasReporter { bytes memory encodedData = EncodeArray.encode(dataToPush); startGasReport("Push data to the table"); - world.pushToField(namespace, name, keyTuple, 0, encodedData); + world.pushToField(namespace, name, keyTuple, 0, encodedData, schema); endGasReport(); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), dataToPush); // Delete the data - world.deleteRecord(namespace, name, keyTuple); + world.deleteRecord(namespace, name, keyTuple, schema); // Push data to the table via direct access - world.pushToField(tableId, keyTuple, 0, encodedData); + world.pushToField(tableId, keyTuple, 0, encodedData, schema); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), dataToPush); // Expect an error when trying to write from an address that doesn't have access (via namespace/name) _expectAccessDenied(address(0x01), namespace, name); - world.pushToField(namespace, name, keyTuple, 0, encodedData); + world.pushToField(namespace, name, keyTuple, 0, encodedData, schema); // Expect an error when trying to write from an address that doesn't have access (via tableId) _expectAccessDenied(address(0x01), namespace, name); - world.pushToField(tableId, keyTuple, 0, encodedData); + world.pushToField(tableId, keyTuple, 0, encodedData, schema); // Expect the World to have access vm.prank(address(world)); - world.pushToField(namespace, name, keyTuple, 0, encodedData); + world.pushToField(namespace, name, keyTuple, 0, encodedData, schema); } function testDeleteRecord() public { bytes16 namespace = "testDeleteRecord"; bytes16 name = "testTable"; + Schema schema = Bool.getSchema(); // Register a new table - bytes32 tableId = world.registerTable(namespace, name, Bool.getSchema(), defaultKeySchema); + bytes32 tableId = world.registerTable(namespace, name, schema, defaultKeySchema); // Write data to the table via the namespace and expect it to be written - world.setRecord(namespace, name, singletonKey, abi.encodePacked(true)); + world.setRecord(namespace, name, singletonKey, abi.encodePacked(true), schema); assertTrue(Bool.get(world, tableId)); startGasReport("Delete record"); - world.deleteRecord(namespace, name, singletonKey); + world.deleteRecord(namespace, name, singletonKey, schema); endGasReport(); // expect it to be deleted assertFalse(Bool.get(world, tableId)); // Write data to the table via the namespace and expect it to be written - world.setRecord("testDeleteRecord", "testTable", singletonKey, abi.encodePacked(true)); + world.setRecord("testDeleteRecord", "testTable", singletonKey, abi.encodePacked(true), schema); assertTrue(Bool.get(world, tableId)); // Delete the record via the tableId and expect it to be deleted - world.deleteRecord(tableId, singletonKey); + world.deleteRecord(tableId, singletonKey, schema); assertFalse(Bool.get(world, tableId)); // Write data to the table via the namespace and expect it to be written - world.setRecord("testDeleteRecord", "testTable", singletonKey, abi.encodePacked(true)); + world.setRecord("testDeleteRecord", "testTable", singletonKey, abi.encodePacked(true), schema); assertTrue(Bool.get(world, tableId)); // Expect an error when trying to delete from an address that doesn't have access when calling via the namespace _expectAccessDenied(address(0x01), "testDeleteRecord", "testTable"); - world.deleteRecord("testDeleteRecord", "testTable", singletonKey); + world.deleteRecord("testDeleteRecord", "testTable", singletonKey, schema); // Expect an error when trying to delete from an address that doesn't have access when calling via the tableId _expectAccessDenied(address(0x02), "testDeleteRecord", "testTable"); - world.deleteRecord(tableId, singletonKey); + world.deleteRecord(tableId, singletonKey, schema); // Expect the World to have access vm.prank(address(world)); - world.deleteRecord("testDeleteRecord", "testTable", singletonKey); + world.deleteRecord("testDeleteRecord", "testTable", singletonKey, schema); } function testCall() public { @@ -593,6 +613,8 @@ contract WorldTest is Test, GasReporter { } function testRegisterTableHook() public { + Schema schema = Bool.getSchema(); + // Register a new table bytes32 tableId = world.registerTable("", "testTable", Bool.getSchema(), defaultKeySchema); @@ -605,8 +627,8 @@ contract WorldTest is Test, GasReporter { // Expect the hook to be notified when a record is written vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, value)); - world.setRecord(tableId, singletonKey, value); + emit HookCalled(abi.encode(tableId, singletonKey, value, schema)); + world.setRecord(tableId, singletonKey, value, schema); // TODO: add tests for other hook methods (onBeforeSetField, onAfterSetField, onDeleteRecord) // (See https://github.com/latticexyz/mud/issues/444) diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index dd1da325dc..5e4f0cd411 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -50,6 +50,7 @@ contract UpdateInFieldTest is Test, GasReporter { keyTuple = new bytes32[](1); keyTuple[0] = key; singletonKey = new bytes32[](0); + Schema schema = AddressArray.getSchema(); // Initialize the data in setUp so that slots aren't warm in tests (to test cold update) @@ -57,7 +58,7 @@ contract UpdateInFieldTest is Test, GasReporter { bytes16 name = "testTable"; // Register a new table - tableId = world.registerTable(namespace, name, AddressArray.getSchema(), defaultKeySchema); + tableId = world.registerTable(namespace, name, schema, defaultKeySchema); // Create data initData = new address[](3); @@ -66,7 +67,7 @@ contract UpdateInFieldTest is Test, GasReporter { initData[2] = address(bytes20(keccak256("another address"))); encodedData = EncodeArray.encode(initData); - world.setField(namespace, name, keyTuple, 0, encodedData); + world.setField(namespace, name, keyTuple, 0, encodedData, schema); } // Expect an error when trying to write from an address that doesn't have access @@ -84,6 +85,7 @@ contract UpdateInFieldTest is Test, GasReporter { function testPopFromField() public { bytes16 namespace = "DynamicUpdTest"; bytes16 name = "testTable"; + Schema schema = AddressArray.getSchema(); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), initData); @@ -92,7 +94,7 @@ contract UpdateInFieldTest is Test, GasReporter { uint256 byteLengthToPop = 20; startGasReport("pop 1 address (cold)"); - world.popFromField(namespace, name, keyTuple, 0, byteLengthToPop); + world.popFromField(namespace, name, keyTuple, 0, byteLengthToPop, schema); endGasReport(); // Expect the data to be updated @@ -106,7 +108,7 @@ contract UpdateInFieldTest is Test, GasReporter { byteLengthToPop = 20; startGasReport("pop 1 address (warm)"); - world.popFromField(namespace, name, keyTuple, 0, byteLengthToPop); + world.popFromField(namespace, name, keyTuple, 0, byteLengthToPop, schema); endGasReport(); // Expect the data to be updated @@ -117,10 +119,10 @@ contract UpdateInFieldTest is Test, GasReporter { } // Reset data - world.setField(namespace, name, keyTuple, 0, encodedData); + world.setField(namespace, name, keyTuple, 0, encodedData, schema); // Pop 2 items via direct access byteLengthToPop = 20 * 2; - world.popFromField(tableId, keyTuple, 0, byteLengthToPop); + world.popFromField(tableId, keyTuple, 0, byteLengthToPop, schema); // Expect the data to be updated loadedData = AddressArray.get(world, tableId, key); assertEq(loadedData.length, initData.length - 2); @@ -130,20 +132,21 @@ contract UpdateInFieldTest is Test, GasReporter { // Expect an error when trying to write from an address that doesn't have access (via namespace/name) _expectAccessDenied(address(0x01), namespace, name); - world.popFromField(namespace, name, keyTuple, 0, 20); + world.popFromField(namespace, name, keyTuple, 0, 20, schema); // Expect an error when trying to write from an address that doesn't have access (via tableId) _expectAccessDenied(address(0x01), namespace, name); - world.popFromField(tableId, keyTuple, 0, 20); + world.popFromField(tableId, keyTuple, 0, 20, schema); // Expect the World to have access vm.prank(address(world)); - world.popFromField(namespace, name, keyTuple, 0, 20); + world.popFromField(namespace, name, keyTuple, 0, 20, schema); } function testUpdateInField() public { bytes16 namespace = "DynamicUpdTest"; bytes16 name = "testTable"; + Schema schema = AddressArray.getSchema(); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), initData); @@ -153,11 +156,11 @@ contract UpdateInFieldTest is Test, GasReporter { dataForUpdate[0] = address(bytes20(keccak256("address for update"))); startGasReport("updateInField 1 item (cold)"); - world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate)); + world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), schema); endGasReport(); startGasReport("updateInField 1 item (warm)"); - world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate)); + world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), schema); endGasReport(); // Expect the data to be updated @@ -165,7 +168,7 @@ contract UpdateInFieldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), initData); // Update index 1 via direct access - world.updateInField(tableId, keyTuple, 0, 20 * 1, EncodeArray.encode(dataForUpdate)); + world.updateInField(tableId, keyTuple, 0, 20 * 1, EncodeArray.encode(dataForUpdate), schema); // Expect the data to be updated initData[1] = dataForUpdate[0]; @@ -173,14 +176,14 @@ contract UpdateInFieldTest is Test, GasReporter { // Expect an error when trying to write from an address that doesn't have access (via namespace/name) _expectAccessDenied(address(0x01), namespace, name); - world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate)); + world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), schema); // Expect an error when trying to write from an address that doesn't have access (via tableId) _expectAccessDenied(address(0x01), namespace, name); - world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate)); + world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), schema); // Expect the World to have access vm.prank(address(world)); - world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate)); + world.updateInField(namespace, name, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), schema); } } diff --git a/packages/world/test/query.t.sol b/packages/world/test/query.t.sol index dd5a419fea..73913ee7ea 100644 --- a/packages/world/test/query.t.sol +++ b/packages/world/test/query.t.sol @@ -86,9 +86,9 @@ contract QueryTest is Test, GasReporter { function testHasQuery() public { _installKeysInTableModule(); - world.setRecord(namespace, name1, key1, abi.encode(1)); - world.setRecord(namespace, name1, key2, abi.encode(1)); - world.setRecord(namespace, name2, key1, abi.encode(0)); + world.setRecord(namespace, name1, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key1, abi.encode(0), tableSchema); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); @@ -107,9 +107,9 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(namespace, name1, key1, abi.encode(2)); - world.setRecord(namespace, name1, key2, abi.encode(1)); - world.setRecord(namespace, name1, key3, abi.encode(1)); + world.setRecord(namespace, name1, key1, abi.encode(2), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(1), tableSchema); // Query should return all keys in table1 with value 1 QueryFragment[] memory fragments = new QueryFragment[](1); fragments[0] = QueryFragment(QueryType.HasValue, table1, abi.encode(1)); @@ -125,12 +125,12 @@ contract QueryTest is Test, GasReporter { function testCombinedHasQuery() public { _installKeysInTableModule(); - world.setRecord(namespace, name1, key1, abi.encode(2)); - world.setRecord(namespace, name1, key2, abi.encode(1)); - world.setRecord(namespace, name1, key3, abi.encode(1)); - world.setRecord(namespace, name2, key2, abi.encode(1)); - world.setRecord(namespace, name2, key3, abi.encode(1)); - world.setRecord(namespace, name3, key1, abi.encode(1)); + world.setRecord(namespace, name1, key1, abi.encode(2), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name3, key1, abi.encode(1), tableSchema); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -149,12 +149,12 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(namespace, name1, key1, abi.encode(2)); - world.setRecord(namespace, name1, key2, abi.encode(2)); - world.setRecord(namespace, name1, key3, abi.encode(1)); - world.setRecord(namespace, name2, key2, abi.encode(1)); - world.setRecord(namespace, name2, key3, abi.encode(1)); - world.setRecord(namespace, name3, key1, abi.encode(1)); + world.setRecord(namespace, name1, key1, abi.encode(2), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(2), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name3, key1, abi.encode(1), tableSchema); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -172,13 +172,13 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(namespace, name1, key1, abi.encode(1)); - world.setRecord(namespace, name1, key2, abi.encode(1)); - world.setRecord(namespace, name1, key3, abi.encode(1)); - world.setRecord(namespace, name2, key1, abi.encode(1)); - world.setRecord(namespace, name2, key2, abi.encode(2)); - world.setRecord(namespace, name2, key3, abi.encode(2)); - world.setRecord(namespace, name2, key4, abi.encode(2)); + world.setRecord(namespace, name1, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key2, abi.encode(2), tableSchema); + world.setRecord(namespace, name2, key3, abi.encode(2), tableSchema); + world.setRecord(namespace, name2, key4, abi.encode(2), tableSchema); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -196,13 +196,13 @@ contract QueryTest is Test, GasReporter { function testCombinedHasNotQuery() public { _installKeysInTableModule(); - world.setRecord(namespace, name1, key1, abi.encode(1)); - world.setRecord(namespace, name1, key2, abi.encode(1)); - world.setRecord(namespace, name1, key3, abi.encode(1)); - world.setRecord(namespace, name2, key1, abi.encode(1)); - world.setRecord(namespace, name2, key2, abi.encode(2)); - world.setRecord(namespace, name2, key3, abi.encode(2)); - world.setRecord(namespace, name2, key4, abi.encode(2)); + world.setRecord(namespace, name1, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key2, abi.encode(2), tableSchema); + world.setRecord(namespace, name2, key3, abi.encode(2), tableSchema); + world.setRecord(namespace, name2, key4, abi.encode(2), tableSchema); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -220,13 +220,13 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(namespace, name1, key1, abi.encode(1)); - world.setRecord(namespace, name1, key2, abi.encode(1)); - world.setRecord(namespace, name1, key3, abi.encode(1)); - world.setRecord(namespace, name2, key1, abi.encode(1)); - world.setRecord(namespace, name2, key2, abi.encode(2)); - world.setRecord(namespace, name2, key3, abi.encode(1)); - world.setRecord(namespace, name2, key4, abi.encode(1)); + world.setRecord(namespace, name1, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key2, abi.encode(2), tableSchema); + world.setRecord(namespace, name2, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key4, abi.encode(1), tableSchema); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -244,16 +244,16 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(namespace, name1, key1, abi.encode(1)); - world.setRecord(namespace, name1, key2, abi.encode(1)); - world.setRecord(namespace, name1, key3, abi.encode(1)); - world.setRecord(namespace, name2, key1, abi.encode(1)); - world.setRecord(namespace, name2, key2, abi.encode(2)); - world.setRecord(namespace, name2, key3, abi.encode(1)); - world.setRecord(namespace, name2, key4, abi.encode(1)); - world.setRecord(namespace, name3, key2, abi.encode(1)); - world.setRecord(namespace, name3, key3, abi.encode(1)); - world.setRecord(namespace, name3, key4, abi.encode(1)); + world.setRecord(namespace, name1, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key1, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key2, abi.encode(2), tableSchema); + world.setRecord(namespace, name2, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name2, key4, abi.encode(1), tableSchema); + world.setRecord(namespace, name3, key2, abi.encode(1), tableSchema); + world.setRecord(namespace, name3, key3, abi.encode(1), tableSchema); + world.setRecord(namespace, name3, key4, abi.encode(1), tableSchema); // Query should return all entities that have table2 and not table1 QueryFragment[] memory fragments = new QueryFragment[](3); @@ -272,9 +272,9 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(namespace, name1, key1, abi.encode(4)); - world.setRecord(namespace, name1, key2, abi.encode(5)); - world.setRecord(namespace, name1, key3, abi.encode(6)); + world.setRecord(namespace, name1, key1, abi.encode(4), tableSchema); + world.setRecord(namespace, name1, key2, abi.encode(5), tableSchema); + world.setRecord(namespace, name1, key3, abi.encode(6), tableSchema); // Query should return all entities with table1 except value 6 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -295,9 +295,9 @@ contract QueryTest is Test, GasReporter { for (uint256 i; i < 100; i++) { bytes32[] memory key = new bytes32[](1); key[0] = bytes32(i); - world.setRecord(namespace, name1, key, abi.encode(1)); + world.setRecord(namespace, name1, key, abi.encode(1), tableSchema); } - world.setRecord(namespace, name2, key1, abi.encode(0)); + world.setRecord(namespace, name2, key1, abi.encode(0), tableSchema); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); @@ -316,9 +316,9 @@ contract QueryTest is Test, GasReporter { for (uint256 i; i < 1000; i++) { bytes32[] memory key = new bytes32[](1); key[0] = bytes32(i); - world.setRecord(namespace, name1, key, abi.encode(1)); + world.setRecord(namespace, name1, key, abi.encode(1), tableSchema); } - world.setRecord(namespace, name2, key1, abi.encode(0)); + world.setRecord(namespace, name2, key1, abi.encode(0), tableSchema); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); diff --git a/packages/world/test/tables/AddressArray.sol b/packages/world/test/tables/AddressArray.sol index a55dc0553e..8b0009b898 100644 --- a/packages/world/test/tables/AddressArray.sol +++ b/packages/world/test/tables/AddressArray.sol @@ -67,7 +67,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -76,7 +76,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -85,7 +85,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getSchema()); } /** Set value (using the specified store) */ @@ -93,7 +93,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getSchema()); } /** Get the length of value */ @@ -137,7 +137,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Push an element to value (using the specified store) */ @@ -145,7 +145,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getSchema()); } /** Pop an element from value */ @@ -153,7 +153,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 20); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 20, getSchema()); } /** Pop an element from value (using the specified store) */ @@ -161,7 +161,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 0, 20); + _store.popFromField(_tableId, _keyTuple, 0, 20, getSchema()); } /** Update an element of value at `_index` */ @@ -169,7 +169,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element))); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getSchema()); } /** Update an element of value (using the specified store) at `_index` */ @@ -177,7 +177,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element))); + _store.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -200,7 +200,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ @@ -208,6 +208,6 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } } diff --git a/packages/world/test/tables/Bool.sol b/packages/world/test/tables/Bool.sol index bcf67c13e3..376ad851a3 100644 --- a/packages/world/test/tables/Bool.sol +++ b/packages/world/test/tables/Bool.sol @@ -65,7 +65,7 @@ library Bool { function get(bytes32 _tableId) internal view returns (bool value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -73,7 +73,7 @@ library Bool { function get(IStore _store, bytes32 _tableId) internal view returns (bool value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getSchema()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -81,14 +81,14 @@ library Bool { function set(bytes32 _tableId, bool value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getSchema()); } /** Set value (using the specified store) */ function set(IStore _store, bytes32 _tableId, bool value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getSchema()); } /** Tightly pack full data using this table's schema */ @@ -105,14 +105,14 @@ library Bool { function deleteRecord(bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getSchema()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store, bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple); + _store.deleteRecord(_tableId, _keyTuple, getSchema()); } }