diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index 96f8d3469e..7191e16357 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -94,6 +94,36 @@ library Dynamics1 { return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** + * @notice Get staticB32 slice. + */ + function getStaticB32Slice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[1] memory staticB32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get staticB32 slice. + */ + function _getStaticB32Slice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[1] memory staticB32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** * @notice Set staticB32. */ @@ -209,6 +239,36 @@ library Dynamics1 { return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); } + /** + * @notice Get staticI32 slice. + */ + function getStaticI32Slice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (int32[2] memory staticI32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, 4 * startIndex, 4 * endIndex); + return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); + } + + /** + * @notice Get staticI32 slice. + */ + function _getStaticI32Slice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (int32[2] memory staticI32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, 4 * startIndex, 4 * endIndex); + return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); + } + /** * @notice Set staticI32. */ @@ -324,6 +384,36 @@ library Dynamics1 { return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); } + /** + * @notice Get staticU128 slice. + */ + function getStaticU128Slice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (uint128[3] memory staticU128) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 2, 16 * startIndex, 16 * endIndex); + return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); + } + + /** + * @notice Get staticU128 slice. + */ + function _getStaticU128Slice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (uint128[3] memory staticU128) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 2, 16 * startIndex, 16 * endIndex); + return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); + } + /** * @notice Set staticU128. */ @@ -439,6 +529,36 @@ library Dynamics1 { return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } + /** + * @notice Get staticAddrs slice. + */ + function getStaticAddrsSlice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (address[4] memory staticAddrs) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 3, 20 * startIndex, 20 * endIndex); + return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + + /** + * @notice Get staticAddrs slice. + */ + function _getStaticAddrsSlice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (address[4] memory staticAddrs) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 3, 20 * startIndex, 20 * endIndex); + return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + /** * @notice Set staticAddrs. */ @@ -554,6 +674,36 @@ library Dynamics1 { return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); } + /** + * @notice Get staticBools slice. + */ + function getStaticBoolsSlice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bool[5] memory staticBools) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 4, 1 * startIndex, 1 * endIndex); + return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); + } + + /** + * @notice Get staticBools slice. + */ + function _getStaticBoolsSlice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bool[5] memory staticBools) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 4, 1 * startIndex, 1 * endIndex); + return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); + } + /** * @notice Set staticBools. */ diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index e2480a74fe..4bfa1e5a30 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -90,6 +90,28 @@ library Dynamics2 { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); } + /** + * @notice Get u64 slice. + */ + function getU64Slice(bytes32 key, uint256 startIndex, uint256 endIndex) internal view returns (uint64[] memory u64) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 8 * startIndex, 8 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); + } + + /** + * @notice Get u64 slice. + */ + function _getU64Slice(bytes32 key, uint256 startIndex, uint256 endIndex) internal view returns (uint64[] memory u64) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 8 * startIndex, 8 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); + } + /** * @notice Set u64. */ diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index 20d508cdf6..1ae1ab539e 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -120,6 +120,26 @@ library Singleton { return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } + /** + * @notice Get v2 slice. + */ + function getV2Slice(uint256 startIndex, uint256 endIndex) internal view returns (uint32[2] memory v2) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 4 * startIndex, 4 * endIndex); + return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** + * @notice Get v2 slice. + */ + function _getV2Slice(uint256 startIndex, uint256 endIndex) internal view returns (uint32[2] memory v2) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 4 * startIndex, 4 * endIndex); + return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + /** * @notice Set v2. */ @@ -227,6 +247,26 @@ library Singleton { return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } + /** + * @notice Get v3 slice. + */ + function getV3Slice(uint256 startIndex, uint256 endIndex) internal view returns (uint32[2] memory v3) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, 4 * startIndex, 4 * endIndex); + return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** + * @notice Get v3 slice. + */ + function _getV3Slice(uint256 startIndex, uint256 endIndex) internal view returns (uint32[2] memory v3) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, 4 * startIndex, 4 * endIndex); + return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + /** * @notice Set v3. */ @@ -334,6 +374,26 @@ library Singleton { return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } + /** + * @notice Get v4 slice. + */ + function getV4Slice(uint256 startIndex, uint256 endIndex) internal view returns (uint32[1] memory v4) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 2, 4 * startIndex, 4 * endIndex); + return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** + * @notice Get v4 slice. + */ + function _getV4Slice(uint256 startIndex, uint256 endIndex) internal view returns (uint32[1] memory v4) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 2, 4 * startIndex, 4 * endIndex); + return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + /** * @notice Set v4. */ diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index a0bbf36faf..887203ed16 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -104,6 +104,70 @@ library Hooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } + /** + * @notice Get hooks slice. + */ + function getHooksSlice( + ResourceId _tableId, + ResourceId resourceId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(resourceId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get hooks slice. + */ + function _getHooksSlice( + ResourceId _tableId, + ResourceId resourceId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(resourceId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get hooks slice. + */ + function getSlice( + ResourceId _tableId, + ResourceId resourceId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(resourceId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get hooks slice. + */ + function _getSlice( + ResourceId _tableId, + ResourceId resourceId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(resourceId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + /** * @notice Set hooks. */ diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index 4aac606501..b6c1d25a17 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -107,6 +107,66 @@ library StoreHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } + /** + * @notice Get hooks slice. + */ + function getHooksSlice( + ResourceId tableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(tableId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get hooks slice. + */ + function _getHooksSlice( + ResourceId tableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(tableId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get hooks slice. + */ + function getSlice( + ResourceId tableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(tableId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get hooks slice. + */ + function _getSlice( + ResourceId tableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory hooks) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(tableId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + /** * @notice Set hooks. */ diff --git a/packages/store/test/codegen/tables/Callbacks.sol b/packages/store/test/codegen/tables/Callbacks.sol index 3def318d75..d61437bef6 100644 --- a/packages/store/test/codegen/tables/Callbacks.sol +++ b/packages/store/test/codegen/tables/Callbacks.sol @@ -104,6 +104,58 @@ library Callbacks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } + /** + * @notice Get value slice. + */ + function getValueSlice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes24[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 24 * startIndex, 24 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); + } + + /** + * @notice Get value slice. + */ + function _getValueSlice( + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes24[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 24 * startIndex, 24 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); + } + + /** + * @notice Get value slice. + */ + function getSlice(bytes32 key, uint256 startIndex, uint256 endIndex) internal view returns (bytes24[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 24 * startIndex, 24 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); + } + + /** + * @notice Get value slice. + */ + function _getSlice(bytes32 key, uint256 startIndex, uint256 endIndex) internal view returns (bytes24[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 24 * startIndex, 24 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); + } + /** * @notice Set value. */ diff --git a/packages/store/test/codegen/tables/Mixed.sol b/packages/store/test/codegen/tables/Mixed.sol index c94148c914..f882999c17 100644 --- a/packages/store/test/codegen/tables/Mixed.sol +++ b/packages/store/test/codegen/tables/Mixed.sol @@ -176,6 +176,28 @@ library Mixed { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } + /** + * @notice Get a32 slice. + */ + function getA32Slice(bytes32 key, uint256 startIndex, uint256 endIndex) internal view returns (uint32[] memory a32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 4 * startIndex, 4 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** + * @notice Get a32 slice. + */ + function _getA32Slice(bytes32 key, uint256 startIndex, uint256 endIndex) internal view returns (uint32[] memory a32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 4 * startIndex, 4 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + /** * @notice Set a32. */ diff --git a/packages/store/ts/codegen/field.ts b/packages/store/ts/codegen/field.ts index 61bfda4372..4acf2085eb 100644 --- a/packages/store/ts/codegen/field.ts +++ b/packages/store/ts/codegen/field.ts @@ -59,6 +59,35 @@ export function renderFieldMethods(options: RenderTableOptions): string { `, ), ); + if (field.isDynamic && field.arrayElement) { + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( + storeArgument, + ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => ` + /** + * @notice Get ${field.name}${_commentSuffix} slice. + */ + function ${_methodNamePrefix}get${_methodNameSuffix}Slice(${renderArguments([ + _typedStore, + _typedTableId, + _typedKeyArgs, + "uint256 startIndex", + "uint256 endIndex", + ])}) internal view returns (${_typedFieldName}) { + ${_keyTupleDefinition} + bytes memory _blob = ${_store}.getDynamicFieldSlice( + _tableId, + _keyTuple, + ${schemaIndex - options.staticFields.length}, + ${field.arrayElement?.staticByteLength}*startIndex, + ${field.arrayElement?.staticByteLength}*endIndex + ); + return ${renderDecodeFieldSingle(field)}; + } + `, + ), + ); + } } result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => diff --git a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol index 57de2ad033..50998eb3ce 100644 --- a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol @@ -115,6 +115,52 @@ library KeysInTable { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** + * @notice Get keys0 slice. + */ + function getKeys0Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys0) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys0 slice. + */ + function _getKeys0Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys0) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys0 (using the specified store) slice. + */ + function getKeys0Slice( + IStore _store, + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys0) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** * @notice Set keys0. */ @@ -358,6 +404,52 @@ library KeysInTable { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** + * @notice Get keys1 slice. + */ + function getKeys1Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys1) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys1 slice. + */ + function _getKeys1Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys1) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys1 (using the specified store) slice. + */ + function getKeys1Slice( + IStore _store, + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys1) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** * @notice Set keys1. */ @@ -601,6 +693,52 @@ library KeysInTable { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** + * @notice Get keys2 slice. + */ + function getKeys2Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys2) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 2, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys2 slice. + */ + function _getKeys2Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys2) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 2, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys2 (using the specified store) slice. + */ + function getKeys2Slice( + IStore _store, + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys2) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 2, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** * @notice Set keys2. */ @@ -844,6 +982,52 @@ library KeysInTable { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** + * @notice Get keys3 slice. + */ + function getKeys3Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys3) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 3, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys3 slice. + */ + function _getKeys3Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys3) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 3, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys3 (using the specified store) slice. + */ + function getKeys3Slice( + IStore _store, + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys3) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 3, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** * @notice Set keys3. */ @@ -1087,6 +1271,52 @@ library KeysInTable { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** + * @notice Get keys4 slice. + */ + function getKeys4Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys4) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 4, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys4 slice. + */ + function _getKeys4Slice( + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys4) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 4, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keys4 (using the specified store) slice. + */ + function getKeys4Slice( + IStore _store, + ResourceId sourceTableId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keys4) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(sourceTableId); + + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 4, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** * @notice Set keys4. */ diff --git a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol index 1e044c7a04..000526bef7 100644 --- a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -144,6 +144,104 @@ library KeysWithValue { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** + * @notice Get keysWithValue slice. + */ + function getKeysWithValueSlice( + ResourceId _tableId, + bytes32 valueHash, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keysWithValue slice. + */ + function _getKeysWithValueSlice( + ResourceId _tableId, + bytes32 valueHash, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keysWithValue (using the specified store) slice. + */ + function getKeysWithValueSlice( + IStore _store, + ResourceId _tableId, + bytes32 valueHash, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keysWithValue slice. + */ + function getSlice( + ResourceId _tableId, + bytes32 valueHash, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keysWithValue slice. + */ + function _getSlice( + ResourceId _tableId, + bytes32 valueHash, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get keysWithValue (using the specified store) slice. + */ + function getSlice( + IStore _store, + ResourceId _tableId, + bytes32 valueHash, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, 32 * startIndex, 32 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** * @notice Set keysWithValue. */ diff --git a/packages/world/src/codegen/tables/SystemHooks.sol b/packages/world/src/codegen/tables/SystemHooks.sol index fcd36499e0..3d19b593fe 100644 --- a/packages/world/src/codegen/tables/SystemHooks.sol +++ b/packages/world/src/codegen/tables/SystemHooks.sol @@ -107,6 +107,66 @@ library SystemHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } + /** + * @notice Get value slice. + */ + function getValueSlice( + ResourceId systemId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(systemId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get value slice. + */ + function _getValueSlice( + ResourceId systemId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(systemId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get value slice. + */ + function getSlice( + ResourceId systemId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(systemId); + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** + * @notice Get value slice. + */ + function _getSlice( + ResourceId systemId, + uint256 startIndex, + uint256 endIndex + ) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = ResourceId.unwrap(systemId); + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 21 * startIndex, 21 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + /** * @notice Set value. */ diff --git a/packages/world/test/codegen/tables/AddressArray.sol b/packages/world/test/codegen/tables/AddressArray.sol index d7b59d9308..3073ffa85f 100644 --- a/packages/world/test/codegen/tables/AddressArray.sol +++ b/packages/world/test/codegen/tables/AddressArray.sol @@ -101,6 +101,70 @@ library AddressArray { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } + /** + * @notice Get value slice. + */ + function getValueSlice( + ResourceId _tableId, + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (address[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 20 * startIndex, 20 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + + /** + * @notice Get value slice. + */ + function _getValueSlice( + ResourceId _tableId, + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (address[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 20 * startIndex, 20 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + + /** + * @notice Get value slice. + */ + function getSlice( + ResourceId _tableId, + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (address[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, 20 * startIndex, 20 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + + /** + * @notice Get value slice. + */ + function _getSlice( + ResourceId _tableId, + bytes32 key, + uint256 startIndex, + uint256 endIndex + ) internal view returns (address[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, 20 * startIndex, 20 * endIndex); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + /** * @notice Set value. */