diff --git a/.changeset/tall-buses-kick.md b/.changeset/tall-buses-kick.md new file mode 100644 index 0000000000..834b2478cc --- /dev/null +++ b/.changeset/tall-buses-kick.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store": minor +--- + +Add an optional `namePrefix` argument to `renderRecordData`, to support inlined logic in codegenned `set` method which uses a struct. diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index e8ba31b96c..bc2f7c4e6e 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -327,17 +327,50 @@ library Multi { /** Set the full data using the data struct */ function set(uint32 a, bool b, uint256 c, int120 d, MultiData memory _table) internal { - set(a, b, c, d, _table.num, _table.value); + 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))); + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(uint32 a, bool b, uint256 c, int120 d, MultiData memory _table) internal { - set(a, b, c, d, _table.num, _table.value); + 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))); + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** 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 { - set(_store, a, b, c, d, _table.num, _table.value); + 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, _fieldLayout); } /** diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index 04f83f9775..30513851e3 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -267,17 +267,41 @@ library Vector { /** Set the full data using the data struct */ function set(uint32 key, VectorData memory _table) internal { - set(key, _table.x, _table.y); + bytes memory _staticData = encodeStatic(_table.x, _table.y); + + PackedCounter _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(uint32 key, VectorData memory _table) internal { - set(key, _table.x, _table.y); + bytes memory _staticData = encodeStatic(_table.x, _table.y); + + PackedCounter _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, uint32 key, VectorData memory _table) internal { - set(_store, key, _table.x, _table.y); + 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, _fieldLayout); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index 4ffe32a5a9..d71529b3dc 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -1338,17 +1338,74 @@ library Dynamics1 { /** Set the full data using the data struct */ function set(bytes32 key, Dynamics1Data memory _table) internal { - set(key, _table.staticB32, _table.staticI32, _table.staticU128, _table.staticAddrs, _table.staticBools); + 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; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(bytes32 key, Dynamics1Data memory _table) internal { - set(key, _table.staticB32, _table.staticI32, _table.staticU128, _table.staticAddrs, _table.staticBools); + 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; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 key, Dynamics1Data memory _table) internal { - set(_store, key, _table.staticB32, _table.staticI32, _table.staticU128, _table.staticAddrs, _table.staticBools); + 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, _fieldLayout); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 86447e9503..8347277c43 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -825,17 +825,38 @@ library Dynamics2 { /** Set the full data using the data struct */ function set(bytes32 key, Dynamics2Data memory _table) internal { - set(key, _table.u64, _table.str, _table.b); + 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; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(bytes32 key, Dynamics2Data memory _table) internal { - set(key, _table.u64, _table.str, _table.b); + 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; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 key, Dynamics2Data memory _table) internal { - set(_store, key, _table.u64, _table.str, _table.b); + 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, _fieldLayout); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index 695fbbf683..0c6d986b4f 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -816,12 +816,38 @@ library Statics { /** Set the full data using the data struct */ function set(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, StaticsData memory _table) internal { - set(k1, k2, k3, k4, k5, k6, _table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); + 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))); + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, StaticsData memory _table) internal { - set(k1, k2, k3, k4, k5, k6, _table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); + 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))); + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ @@ -835,7 +861,20 @@ library Statics { Enum2 k6, StaticsData memory _table ) internal { - set(_store, k1, k2, k3, k4, k5, k6, _table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); + 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, _fieldLayout); } /** diff --git a/packages/store/src/codegen/tables/Mixed.sol b/packages/store/src/codegen/tables/Mixed.sol index 4d493762ae..2aca3ce5d4 100644 --- a/packages/store/src/codegen/tables/Mixed.sol +++ b/packages/store/src/codegen/tables/Mixed.sol @@ -713,17 +713,41 @@ library Mixed { /** Set the full data using the data struct */ function set(bytes32 key, MixedData memory _table) internal { - set(key, _table.u32, _table.u128, _table.a32, _table.s); + 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; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(bytes32 key, MixedData memory _table) internal { - set(key, _table.u32, _table.u128, _table.a32, _table.s); + 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; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 key, MixedData memory _table) internal { - set(_store, key, _table.u32, _table.u128, _table.a32, _table.s); + 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, _fieldLayout); } /** diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index f0d2954252..ffdd1b208a 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -803,39 +803,41 @@ library Tables { /** Set the full data using the data struct */ function set(bytes32 tableId, TablesData memory _table) internal { - set( - tableId, - _table.fieldLayout, - _table.keySchema, - _table.valueSchema, - _table.abiEncodedKeyNames, - _table.abiEncodedFieldNames - ); + 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] = tableId; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(bytes32 tableId, TablesData memory _table) internal { - set( - tableId, - _table.fieldLayout, - _table.keySchema, - _table.valueSchema, - _table.abiEncodedKeyNames, - _table.abiEncodedFieldNames - ); + 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] = tableId; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 tableId, TablesData memory _table) internal { - set( - _store, - tableId, - _table.fieldLayout, - _table.keySchema, - _table.valueSchema, - _table.abiEncodedKeyNames, - _table.abiEncodedFieldNames - ); + 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] = tableId; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** diff --git a/packages/store/src/codegen/tables/Vector2.sol b/packages/store/src/codegen/tables/Vector2.sol index 28ccb78e42..69a48138d5 100644 --- a/packages/store/src/codegen/tables/Vector2.sol +++ b/packages/store/src/codegen/tables/Vector2.sol @@ -267,17 +267,41 @@ library Vector2 { /** Set the full data using the data struct */ function set(bytes32 key, Vector2Data memory _table) internal { - set(key, _table.x, _table.y); + bytes memory _staticData = encodeStatic(_table.x, _table.y); + + PackedCounter _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(bytes32 key, Vector2Data memory _table) internal { - set(key, _table.x, _table.y); + bytes memory _staticData = encodeStatic(_table.x, _table.y); + + PackedCounter _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 key, Vector2Data memory _table) internal { - set(_store, key, _table.x, _table.y); + 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, _fieldLayout); } /** diff --git a/packages/store/ts/codegen/record.ts b/packages/store/ts/codegen/record.ts index bca8884879..8824a08e63 100644 --- a/packages/store/ts/codegen/record.ts +++ b/packages/store/ts/codegen/record.ts @@ -10,7 +10,7 @@ import { RenderTableOptions } from "./types"; export function renderRecordMethods(options: RenderTableOptions) { const { structName, storeArgument } = options; - const { _tableId, _typedTableId, _keyArgs, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options); + const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options); let result = ""; @@ -67,12 +67,11 @@ export function renderRecordMethods(options: RenderTableOptions) { _typedKeyArgs, `${structName} memory _table`, ])}) internal { - set(${renderArguments([ - _untypedStore, - _tableId, - _keyArgs, - renderArguments(options.fields.map(({ name }) => `_table.${name}`)), - ])}); + ${renderRecordData(options, "_table.")} + + ${_keyTupleDefinition} + + ${_store}.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } ` ); @@ -83,11 +82,13 @@ export function renderRecordMethods(options: RenderTableOptions) { return result; } -export function renderRecordData(options: RenderTableOptions) { +export function renderRecordData(options: RenderTableOptions, namePrefix = "") { let result = ""; if (options.staticFields.length > 0) { result += ` - bytes memory _staticData = encodeStatic(${renderArguments(options.staticFields.map(({ name }) => name))}); + bytes memory _staticData = encodeStatic( + ${renderArguments(options.staticFields.map(({ name }) => `${namePrefix}${name}`))} + ); `; } else { result += `bytes memory _staticData;`; @@ -95,8 +96,12 @@ export function renderRecordData(options: RenderTableOptions) { if (options.dynamicFields.length > 0) { result += ` - PackedCounter _encodedLengths = encodeLengths(${renderArguments(options.dynamicFields.map(({ name }) => name))}); - bytes memory _dynamicData = encodeDynamic(${renderArguments(options.dynamicFields.map(({ name }) => name))}); + PackedCounter _encodedLengths = encodeLengths( + ${renderArguments(options.dynamicFields.map(({ name }) => `${namePrefix}${name}`))} + ); + bytes memory _dynamicData = encodeDynamic( + ${renderArguments(options.dynamicFields.map(({ name }) => `${namePrefix}${name}`))} + ); `; } else { result += ` diff --git a/packages/world/src/modules/keysintable/tables/KeysInTable.sol b/packages/world/src/modules/keysintable/tables/KeysInTable.sol index 1b8ea4ff81..1939a1ffdb 100644 --- a/packages/world/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world/src/modules/keysintable/tables/KeysInTable.sol @@ -1328,17 +1328,38 @@ library KeysInTable { /** Set the full data using the data struct */ function set(bytes32 sourceTable, KeysInTableData memory _table) internal { - set(sourceTable, _table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + bytes memory _staticData; + PackedCounter _encodedLengths = encodeLengths(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + bytes memory _dynamicData = encodeDynamic(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = sourceTable; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(bytes32 sourceTable, KeysInTableData memory _table) internal { - set(sourceTable, _table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + bytes memory _staticData; + PackedCounter _encodedLengths = encodeLengths(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + bytes memory _dynamicData = encodeDynamic(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = sourceTable; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 sourceTable, KeysInTableData memory _table) internal { - set(_store, sourceTable, _table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + bytes memory _staticData; + PackedCounter _encodedLengths = encodeLengths(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + bytes memory _dynamicData = encodeDynamic(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = sourceTable; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index 8f4495582e..bb7632f63a 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -321,17 +321,41 @@ library Position { /** Set the full data using the data struct */ function set(bytes32 key, PositionData memory _table) internal { - set(key, _table.x, _table.y, _table.z); + bytes memory _staticData = encodeStatic(_table.x, _table.y, _table.z); + + PackedCounter _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct */ function _set(bytes32 key, PositionData memory _table) internal { - set(key, _table.x, _table.y, _table.z); + bytes memory _staticData = encodeStatic(_table.x, _table.y, _table.z); + + PackedCounter _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 key, PositionData memory _table) internal { - set(_store, key, _table.x, _table.y, _table.z); + 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, _fieldLayout); } /**