diff --git a/.changeset/angry-ladybugs-invent.md b/.changeset/angry-ladybugs-invent.md new file mode 100644 index 0000000000..1b41fb1613 --- /dev/null +++ b/.changeset/angry-ladybugs-invent.md @@ -0,0 +1,26 @@ +--- +"@latticexyz/cli": patch +"@latticexyz/store": major +"@latticexyz/world-modules": patch +"@latticexyz/world": patch +"create-mud": patch +--- + +Store config now defaults `storeArgument: false` for all tables. This means that table libraries, by default, will no longer include the extra functions with the `_store` argument. This default was changed to clear up the confusion around using table libraries in tests, `PostDeploy` scripts, etc. + +If you are sure you need to manually specify a store when interacting with tables, you can still manually toggle it back on with `storeArgument: true` in the table settings of your MUD config. + +If you want to use table libraries in `PostDeploy.s.sol`, you can add the following lines: + +```diff + import { Script } from "forge-std/Script.sol"; + import { console } from "forge-std/console.sol"; + import { IWorld } from "../src/codegen/world/IWorld.sol"; ++ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; + + contract PostDeploy is Script { + function run(address worldAddress) external { ++ StoreSwitch.setStoreAddress(worldAddress); ++ ++ SomeTable.get(someKey); +``` diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index 97d73570bb..a881e1403d 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -105,13 +105,6 @@ library Multi { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get num. */ @@ -140,20 +133,6 @@ library Multi { return (int256(uint256(bytes32(_blob)))); } - /** - * @notice Get num (using the specified store). - */ - function getNum(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal view returns (int256 num) { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(bytes32(_blob)))); - } - /** * @notice Set num. */ @@ -180,19 +159,6 @@ library Multi { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((num)), _fieldLayout); } - /** - * @notice Set num (using the specified store). - */ - function setNum(IStore _store, uint32 a, bool b, uint256 c, int120 d, int256 num) internal { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((num)), _fieldLayout); - } - /** * @notice Get value. */ @@ -221,20 +187,6 @@ library Multi { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal view returns (bool value) { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set value. */ @@ -261,19 +213,6 @@ library Multi { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, uint32 a, bool b, uint256 c, int120 d, bool value) internal { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -310,24 +249,6 @@ library Multi { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal view returns (MultiData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -364,24 +285,6 @@ library Multi { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, uint32 a, bool b, uint256 c, int120 d, int256 num, bool value) internal { - bytes memory _staticData = encodeStatic(num, value); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -418,24 +321,6 @@ library Multi { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, uint32 a, bool b, uint256 c, int120 d, MultiData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.num, _table.value); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -485,19 +370,6 @@ library Multi { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(a)); - _keyTuple[1] = _boolToBytes32(b); - _keyTuple[2] = bytes32(uint256(c)); - _keyTuple[3] = bytes32(uint256(int256(d))); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index 85ca6d6caf..5464204518 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -92,13 +92,6 @@ library Number { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -121,17 +114,6 @@ library Number { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store, uint32 key) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Get value. */ @@ -154,17 +136,6 @@ library Number { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store, uint32 key) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set value. */ @@ -185,16 +156,6 @@ library Number { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, uint32 key, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Set value. */ @@ -215,16 +176,6 @@ library Number { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, uint32 key, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -245,16 +196,6 @@ library Number { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, uint32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index 3ef2f51511..af5daed541 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -90,13 +90,6 @@ library NumberList { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -117,16 +110,6 @@ library NumberList { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store) internal view returns (uint32[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - /** * @notice Get value. */ @@ -147,16 +130,6 @@ library NumberList { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store) internal view returns (uint32[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - /** * @notice Set value. */ @@ -175,15 +148,6 @@ library NumberList { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, uint32[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Set value. */ @@ -202,15 +166,6 @@ library NumberList { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, uint32[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Get the length of value. */ @@ -235,18 +190,6 @@ library NumberList { } } - /** - * @notice Get the length of value (using the specified store). - */ - function lengthValue(IStore _store) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 4; - } - } - /** * @notice Get the length of value. */ @@ -271,18 +214,6 @@ library NumberList { } } - /** - * @notice Get the length of value (using the specified store). - */ - function length(IStore _store) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 4; - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -309,19 +240,6 @@ library NumberList { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemValue(IStore _store, uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -348,19 +266,6 @@ library NumberList { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItem(IStore _store, uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - /** * @notice Push an element to value. */ @@ -379,15 +284,6 @@ library NumberList { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function pushValue(IStore _store, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Push an element to value. */ @@ -406,15 +302,6 @@ library NumberList { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function push(IStore _store, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from value. */ @@ -433,15 +320,6 @@ library NumberList { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 4); } - /** - * @notice Pop an element from value (using the specified store). - */ - function popValue(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 4); - } - /** * @notice Pop an element from value. */ @@ -460,15 +338,6 @@ library NumberList { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 4); } - /** - * @notice Pop an element from value (using the specified store). - */ - function pop(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 4); - } - /** * @notice Update an element of value at `_index`. */ @@ -493,18 +362,6 @@ library NumberList { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function updateValue(IStore _store, uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - /** * @notice Update an element of value at `_index`. */ @@ -529,18 +386,6 @@ library NumberList { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function update(IStore _store, uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - /** * @notice Delete all data for given keys. */ @@ -559,15 +404,6 @@ library NumberList { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index 52387a6c34..a084416923 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -99,13 +99,6 @@ library Vector { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get x. */ @@ -128,17 +121,6 @@ library Vector { return (int32(uint32(bytes4(_blob)))); } - /** - * @notice Get x (using the specified store). - */ - function getX(IStore _store, uint32 key) internal view returns (int32 x) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - /** * @notice Set x. */ @@ -159,16 +141,6 @@ library Vector { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout); } - /** - * @notice Set x (using the specified store). - */ - function setX(IStore _store, uint32 key, int32 x) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout); - } - /** * @notice Get y. */ @@ -191,17 +163,6 @@ library Vector { return (int32(uint32(bytes4(_blob)))); } - /** - * @notice Get y (using the specified store). - */ - function getY(IStore _store, uint32 key) internal view returns (int32 y) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - /** * @notice Set y. */ @@ -222,16 +183,6 @@ library Vector { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout); } - /** - * @notice Set y (using the specified store). - */ - function setY(IStore _store, uint32 key, int32 y) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -262,21 +213,6 @@ library Vector { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, uint32 key) internal view returns (VectorData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -307,21 +243,6 @@ library Vector { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, uint32 key, int32 x, int32 y) internal { - bytes memory _staticData = encodeStatic(x, y); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -352,21 +273,6 @@ library Vector { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, uint32 key, VectorData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.x, _table.y); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -410,16 +316,6 @@ library Vector { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, uint32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(key)); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index a7aba783c5..0601a0afc3 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -96,13 +96,6 @@ library Inventory { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get amount. */ @@ -129,24 +122,6 @@ library Inventory { return (uint32(bytes4(_blob))); } - /** - * @notice Get amount (using the specified store). - */ - function getAmount( - IStore _store, - address owner, - uint32 item, - uint32 itemVariant - ) internal view returns (uint32 amount) { - bytes32[] memory _keyTuple = new bytes32[](3); - _keyTuple[0] = bytes32(uint256(uint160(owner))); - _keyTuple[1] = bytes32(uint256(item)); - _keyTuple[2] = bytes32(uint256(itemVariant)); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Get amount. */ @@ -173,19 +148,6 @@ library Inventory { return (uint32(bytes4(_blob))); } - /** - * @notice Get amount (using the specified store). - */ - function get(IStore _store, address owner, uint32 item, uint32 itemVariant) internal view returns (uint32 amount) { - bytes32[] memory _keyTuple = new bytes32[](3); - _keyTuple[0] = bytes32(uint256(uint160(owner))); - _keyTuple[1] = bytes32(uint256(item)); - _keyTuple[2] = bytes32(uint256(itemVariant)); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set amount. */ @@ -210,18 +172,6 @@ library Inventory { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), _fieldLayout); } - /** - * @notice Set amount (using the specified store). - */ - function setAmount(IStore _store, address owner, uint32 item, uint32 itemVariant, uint32 amount) internal { - bytes32[] memory _keyTuple = new bytes32[](3); - _keyTuple[0] = bytes32(uint256(uint160(owner))); - _keyTuple[1] = bytes32(uint256(item)); - _keyTuple[2] = bytes32(uint256(itemVariant)); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), _fieldLayout); - } - /** * @notice Set amount. */ @@ -246,18 +196,6 @@ library Inventory { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), _fieldLayout); } - /** - * @notice Set amount (using the specified store). - */ - function set(IStore _store, address owner, uint32 item, uint32 itemVariant, uint32 amount) internal { - bytes32[] memory _keyTuple = new bytes32[](3); - _keyTuple[0] = bytes32(uint256(uint160(owner))); - _keyTuple[1] = bytes32(uint256(item)); - _keyTuple[2] = bytes32(uint256(itemVariant)); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -282,18 +220,6 @@ library Inventory { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, address owner, uint32 item, uint32 itemVariant) internal { - bytes32[] memory _keyTuple = new bytes32[](3); - _keyTuple[0] = bytes32(uint256(uint160(owner))); - _keyTuple[1] = bytes32(uint256(item)); - _keyTuple[2] = bytes32(uint256(itemVariant)); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol index 3f5c1ba2a5..c770e69eb2 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol @@ -90,13 +90,6 @@ library MessageTable { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Set the full data using individual values. */ @@ -123,19 +116,6 @@ library MessageTable { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, string memory value) internal { - bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); - bytes memory _dynamicData = encodeDynamic(value); - - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ @@ -183,15 +163,6 @@ library MessageTable { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/examples/minimal/packages/contracts/test/CounterTest.t.sol b/examples/minimal/packages/contracts/test/CounterTest.t.sol index 6faea6b1b0..f47081eb89 100644 --- a/examples/minimal/packages/contracts/test/CounterTest.t.sol +++ b/examples/minimal/packages/contracts/test/CounterTest.t.sol @@ -9,13 +9,6 @@ import { IWorld } from "../src/codegen/world/IWorld.sol"; import { CounterTable, CounterTableTableId } from "../src/codegen/index.sol"; contract CounterTest is MudTest { - IWorld world; - - function setUp() public override { - super.setUp(); - world = IWorld(worldAddress); - } - function testWorldExists() public { uint256 codeSize; address addr = worldAddress; @@ -31,7 +24,7 @@ contract CounterTest is MudTest { assertEq(counter, 1); // Expect the counter to be 2 after calling increment. - world.increment(); + IWorld(worldAddress).increment(); counter = CounterTable.get(); assertEq(counter, 2); } diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index b485393242..0c656c4b95 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -108,13 +108,6 @@ library Dynamics1 { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get staticB32. */ @@ -137,17 +130,6 @@ library Dynamics1 { return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } - /** - * @notice Get staticB32 (using the specified store). - */ - function getStaticB32(IStore _store, bytes32 key) internal view returns (bytes32[1] memory staticB32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); - } - /** * @notice Set staticB32. */ @@ -168,16 +150,6 @@ library Dynamics1 { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_bytes32_1(staticB32))); } - /** - * @notice Set staticB32 (using the specified store). - */ - function setStaticB32(IStore _store, bytes32 key, bytes32[1] memory staticB32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_bytes32_1(staticB32))); - } - /** * @notice Get the length of staticB32. */ @@ -204,19 +176,6 @@ library Dynamics1 { } } - /** - * @notice Get the length of staticB32 (using the specified store). - */ - function lengthStaticB32(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 32; - } - } - /** * @notice Get an item of staticB32. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -245,20 +204,6 @@ library Dynamics1 { } } - /** - * @notice Get an item of staticB32 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticB32(IStore _store, bytes32 key, uint256 _index) internal view returns (bytes32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32); - return (bytes32(_blob)); - } - } - /** * @notice Push an element to staticB32. */ @@ -279,16 +224,6 @@ library Dynamics1 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to staticB32 (using the specified store). - */ - function pushStaticB32(IStore _store, bytes32 key, bytes32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from staticB32. */ @@ -309,16 +244,6 @@ library Dynamics1 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 32); } - /** - * @notice Pop an element from staticB32 (using the specified store). - */ - function popStaticB32(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 32); - } - /** * @notice Update an element of staticB32 at `_index`. */ @@ -345,19 +270,6 @@ library Dynamics1 { } } - /** - * @notice Update an element of staticB32 (using the specified store) at `_index`. - */ - function updateStaticB32(IStore _store, bytes32 key, uint256 _index, bytes32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get staticI32. */ @@ -380,17 +292,6 @@ library Dynamics1 { return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); } - /** - * @notice Get staticI32 (using the specified store). - */ - function getStaticI32(IStore _store, bytes32 key) internal view returns (int32[2] memory staticI32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); - return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); - } - /** * @notice Set staticI32. */ @@ -411,16 +312,6 @@ library Dynamics1 { StoreCore.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_int32_2(staticI32))); } - /** - * @notice Set staticI32 (using the specified store). - */ - function setStaticI32(IStore _store, bytes32 key, int32[2] memory staticI32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_int32_2(staticI32))); - } - /** * @notice Get the length of staticI32. */ @@ -447,19 +338,6 @@ library Dynamics1 { } } - /** - * @notice Get the length of staticI32 (using the specified store). - */ - function lengthStaticI32(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 1); - unchecked { - return _byteLength / 4; - } - } - /** * @notice Get an item of staticI32. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -488,20 +366,6 @@ library Dynamics1 { } } - /** - * @notice Get an item of staticI32 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticI32(IStore _store, bytes32 key, uint256 _index) internal view returns (int32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 4, (_index + 1) * 4); - return (int32(uint32(bytes4(_blob)))); - } - } - /** * @notice Push an element to staticI32. */ @@ -522,16 +386,6 @@ library Dynamics1 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); } - /** - * @notice Push an element to staticI32 (using the specified store). - */ - function pushStaticI32(IStore _store, bytes32 key, int32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); - } - /** * @notice Pop an element from staticI32. */ @@ -552,16 +406,6 @@ library Dynamics1 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 4); } - /** - * @notice Pop an element from staticI32 (using the specified store). - */ - function popStaticI32(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 1, 4); - } - /** * @notice Update an element of staticI32 at `_index`. */ @@ -588,19 +432,6 @@ library Dynamics1 { } } - /** - * @notice Update an element of staticI32 (using the specified store) at `_index`. - */ - function updateStaticI32(IStore _store, bytes32 key, uint256 _index, int32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get staticU128. */ @@ -623,17 +454,6 @@ library Dynamics1 { return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); } - /** - * @notice Get staticU128 (using the specified store). - */ - function getStaticU128(IStore _store, bytes32 key) internal view returns (uint128[3] memory staticU128) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 2); - return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); - } - /** * @notice Set staticU128. */ @@ -654,16 +474,6 @@ library Dynamics1 { StoreCore.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint128_3(staticU128))); } - /** - * @notice Set staticU128 (using the specified store). - */ - function setStaticU128(IStore _store, bytes32 key, uint128[3] memory staticU128) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint128_3(staticU128))); - } - /** * @notice Get the length of staticU128. */ @@ -690,19 +500,6 @@ library Dynamics1 { } } - /** - * @notice Get the length of staticU128 (using the specified store). - */ - function lengthStaticU128(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 2); - unchecked { - return _byteLength / 16; - } - } - /** * @notice Get an item of staticU128. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -731,20 +528,6 @@ library Dynamics1 { } } - /** - * @notice Get an item of staticU128 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticU128(IStore _store, bytes32 key, uint256 _index) internal view returns (uint128) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 16, (_index + 1) * 16); - return (uint128(bytes16(_blob))); - } - } - /** * @notice Push an element to staticU128. */ @@ -765,16 +548,6 @@ library Dynamics1 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); } - /** - * @notice Push an element to staticU128 (using the specified store). - */ - function pushStaticU128(IStore _store, bytes32 key, uint128 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); - } - /** * @notice Pop an element from staticU128. */ @@ -795,16 +568,6 @@ library Dynamics1 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 2, 16); } - /** - * @notice Pop an element from staticU128 (using the specified store). - */ - function popStaticU128(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 2, 16); - } - /** * @notice Update an element of staticU128 at `_index`. */ @@ -831,19 +594,6 @@ library Dynamics1 { } } - /** - * @notice Update an element of staticU128 (using the specified store) at `_index`. - */ - function updateStaticU128(IStore _store, bytes32 key, uint256 _index, uint128 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 16), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get staticAddrs. */ @@ -866,17 +616,6 @@ library Dynamics1 { return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } - /** - * @notice Get staticAddrs (using the specified store). - */ - function getStaticAddrs(IStore _store, bytes32 key) internal view returns (address[4] memory staticAddrs) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 3); - return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); - } - /** * @notice Set staticAddrs. */ @@ -897,16 +636,6 @@ library Dynamics1 { StoreCore.setDynamicField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_address_4(staticAddrs))); } - /** - * @notice Set staticAddrs (using the specified store). - */ - function setStaticAddrs(IStore _store, bytes32 key, address[4] memory staticAddrs) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_address_4(staticAddrs))); - } - /** * @notice Get the length of staticAddrs. */ @@ -933,19 +662,6 @@ library Dynamics1 { } } - /** - * @notice Get the length of staticAddrs (using the specified store). - */ - function lengthStaticAddrs(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 3); - unchecked { - return _byteLength / 20; - } - } - /** * @notice Get an item of staticAddrs. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -974,20 +690,6 @@ library Dynamics1 { } } - /** - * @notice Get an item of staticAddrs (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticAddrs(IStore _store, bytes32 key, uint256 _index) internal view returns (address) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 3, _index * 20, (_index + 1) * 20); - return (address(bytes20(_blob))); - } - } - /** * @notice Push an element to staticAddrs. */ @@ -1008,16 +710,6 @@ library Dynamics1 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 3, abi.encodePacked((_element))); } - /** - * @notice Push an element to staticAddrs (using the specified store). - */ - function pushStaticAddrs(IStore _store, bytes32 key, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 3, abi.encodePacked((_element))); - } - /** * @notice Pop an element from staticAddrs. */ @@ -1038,16 +730,6 @@ library Dynamics1 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 3, 20); } - /** - * @notice Pop an element from staticAddrs (using the specified store). - */ - function popStaticAddrs(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 3, 20); - } - /** * @notice Update an element of staticAddrs at `_index`. */ @@ -1074,19 +756,6 @@ library Dynamics1 { } } - /** - * @notice Update an element of staticAddrs (using the specified store) at `_index`. - */ - function updateStaticAddrs(IStore _store, bytes32 key, uint256 _index, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 3, uint40(_index * 20), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get staticBools. */ @@ -1109,17 +778,6 @@ library Dynamics1 { return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); } - /** - * @notice Get staticBools (using the specified store). - */ - function getStaticBools(IStore _store, bytes32 key) internal view returns (bool[5] memory staticBools) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 4); - return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); - } - /** * @notice Set staticBools. */ @@ -1140,16 +798,6 @@ library Dynamics1 { StoreCore.setDynamicField(_tableId, _keyTuple, 4, EncodeArray.encode(fromStaticArray_bool_5(staticBools))); } - /** - * @notice Set staticBools (using the specified store). - */ - function setStaticBools(IStore _store, bytes32 key, bool[5] memory staticBools) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 4, EncodeArray.encode(fromStaticArray_bool_5(staticBools))); - } - /** * @notice Get the length of staticBools. */ @@ -1176,19 +824,6 @@ library Dynamics1 { } } - /** - * @notice Get the length of staticBools (using the specified store). - */ - function lengthStaticBools(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 4); - unchecked { - return _byteLength / 1; - } - } - /** * @notice Get an item of staticBools. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -1217,20 +852,6 @@ library Dynamics1 { } } - /** - * @notice Get an item of staticBools (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticBools(IStore _store, bytes32 key, uint256 _index) internal view returns (bool) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 4, _index * 1, (_index + 1) * 1); - return (_toBool(uint8(bytes1(_blob)))); - } - } - /** * @notice Push an element to staticBools. */ @@ -1251,16 +872,6 @@ library Dynamics1 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 4, abi.encodePacked((_element))); } - /** - * @notice Push an element to staticBools (using the specified store). - */ - function pushStaticBools(IStore _store, bytes32 key, bool _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 4, abi.encodePacked((_element))); - } - /** * @notice Pop an element from staticBools. */ @@ -1281,16 +892,6 @@ library Dynamics1 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 4, 1); } - /** - * @notice Pop an element from staticBools (using the specified store). - */ - function popStaticBools(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 4, 1); - } - /** * @notice Update an element of staticBools at `_index`. */ @@ -1317,19 +918,6 @@ library Dynamics1 { } } - /** - * @notice Update an element of staticBools (using the specified store) at `_index`. - */ - function updateStaticBools(IStore _store, bytes32 key, uint256 _index, bool _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 4, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get the full data. */ @@ -1360,21 +948,6 @@ library Dynamics1 { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, bytes32 key) internal view returns (Dynamics1Data memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -1417,28 +990,6 @@ library Dynamics1 { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set( - IStore _store, - bytes32 key, - bytes32[1] memory staticB32, - int32[2] memory staticI32, - uint128[3] memory staticU128, - address[4] memory staticAddrs, - bool[5] memory staticBools - ) internal { - bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); - bytes memory _dynamicData = encodeDynamic(staticB32, staticI32, staticU128, staticAddrs, staticBools); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -1491,32 +1042,6 @@ library Dynamics1 { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, bytes32 key, Dynamics1Data memory _table) internal { - bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths( - _table.staticB32, - _table.staticI32, - _table.staticU128, - _table.staticAddrs, - _table.staticBools - ); - bytes memory _dynamicData = encodeDynamic( - _table.staticB32, - _table.staticI32, - _table.staticU128, - _table.staticAddrs, - _table.staticBools - ); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ @@ -1603,16 +1128,6 @@ library Dynamics1 { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 5ffb53fd5d..f697ba36d3 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -102,13 +102,6 @@ library Dynamics2 { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get u64. */ @@ -131,17 +124,6 @@ library Dynamics2 { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); } - /** - * @notice Get u64 (using the specified store). - */ - function getU64(IStore _store, bytes32 key) internal view returns (uint64[] memory u64) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); - } - /** * @notice Set u64. */ @@ -162,16 +144,6 @@ library Dynamics2 { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((u64))); } - /** - * @notice Set u64 (using the specified store). - */ - function setU64(IStore _store, bytes32 key, uint64[] memory u64) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((u64))); - } - /** * @notice Get the length of u64. */ @@ -198,19 +170,6 @@ library Dynamics2 { } } - /** - * @notice Get the length of u64 (using the specified store). - */ - function lengthU64(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 8; - } - } - /** * @notice Get an item of u64. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -239,20 +198,6 @@ library Dynamics2 { } } - /** - * @notice Get an item of u64 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemU64(IStore _store, bytes32 key, uint256 _index) internal view returns (uint64) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 8, (_index + 1) * 8); - return (uint64(bytes8(_blob))); - } - } - /** * @notice Push an element to u64. */ @@ -273,16 +218,6 @@ library Dynamics2 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to u64 (using the specified store). - */ - function pushU64(IStore _store, bytes32 key, uint64 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from u64. */ @@ -303,16 +238,6 @@ library Dynamics2 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 8); } - /** - * @notice Pop an element from u64 (using the specified store). - */ - function popU64(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 8); - } - /** * @notice Update an element of u64 at `_index`. */ @@ -339,19 +264,6 @@ library Dynamics2 { } } - /** - * @notice Update an element of u64 (using the specified store) at `_index`. - */ - function updateU64(IStore _store, bytes32 key, uint256 _index, uint64 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 8), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get str. */ @@ -374,17 +286,6 @@ library Dynamics2 { return (string(_blob)); } - /** - * @notice Get str (using the specified store). - */ - function getStr(IStore _store, bytes32 key) internal view returns (string memory str) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); - return (string(_blob)); - } - /** * @notice Set str. */ @@ -405,16 +306,6 @@ library Dynamics2 { StoreCore.setDynamicField(_tableId, _keyTuple, 1, bytes((str))); } - /** - * @notice Set str (using the specified store). - */ - function setStr(IStore _store, bytes32 key, string memory str) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 1, bytes((str))); - } - /** * @notice Get the length of str. */ @@ -441,19 +332,6 @@ library Dynamics2 { } } - /** - * @notice Get the length of str (using the specified store). - */ - function lengthStr(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 1); - unchecked { - return _byteLength / 1; - } - } - /** * @notice Get an item of str. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -482,20 +360,6 @@ library Dynamics2 { } } - /** - * @notice Get an item of str (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStr(IStore _store, bytes32 key, uint256 _index) internal view returns (string memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); - return (string(_blob)); - } - } - /** * @notice Push a slice to str. */ @@ -516,16 +380,6 @@ library Dynamics2 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); } - /** - * @notice Push a slice to str (using the specified store). - */ - function pushStr(IStore _store, bytes32 key, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); - } - /** * @notice Pop a slice from str. */ @@ -546,16 +400,6 @@ library Dynamics2 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 1); } - /** - * @notice Pop a slice from str (using the specified store). - */ - function popStr(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 1, 1); - } - /** * @notice Update a slice of str at `_index`. */ @@ -582,19 +426,6 @@ library Dynamics2 { } } - /** - * @notice Update a slice of str (using the specified store) at `_index`. - */ - function updateStr(IStore _store, bytes32 key, uint256 _index, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = bytes((_slice)); - _store.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get b. */ @@ -617,17 +448,6 @@ library Dynamics2 { return (bytes(_blob)); } - /** - * @notice Get b (using the specified store). - */ - function getB(IStore _store, bytes32 key) internal view returns (bytes memory b) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 2); - return (bytes(_blob)); - } - /** * @notice Set b. */ @@ -648,16 +468,6 @@ library Dynamics2 { StoreCore.setDynamicField(_tableId, _keyTuple, 2, bytes((b))); } - /** - * @notice Set b (using the specified store). - */ - function setB(IStore _store, bytes32 key, bytes memory b) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 2, bytes((b))); - } - /** * @notice Get the length of b. */ @@ -684,19 +494,6 @@ library Dynamics2 { } } - /** - * @notice Get the length of b (using the specified store). - */ - function lengthB(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 2); - unchecked { - return _byteLength / 1; - } - } - /** * @notice Get an item of b. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -725,20 +522,6 @@ library Dynamics2 { } } - /** - * @notice Get an item of b (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemB(IStore _store, bytes32 key, uint256 _index) internal view returns (bytes memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 1, (_index + 1) * 1); - return (bytes(_blob)); - } - } - /** * @notice Push a slice to b. */ @@ -759,16 +542,6 @@ library Dynamics2 { StoreCore.pushToDynamicField(_tableId, _keyTuple, 2, bytes((_slice))); } - /** - * @notice Push a slice to b (using the specified store). - */ - function pushB(IStore _store, bytes32 key, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 2, bytes((_slice))); - } - /** * @notice Pop a slice from b. */ @@ -789,16 +562,6 @@ library Dynamics2 { StoreCore.popFromDynamicField(_tableId, _keyTuple, 2, 1); } - /** - * @notice Pop a slice from b (using the specified store). - */ - function popB(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 2, 1); - } - /** * @notice Update a slice of b at `_index`. */ @@ -825,19 +588,6 @@ library Dynamics2 { } } - /** - * @notice Update a slice of b (using the specified store) at `_index`. - */ - function updateB(IStore _store, bytes32 key, uint256 _index, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = bytes((_slice)); - _store.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get the full data. */ @@ -868,21 +618,6 @@ library Dynamics2 { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, bytes32 key) internal view returns (Dynamics2Data memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -911,20 +646,6 @@ library Dynamics2 { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, bytes32 key, uint64[] memory u64, string memory str, bytes memory b) internal { - bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(u64, str, b); - bytes memory _dynamicData = encodeDynamic(u64, str, b); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -953,20 +674,6 @@ library Dynamics2 { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, bytes32 key, Dynamics2Data memory _table) internal { - bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.u64, _table.str, _table.b); - bytes memory _dynamicData = encodeDynamic(_table.u64, _table.str, _table.b); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ @@ -1028,16 +735,6 @@ library Dynamics2 { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/cli/contracts/src/codegen/tables/Offchain.sol b/packages/cli/contracts/src/codegen/tables/Offchain.sol index 43096d1173..19d095c784 100644 --- a/packages/cli/contracts/src/codegen/tables/Offchain.sol +++ b/packages/cli/contracts/src/codegen/tables/Offchain.sol @@ -92,13 +92,6 @@ library Offchain { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Set value. */ @@ -119,16 +112,6 @@ library Offchain { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, bytes32 key, uint256 value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Set the full data using individual values. */ @@ -159,21 +142,6 @@ library Offchain { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, bytes32 key, uint256 value) internal { - bytes memory _staticData = encodeStatic(value); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -211,16 +179,6 @@ library Offchain { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index a93faf8524..ea0ee6dcca 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -96,13 +96,6 @@ library Singleton { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get v1. */ @@ -123,16 +116,6 @@ library Singleton { return (int256(uint256(bytes32(_blob)))); } - /** - * @notice Get v1 (using the specified store). - */ - function getV1(IStore _store) internal view returns (int256 v1) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(bytes32(_blob)))); - } - /** * @notice Set v1. */ @@ -151,15 +134,6 @@ library Singleton { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); } - /** - * @notice Set v1 (using the specified store). - */ - function setV1(IStore _store, int256 v1) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); - } - /** * @notice Get v2. */ @@ -180,16 +154,6 @@ library Singleton { return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } - /** - * @notice Get v2 (using the specified store). - */ - function getV2(IStore _store) internal view returns (uint32[2] memory v2) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - /** * @notice Set v2. */ @@ -208,15 +172,6 @@ library Singleton { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_uint32_2(v2))); } - /** - * @notice Set v2 (using the specified store). - */ - function setV2(IStore _store, uint32[2] memory v2) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_uint32_2(v2))); - } - /** * @notice Get the length of v2. */ @@ -241,18 +196,6 @@ library Singleton { } } - /** - * @notice Get the length of v2 (using the specified store). - */ - function lengthV2(IStore _store) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 4; - } - } - /** * @notice Get an item of v2. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -279,19 +222,6 @@ library Singleton { } } - /** - * @notice Get an item of v2 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemV2(IStore _store, uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - /** * @notice Push an element to v2. */ @@ -310,15 +240,6 @@ library Singleton { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to v2 (using the specified store). - */ - function pushV2(IStore _store, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from v2. */ @@ -337,15 +258,6 @@ library Singleton { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 4); } - /** - * @notice Pop an element from v2 (using the specified store). - */ - function popV2(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 4); - } - /** * @notice Update an element of v2 at `_index`. */ @@ -370,18 +282,6 @@ library Singleton { } } - /** - * @notice Update an element of v2 (using the specified store) at `_index`. - */ - function updateV2(IStore _store, uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get v3. */ @@ -402,16 +302,6 @@ library Singleton { return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } - /** - * @notice Get v3 (using the specified store). - */ - function getV3(IStore _store) internal view returns (uint32[2] memory v3) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); - return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - /** * @notice Set v3. */ @@ -430,15 +320,6 @@ library Singleton { StoreCore.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v3))); } - /** - * @notice Set v3 (using the specified store). - */ - function setV3(IStore _store, uint32[2] memory v3) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v3))); - } - /** * @notice Get the length of v3. */ @@ -463,18 +344,6 @@ library Singleton { } } - /** - * @notice Get the length of v3 (using the specified store). - */ - function lengthV3(IStore _store) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 1); - unchecked { - return _byteLength / 4; - } - } - /** * @notice Get an item of v3. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -501,19 +370,6 @@ library Singleton { } } - /** - * @notice Get an item of v3 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemV3(IStore _store, uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - /** * @notice Push an element to v3. */ @@ -532,15 +388,6 @@ library Singleton { StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); } - /** - * @notice Push an element to v3 (using the specified store). - */ - function pushV3(IStore _store, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.pushToDynamicField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); - } - /** * @notice Pop an element from v3. */ @@ -559,15 +406,6 @@ library Singleton { StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 4); } - /** - * @notice Pop an element from v3 (using the specified store). - */ - function popV3(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.popFromDynamicField(_tableId, _keyTuple, 1, 4); - } - /** * @notice Update an element of v3 at `_index`. */ @@ -592,18 +430,6 @@ library Singleton { } } - /** - * @notice Update an element of v3 (using the specified store) at `_index`. - */ - function updateV3(IStore _store, uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get v4. */ @@ -624,16 +450,6 @@ library Singleton { return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } - /** - * @notice Get v4 (using the specified store). - */ - function getV4(IStore _store) internal view returns (uint32[1] memory v4) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 2); - return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - /** * @notice Set v4. */ @@ -652,15 +468,6 @@ library Singleton { StoreCore.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_1(v4))); } - /** - * @notice Set v4 (using the specified store). - */ - function setV4(IStore _store, uint32[1] memory v4) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_1(v4))); - } - /** * @notice Get the length of v4. */ @@ -685,18 +492,6 @@ library Singleton { } } - /** - * @notice Get the length of v4 (using the specified store). - */ - function lengthV4(IStore _store) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 2); - unchecked { - return _byteLength / 4; - } - } - /** * @notice Get an item of v4. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -723,19 +518,6 @@ library Singleton { } } - /** - * @notice Get an item of v4 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemV4(IStore _store, uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - /** * @notice Push an element to v4. */ @@ -754,15 +536,6 @@ library Singleton { StoreCore.pushToDynamicField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); } - /** - * @notice Push an element to v4 (using the specified store). - */ - function pushV4(IStore _store, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.pushToDynamicField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); - } - /** * @notice Pop an element from v4. */ @@ -781,15 +554,6 @@ library Singleton { StoreCore.popFromDynamicField(_tableId, _keyTuple, 2, 4); } - /** - * @notice Pop an element from v4 (using the specified store). - */ - function popV4(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.popFromDynamicField(_tableId, _keyTuple, 2, 4); - } - /** * @notice Update an element of v4 at `_index`. */ @@ -814,18 +578,6 @@ library Singleton { } } - /** - * @notice Update an element of v4 (using the specified store) at `_index`. - */ - function updateV4(IStore _store, uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get the full data. */ @@ -854,22 +606,6 @@ library Singleton { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get( - IStore _store - ) internal view returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { - bytes32[] memory _keyTuple = new bytes32[](0); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -898,20 +634,6 @@ library Singleton { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) internal { - bytes memory _staticData = encodeStatic(v1); - - PackedCounter _encodedLengths = encodeLengths(v2, v3, v4); - bytes memory _dynamicData = encodeDynamic(v2, v3, v4); - - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -980,15 +702,6 @@ library Singleton { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index baf804811f..d906ebeeda 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -124,13 +124,6 @@ library Statics { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get v1. */ @@ -163,30 +156,6 @@ library Statics { return (uint256(bytes32(_blob))); } - /** - * @notice Get v1 (using the specified store). - */ - function getV1( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (uint256 v1) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - /** * @notice Set v1. */ @@ -217,21 +186,6 @@ library Statics { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); } - /** - * @notice Set v1 (using the specified store). - */ - function setV1(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, uint256 v1) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); - } - /** * @notice Get v2. */ @@ -264,30 +218,6 @@ library Statics { return (int32(uint32(bytes4(_blob)))); } - /** - * @notice Get v2 (using the specified store). - */ - function getV2( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (int32 v2) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - /** * @notice Set v2. */ @@ -318,21 +248,6 @@ library Statics { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), _fieldLayout); } - /** - * @notice Set v2 (using the specified store). - */ - function setV2(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, int32 v2) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), _fieldLayout); - } - /** * @notice Get v3. */ @@ -365,30 +280,6 @@ library Statics { return (bytes16(_blob)); } - /** - * @notice Get v3 (using the specified store). - */ - function getV3( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (bytes16 v3) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return (bytes16(_blob)); - } - /** * @notice Set v3. */ @@ -419,21 +310,6 @@ library Statics { StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), _fieldLayout); } - /** - * @notice Set v3 (using the specified store). - */ - function setV3(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, bytes16 v3) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), _fieldLayout); - } - /** * @notice Get v4. */ @@ -466,30 +342,6 @@ library Statics { return (address(bytes20(_blob))); } - /** - * @notice Get v4 (using the specified store). - */ - function getV4( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (address v4) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); - return (address(bytes20(_blob))); - } - /** * @notice Set v4. */ @@ -520,21 +372,6 @@ library Statics { StoreCore.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), _fieldLayout); } - /** - * @notice Set v4 (using the specified store). - */ - function setV4(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, address v4) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), _fieldLayout); - } - /** * @notice Get v5. */ @@ -567,30 +404,6 @@ library Statics { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get v5 (using the specified store). - */ - function getV5( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (bool v5) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set v5. */ @@ -621,21 +434,6 @@ library Statics { StoreCore.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), _fieldLayout); } - /** - * @notice Set v5 (using the specified store). - */ - function setV5(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, bool v5) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), _fieldLayout); - } - /** * @notice Get v6. */ @@ -668,30 +466,6 @@ library Statics { return Enum1(uint8(bytes1(_blob))); } - /** - * @notice Get v6 (using the specified store). - */ - function getV6( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (Enum1 v6) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); - return Enum1(uint8(bytes1(_blob))); - } - /** * @notice Set v6. */ @@ -722,21 +496,6 @@ library Statics { StoreCore.setStaticField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), _fieldLayout); } - /** - * @notice Set v6 (using the specified store). - */ - function setV6(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, Enum1 v6) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -791,34 +550,6 @@ library Statics { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (StaticsData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -885,40 +616,6 @@ library Statics { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6, - uint256 v1, - int32 v2, - bytes16 v3, - address v4, - bool v5, - Enum1 v6 - ) internal { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5, v6); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -959,35 +656,6 @@ library Statics { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6, - StaticsData memory _table - ) internal { - bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -1051,21 +719,6 @@ library Statics { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/cli/contracts/src/codegen/tables/UserTyped.sol b/packages/cli/contracts/src/codegen/tables/UserTyped.sol index 4a64d73521..24a11dbb75 100644 --- a/packages/cli/contracts/src/codegen/tables/UserTyped.sol +++ b/packages/cli/contracts/src/codegen/tables/UserTyped.sol @@ -120,13 +120,6 @@ library UserTyped { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get v1. */ @@ -169,28 +162,6 @@ library UserTyped { return TestTypeAddress.wrap(address(bytes20(_blob))); } - /** - * @notice Get v1 (using the specified store). - */ - function getV1( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeAddress v1) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return TestTypeAddress.wrap(address(bytes20(_blob))); - } - /** * @notice Set v1. */ @@ -233,28 +204,6 @@ library UserTyped { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(TestTypeAddress.unwrap(v1)), _fieldLayout); } - /** - * @notice Set v1 (using the specified store). - */ - function setV1( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeAddress v1 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(TestTypeAddress.unwrap(v1)), _fieldLayout); - } - /** * @notice Get v2. */ @@ -297,28 +246,6 @@ library UserTyped { return TestTypeInt64.wrap(int64(uint64(bytes8(_blob)))); } - /** - * @notice Get v2 (using the specified store). - */ - function getV2( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeInt64 v2) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return TestTypeInt64.wrap(int64(uint64(bytes8(_blob)))); - } - /** * @notice Set v2. */ @@ -361,28 +288,6 @@ library UserTyped { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(TestTypeInt64.unwrap(v2)), _fieldLayout); } - /** - * @notice Set v2 (using the specified store). - */ - function setV2( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeInt64 v2 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(TestTypeInt64.unwrap(v2)), _fieldLayout); - } - /** * @notice Get v3. */ @@ -425,28 +330,6 @@ library UserTyped { return TestTypeLibrary.TestTypeBool.wrap(_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get v3 (using the specified store). - */ - function getV3( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeLibrary.TestTypeBool v3) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return TestTypeLibrary.TestTypeBool.wrap(_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set v3. */ @@ -501,34 +384,6 @@ library UserTyped { ); } - /** - * @notice Set v3 (using the specified store). - */ - function setV3( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeLibrary.TestTypeBool v3 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.setStaticField( - _tableId, - _keyTuple, - 2, - abi.encodePacked(TestTypeLibrary.TestTypeBool.unwrap(v3)), - _fieldLayout - ); - } - /** * @notice Get v4. */ @@ -571,28 +426,6 @@ library UserTyped { return TestTypeLibrary.TestTypeUint128.wrap(uint128(bytes16(_blob))); } - /** - * @notice Get v4 (using the specified store). - */ - function getV4( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeLibrary.TestTypeUint128 v4) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); - return TestTypeLibrary.TestTypeUint128.wrap(uint128(bytes16(_blob))); - } - /** * @notice Set v4. */ @@ -647,34 +480,6 @@ library UserTyped { ); } - /** - * @notice Set v4 (using the specified store). - */ - function setV4( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeLibrary.TestTypeUint128 v4 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.setStaticField( - _tableId, - _keyTuple, - 3, - abi.encodePacked(TestTypeLibrary.TestTypeUint128.unwrap(v4)), - _fieldLayout - ); - } - /** * @notice Get v5. */ @@ -717,28 +522,6 @@ library UserTyped { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get v5 (using the specified store). - */ - function getV5( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (ResourceId v5) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Set v5. */ @@ -781,28 +564,6 @@ library UserTyped { StoreCore.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked(ResourceId.unwrap(v5)), _fieldLayout); } - /** - * @notice Set v5 (using the specified store). - */ - function setV5( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - ResourceId v5 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked(ResourceId.unwrap(v5)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -853,32 +614,6 @@ library UserTyped { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (UserTypedData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -939,37 +674,6 @@ library UserTyped { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeAddress v1, - TestTypeInt64 v2, - TestTypeLibrary.TestTypeBool v3, - TestTypeLibrary.TestTypeUint128 v4, - ResourceId v5 - ) internal { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -1022,33 +726,6 @@ library UserTyped { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - UserTypedData memory _table - ) internal { - bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -1130,27 +807,6 @@ library UserTyped { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord( - IStore _store, - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index 5a42e6472b..ed1be30ddd 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -90,13 +90,6 @@ library Hooks { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store, ResourceId _tableId) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get hooks. */ @@ -119,21 +112,6 @@ library Hooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } - /** - * @notice Get hooks (using the specified store). - */ - function getHooks( - IStore _store, - ResourceId _tableId, - ResourceId resourceId - ) internal view returns (bytes21[] memory hooks) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); - } - /** * @notice Get hooks. */ @@ -156,21 +134,6 @@ library Hooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } - /** - * @notice Get hooks (using the specified store). - */ - function get( - IStore _store, - ResourceId _tableId, - ResourceId resourceId - ) internal view returns (bytes21[] memory hooks) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); - } - /** * @notice Set hooks. */ @@ -191,16 +154,6 @@ library Hooks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); } - /** - * @notice Set hooks (using the specified store). - */ - function setHooks(IStore _store, ResourceId _tableId, ResourceId resourceId, bytes21[] memory hooks) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); - } - /** * @notice Set hooks. */ @@ -221,16 +174,6 @@ library Hooks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); } - /** - * @notice Set hooks (using the specified store). - */ - function set(IStore _store, ResourceId _tableId, ResourceId resourceId, bytes21[] memory hooks) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); - } - /** * @notice Get the length of hooks. */ @@ -257,19 +200,6 @@ library Hooks { } } - /** - * @notice Get the length of hooks (using the specified store). - */ - function lengthHooks(IStore _store, ResourceId _tableId, ResourceId resourceId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 21; - } - } - /** * @notice Get the length of hooks. */ @@ -296,19 +226,6 @@ library Hooks { } } - /** - * @notice Get the length of hooks (using the specified store). - */ - function length(IStore _store, ResourceId _tableId, ResourceId resourceId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 21; - } - } - /** * @notice Get an item of hooks. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -337,25 +254,6 @@ library Hooks { } } - /** - * @notice Get an item of hooks (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemHooks( - IStore _store, - ResourceId _tableId, - ResourceId resourceId, - uint256 _index - ) internal view returns (bytes21) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 21, (_index + 1) * 21); - return (bytes21(_blob)); - } - } - /** * @notice Get an item of hooks. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -384,25 +282,6 @@ library Hooks { } } - /** - * @notice Get an item of hooks (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItem( - IStore _store, - ResourceId _tableId, - ResourceId resourceId, - uint256 _index - ) internal view returns (bytes21) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 21, (_index + 1) * 21); - return (bytes21(_blob)); - } - } - /** * @notice Push an element to hooks. */ @@ -423,16 +302,6 @@ library Hooks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to hooks (using the specified store). - */ - function pushHooks(IStore _store, ResourceId _tableId, ResourceId resourceId, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Push an element to hooks. */ @@ -453,16 +322,6 @@ library Hooks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to hooks (using the specified store). - */ - function push(IStore _store, ResourceId _tableId, ResourceId resourceId, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from hooks. */ @@ -483,16 +342,6 @@ library Hooks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 21); } - /** - * @notice Pop an element from hooks (using the specified store). - */ - function popHooks(IStore _store, ResourceId _tableId, ResourceId resourceId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 21); - } - /** * @notice Pop an element from hooks. */ @@ -513,16 +362,6 @@ library Hooks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 21); } - /** - * @notice Pop an element from hooks (using the specified store). - */ - function pop(IStore _store, ResourceId _tableId, ResourceId resourceId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 21); - } - /** * @notice Update an element of hooks at `_index`. */ @@ -549,25 +388,6 @@ library Hooks { } } - /** - * @notice Update an element of hooks (using the specified store) at `_index`. - */ - function updateHooks( - IStore _store, - ResourceId _tableId, - ResourceId resourceId, - uint256 _index, - bytes21 _element - ) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 21), uint40(_encoded.length), _encoded); - } - } - /** * @notice Update an element of hooks at `_index`. */ @@ -594,25 +414,6 @@ library Hooks { } } - /** - * @notice Update an element of hooks (using the specified store) at `_index`. - */ - function update( - IStore _store, - ResourceId _tableId, - ResourceId resourceId, - uint256 _index, - bytes21 _element - ) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 21), uint40(_encoded.length), _encoded); - } - } - /** * @notice Delete all data for given keys. */ @@ -633,16 +434,6 @@ library Hooks { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId _tableId, ResourceId resourceId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/store/src/codegen/tables/ResourceIds.sol b/packages/store/src/codegen/tables/ResourceIds.sol index de17d2eef5..5b33c94693 100644 --- a/packages/store/src/codegen/tables/ResourceIds.sol +++ b/packages/store/src/codegen/tables/ResourceIds.sol @@ -95,13 +95,6 @@ library ResourceIds { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get exists. */ @@ -124,17 +117,6 @@ library ResourceIds { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get exists (using the specified store). - */ - function getExists(IStore _store, ResourceId resourceId) internal view returns (bool exists) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Get exists. */ @@ -157,17 +139,6 @@ library ResourceIds { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get exists (using the specified store). - */ - function get(IStore _store, ResourceId resourceId) internal view returns (bool exists) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set exists. */ @@ -188,16 +159,6 @@ library ResourceIds { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((exists)), _fieldLayout); } - /** - * @notice Set exists (using the specified store). - */ - function setExists(IStore _store, ResourceId resourceId, bool exists) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((exists)), _fieldLayout); - } - /** * @notice Set exists. */ @@ -218,16 +179,6 @@ library ResourceIds { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((exists)), _fieldLayout); } - /** - * @notice Set exists (using the specified store). - */ - function set(IStore _store, ResourceId resourceId, bool exists) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((exists)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -248,16 +199,6 @@ library ResourceIds { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId resourceId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(resourceId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index 830a2f33a4..40e49c7770 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -95,13 +95,6 @@ library StoreHooks { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get hooks. */ @@ -124,17 +117,6 @@ library StoreHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } - /** - * @notice Get hooks (using the specified store). - */ - function getHooks(IStore _store, ResourceId tableId) internal view returns (bytes21[] memory hooks) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); - } - /** * @notice Get hooks. */ @@ -157,17 +139,6 @@ library StoreHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } - /** - * @notice Get hooks (using the specified store). - */ - function get(IStore _store, ResourceId tableId) internal view returns (bytes21[] memory hooks) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); - } - /** * @notice Set hooks. */ @@ -188,16 +159,6 @@ library StoreHooks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); } - /** - * @notice Set hooks (using the specified store). - */ - function setHooks(IStore _store, ResourceId tableId, bytes21[] memory hooks) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); - } - /** * @notice Set hooks. */ @@ -218,16 +179,6 @@ library StoreHooks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); } - /** - * @notice Set hooks (using the specified store). - */ - function set(IStore _store, ResourceId tableId, bytes21[] memory hooks) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((hooks))); - } - /** * @notice Get the length of hooks. */ @@ -254,19 +205,6 @@ library StoreHooks { } } - /** - * @notice Get the length of hooks (using the specified store). - */ - function lengthHooks(IStore _store, ResourceId tableId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 21; - } - } - /** * @notice Get the length of hooks. */ @@ -293,19 +231,6 @@ library StoreHooks { } } - /** - * @notice Get the length of hooks (using the specified store). - */ - function length(IStore _store, ResourceId tableId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 21; - } - } - /** * @notice Get an item of hooks. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -334,20 +259,6 @@ library StoreHooks { } } - /** - * @notice Get an item of hooks (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemHooks(IStore _store, ResourceId tableId, uint256 _index) internal view returns (bytes21) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 21, (_index + 1) * 21); - return (bytes21(_blob)); - } - } - /** * @notice Get an item of hooks. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -376,20 +287,6 @@ library StoreHooks { } } - /** - * @notice Get an item of hooks (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItem(IStore _store, ResourceId tableId, uint256 _index) internal view returns (bytes21) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 21, (_index + 1) * 21); - return (bytes21(_blob)); - } - } - /** * @notice Push an element to hooks. */ @@ -410,16 +307,6 @@ library StoreHooks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to hooks (using the specified store). - */ - function pushHooks(IStore _store, ResourceId tableId, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Push an element to hooks. */ @@ -440,16 +327,6 @@ library StoreHooks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to hooks (using the specified store). - */ - function push(IStore _store, ResourceId tableId, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from hooks. */ @@ -470,16 +347,6 @@ library StoreHooks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 21); } - /** - * @notice Pop an element from hooks (using the specified store). - */ - function popHooks(IStore _store, ResourceId tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 21); - } - /** * @notice Pop an element from hooks. */ @@ -500,16 +367,6 @@ library StoreHooks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 21); } - /** - * @notice Pop an element from hooks (using the specified store). - */ - function pop(IStore _store, ResourceId tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 21); - } - /** * @notice Update an element of hooks at `_index`. */ @@ -536,19 +393,6 @@ library StoreHooks { } } - /** - * @notice Update an element of hooks (using the specified store) at `_index`. - */ - function updateHooks(IStore _store, ResourceId tableId, uint256 _index, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 21), uint40(_encoded.length), _encoded); - } - } - /** * @notice Update an element of hooks at `_index`. */ @@ -575,19 +419,6 @@ library StoreHooks { } } - /** - * @notice Update an element of hooks (using the specified store) at `_index`. - */ - function update(IStore _store, ResourceId tableId, uint256 _index, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 21), uint40(_encoded.length), _encoded); - } - } - /** * @notice Delete all data for given keys. */ @@ -608,16 +439,6 @@ library StoreHooks { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index 830ba9644f..e62e947299 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -113,13 +113,6 @@ library Tables { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get fieldLayout. */ @@ -142,17 +135,6 @@ library Tables { return FieldLayout.wrap(bytes32(_blob)); } - /** - * @notice Get fieldLayout (using the specified store). - */ - function getFieldLayout(IStore _store, ResourceId tableId) internal view returns (FieldLayout fieldLayout) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return FieldLayout.wrap(bytes32(_blob)); - } - /** * @notice Set fieldLayout. */ @@ -173,16 +155,6 @@ library Tables { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(FieldLayout.unwrap(fieldLayout)), _fieldLayout); } - /** - * @notice Set fieldLayout (using the specified store). - */ - function setFieldLayout(IStore _store, ResourceId tableId, FieldLayout fieldLayout) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(FieldLayout.unwrap(fieldLayout)), _fieldLayout); - } - /** * @notice Get keySchema. */ @@ -205,17 +177,6 @@ library Tables { return Schema.wrap(bytes32(_blob)); } - /** - * @notice Get keySchema (using the specified store). - */ - function getKeySchema(IStore _store, ResourceId tableId) internal view returns (Schema keySchema) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return Schema.wrap(bytes32(_blob)); - } - /** * @notice Set keySchema. */ @@ -236,16 +197,6 @@ library Tables { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(Schema.unwrap(keySchema)), _fieldLayout); } - /** - * @notice Set keySchema (using the specified store). - */ - function setKeySchema(IStore _store, ResourceId tableId, Schema keySchema) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(Schema.unwrap(keySchema)), _fieldLayout); - } - /** * @notice Get valueSchema. */ @@ -268,17 +219,6 @@ library Tables { return Schema.wrap(bytes32(_blob)); } - /** - * @notice Get valueSchema (using the specified store). - */ - function getValueSchema(IStore _store, ResourceId tableId) internal view returns (Schema valueSchema) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return Schema.wrap(bytes32(_blob)); - } - /** * @notice Set valueSchema. */ @@ -299,16 +239,6 @@ library Tables { StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked(Schema.unwrap(valueSchema)), _fieldLayout); } - /** - * @notice Set valueSchema (using the specified store). - */ - function setValueSchema(IStore _store, ResourceId tableId, Schema valueSchema) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked(Schema.unwrap(valueSchema)), _fieldLayout); - } - /** * @notice Get abiEncodedKeyNames. */ @@ -331,20 +261,6 @@ library Tables { return (bytes(_blob)); } - /** - * @notice Get abiEncodedKeyNames (using the specified store). - */ - function getAbiEncodedKeyNames( - IStore _store, - ResourceId tableId - ) internal view returns (bytes memory abiEncodedKeyNames) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (bytes(_blob)); - } - /** * @notice Set abiEncodedKeyNames. */ @@ -365,16 +281,6 @@ library Tables { StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((abiEncodedKeyNames))); } - /** - * @notice Set abiEncodedKeyNames (using the specified store). - */ - function setAbiEncodedKeyNames(IStore _store, ResourceId tableId, bytes memory abiEncodedKeyNames) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setDynamicField(_tableId, _keyTuple, 0, bytes((abiEncodedKeyNames))); - } - /** * @notice Get the length of abiEncodedKeyNames. */ @@ -401,19 +307,6 @@ library Tables { } } - /** - * @notice Get the length of abiEncodedKeyNames (using the specified store). - */ - function lengthAbiEncodedKeyNames(IStore _store, ResourceId tableId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 1; - } - } - /** * @notice Get an item of abiEncodedKeyNames. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -442,24 +335,6 @@ library Tables { } } - /** - * @notice Get an item of abiEncodedKeyNames (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemAbiEncodedKeyNames( - IStore _store, - ResourceId tableId, - uint256 _index - ) internal view returns (bytes memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); - return (bytes(_blob)); - } - } - /** * @notice Push a slice to abiEncodedKeyNames. */ @@ -480,16 +355,6 @@ library Tables { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); } - /** - * @notice Push a slice to abiEncodedKeyNames (using the specified store). - */ - function pushAbiEncodedKeyNames(IStore _store, ResourceId tableId, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); - } - /** * @notice Pop a slice from abiEncodedKeyNames. */ @@ -510,16 +375,6 @@ library Tables { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1); } - /** - * @notice Pop a slice from abiEncodedKeyNames (using the specified store). - */ - function popAbiEncodedKeyNames(IStore _store, ResourceId tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 1); - } - /** * @notice Update a slice of abiEncodedKeyNames at `_index`. */ @@ -546,19 +401,6 @@ library Tables { } } - /** - * @notice Update a slice of abiEncodedKeyNames (using the specified store) at `_index`. - */ - function updateAbiEncodedKeyNames(IStore _store, ResourceId tableId, uint256 _index, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _encoded = bytes((_slice)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get abiEncodedFieldNames. */ @@ -581,20 +423,6 @@ library Tables { return (bytes(_blob)); } - /** - * @notice Get abiEncodedFieldNames (using the specified store). - */ - function getAbiEncodedFieldNames( - IStore _store, - ResourceId tableId - ) internal view returns (bytes memory abiEncodedFieldNames) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); - return (bytes(_blob)); - } - /** * @notice Set abiEncodedFieldNames. */ @@ -615,16 +443,6 @@ library Tables { StoreCore.setDynamicField(_tableId, _keyTuple, 1, bytes((abiEncodedFieldNames))); } - /** - * @notice Set abiEncodedFieldNames (using the specified store). - */ - function setAbiEncodedFieldNames(IStore _store, ResourceId tableId, bytes memory abiEncodedFieldNames) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setDynamicField(_tableId, _keyTuple, 1, bytes((abiEncodedFieldNames))); - } - /** * @notice Get the length of abiEncodedFieldNames. */ @@ -651,19 +469,6 @@ library Tables { } } - /** - * @notice Get the length of abiEncodedFieldNames (using the specified store). - */ - function lengthAbiEncodedFieldNames(IStore _store, ResourceId tableId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 1); - unchecked { - return _byteLength / 1; - } - } - /** * @notice Get an item of abiEncodedFieldNames. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -692,24 +497,6 @@ library Tables { } } - /** - * @notice Get an item of abiEncodedFieldNames (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemAbiEncodedFieldNames( - IStore _store, - ResourceId tableId, - uint256 _index - ) internal view returns (bytes memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); - return (bytes(_blob)); - } - } - /** * @notice Push a slice to abiEncodedFieldNames. */ @@ -730,16 +517,6 @@ library Tables { StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); } - /** - * @notice Push a slice to abiEncodedFieldNames (using the specified store). - */ - function pushAbiEncodedFieldNames(IStore _store, ResourceId tableId, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); - } - /** * @notice Pop a slice from abiEncodedFieldNames. */ @@ -760,16 +537,6 @@ library Tables { StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 1); } - /** - * @notice Pop a slice from abiEncodedFieldNames (using the specified store). - */ - function popAbiEncodedFieldNames(IStore _store, ResourceId tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.popFromDynamicField(_tableId, _keyTuple, 1, 1); - } - /** * @notice Update a slice of abiEncodedFieldNames at `_index`. */ @@ -796,19 +563,6 @@ library Tables { } } - /** - * @notice Update a slice of abiEncodedFieldNames (using the specified store) at `_index`. - */ - function updateAbiEncodedFieldNames(IStore _store, ResourceId tableId, uint256 _index, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - unchecked { - bytes memory _encoded = bytes((_slice)); - _store.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get the full data. */ @@ -839,21 +593,6 @@ library Tables { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, ResourceId tableId) internal view returns (TablesData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -898,29 +637,6 @@ library Tables { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set( - IStore _store, - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - bytes memory abiEncodedKeyNames, - bytes memory abiEncodedFieldNames - ) internal { - bytes memory _staticData = encodeStatic(fieldLayout, keySchema, valueSchema); - - PackedCounter _encodedLengths = encodeLengths(abiEncodedKeyNames, abiEncodedFieldNames); - bytes memory _dynamicData = encodeDynamic(abiEncodedKeyNames, abiEncodedFieldNames); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -951,21 +667,6 @@ library Tables { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, ResourceId tableId, TablesData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.fieldLayout, _table.keySchema, _table.valueSchema); - - PackedCounter _encodedLengths = encodeLengths(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); - bytes memory _dynamicData = encodeDynamic(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -1036,16 +737,6 @@ library Tables { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(tableId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index ea2e5d5c83..fea7a9054e 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -95,10 +95,10 @@ contract StoreCoreTest is Test, StoreMock { assertEq(IStore(this).getValueSchema(tableId).unwrap(), valueSchema.unwrap()); assertEq(IStore(this).getKeySchema(tableId).unwrap(), keySchema.unwrap()); - bytes memory loadedKeyNames = Tables.getAbiEncodedKeyNames(IStore(this), tableId); + bytes memory loadedKeyNames = Tables.getAbiEncodedKeyNames(tableId); assertEq(loadedKeyNames, abi.encode(keyNames)); - bytes memory loadedFieldNames = Tables.getAbiEncodedFieldNames(IStore(this), tableId); + bytes memory loadedFieldNames = Tables.getAbiEncodedFieldNames(tableId); assertEq(loadedFieldNames, abi.encode(fieldNames)); // Expect the table ID to be registered diff --git a/packages/store/test/StoreMock.sol b/packages/store/test/StoreMock.sol index f8427117f8..48bab109db 100644 --- a/packages/store/test/StoreMock.sol +++ b/packages/store/test/StoreMock.sol @@ -3,6 +3,7 @@ pragma solidity >=0.8.21; import { IStore } from "../src/IStore.sol"; import { IStoreHook } from "../src/IStoreHook.sol"; +import { StoreSwitch } from "../src/StoreSwitch.sol"; import { StoreData } from "../src/StoreData.sol"; import { PackedCounter } from "../src/PackedCounter.sol"; import { StoreCore } from "../src/StoreCore.sol"; @@ -18,6 +19,7 @@ contract StoreMock is IStore, StoreData { constructor() { StoreCore.initialize(); StoreCore.registerCoreTables(); + StoreSwitch.setStoreAddress(address(this)); } // Set full record (including full dynamic data) diff --git a/packages/store/test/codegen/tables/Callbacks.sol b/packages/store/test/codegen/tables/Callbacks.sol index 7f080822dc..5d3552e1b8 100644 --- a/packages/store/test/codegen/tables/Callbacks.sol +++ b/packages/store/test/codegen/tables/Callbacks.sol @@ -92,13 +92,6 @@ library Callbacks { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -121,17 +114,6 @@ library Callbacks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store, bytes32 key) internal view returns (bytes24[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); - } - /** * @notice Get value. */ @@ -154,17 +136,6 @@ library Callbacks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store, bytes32 key) internal view returns (bytes24[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); - } - /** * @notice Set value. */ @@ -185,16 +156,6 @@ library Callbacks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, bytes32 key, bytes24[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Set value. */ @@ -215,16 +176,6 @@ library Callbacks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, bytes32 key, bytes24[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Get the length of value. */ @@ -251,19 +202,6 @@ library Callbacks { } } - /** - * @notice Get the length of value (using the specified store). - */ - function lengthValue(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 24; - } - } - /** * @notice Get the length of value. */ @@ -290,19 +228,6 @@ library Callbacks { } } - /** - * @notice Get the length of value (using the specified store). - */ - function length(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 24; - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -331,20 +256,6 @@ library Callbacks { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemValue(IStore _store, bytes32 key, uint256 _index) internal view returns (bytes24) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 24, (_index + 1) * 24); - return (bytes24(_blob)); - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -373,20 +284,6 @@ library Callbacks { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItem(IStore _store, bytes32 key, uint256 _index) internal view returns (bytes24) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 24, (_index + 1) * 24); - return (bytes24(_blob)); - } - } - /** * @notice Push an element to value. */ @@ -407,16 +304,6 @@ library Callbacks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function pushValue(IStore _store, bytes32 key, bytes24 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Push an element to value. */ @@ -437,16 +324,6 @@ library Callbacks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function push(IStore _store, bytes32 key, bytes24 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from value. */ @@ -467,16 +344,6 @@ library Callbacks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 24); } - /** - * @notice Pop an element from value (using the specified store). - */ - function popValue(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 24); - } - /** * @notice Pop an element from value. */ @@ -497,16 +364,6 @@ library Callbacks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 24); } - /** - * @notice Pop an element from value (using the specified store). - */ - function pop(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 24); - } - /** * @notice Update an element of value at `_index`. */ @@ -533,19 +390,6 @@ library Callbacks { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function updateValue(IStore _store, bytes32 key, uint256 _index, bytes24 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 24), uint40(_encoded.length), _encoded); - } - } - /** * @notice Update an element of value at `_index`. */ @@ -572,19 +416,6 @@ library Callbacks { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function update(IStore _store, bytes32 key, uint256 _index, bytes24 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 24), uint40(_encoded.length), _encoded); - } - } - /** * @notice Delete all data for given keys. */ @@ -605,16 +436,6 @@ library Callbacks { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/store/test/codegen/tables/KeyEncoding.sol b/packages/store/test/codegen/tables/KeyEncoding.sol index 682355c425..44ab473659 100644 --- a/packages/store/test/codegen/tables/KeyEncoding.sol +++ b/packages/store/test/codegen/tables/KeyEncoding.sol @@ -105,13 +105,6 @@ library KeyEncoding { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -158,30 +151,6 @@ library KeyEncoding { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get value (using the specified store). - */ - function getValue( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - ExampleEnum k6 - ) internal view returns (bool value) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Get value. */ @@ -228,30 +197,6 @@ library KeyEncoding { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get value (using the specified store). - */ - function get( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - ExampleEnum k6 - ) internal view returns (bool value) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set value. */ @@ -282,30 +227,6 @@ library KeyEncoding { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - ExampleEnum k6, - bool value - ) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Set value. */ @@ -336,30 +257,6 @@ library KeyEncoding { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function set( - IStore _store, - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - ExampleEnum k6, - bool value - ) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -390,21 +287,6 @@ library KeyEncoding { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, ExampleEnum k6) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/store/test/codegen/tables/Mixed.sol b/packages/store/test/codegen/tables/Mixed.sol index eb1e585cad..f772c1ea84 100644 --- a/packages/store/test/codegen/tables/Mixed.sol +++ b/packages/store/test/codegen/tables/Mixed.sol @@ -105,13 +105,6 @@ library Mixed { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get u32. */ @@ -134,17 +127,6 @@ library Mixed { return (uint32(bytes4(_blob))); } - /** - * @notice Get u32 (using the specified store). - */ - function getU32(IStore _store, bytes32 key) internal view returns (uint32 u32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set u32. */ @@ -165,16 +147,6 @@ library Mixed { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((u32)), _fieldLayout); } - /** - * @notice Set u32 (using the specified store). - */ - function setU32(IStore _store, bytes32 key, uint32 u32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((u32)), _fieldLayout); - } - /** * @notice Get u128. */ @@ -197,17 +169,6 @@ library Mixed { return (uint128(bytes16(_blob))); } - /** - * @notice Get u128 (using the specified store). - */ - function getU128(IStore _store, bytes32 key) internal view returns (uint128 u128) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint128(bytes16(_blob))); - } - /** * @notice Set u128. */ @@ -228,16 +189,6 @@ library Mixed { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((u128)), _fieldLayout); } - /** - * @notice Set u128 (using the specified store). - */ - function setU128(IStore _store, bytes32 key, uint128 u128) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((u128)), _fieldLayout); - } - /** * @notice Get a32. */ @@ -260,17 +211,6 @@ library Mixed { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } - /** - * @notice Get a32 (using the specified store). - */ - function getA32(IStore _store, bytes32 key) internal view returns (uint32[] memory a32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - /** * @notice Set a32. */ @@ -291,16 +231,6 @@ library Mixed { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((a32))); } - /** - * @notice Set a32 (using the specified store). - */ - function setA32(IStore _store, bytes32 key, uint32[] memory a32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((a32))); - } - /** * @notice Get the length of a32. */ @@ -327,19 +257,6 @@ library Mixed { } } - /** - * @notice Get the length of a32 (using the specified store). - */ - function lengthA32(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 4; - } - } - /** * @notice Get an item of a32. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -368,20 +285,6 @@ library Mixed { } } - /** - * @notice Get an item of a32 (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemA32(IStore _store, bytes32 key, uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - /** * @notice Push an element to a32. */ @@ -402,16 +305,6 @@ library Mixed { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to a32 (using the specified store). - */ - function pushA32(IStore _store, bytes32 key, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from a32. */ @@ -432,16 +325,6 @@ library Mixed { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 4); } - /** - * @notice Pop an element from a32 (using the specified store). - */ - function popA32(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 4); - } - /** * @notice Update an element of a32 at `_index`. */ @@ -468,19 +351,6 @@ library Mixed { } } - /** - * @notice Update an element of a32 (using the specified store) at `_index`. - */ - function updateA32(IStore _store, bytes32 key, uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get s. */ @@ -503,17 +373,6 @@ library Mixed { return (string(_blob)); } - /** - * @notice Get s (using the specified store). - */ - function getS(IStore _store, bytes32 key) internal view returns (string memory s) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); - return (string(_blob)); - } - /** * @notice Set s. */ @@ -534,16 +393,6 @@ library Mixed { StoreCore.setDynamicField(_tableId, _keyTuple, 1, bytes((s))); } - /** - * @notice Set s (using the specified store). - */ - function setS(IStore _store, bytes32 key, string memory s) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 1, bytes((s))); - } - /** * @notice Get the length of s. */ @@ -570,19 +419,6 @@ library Mixed { } } - /** - * @notice Get the length of s (using the specified store). - */ - function lengthS(IStore _store, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 1); - unchecked { - return _byteLength / 1; - } - } - /** * @notice Get an item of s. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -611,20 +447,6 @@ library Mixed { } } - /** - * @notice Get an item of s (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemS(IStore _store, bytes32 key, uint256 _index) internal view returns (string memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); - return (string(_blob)); - } - } - /** * @notice Push a slice to s. */ @@ -645,16 +467,6 @@ library Mixed { StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); } - /** - * @notice Push a slice to s (using the specified store). - */ - function pushS(IStore _store, bytes32 key, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); - } - /** * @notice Pop a slice from s. */ @@ -675,16 +487,6 @@ library Mixed { StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 1); } - /** - * @notice Pop a slice from s (using the specified store). - */ - function popS(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 1, 1); - } - /** * @notice Update a slice of s at `_index`. */ @@ -711,19 +513,6 @@ library Mixed { } } - /** - * @notice Update a slice of s (using the specified store) at `_index`. - */ - function updateS(IStore _store, bytes32 key, uint256 _index, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = bytes((_slice)); - _store.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - /** * @notice Get the full data. */ @@ -754,21 +543,6 @@ library Mixed { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, bytes32 key) internal view returns (MixedData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -799,21 +573,6 @@ library Mixed { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, bytes32 key, uint32 u32, uint128 u128, uint32[] memory a32, string memory s) internal { - bytes memory _staticData = encodeStatic(u32, u128); - - PackedCounter _encodedLengths = encodeLengths(a32, s); - bytes memory _dynamicData = encodeDynamic(a32, s); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -844,21 +603,6 @@ library Mixed { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, bytes32 key, MixedData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.u32, _table.u128); - - PackedCounter _encodedLengths = encodeLengths(_table.a32, _table.s); - bytes memory _dynamicData = encodeDynamic(_table.a32, _table.s); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -925,16 +669,6 @@ library Mixed { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/store/test/codegen/tables/Vector2.sol b/packages/store/test/codegen/tables/Vector2.sol index e73bb0291e..e39a5c9440 100644 --- a/packages/store/test/codegen/tables/Vector2.sol +++ b/packages/store/test/codegen/tables/Vector2.sol @@ -99,13 +99,6 @@ library Vector2 { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get x. */ @@ -128,17 +121,6 @@ library Vector2 { return (uint32(bytes4(_blob))); } - /** - * @notice Get x (using the specified store). - */ - function getX(IStore _store, bytes32 key) internal view returns (uint32 x) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set x. */ @@ -159,16 +141,6 @@ library Vector2 { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout); } - /** - * @notice Set x (using the specified store). - */ - function setX(IStore _store, bytes32 key, uint32 x) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout); - } - /** * @notice Get y. */ @@ -191,17 +163,6 @@ library Vector2 { return (uint32(bytes4(_blob))); } - /** - * @notice Get y (using the specified store). - */ - function getY(IStore _store, bytes32 key) internal view returns (uint32 y) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set y. */ @@ -222,16 +183,6 @@ library Vector2 { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout); } - /** - * @notice Set y (using the specified store). - */ - function setY(IStore _store, bytes32 key, uint32 y) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -262,21 +213,6 @@ library Vector2 { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, bytes32 key) internal view returns (Vector2Data memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -307,21 +243,6 @@ library Vector2 { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, bytes32 key, uint32 x, uint32 y) internal { - bytes memory _staticData = encodeStatic(x, y); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -352,21 +273,6 @@ library Vector2 { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, bytes32 key, Vector2Data memory _table) internal { - bytes memory _staticData = encodeStatic(_table.x, _table.y); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -410,16 +316,6 @@ library Vector2 { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/store/ts/config/defaults.ts b/packages/store/ts/config/defaults.ts index c7360eeb39..328d4ffb8c 100644 --- a/packages/store/ts/config/defaults.ts +++ b/packages/store/ts/config/defaults.ts @@ -15,6 +15,6 @@ export const TABLE_DEFAULTS = { directory: "tables", keySchema: { key: "bytes32" }, tableIdArgument: false, - storeArgument: true, + storeArgument: false, offchainOnly: false, } as const; diff --git a/packages/world-modules/gas-report.json b/packages/world-modules/gas-report.json index c806f19a87..a32ae89a2f 100644 --- a/packages/world-modules/gas-report.json +++ b/packages/world-modules/gas-report.json @@ -69,7 +69,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "Get list of keys with a given value", - "gasUsed": 5635 + "gasUsed": 5665 }, { "file": "test/KeysWithValueModule.t.sol", diff --git a/packages/world-modules/mud.config.ts b/packages/world-modules/mud.config.ts index 5dd8ba75e8..bf8e4bc6e7 100644 --- a/packages/world-modules/mud.config.ts +++ b/packages/world-modules/mud.config.ts @@ -22,6 +22,7 @@ export default mudConfig({ keysWithValue: "bytes32[]", // For now only supports 1 key per value }, tableIdArgument: true, + storeArgument: true, }, KeysInTable: { directory: "modules/keysintable/tables", @@ -33,6 +34,7 @@ export default mudConfig({ keys3: "bytes32[]", keys4: "bytes32[]", }, + storeArgument: true, }, UsedKeysIndex: { directory: "modules/keysintable/tables", @@ -42,6 +44,7 @@ export default mudConfig({ }, valueSchema: { has: "bool", index: "uint40" }, dataStruct: false, + storeArgument: true, }, UniqueEntity: { directory: "modules/uniqueentity/tables", diff --git a/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol index c368d68dc9..1e4b96c541 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -101,13 +101,6 @@ library CallboundDelegations { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get availableCalls. */ @@ -146,26 +139,6 @@ library CallboundDelegations { return (uint256(bytes32(_blob))); } - /** - * @notice Get availableCalls (using the specified store). - */ - function getAvailableCalls( - IStore _store, - address delegator, - address delegatee, - ResourceId systemId, - bytes32 callDataHash - ) internal view returns (uint256 availableCalls) { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _keyTuple[2] = ResourceId.unwrap(systemId); - _keyTuple[3] = callDataHash; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - /** * @notice Get availableCalls. */ @@ -204,26 +177,6 @@ library CallboundDelegations { return (uint256(bytes32(_blob))); } - /** - * @notice Get availableCalls (using the specified store). - */ - function get( - IStore _store, - address delegator, - address delegatee, - ResourceId systemId, - bytes32 callDataHash - ) internal view returns (uint256 availableCalls) { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _keyTuple[2] = ResourceId.unwrap(systemId); - _keyTuple[3] = callDataHash; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - /** * @notice Set availableCalls. */ @@ -262,26 +215,6 @@ library CallboundDelegations { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); } - /** - * @notice Set availableCalls (using the specified store). - */ - function setAvailableCalls( - IStore _store, - address delegator, - address delegatee, - ResourceId systemId, - bytes32 callDataHash, - uint256 availableCalls - ) internal { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _keyTuple[2] = ResourceId.unwrap(systemId); - _keyTuple[3] = callDataHash; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); - } - /** * @notice Set availableCalls. */ @@ -320,26 +253,6 @@ library CallboundDelegations { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); } - /** - * @notice Set availableCalls (using the specified store). - */ - function set( - IStore _store, - address delegator, - address delegatee, - ResourceId systemId, - bytes32 callDataHash, - uint256 availableCalls - ) internal { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _keyTuple[2] = ResourceId.unwrap(systemId); - _keyTuple[3] = callDataHash; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -366,25 +279,6 @@ library CallboundDelegations { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord( - IStore _store, - address delegator, - address delegatee, - ResourceId systemId, - bytes32 callDataHash - ) internal { - bytes32[] memory _keyTuple = new bytes32[](4); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _keyTuple[2] = ResourceId.unwrap(systemId); - _keyTuple[3] = callDataHash; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol b/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol index a84c42dbd9..48e4445f61 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -94,13 +94,6 @@ library TimeboundDelegations { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get maxTimestamp. */ @@ -125,22 +118,6 @@ library TimeboundDelegations { return (uint256(bytes32(_blob))); } - /** - * @notice Get maxTimestamp (using the specified store). - */ - function getMaxTimestamp( - IStore _store, - address delegator, - address delegatee - ) internal view returns (uint256 maxTimestamp) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - /** * @notice Get maxTimestamp. */ @@ -165,18 +142,6 @@ library TimeboundDelegations { return (uint256(bytes32(_blob))); } - /** - * @notice Get maxTimestamp (using the specified store). - */ - function get(IStore _store, address delegator, address delegatee) internal view returns (uint256 maxTimestamp) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - /** * @notice Set maxTimestamp. */ @@ -199,17 +164,6 @@ library TimeboundDelegations { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout); } - /** - * @notice Set maxTimestamp (using the specified store). - */ - function setMaxTimestamp(IStore _store, address delegator, address delegatee, uint256 maxTimestamp) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout); - } - /** * @notice Set maxTimestamp. */ @@ -232,17 +186,6 @@ library TimeboundDelegations { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout); } - /** - * @notice Set maxTimestamp (using the specified store). - */ - function set(IStore _store, address delegator, address delegatee, uint256 maxTimestamp) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -265,17 +208,6 @@ library TimeboundDelegations { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, address delegator, address delegatee) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world-modules/test/KeysWithValueModule.t.sol b/packages/world-modules/test/KeysWithValueModule.t.sol index b881def01a..a01b0d68a2 100644 --- a/packages/world-modules/test/KeysWithValueModule.t.sol +++ b/packages/world-modules/test/KeysWithValueModule.t.sol @@ -6,6 +6,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId, ResourceIdInstance } from "@latticexyz/store/src/ResourceId.sol"; @@ -50,14 +51,17 @@ contract KeysWithValueModuleTest is Test, GasReporter { sourceTableFieldLayout = FieldLayoutEncodeHelper.encode(32, 0); sourceTableSchema = SchemaEncodeHelper.encode(SchemaType.UINT256); sourceTableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); + sourceTableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: sourceName }); + targetTableId = getTargetTableId(MODULE_NAMESPACE, sourceTableId); + world = IBaseWorld(address(new World())); world.initialize(new CoreModule()); + StoreSwitch.setStoreAddress(address(world)); + keyTuple1 = new bytes32[](1); keyTuple1[0] = key1; keyTuple2 = new bytes32[](1); keyTuple2[0] = key2; - sourceTableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: sourceName }); - targetTableId = getTargetTableId(MODULE_NAMESPACE, sourceTableId); } function _installKeysWithValueModule() internal { @@ -93,7 +97,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { endGasReport(); // Get the list of entities with this value from the target table - bytes32[] memory keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encodePacked(value))); + bytes32[] memory keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value))); // Assert that the list is correct assertEq(keysWithValue.length, 1); @@ -109,7 +113,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); // Get the list of entities with value1 from the target table - bytes32[] memory keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encodePacked(value1))); + bytes32[] memory keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value1))); // Assert that the list is correct assertEq(keysWithValue.length, 1, "1"); @@ -119,7 +123,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); // Get the list of entities with value2 from the target table - keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encodePacked(value1))); + keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value1))); // Assert that the list is correct assertEq(keysWithValue.length, 2); @@ -134,14 +138,14 @@ contract KeysWithValueModuleTest is Test, GasReporter { endGasReport(); // Get the list of entities with value1 from the target table - keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encodePacked(value1))); + keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value1))); // Assert that the list is correct assertEq(keysWithValue.length, 1, "5"); assertEq(keysWithValue[0], key2, "6"); // Get the list of entities with value2 from the target table - keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encodePacked(value2))); + keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value2))); // Assert that the list is correct assertEq(keysWithValue.length, 1, "7"); @@ -153,7 +157,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { endGasReport(); // Get the list of entities with value2 from the target table - keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encodePacked(value2))); + keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value2))); // Assert that the list is correct assertEq(keysWithValue.length, 0, "9"); @@ -170,7 +174,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { endGasReport(); // Get the list of entities with value1 from the target table - bytes32[] memory keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encode(value1))); + bytes32[] memory keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encode(value1))); // Assert that the list is correct assertEq(keysWithValue.length, 1); @@ -184,13 +188,13 @@ contract KeysWithValueModuleTest is Test, GasReporter { endGasReport(); // Get the list of entities with value1 from the target table - keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encode(value1))); + keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encode(value1))); // Assert that the list is correct assertEq(keysWithValue.length, 0); // Get the list of entities with value2 from the target table - keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encode(value2))); + keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encode(value2))); // Assert that the list is correct assertEq(keysWithValue.length, 1); diff --git a/packages/world-modules/test/UniqueEntityModule.t.sol b/packages/world-modules/test/UniqueEntityModule.t.sol index c5f12dfb2e..6b0dd8ea45 100644 --- a/packages/world-modules/test/UniqueEntityModule.t.sol +++ b/packages/world-modules/test/UniqueEntityModule.t.sol @@ -4,6 +4,7 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { World } from "@latticexyz/world/src/World.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; @@ -36,6 +37,7 @@ contract UniqueEntityModuleTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); world.initialize(new CoreModule()); + StoreSwitch.setStoreAddress(address(world)); } function testInstall() public { @@ -50,10 +52,10 @@ contract UniqueEntityModuleTest is Test, GasReporter { endGasReport(); // Table must have the same entity set - assertEq(UniqueEntity.get(world, tableId), uniqueEntity); + assertEq(UniqueEntity.get(tableId), uniqueEntity); // The next entity must be incremented assertEq(uint256(getUniqueEntity(world)), uniqueEntity + 1); - assertEq(UniqueEntity.get(world, tableId), uniqueEntity + 1); + assertEq(UniqueEntity.get(tableId), uniqueEntity + 1); } function testInstallRoot() public { @@ -68,10 +70,10 @@ contract UniqueEntityModuleTest is Test, GasReporter { endGasReport(); // Table must have the same entity set - assertEq(UniqueEntity.get(world, tableId), uniqueEntity); + assertEq(UniqueEntity.get(tableId), uniqueEntity); // The next entity must be incremented assertEq(uint256(getUniqueEntity(world)), uniqueEntity + 1); - assertEq(UniqueEntity.get(world, tableId), uniqueEntity + 1); + assertEq(UniqueEntity.get(tableId), uniqueEntity + 1); } function testPublicAccess() public { @@ -85,10 +87,10 @@ contract UniqueEntityModuleTest is Test, GasReporter { uint256 uniqueEntity = uint256(getUniqueEntity(world)); // Table must have the same entity set - assertEq(UniqueEntity.get(world, tableId), uniqueEntity); + assertEq(UniqueEntity.get(tableId), uniqueEntity); // The next entity must be incremented assertEq(uint256(getUniqueEntity(world)), uniqueEntity + 1); - assertEq(UniqueEntity.get(world, tableId), uniqueEntity + 1); + assertEq(UniqueEntity.get(tableId), uniqueEntity + 1); // But changing the table directly isn't allowed vm.expectRevert( diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 36848f6dbc..007eafe3d9 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -117,7 +117,7 @@ "file": "test/World.t.sol", "test": "testRegisterTable", "name": "Register a new table in the namespace", - "gasUsed": 637399 + "gasUsed": 637367 }, { "file": "test/World.t.sol", @@ -129,13 +129,13 @@ "file": "test/World.t.sol", "test": "testSetRecord", "name": "Write data to the table", - "gasUsed": 36896 + "gasUsed": 39039 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testPopFromDynamicField", "name": "pop 1 address (cold)", - "gasUsed": 23602 + "gasUsed": 25602 }, { "file": "test/WorldDynamicUpdate.t.sol", @@ -147,7 +147,7 @@ "file": "test/WorldDynamicUpdate.t.sol", "test": "testSpliceDynamicData", "name": "update in field 1 item (cold)", - "gasUsed": 23953 + "gasUsed": 25953 }, { "file": "test/WorldDynamicUpdate.t.sol", diff --git a/packages/world/src/codegen/tables/Balances.sol b/packages/world/src/codegen/tables/Balances.sol index 16e2caf999..96d0fe791e 100644 --- a/packages/world/src/codegen/tables/Balances.sol +++ b/packages/world/src/codegen/tables/Balances.sol @@ -95,13 +95,6 @@ library Balances { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get balance. */ @@ -124,17 +117,6 @@ library Balances { return (uint256(bytes32(_blob))); } - /** - * @notice Get balance (using the specified store). - */ - function getBalance(IStore _store, ResourceId namespaceId) internal view returns (uint256 balance) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - /** * @notice Get balance. */ @@ -157,17 +139,6 @@ library Balances { return (uint256(bytes32(_blob))); } - /** - * @notice Get balance (using the specified store). - */ - function get(IStore _store, ResourceId namespaceId) internal view returns (uint256 balance) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - /** * @notice Set balance. */ @@ -188,16 +159,6 @@ library Balances { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout); } - /** - * @notice Set balance (using the specified store). - */ - function setBalance(IStore _store, ResourceId namespaceId, uint256 balance) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout); - } - /** * @notice Set balance. */ @@ -218,16 +179,6 @@ library Balances { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout); } - /** - * @notice Set balance (using the specified store). - */ - function set(IStore _store, ResourceId namespaceId, uint256 balance) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -248,16 +199,6 @@ library Balances { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId namespaceId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/FunctionSelectors.sol b/packages/world/src/codegen/tables/FunctionSelectors.sol index 4957108080..e58c224c9a 100644 --- a/packages/world/src/codegen/tables/FunctionSelectors.sol +++ b/packages/world/src/codegen/tables/FunctionSelectors.sol @@ -97,13 +97,6 @@ library FunctionSelectors { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get systemId. */ @@ -126,17 +119,6 @@ library FunctionSelectors { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get systemId (using the specified store). - */ - function getSystemId(IStore _store, bytes4 functionSelector) internal view returns (ResourceId systemId) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Set systemId. */ @@ -157,16 +139,6 @@ library FunctionSelectors { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); } - /** - * @notice Set systemId (using the specified store). - */ - function setSystemId(IStore _store, bytes4 functionSelector, ResourceId systemId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); - } - /** * @notice Get systemFunctionSelector. */ @@ -189,20 +161,6 @@ library FunctionSelectors { return (bytes4(_blob)); } - /** - * @notice Get systemFunctionSelector (using the specified store). - */ - function getSystemFunctionSelector( - IStore _store, - bytes4 functionSelector - ) internal view returns (bytes4 systemFunctionSelector) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (bytes4(_blob)); - } - /** * @notice Set systemFunctionSelector. */ @@ -223,16 +181,6 @@ library FunctionSelectors { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), _fieldLayout); } - /** - * @notice Set systemFunctionSelector (using the specified store). - */ - function setSystemFunctionSelector(IStore _store, bytes4 functionSelector, bytes4 systemFunctionSelector) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -263,24 +211,6 @@ library FunctionSelectors { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get( - IStore _store, - bytes4 functionSelector - ) internal view returns (ResourceId systemId, bytes4 systemFunctionSelector) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -311,21 +241,6 @@ library FunctionSelectors { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, bytes4 functionSelector, ResourceId systemId, bytes4 systemFunctionSelector) internal { - bytes memory _staticData = encodeStatic(systemId, systemFunctionSelector); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -369,16 +284,6 @@ library FunctionSelectors { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes4 functionSelector) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/FunctionSignatures.sol b/packages/world/src/codegen/tables/FunctionSignatures.sol index dc30c5e1b5..45f8efd487 100644 --- a/packages/world/src/codegen/tables/FunctionSignatures.sol +++ b/packages/world/src/codegen/tables/FunctionSignatures.sol @@ -92,13 +92,6 @@ library FunctionSignatures { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Set the full data using individual values. */ @@ -127,20 +120,6 @@ library FunctionSignatures { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, bytes4 functionSelector, string memory functionSignature) internal { - bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(functionSignature); - bytes memory _dynamicData = encodeDynamic(functionSignature); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ @@ -190,16 +169,6 @@ library FunctionSignatures { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes4 functionSelector) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/world/src/codegen/tables/InstalledModules.sol b/packages/world/src/codegen/tables/InstalledModules.sol index f59d7ac5e7..ff16296f5d 100644 --- a/packages/world/src/codegen/tables/InstalledModules.sol +++ b/packages/world/src/codegen/tables/InstalledModules.sol @@ -94,13 +94,6 @@ library InstalledModules { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get moduleAddress. */ @@ -125,22 +118,6 @@ library InstalledModules { return (address(bytes20(_blob))); } - /** - * @notice Get moduleAddress (using the specified store). - */ - function getModuleAddress( - IStore _store, - bytes16 moduleName, - bytes32 argumentsHash - ) internal view returns (address moduleAddress) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(moduleName); - _keyTuple[1] = argumentsHash; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(bytes20(_blob))); - } - /** * @notice Get moduleAddress. */ @@ -165,18 +142,6 @@ library InstalledModules { return (address(bytes20(_blob))); } - /** - * @notice Get moduleAddress (using the specified store). - */ - function get(IStore _store, bytes16 moduleName, bytes32 argumentsHash) internal view returns (address moduleAddress) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(moduleName); - _keyTuple[1] = argumentsHash; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(bytes20(_blob))); - } - /** * @notice Set moduleAddress. */ @@ -199,17 +164,6 @@ library InstalledModules { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), _fieldLayout); } - /** - * @notice Set moduleAddress (using the specified store). - */ - function setModuleAddress(IStore _store, bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(moduleName); - _keyTuple[1] = argumentsHash; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), _fieldLayout); - } - /** * @notice Set moduleAddress. */ @@ -232,17 +186,6 @@ library InstalledModules { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), _fieldLayout); } - /** - * @notice Set moduleAddress (using the specified store). - */ - function set(IStore _store, bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(moduleName); - _keyTuple[1] = argumentsHash; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -265,17 +208,6 @@ library InstalledModules { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes16 moduleName, bytes32 argumentsHash) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(moduleName); - _keyTuple[1] = argumentsHash; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol index dfd31e34d9..5c13ef1dab 100644 --- a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol +++ b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol @@ -95,13 +95,6 @@ library NamespaceDelegationControl { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get delegationControlId. */ @@ -124,20 +117,6 @@ library NamespaceDelegationControl { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get delegationControlId (using the specified store). - */ - function getDelegationControlId( - IStore _store, - ResourceId namespaceId - ) internal view returns (ResourceId delegationControlId) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Get delegationControlId. */ @@ -160,17 +139,6 @@ library NamespaceDelegationControl { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get delegationControlId (using the specified store). - */ - function get(IStore _store, ResourceId namespaceId) internal view returns (ResourceId delegationControlId) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Set delegationControlId. */ @@ -203,22 +171,6 @@ library NamespaceDelegationControl { ); } - /** - * @notice Set delegationControlId (using the specified store). - */ - function setDelegationControlId(IStore _store, ResourceId namespaceId, ResourceId delegationControlId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.setStaticField( - _tableId, - _keyTuple, - 0, - abi.encodePacked(ResourceId.unwrap(delegationControlId)), - _fieldLayout - ); - } - /** * @notice Set delegationControlId. */ @@ -251,22 +203,6 @@ library NamespaceDelegationControl { ); } - /** - * @notice Set delegationControlId (using the specified store). - */ - function set(IStore _store, ResourceId namespaceId, ResourceId delegationControlId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.setStaticField( - _tableId, - _keyTuple, - 0, - abi.encodePacked(ResourceId.unwrap(delegationControlId)), - _fieldLayout - ); - } - /** * @notice Delete all data for given keys. */ @@ -287,16 +223,6 @@ library NamespaceDelegationControl { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId namespaceId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/NamespaceOwner.sol b/packages/world/src/codegen/tables/NamespaceOwner.sol index 054779e417..84c23e729f 100644 --- a/packages/world/src/codegen/tables/NamespaceOwner.sol +++ b/packages/world/src/codegen/tables/NamespaceOwner.sol @@ -95,13 +95,6 @@ library NamespaceOwner { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get owner. */ @@ -124,17 +117,6 @@ library NamespaceOwner { return (address(bytes20(_blob))); } - /** - * @notice Get owner (using the specified store). - */ - function getOwner(IStore _store, ResourceId namespaceId) internal view returns (address owner) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(bytes20(_blob))); - } - /** * @notice Get owner. */ @@ -157,17 +139,6 @@ library NamespaceOwner { return (address(bytes20(_blob))); } - /** - * @notice Get owner (using the specified store). - */ - function get(IStore _store, ResourceId namespaceId) internal view returns (address owner) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(bytes20(_blob))); - } - /** * @notice Set owner. */ @@ -188,16 +159,6 @@ library NamespaceOwner { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout); } - /** - * @notice Set owner (using the specified store). - */ - function setOwner(IStore _store, ResourceId namespaceId, address owner) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout); - } - /** * @notice Set owner. */ @@ -218,16 +179,6 @@ library NamespaceOwner { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout); } - /** - * @notice Set owner (using the specified store). - */ - function set(IStore _store, ResourceId namespaceId, address owner) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -248,16 +199,6 @@ library NamespaceOwner { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId namespaceId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(namespaceId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/ResourceAccess.sol b/packages/world/src/codegen/tables/ResourceAccess.sol index 62821598fe..c7a4064708 100644 --- a/packages/world/src/codegen/tables/ResourceAccess.sol +++ b/packages/world/src/codegen/tables/ResourceAccess.sol @@ -97,13 +97,6 @@ library ResourceAccess { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get access. */ @@ -128,18 +121,6 @@ library ResourceAccess { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get access (using the specified store). - */ - function getAccess(IStore _store, ResourceId resourceId, address caller) internal view returns (bool access) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = ResourceId.unwrap(resourceId); - _keyTuple[1] = bytes32(uint256(uint160(caller))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Get access. */ @@ -164,18 +145,6 @@ library ResourceAccess { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get access (using the specified store). - */ - function get(IStore _store, ResourceId resourceId, address caller) internal view returns (bool access) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = ResourceId.unwrap(resourceId); - _keyTuple[1] = bytes32(uint256(uint160(caller))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set access. */ @@ -198,17 +167,6 @@ library ResourceAccess { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((access)), _fieldLayout); } - /** - * @notice Set access (using the specified store). - */ - function setAccess(IStore _store, ResourceId resourceId, address caller, bool access) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = ResourceId.unwrap(resourceId); - _keyTuple[1] = bytes32(uint256(uint160(caller))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((access)), _fieldLayout); - } - /** * @notice Set access. */ @@ -231,17 +189,6 @@ library ResourceAccess { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((access)), _fieldLayout); } - /** - * @notice Set access (using the specified store). - */ - function set(IStore _store, ResourceId resourceId, address caller, bool access) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = ResourceId.unwrap(resourceId); - _keyTuple[1] = bytes32(uint256(uint160(caller))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((access)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -264,17 +211,6 @@ library ResourceAccess { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId resourceId, address caller) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = ResourceId.unwrap(resourceId); - _keyTuple[1] = bytes32(uint256(uint160(caller))); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/SystemHooks.sol b/packages/world/src/codegen/tables/SystemHooks.sol index 3741750b78..01d11b7bbe 100644 --- a/packages/world/src/codegen/tables/SystemHooks.sol +++ b/packages/world/src/codegen/tables/SystemHooks.sol @@ -95,13 +95,6 @@ library SystemHooks { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -124,17 +117,6 @@ library SystemHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store, ResourceId systemId) internal view returns (bytes21[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); - } - /** * @notice Get value. */ @@ -157,17 +139,6 @@ library SystemHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store, ResourceId systemId) internal view returns (bytes21[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); - } - /** * @notice Set value. */ @@ -188,16 +159,6 @@ library SystemHooks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, ResourceId systemId, bytes21[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Set value. */ @@ -218,16 +179,6 @@ library SystemHooks { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, ResourceId systemId, bytes21[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Get the length of value. */ @@ -254,19 +205,6 @@ library SystemHooks { } } - /** - * @notice Get the length of value (using the specified store). - */ - function lengthValue(IStore _store, ResourceId systemId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 21; - } - } - /** * @notice Get the length of value. */ @@ -293,19 +231,6 @@ library SystemHooks { } } - /** - * @notice Get the length of value (using the specified store). - */ - function length(IStore _store, ResourceId systemId) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 21; - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -334,20 +259,6 @@ library SystemHooks { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemValue(IStore _store, ResourceId systemId, uint256 _index) internal view returns (bytes21) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 21, (_index + 1) * 21); - return (bytes21(_blob)); - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -376,20 +287,6 @@ library SystemHooks { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItem(IStore _store, ResourceId systemId, uint256 _index) internal view returns (bytes21) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 21, (_index + 1) * 21); - return (bytes21(_blob)); - } - } - /** * @notice Push an element to value. */ @@ -410,16 +307,6 @@ library SystemHooks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function pushValue(IStore _store, ResourceId systemId, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Push an element to value. */ @@ -440,16 +327,6 @@ library SystemHooks { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function push(IStore _store, ResourceId systemId, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from value. */ @@ -470,16 +347,6 @@ library SystemHooks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 21); } - /** - * @notice Pop an element from value (using the specified store). - */ - function popValue(IStore _store, ResourceId systemId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 21); - } - /** * @notice Pop an element from value. */ @@ -500,16 +367,6 @@ library SystemHooks { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 21); } - /** - * @notice Pop an element from value (using the specified store). - */ - function pop(IStore _store, ResourceId systemId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 21); - } - /** * @notice Update an element of value at `_index`. */ @@ -536,19 +393,6 @@ library SystemHooks { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function updateValue(IStore _store, ResourceId systemId, uint256 _index, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 21), uint40(_encoded.length), _encoded); - } - } - /** * @notice Update an element of value at `_index`. */ @@ -575,19 +419,6 @@ library SystemHooks { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function update(IStore _store, ResourceId systemId, uint256 _index, bytes21 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 21), uint40(_encoded.length), _encoded); - } - } - /** * @notice Delete all data for given keys. */ @@ -608,16 +439,6 @@ library SystemHooks { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId systemId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/world/src/codegen/tables/SystemRegistry.sol b/packages/world/src/codegen/tables/SystemRegistry.sol index b88a78d708..150d77a536 100644 --- a/packages/world/src/codegen/tables/SystemRegistry.sol +++ b/packages/world/src/codegen/tables/SystemRegistry.sol @@ -95,13 +95,6 @@ library SystemRegistry { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get systemId. */ @@ -124,17 +117,6 @@ library SystemRegistry { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get systemId (using the specified store). - */ - function getSystemId(IStore _store, address system) internal view returns (ResourceId systemId) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(system))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Get systemId. */ @@ -157,17 +139,6 @@ library SystemRegistry { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get systemId (using the specified store). - */ - function get(IStore _store, address system) internal view returns (ResourceId systemId) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(system))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Set systemId. */ @@ -188,16 +159,6 @@ library SystemRegistry { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); } - /** - * @notice Set systemId (using the specified store). - */ - function setSystemId(IStore _store, address system, ResourceId systemId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(system))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); - } - /** * @notice Set systemId. */ @@ -218,16 +179,6 @@ library SystemRegistry { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); } - /** - * @notice Set systemId (using the specified store). - */ - function set(IStore _store, address system, ResourceId systemId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(system))); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -248,16 +199,6 @@ library SystemRegistry { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, address system) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(system))); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/Systems.sol b/packages/world/src/codegen/tables/Systems.sol index 48cabe9b8c..09dc0c4b3f 100644 --- a/packages/world/src/codegen/tables/Systems.sol +++ b/packages/world/src/codegen/tables/Systems.sol @@ -97,13 +97,6 @@ library Systems { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get system. */ @@ -126,17 +119,6 @@ library Systems { return (address(bytes20(_blob))); } - /** - * @notice Get system (using the specified store). - */ - function getSystem(IStore _store, ResourceId systemId) internal view returns (address system) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(bytes20(_blob))); - } - /** * @notice Set system. */ @@ -157,16 +139,6 @@ library Systems { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((system)), _fieldLayout); } - /** - * @notice Set system (using the specified store). - */ - function setSystem(IStore _store, ResourceId systemId, address system) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((system)), _fieldLayout); - } - /** * @notice Get publicAccess. */ @@ -189,17 +161,6 @@ library Systems { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get publicAccess (using the specified store). - */ - function getPublicAccess(IStore _store, ResourceId systemId) internal view returns (bool publicAccess) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set publicAccess. */ @@ -220,16 +181,6 @@ library Systems { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), _fieldLayout); } - /** - * @notice Set publicAccess (using the specified store). - */ - function setPublicAccess(IStore _store, ResourceId systemId, bool publicAccess) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -260,21 +211,6 @@ library Systems { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, ResourceId systemId) internal view returns (address system, bool publicAccess) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -305,21 +241,6 @@ library Systems { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, ResourceId systemId, address system, bool publicAccess) internal { - bytes memory _staticData = encodeStatic(system, publicAccess); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -363,16 +284,6 @@ library Systems { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId systemId) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = ResourceId.unwrap(systemId); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/src/codegen/tables/UserDelegationControl.sol b/packages/world/src/codegen/tables/UserDelegationControl.sol index 95076ac43b..6e075b4211 100644 --- a/packages/world/src/codegen/tables/UserDelegationControl.sol +++ b/packages/world/src/codegen/tables/UserDelegationControl.sol @@ -97,13 +97,6 @@ library UserDelegationControl { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get delegationControlId. */ @@ -134,22 +127,6 @@ library UserDelegationControl { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get delegationControlId (using the specified store). - */ - function getDelegationControlId( - IStore _store, - address delegator, - address delegatee - ) internal view returns (ResourceId delegationControlId) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Get delegationControlId. */ @@ -174,22 +151,6 @@ library UserDelegationControl { return ResourceId.wrap(bytes32(_blob)); } - /** - * @notice Get delegationControlId (using the specified store). - */ - function get( - IStore _store, - address delegator, - address delegatee - ) internal view returns (ResourceId delegationControlId) { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - /** * @notice Set delegationControlId. */ @@ -224,28 +185,6 @@ library UserDelegationControl { ); } - /** - * @notice Set delegationControlId (using the specified store). - */ - function setDelegationControlId( - IStore _store, - address delegator, - address delegatee, - ResourceId delegationControlId - ) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - _store.setStaticField( - _tableId, - _keyTuple, - 0, - abi.encodePacked(ResourceId.unwrap(delegationControlId)), - _fieldLayout - ); - } - /** * @notice Set delegationControlId. */ @@ -280,23 +219,6 @@ library UserDelegationControl { ); } - /** - * @notice Set delegationControlId (using the specified store). - */ - function set(IStore _store, address delegator, address delegatee, ResourceId delegationControlId) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - _store.setStaticField( - _tableId, - _keyTuple, - 0, - abi.encodePacked(ResourceId.unwrap(delegationControlId)), - _fieldLayout - ); - } - /** * @notice Delete all data for given keys. */ @@ -319,17 +241,6 @@ library UserDelegationControl { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, address delegator, address delegatee) internal { - bytes32[] memory _keyTuple = new bytes32[](2); - _keyTuple[0] = bytes32(uint256(uint160(delegator))); - _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index ae6c8f4c7e..678e276c8b 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -171,6 +171,7 @@ contract WorldTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); world.initialize(new CoreModule()); + StoreSwitch.setStoreAddress(address(world)); key = "testKey"; keyTuple = new bytes32[](1); @@ -196,6 +197,7 @@ contract WorldTest is Test, GasReporter { vm.expectEmit(true, true, true, true); emit HelloWorld(WORLD_VERSION); IBaseWorld newWorld = IBaseWorld(address(new World())); + StoreSwitch.setStoreAddress(address(newWorld)); // Expect the creator to be the original deployer assertEq(newWorld.creator(), address(this)); @@ -215,7 +217,7 @@ contract WorldTest is Test, GasReporter { newWorld.initialize(coreModule); // Should have registered the core system function selectors - CoreSystem coreSystem = CoreSystem(Systems.getSystem(world, CORE_SYSTEM_ID)); + CoreSystem coreSystem = CoreSystem(Systems.getSystem(CORE_SYSTEM_ID)); bytes4[19] memory coreFunctionSignatures = [ // --- AccessManagementSystem --- coreSystem.grantAccess.selector, @@ -245,30 +247,21 @@ contract WorldTest is Test, GasReporter { ]; for (uint256 i; i < coreFunctionSignatures.length; i++) { - assertEq( - FunctionSelectors.getSystemFunctionSelector(world, coreFunctionSignatures[i]), - coreFunctionSignatures[i] - ); + assertEq(FunctionSelectors.getSystemFunctionSelector(coreFunctionSignatures[i]), coreFunctionSignatures[i]); } // Should have registered the table data table (fka schema table) - assertEq( - FieldLayout.unwrap(Tables.getFieldLayout(newWorld, TablesTableId)), - FieldLayout.unwrap(Tables.getFieldLayout()) - ); - assertEq(Tables.getAbiEncodedKeyNames(newWorld, TablesTableId), abi.encode(Tables.getKeyNames())); - assertEq(Tables.getAbiEncodedFieldNames(newWorld, TablesTableId), abi.encode(Tables.getFieldNames())); + assertEq(FieldLayout.unwrap(Tables.getFieldLayout(TablesTableId)), FieldLayout.unwrap(Tables.getFieldLayout())); + assertEq(Tables.getAbiEncodedKeyNames(TablesTableId), abi.encode(Tables.getKeyNames())); + assertEq(Tables.getAbiEncodedFieldNames(TablesTableId), abi.encode(Tables.getFieldNames())); // Should have registered the namespace owner table assertEq( - FieldLayout.unwrap(Tables.getFieldLayout(newWorld, NamespaceOwnerTableId)), + FieldLayout.unwrap(Tables.getFieldLayout(NamespaceOwnerTableId)), FieldLayout.unwrap(NamespaceOwner.getFieldLayout()) ); - assertEq(Tables.getAbiEncodedKeyNames(newWorld, NamespaceOwnerTableId), abi.encode(NamespaceOwner.getKeyNames())); - assertEq( - Tables.getAbiEncodedFieldNames(newWorld, NamespaceOwnerTableId), - abi.encode(NamespaceOwner.getFieldNames()) - ); + assertEq(Tables.getAbiEncodedKeyNames(NamespaceOwnerTableId), abi.encode(NamespaceOwner.getKeyNames())); + assertEq(Tables.getAbiEncodedFieldNames(NamespaceOwnerTableId), abi.encode(NamespaceOwner.getFieldNames())); // Expect it to not be possible to initialize the World again vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AlreadyInitialized.selector)); @@ -299,11 +292,11 @@ contract WorldTest is Test, GasReporter { function testRootNamespace() public { // Owner of root route should be the creator of the World - address rootOwner = NamespaceOwner.get(world, ROOT_NAMESPACE_ID); + address rootOwner = NamespaceOwner.get(ROOT_NAMESPACE_ID); assertEq(rootOwner, address(this)); // The creator of the World should have access to the root namespace - assertTrue(ResourceAccess.get(world, ROOT_NAMESPACE_ID, address(this))); + assertTrue(ResourceAccess.get(ROOT_NAMESPACE_ID, address(this))); } function testStoreAddress() public { @@ -329,13 +322,13 @@ contract WorldTest is Test, GasReporter { endGasReport(); // Expect the caller to be the namespace owner - assertEq(NamespaceOwner.get(world, namespaceId), address(this), "caller should be namespace owner"); + assertEq(NamespaceOwner.get(namespaceId), address(this), "caller should be namespace owner"); // Expect the caller to have access - assertEq(ResourceAccess.get(world, namespaceId, address(this)), true, "caller should have access"); + assertEq(ResourceAccess.get(namespaceId, address(this)), true, "caller should have access"); // Expect the resource ID to have been registered - assertTrue(ResourceIds.getExists(world, namespaceId)); + assertTrue(ResourceIds.getExists(namespaceId)); // Expect an error when registering an existing namespace vm.expectRevert( @@ -400,32 +393,25 @@ contract WorldTest is Test, GasReporter { // Expect the new owner to not be namespace owner before transfer assertFalse( - (NamespaceOwner.get(world, namespaceId)) == address(1), + (NamespaceOwner.get(namespaceId)) == address(1), "new owner should not be namespace owner before transfer" ); // Expect the new owner to not have access before transfer - assertEq( - ResourceAccess.get(world, namespaceId, address(1)), - false, - "new owner should not have access before transfer" - ); + assertEq(ResourceAccess.get(namespaceId, address(1)), false, "new owner should not have access before transfer"); world.transferOwnership(namespaceId, address(1)); // Expect the new owner to be namespace owner - assertEq(NamespaceOwner.get(world, namespaceId), address(1), "new owner should be namespace owner"); + assertEq(NamespaceOwner.get(namespaceId), address(1), "new owner should be namespace owner"); // Expect the new owner to have access - assertEq(ResourceAccess.get(world, namespaceId, address(1)), true, "new owner should have access"); + assertEq(ResourceAccess.get(namespaceId, address(1)), true, "new owner should have access"); // Expect previous owner to no longer be owner - assertFalse( - (NamespaceOwner.get(world, namespaceId)) == address(this), - "caller should no longer be namespace owner" - ); + assertFalse((NamespaceOwner.get(namespaceId)) == address(this), "caller should no longer be namespace owner"); // Expect previous owner to no longer have access - assertEq(ResourceAccess.get(world, namespaceId, address(this)), false, "caller should no longer have access"); + assertEq(ResourceAccess.get(namespaceId, address(this)), false, "caller should no longer have access"); // Expect revert if caller is not the owner _expectAccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE); @@ -451,15 +437,15 @@ contract WorldTest is Test, GasReporter { endGasReport(); // Expect the namespace to be created and owned by the caller - assertEq(NamespaceOwner.get(world, namespaceId), address(this), "namespace should be created by caller"); + assertEq(NamespaceOwner.get(namespaceId), address(this), "namespace should be created by caller"); // Expect the table to be registered assertEq(world.getFieldLayout(tableId).unwrap(), fieldLayout.unwrap(), "value schema should be registered"); - bytes memory loadedKeyNames = Tables.getAbiEncodedKeyNames(world, tableId); + bytes memory loadedKeyNames = Tables.getAbiEncodedKeyNames(tableId); assertEq(loadedKeyNames, abi.encode(keyNames), "key names should be registered"); - bytes memory loadedfieldNames = Tables.getAbiEncodedFieldNames(world, tableId); + bytes memory loadedfieldNames = Tables.getAbiEncodedFieldNames(tableId); assertEq(loadedfieldNames, abi.encode(fieldNames), "value names should be registered"); // Expect an error when registering an existing table @@ -497,37 +483,37 @@ contract WorldTest is Test, GasReporter { endGasReport(); // Expect the system to be registered - (address registeredAddress, bool publicAccess) = Systems.get(world, systemId); + (address registeredAddress, bool publicAccess) = Systems.get(systemId); assertEq(registeredAddress, address(system)); // Expect the system's resource ID to have been registered - assertTrue(ResourceIds.getExists(world, systemId)); + assertTrue(ResourceIds.getExists(systemId)); // Expect the system namespace to be owned by the caller - address routeOwner = NamespaceOwner.get(world, namespaceId); + address routeOwner = NamespaceOwner.get(namespaceId); assertEq(routeOwner, address(this)); // Expect the system to not be publicly accessible assertFalse(publicAccess); // Expect the system to be accessible by the caller - assertTrue(ResourceAccess.get({ _store: world, resourceId: namespaceId, caller: address(this) })); + assertTrue(ResourceAccess.get({ resourceId: namespaceId, caller: address(this) })); // Expect the system to not be accessible by another address - assertFalse(ResourceAccess.get({ _store: world, resourceId: namespaceId, caller: address(0x1) })); + assertFalse(ResourceAccess.get({ resourceId: namespaceId, caller: address(0x1) })); // Expect the system to have access to its own namespace - assertTrue(ResourceAccess.get({ _store: world, resourceId: namespaceId, caller: address(system) })); + assertTrue(ResourceAccess.get({ resourceId: namespaceId, caller: address(system) })); ResourceId newNamespaceId = WorldResourceIdLib.encodeNamespace("newNamespace"); // Expect the namespace to be created if it doesn't exist yet - assertEq(NamespaceOwner.get(world, newNamespaceId), address(0)); + assertEq(NamespaceOwner.get(newNamespaceId), address(0)); world.registerSystem( WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "newNamespace", name: "testSystem" }), new System(), false ); - assertEq(NamespaceOwner.get(world, newNamespaceId), address(this)); + assertEq(NamespaceOwner.get(newNamespaceId), address(this)); // Expect an error when registering an existing system at a new system ID vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_SystemAlreadyExists.selector, address(system))); @@ -615,16 +601,16 @@ contract WorldTest is Test, GasReporter { world.registerSystem(systemId, newSystem, false); // Expect the system address and public access to be updated in the System table - (address registeredAddress, bool publicAccess) = Systems.get(world, systemId); + (address registeredAddress, bool publicAccess) = Systems.get(systemId); assertEq(registeredAddress, address(newSystem), "system address should be updated"); assertEq(publicAccess, false, "public access should be updated"); // Expect the SystemRegistry table to not have a reference to the old system anymore - ResourceId registeredSystemId = SystemRegistry.get(world, address(oldSystem)); + ResourceId registeredSystemId = SystemRegistry.get(address(oldSystem)); assertEq(ResourceId.unwrap(registeredSystemId), bytes32(0), "old system should be removed from SystemRegistry"); // Expect the SystemRegistry table to have a reference to the new system - registeredSystemId = SystemRegistry.get(world, address(newSystem)); + registeredSystemId = SystemRegistry.get(address(newSystem)); assertEq( ResourceId.unwrap(registeredSystemId), ResourceId.unwrap(systemId), @@ -633,18 +619,15 @@ contract WorldTest is Test, GasReporter { // Expect the old system to not have access to the namespace anymore assertFalse( - ResourceAccess.get(world, namespaceId, address(oldSystem)), + ResourceAccess.get(namespaceId, address(oldSystem)), "old system should not have access to the namespace" ); // Expect the new system to have access to the namespace - assertTrue( - ResourceAccess.get(world, namespaceId, address(newSystem)), - "new system should have access to the namespace" - ); + assertTrue(ResourceAccess.get(namespaceId, address(newSystem)), "new system should have access to the namespace"); // Expect the resource ID to still be registered - assertTrue(ResourceIds.getExists(world, systemId), "resource type should still be SYSTEM"); + assertTrue(ResourceIds.getExists(systemId), "resource type should still be SYSTEM"); } function testInvalidIds() public { @@ -734,22 +717,22 @@ contract WorldTest is Test, GasReporter { ); startGasReport("Write data to the table"); - TwoFields.set(world, tableId, true, true); + TwoFields.set(tableId, true, true); endGasReport(); // Expect the data to be written - TwoFieldsData memory tableData = (TwoFields.get(world, tableId)); + TwoFieldsData memory tableData = (TwoFields.get(tableId)); assertTrue(tableData.value1); assertTrue(tableData.value2); // Expect an error when trying to write from an address that doesn't have access _expectAccessDenied(address(0x01), "testSetRecord", "testTable", RESOURCE_TABLE); - TwoFields.set(world, tableId, true, true); + TwoFields.set(tableId, true, true); // Expect the World to not have access vm.prank(address(world)); vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.setRecord.selector)); - TwoFields.set(world, tableId, true, true); + TwoFields.set(tableId, true, true); } function testSetField() public { @@ -767,7 +750,7 @@ contract WorldTest is Test, GasReporter { endGasReport(); // Expect the data to be written - assertTrue(Bool.get(world, tableId)); + assertTrue(Bool.get(tableId)); // Expect an error when trying to write from an address that doesn't have access _expectAccessDenied(address(0x01), "testSetField", "testTable", RESOURCE_TABLE); @@ -803,7 +786,7 @@ contract WorldTest is Test, GasReporter { endGasReport(); // Expect the data to be written - assertEq(AddressArray.get(world, tableId, key), dataToPush); + assertEq(AddressArray.get(tableId, key), dataToPush); // Delete the data world.deleteRecord(tableId, keyTuple); @@ -812,7 +795,7 @@ contract WorldTest is Test, GasReporter { world.pushToDynamicField(tableId, keyTuple, 0, encodedData); // Expect the data to be written - assertEq(AddressArray.get(world, tableId, key), dataToPush); + assertEq(AddressArray.get(tableId, key), dataToPush); // Expect an error when trying to write from an address that doesn't have access _expectAccessDenied(address(0x01), namespace, name, RESOURCE_TABLE); @@ -838,19 +821,19 @@ contract WorldTest is Test, GasReporter { // Write data to the table and expect it to be written world.setRecord(tableId, singletonKey, abi.encodePacked(true), PackedCounter.wrap(bytes32(0)), new bytes(0)); - assertTrue(Bool.get(world, tableId)); + assertTrue(Bool.get(tableId)); startGasReport("Delete record"); world.deleteRecord(tableId, singletonKey); endGasReport(); // expect it to be deleted - assertFalse(Bool.get(world, tableId)); + assertFalse(Bool.get(tableId)); // Write data to the table and expect it to be written world.setRecord(tableId, singletonKey, abi.encodePacked(true), PackedCounter.wrap(bytes32(0)), new bytes(0)); - assertTrue(Bool.get(world, tableId)); - assertTrue(Bool.get(world, tableId)); + assertTrue(Bool.get(tableId)); + assertTrue(Bool.get(tableId)); // Expect an error when trying to delete from an address that doesn't have access _expectAccessDenied(address(0x02), namespace, name, RESOURCE_TABLE); @@ -1344,7 +1327,7 @@ contract WorldTest is Test, GasReporter { world.call(rootSystemId, abi.encodeCall(WorldTestSystem.writeData, ("namespace", "testTable", true))); // Expect the data to be written - assertTrue(Bool.get(world, tableId)); + assertTrue(Bool.get(tableId)); } function testWriteNonRootSystem() public { @@ -1376,7 +1359,7 @@ contract WorldTest is Test, GasReporter { world.call(systemId, abi.encodeCall(WorldTestSystem.writeData, ("namespace", "testTable", true))); // Expect the data to be written - assertTrue(Bool.get(world, tableId)); + assertTrue(Bool.get(tableId)); } function testDelegatecallRootSystem() public { diff --git a/packages/world/test/WorldBalance.t.sol b/packages/world/test/WorldBalance.t.sol index 3ea58da830..c43c09b0dc 100644 --- a/packages/world/test/WorldBalance.t.sol +++ b/packages/world/test/WorldBalance.t.sol @@ -3,6 +3,7 @@ pragma solidity >=0.8.21; import "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { World } from "../src/World.sol"; import { System } from "../src/System.sol"; import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; @@ -36,6 +37,8 @@ contract WorldBalanceTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); world.initialize(new CoreModule()); + StoreSwitch.setStoreAddress(address(world)); + world.registerSystem(rootSystemId, rootSystem, true); world.registerSystem(nonRootSystemId, nonRootSystem, true); @@ -47,8 +50,8 @@ contract WorldBalanceTest is Test, GasReporter { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Call a function on the root system with value via call vm.deal(caller, value); @@ -57,7 +60,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(abi.decode(data, (uint256)), value); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Call a function on a non-root system with value via call vm.deal(caller, value); @@ -66,18 +69,18 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(abi.decode(data, (uint256)), value); // Expect the non root namespace to have the value as balance - assertEq(Balances.get(world, namespaceId), value); + assertEq(Balances.get(namespaceId), value); // Expect the root namespace to still have the same balance as before - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); } function testCallFromWithValue() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Call a function on the root system with value via callFrom vm.deal(caller, value); @@ -86,7 +89,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(abi.decode(data, (uint256)), value); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Call a function on a non-root system with value via callFrom vm.deal(caller, value); @@ -95,18 +98,18 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(abi.decode(data, (uint256)), value); // Expect the non root namespace to have the value as balance - assertEq(Balances.get(world, namespaceId), value); + assertEq(Balances.get(namespaceId), value); // Expect the root namespace to still have the same balance as before - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); } function testFallbackWithValue() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Call a function on the root system with value via the registered root function selector vm.deal(caller, value); @@ -116,7 +119,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(abi.decode(data, (uint256)), value); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Call a function on a non-root system with value vm.deal(caller, value); @@ -126,17 +129,17 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(abi.decode(data, (uint256)), value); // Expect the non root namespace to have the value as balance - assertEq(Balances.get(world, namespaceId), value); + assertEq(Balances.get(namespaceId), value); // Expect the root namespace to still have the same balance as before - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); } function testReceiveWithValue() public { uint256 value = 1 ether; // Expect the root to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); // Send value to the world without calldata vm.deal(caller, value); @@ -146,15 +149,15 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); } function testTransferBalanceToNamespace() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Send balance to root namespace vm.deal(caller, value); @@ -164,24 +167,24 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Transfer the balance to another namespace world.transferBalanceToNamespace(ROOT_NAMESPACE_ID, namespaceId, value); // Expect the root namespace to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); // Expect the non root namespace to have the value as balance - assertEq(Balances.get(world, namespaceId), value); + assertEq(Balances.get(namespaceId), value); } function testTransferBalanceToNamespaceRevertInsufficientBalance() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Send balance to root namespace vm.deal(caller, value); @@ -191,25 +194,25 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect revert when attempting to transfer more than the balance vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_InsufficientBalance.selector, value, value + 1)); world.transferBalanceToNamespace(ROOT_NAMESPACE_ID, namespaceId, value + 1); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the non root namespace to have no balance - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(namespaceId), 0); } function testTransferBalanceToNamespaceRevertAccessDenied() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Send balance to root namespace vm.deal(caller, value); @@ -219,7 +222,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect revert when attempting to transfer from a namespace without access vm.prank(caller); @@ -229,17 +232,17 @@ contract WorldBalanceTest is Test, GasReporter { world.transferBalanceToNamespace(ROOT_NAMESPACE_ID, namespaceId, value); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the non root namespace to have no balance - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(namespaceId), 0); } function testTransferBalanceToNamespaceRevertInvalidResourceType() public { uint256 value = 1 ether; // Expect the root namespace to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); // Send balance to root namespace vm.deal(caller, value); @@ -249,7 +252,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect revert when attempting to transfer to an invalid namespace ResourceId invalidNamespace = WorldResourceIdLib.encode({ typeId: "xx", namespace: "something", name: "invalid" }); @@ -265,18 +268,18 @@ contract WorldBalanceTest is Test, GasReporter { world.transferBalanceToNamespace(ROOT_NAMESPACE_ID, invalidNamespace, value); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the non root namespace to have no balance - assertEq(Balances.get(world, invalidNamespace), 0); + assertEq(Balances.get(invalidNamespace), 0); } function testTransferBalanceToAddress() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Send balance to root namespace vm.deal(caller, value); @@ -286,7 +289,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the receiver to not have any balance address receiver = address(1234); @@ -296,7 +299,7 @@ contract WorldBalanceTest is Test, GasReporter { world.transferBalanceToAddress(ROOT_NAMESPACE_ID, receiver, value); // Expect the root namespace to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); // Expect the receiver to have value as balance assertEq(receiver.balance, value); @@ -306,8 +309,8 @@ contract WorldBalanceTest is Test, GasReporter { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Send balance to root namespace vm.deal(caller, value); @@ -317,7 +320,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the receiver to not have any balance address receiver = address(1234); @@ -328,7 +331,7 @@ contract WorldBalanceTest is Test, GasReporter { world.transferBalanceToAddress(ROOT_NAMESPACE_ID, receiver, value + 1); // Expect the root namespace to have value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the receiver to have no balance assertEq(receiver.balance, 0); @@ -338,8 +341,8 @@ contract WorldBalanceTest is Test, GasReporter { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), 0); - assertEq(Balances.get(world, namespaceId), 0); + assertEq(Balances.get(ROOT_NAMESPACE_ID), 0); + assertEq(Balances.get(namespaceId), 0); // Send balance to root namespace vm.deal(caller, value); @@ -349,7 +352,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(data.length, 0); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the receiver to not have any balance address receiver = address(1234); @@ -367,7 +370,7 @@ contract WorldBalanceTest is Test, GasReporter { world.transferBalanceToAddress(ROOT_NAMESPACE_ID, receiver, value); // Expect the root namespace to have the value as balance - assertEq(Balances.get(world, ROOT_NAMESPACE_ID), value); + assertEq(Balances.get(ROOT_NAMESPACE_ID), value); // Expect the receiver to have no balance assertEq(receiver.balance, 0); diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index 15c805a8e6..f8680e6fa0 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -48,6 +48,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); world.initialize(new CoreModule()); + StoreSwitch.setStoreAddress(address(world)); key = "testKey"; keyTuple = new bytes32[](1); @@ -85,7 +86,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { FieldLayout fieldLayout = AddressArray.getFieldLayout(); // Expect the data to be written - assertEq(AddressArray.get(world, tableId, key), initData); + assertEq(AddressArray.get(tableId, key), initData); // Pop 1 item uint256 byteLengthToPop = 20; @@ -95,7 +96,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { endGasReport(); // Expect the data to be updated - address[] memory loadedData = AddressArray.get(world, tableId, key); + address[] memory loadedData = AddressArray.get(tableId, key); assertEq(loadedData.length, initData.length - 1); for (uint256 i; i < loadedData.length; i++) { assertEq(loadedData[i], initData[i]); @@ -109,7 +110,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { endGasReport(); // Expect the data to be updated - loadedData = AddressArray.get(world, tableId, key); + loadedData = AddressArray.get(tableId, key); assertEq(loadedData.length, initData.length - 2); for (uint256 i; i < loadedData.length; i++) { assertEq(loadedData[i], initData[i]); @@ -121,7 +122,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { byteLengthToPop = 20 * 2; world.popFromDynamicField(tableId, keyTuple, 0, byteLengthToPop); // Expect the data to be updated - loadedData = AddressArray.get(world, tableId, key); + loadedData = AddressArray.get(tableId, key); assertEq(loadedData.length, initData.length - 2); for (uint256 i; i < loadedData.length; i++) { assertEq(loadedData[i], initData[i]); @@ -141,7 +142,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { function testSpliceDynamicData() public { // Expect the data to be written - assertEq(AddressArray.get(world, tableId, key), initData); + assertEq(AddressArray.get(tableId, key), initData); // Update index 0 address[] memory dataForUpdate = new address[](1); @@ -158,7 +159,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { // Expect the data to be updated initData[0] = dataForUpdate[0]; - assertEq(AddressArray.get(world, tableId, key), initData); + assertEq(AddressArray.get(tableId, key), initData); // Update index 1 via direct access world.spliceDynamicData( @@ -172,7 +173,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { // Expect the data to be updated initData[1] = dataForUpdate[0]; - assertEq(AddressArray.get(world, tableId, key), initData); + assertEq(AddressArray.get(tableId, key), initData); // Expect an error when trying to write from an address that doesn't have access _expectAccessDenied(address(0x01), tableId); diff --git a/packages/world/test/codegen/tables/AddressArray.sol b/packages/world/test/codegen/tables/AddressArray.sol index f51f415e9e..2fd41c8983 100644 --- a/packages/world/test/codegen/tables/AddressArray.sol +++ b/packages/world/test/codegen/tables/AddressArray.sol @@ -87,13 +87,6 @@ library AddressArray { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store, ResourceId _tableId) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -116,17 +109,6 @@ library AddressArray { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store, ResourceId _tableId, bytes32 key) internal view returns (address[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); - } - /** * @notice Get value. */ @@ -149,17 +131,6 @@ library AddressArray { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store, ResourceId _tableId, bytes32 key) internal view returns (address[] memory value) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); - } - /** * @notice Set value. */ @@ -180,16 +151,6 @@ library AddressArray { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, ResourceId _tableId, bytes32 key, address[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Set value. */ @@ -210,16 +171,6 @@ library AddressArray { StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, ResourceId _tableId, bytes32 key, address[] memory value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((value))); - } - /** * @notice Get the length of value. */ @@ -246,19 +197,6 @@ library AddressArray { } } - /** - * @notice Get the length of value (using the specified store). - */ - function lengthValue(IStore _store, ResourceId _tableId, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 20; - } - } - /** * @notice Get the length of value. */ @@ -285,19 +223,6 @@ library AddressArray { } } - /** - * @notice Get the length of value (using the specified store). - */ - function length(IStore _store, ResourceId _tableId, bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 20; - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -326,25 +251,6 @@ library AddressArray { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemValue( - IStore _store, - ResourceId _tableId, - bytes32 key, - uint256 _index - ) internal view returns (address) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 20, (_index + 1) * 20); - return (address(bytes20(_blob))); - } - } - /** * @notice Get an item of value. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. @@ -373,20 +279,6 @@ library AddressArray { } } - /** - * @notice Get an item of value (using the specified store). - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItem(IStore _store, ResourceId _tableId, bytes32 key, uint256 _index) internal view returns (address) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 20, (_index + 1) * 20); - return (address(bytes20(_blob))); - } - } - /** * @notice Push an element to value. */ @@ -407,16 +299,6 @@ library AddressArray { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function pushValue(IStore _store, ResourceId _tableId, bytes32 key, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Push an element to value. */ @@ -437,16 +319,6 @@ library AddressArray { StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); } - /** - * @notice Push an element to value (using the specified store). - */ - function push(IStore _store, ResourceId _tableId, bytes32 key, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - /** * @notice Pop an element from value. */ @@ -467,16 +339,6 @@ library AddressArray { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 20); } - /** - * @notice Pop an element from value (using the specified store). - */ - function popValue(IStore _store, ResourceId _tableId, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 20); - } - /** * @notice Pop an element from value. */ @@ -497,16 +359,6 @@ library AddressArray { StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 20); } - /** - * @notice Pop an element from value (using the specified store). - */ - function pop(IStore _store, ResourceId _tableId, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.popFromDynamicField(_tableId, _keyTuple, 0, 20); - } - /** * @notice Update an element of value at `_index`. */ @@ -533,19 +385,6 @@ library AddressArray { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function updateValue(IStore _store, ResourceId _tableId, bytes32 key, uint256 _index, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 20), uint40(_encoded.length), _encoded); - } - } - /** * @notice Update an element of value at `_index`. */ @@ -572,19 +411,6 @@ library AddressArray { } } - /** - * @notice Update an element of value (using the specified store) at `_index`. - */ - function update(IStore _store, ResourceId _tableId, bytes32 key, uint256 _index, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 20), uint40(_encoded.length), _encoded); - } - } - /** * @notice Delete all data for given keys. */ @@ -605,16 +431,6 @@ library AddressArray { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId _tableId, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). diff --git a/packages/world/test/codegen/tables/Bool.sol b/packages/world/test/codegen/tables/Bool.sol index 377e26aa46..ce8ed61ffa 100644 --- a/packages/world/test/codegen/tables/Bool.sol +++ b/packages/world/test/codegen/tables/Bool.sol @@ -85,13 +85,6 @@ library Bool { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store, ResourceId _tableId) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -112,16 +105,6 @@ library Bool { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store, ResourceId _tableId) internal view returns (bool value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Get value. */ @@ -142,16 +125,6 @@ library Bool { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store, ResourceId _tableId) internal view returns (bool value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set value. */ @@ -170,15 +143,6 @@ library Bool { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, ResourceId _tableId, bool value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Set value. */ @@ -197,15 +161,6 @@ library Bool { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, ResourceId _tableId, bool value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -224,15 +179,6 @@ library Bool { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId _tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/packages/world/test/codegen/tables/TwoFields.sol b/packages/world/test/codegen/tables/TwoFields.sol index 9b34fb7618..6bfccb3758 100644 --- a/packages/world/test/codegen/tables/TwoFields.sol +++ b/packages/world/test/codegen/tables/TwoFields.sol @@ -92,13 +92,6 @@ library TwoFields { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store, ResourceId _tableId) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value1. */ @@ -119,16 +112,6 @@ library TwoFields { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get value1 (using the specified store). - */ - function getValue1(IStore _store, ResourceId _tableId) internal view returns (bool value1) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set value1. */ @@ -147,15 +130,6 @@ library TwoFields { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value1)), _fieldLayout); } - /** - * @notice Set value1 (using the specified store). - */ - function setValue1(IStore _store, ResourceId _tableId, bool value1) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value1)), _fieldLayout); - } - /** * @notice Get value2. */ @@ -176,16 +150,6 @@ library TwoFields { return (_toBool(uint8(bytes1(_blob)))); } - /** - * @notice Get value2 (using the specified store). - */ - function getValue2(IStore _store, ResourceId _tableId) internal view returns (bool value2) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - /** * @notice Set value2. */ @@ -204,15 +168,6 @@ library TwoFields { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((value2)), _fieldLayout); } - /** - * @notice Set value2 (using the specified store). - */ - function setValue2(IStore _store, ResourceId _tableId, bool value2) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((value2)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -241,20 +196,6 @@ library TwoFields { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, ResourceId _tableId) internal view returns (TwoFieldsData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](0); - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -283,20 +224,6 @@ library TwoFields { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, ResourceId _tableId, bool value1, bool value2) internal { - bytes memory _staticData = encodeStatic(value1, value2); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -325,20 +252,6 @@ library TwoFields { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, ResourceId _tableId, TwoFieldsData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.value1, _table.value2); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -380,15 +293,6 @@ library TwoFields { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, ResourceId _tableId) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index f21ae6ebab..7239ee6e69 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -90,13 +90,6 @@ library Counter { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -117,16 +110,6 @@ library Counter { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Get value. */ @@ -147,16 +130,6 @@ library Counter { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set value. */ @@ -175,15 +148,6 @@ library Counter { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Set value. */ @@ -202,15 +166,6 @@ library Counter { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -229,15 +184,6 @@ library Counter { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/templates/phaser/packages/contracts/test/CounterTest.t.sol b/templates/phaser/packages/contracts/test/CounterTest.t.sol index 21b38dc8e5..69794ce2a9 100644 --- a/templates/phaser/packages/contracts/test/CounterTest.t.sol +++ b/templates/phaser/packages/contracts/test/CounterTest.t.sol @@ -9,13 +9,6 @@ import { IWorld } from "../src/codegen/world/IWorld.sol"; import { Counter, CounterTableId } from "../src/codegen/index.sol"; contract CounterTest is MudTest { - IWorld public world; - - function setUp() public override { - super.setUp(); - world = IWorld(worldAddress); - } - function testWorldExists() public { uint256 codeSize; address addr = worldAddress; @@ -27,12 +20,12 @@ contract CounterTest is MudTest { function testCounter() public { // Expect the counter to be 1 because it was incremented in the PostDeploy script. - uint32 counter = Counter.get(world); + uint32 counter = Counter.get(); assertEq(counter, 1); // Expect the counter to be 2 after calling increment. - world.increment(); - counter = Counter.get(world); + IWorld(worldAddress).increment(); + counter = Counter.get(); assertEq(counter, 2); } } diff --git a/templates/react/packages/contracts/src/codegen/tables/Counter.sol b/templates/react/packages/contracts/src/codegen/tables/Counter.sol index f21ae6ebab..7239ee6e69 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Counter.sol @@ -90,13 +90,6 @@ library Counter { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -117,16 +110,6 @@ library Counter { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Get value. */ @@ -147,16 +130,6 @@ library Counter { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set value. */ @@ -175,15 +148,6 @@ library Counter { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Set value. */ @@ -202,15 +166,6 @@ library Counter { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -229,15 +184,6 @@ library Counter { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/templates/react/packages/contracts/test/CounterTest.t.sol b/templates/react/packages/contracts/test/CounterTest.t.sol index 21b38dc8e5..69794ce2a9 100644 --- a/templates/react/packages/contracts/test/CounterTest.t.sol +++ b/templates/react/packages/contracts/test/CounterTest.t.sol @@ -9,13 +9,6 @@ import { IWorld } from "../src/codegen/world/IWorld.sol"; import { Counter, CounterTableId } from "../src/codegen/index.sol"; contract CounterTest is MudTest { - IWorld public world; - - function setUp() public override { - super.setUp(); - world = IWorld(worldAddress); - } - function testWorldExists() public { uint256 codeSize; address addr = worldAddress; @@ -27,12 +20,12 @@ contract CounterTest is MudTest { function testCounter() public { // Expect the counter to be 1 because it was incremented in the PostDeploy script. - uint32 counter = Counter.get(world); + uint32 counter = Counter.get(); assertEq(counter, 1); // Expect the counter to be 2 after calling increment. - world.increment(); - counter = Counter.get(world); + IWorld(worldAddress).increment(); + counter = Counter.get(); assertEq(counter, 2); } } diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index c860c38273..346fa619ee 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -102,13 +102,6 @@ library Position { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get x. */ @@ -131,17 +124,6 @@ library Position { return (int32(uint32(bytes4(_blob)))); } - /** - * @notice Get x (using the specified store). - */ - function getX(IStore _store, bytes32 key) internal view returns (int32 x) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - /** * @notice Set x. */ @@ -162,16 +144,6 @@ library Position { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout); } - /** - * @notice Set x (using the specified store). - */ - function setX(IStore _store, bytes32 key, int32 x) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout); - } - /** * @notice Get y. */ @@ -194,17 +166,6 @@ library Position { return (int32(uint32(bytes4(_blob)))); } - /** - * @notice Get y (using the specified store). - */ - function getY(IStore _store, bytes32 key) internal view returns (int32 y) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - /** * @notice Set y. */ @@ -225,16 +186,6 @@ library Position { StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout); } - /** - * @notice Set y (using the specified store). - */ - function setY(IStore _store, bytes32 key, int32 y) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout); - } - /** * @notice Get z. */ @@ -257,17 +208,6 @@ library Position { return (int32(uint32(bytes4(_blob)))); } - /** - * @notice Get z (using the specified store). - */ - function getZ(IStore _store, bytes32 key) internal view returns (int32 z) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - /** * @notice Set z. */ @@ -288,16 +228,6 @@ library Position { StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((z)), _fieldLayout); } - /** - * @notice Set z (using the specified store). - */ - function setZ(IStore _store, bytes32 key, int32 z) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((z)), _fieldLayout); - } - /** * @notice Get the full data. */ @@ -328,21 +258,6 @@ library Position { return decode(_staticData, _encodedLengths, _dynamicData); } - /** - * @notice Get the full data (using the specified store). - */ - function get(IStore _store, bytes32 key) internal view returns (PositionData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using individual values. */ @@ -373,21 +288,6 @@ library Position { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using individual values (using the specified store). - */ - function set(IStore _store, bytes32 key, int32 x, int32 y, int32 z) internal { - bytes memory _staticData = encodeStatic(x, y, z); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Set the full data using the data struct. */ @@ -418,21 +318,6 @@ library Position { StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } - /** - * @notice Set the full data using the data struct (using the specified store). - */ - function set(IStore _store, bytes32 key, PositionData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.x, _table.y, _table.z); - - PackedCounter _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ @@ -478,16 +363,6 @@ library Position { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store, bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index f21ae6ebab..7239ee6e69 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -90,13 +90,6 @@ library Counter { StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - /** - * @notice Register the table with its config (using the specified store). - */ - function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); - } - /** * @notice Get value. */ @@ -117,16 +110,6 @@ library Counter { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function getValue(IStore _store) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Get value. */ @@ -147,16 +130,6 @@ library Counter { return (uint32(bytes4(_blob))); } - /** - * @notice Get value (using the specified store). - */ - function get(IStore _store) internal view returns (uint32 value) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(bytes4(_blob))); - } - /** * @notice Set value. */ @@ -175,15 +148,6 @@ library Counter { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function setValue(IStore _store, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Set value. */ @@ -202,15 +166,6 @@ library Counter { StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); } - /** - * @notice Set value (using the specified store). - */ - function set(IStore _store, uint32 value) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - /** * @notice Delete all data for given keys. */ @@ -229,15 +184,6 @@ library Counter { StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } - /** - * @notice Delete all data for given keys (using the specified store). - */ - function deleteRecord(IStore _store) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - _store.deleteRecord(_tableId, _keyTuple); - } - /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. diff --git a/templates/vanilla/packages/contracts/test/CounterTest.t.sol b/templates/vanilla/packages/contracts/test/CounterTest.t.sol index 21b38dc8e5..69794ce2a9 100644 --- a/templates/vanilla/packages/contracts/test/CounterTest.t.sol +++ b/templates/vanilla/packages/contracts/test/CounterTest.t.sol @@ -9,13 +9,6 @@ import { IWorld } from "../src/codegen/world/IWorld.sol"; import { Counter, CounterTableId } from "../src/codegen/index.sol"; contract CounterTest is MudTest { - IWorld public world; - - function setUp() public override { - super.setUp(); - world = IWorld(worldAddress); - } - function testWorldExists() public { uint256 codeSize; address addr = worldAddress; @@ -27,12 +20,12 @@ contract CounterTest is MudTest { function testCounter() public { // Expect the counter to be 1 because it was incremented in the PostDeploy script. - uint32 counter = Counter.get(world); + uint32 counter = Counter.get(); assertEq(counter, 1); // Expect the counter to be 2 after calling increment. - world.increment(); - counter = Counter.get(world); + IWorld(worldAddress).increment(); + counter = Counter.get(); assertEq(counter, 2); } }