diff --git a/packages/common/src/codegen/render-solidity/common.ts b/packages/common/src/codegen/render-solidity/common.ts index dae876ee4a..96041373fb 100644 --- a/packages/common/src/codegen/render-solidity/common.ts +++ b/packages/common/src/codegen/render-solidity/common.ts @@ -125,7 +125,7 @@ export function renderWithStore( _store: string; _commentSuffix: string; _methodNamePrefix: string; - _internal?: boolean; + _useExplicitFieldLayout?: boolean; }) => string ): string { let result = ""; @@ -135,7 +135,7 @@ export function renderWithStore( _store: "StoreCore", _commentSuffix: "", _methodNamePrefix: "_", - _internal: true, + _useExplicitFieldLayout: true, }); if (storeArgument) { diff --git a/packages/store/ts/codegen/record.ts b/packages/store/ts/codegen/record.ts index 2b6d307f6e..33d726ffdc 100644 --- a/packages/store/ts/codegen/record.ts +++ b/packages/store/ts/codegen/record.ts @@ -39,18 +39,21 @@ export function renderRecordMethods(options: RenderTableOptions) { ); } - result += renderWithStore(storeArgument, ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _internal }) => { - const externalArguments = renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - renderArguments(options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`)), - ]); - - const internalArguments = - "_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData" + (_internal ? ", _fieldLayout" : ""); - - return ` + result += renderWithStore( + storeArgument, + ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => { + const externalArguments = renderArguments([ + _typedStore, + _typedTableId, + _typedKeyArgs, + renderArguments(options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`)), + ]); + + const internalArguments = + "_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData" + + (_useExplicitFieldLayout ? ", _fieldLayout" : ""); + + return ` /** * @notice Set the full data using individual values${_commentSuffix}. */ @@ -62,12 +65,13 @@ export function renderRecordMethods(options: RenderTableOptions) { ${_store}.setRecord(${internalArguments}); } `; - }); + } + ); if (structName !== undefined) { result += renderWithStore( storeArgument, - ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _internal }) => { + ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => { const externalArguments = renderArguments([ _typedStore, _typedTableId, @@ -76,7 +80,8 @@ export function renderRecordMethods(options: RenderTableOptions) { ]); const internalArguments = - "_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData" + (_internal ? ", _fieldLayout" : ""); + "_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData" + + (_useExplicitFieldLayout ? ", _fieldLayout" : ""); return ` /** @@ -134,20 +139,23 @@ export function renderDeleteRecordMethods(options: RenderTableOptions) { const { storeArgument } = options; const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options); - return renderWithStore(storeArgument, ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _internal }) => { - const externalArguments = renderArguments([_typedStore, _typedTableId, _typedKeyArgs]); - const internalArguments = "_tableId, _keyTuple" + (_internal ? ", _fieldLayout" : ""); + return renderWithStore( + storeArgument, + ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => { + const externalArguments = renderArguments([_typedStore, _typedTableId, _typedKeyArgs]); + const internalArguments = "_tableId, _keyTuple" + (_useExplicitFieldLayout ? ", _fieldLayout" : ""); - return ` - /** - * @notice Delete all data for given keys${_commentSuffix}. - */ - function ${_methodNamePrefix}deleteRecord(${externalArguments}) internal { - ${_keyTupleDefinition} - ${_store}.deleteRecord(${internalArguments}); - } - `; - }); + return ` + /** + * @notice Delete all data for given keys${_commentSuffix}. + */ + function ${_methodNamePrefix}deleteRecord(${externalArguments}) internal { + ${_keyTupleDefinition} + ${_store}.deleteRecord(${internalArguments}); + } + `; + } + ); } // Renders the `decode` function that parses a bytes blob into the table data diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index a0c03bade7..52ba690c3a 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -144,7 +144,7 @@ export function renderTable(options: RenderTableOptions) { ${renderEncodeStatic(staticFields)} - ${renderEncodedLengths(dynamicFields)} + ${renderEncodeLengths(dynamicFields)} ${renderEncodeDynamic(dynamicFields)} @@ -191,7 +191,7 @@ function renderEncodeStatic(staticFields: RenderStaticField[]) { `; } -function renderEncodedLengths(dynamicFields: RenderDynamicField[]) { +function renderEncodeLengths(dynamicFields: RenderDynamicField[]) { if (dynamicFields.length === 0) return ""; return ` diff --git a/packages/world/ts/node/render-solidity/index.ts b/packages/world/ts/node/render-solidity/index.ts index 9411b7acef..67ab048d2d 100644 --- a/packages/world/ts/node/render-solidity/index.ts +++ b/packages/world/ts/node/render-solidity/index.ts @@ -1,4 +1,4 @@ export * from "./renderSystemInterface"; -export * from "./renderWorld"; +export * from "./renderWorldInterface"; export * from "./types"; export * from "./worldgen"; diff --git a/packages/world/ts/node/render-solidity/renderWorld.ts b/packages/world/ts/node/render-solidity/renderWorldInterface.ts similarity index 94% rename from packages/world/ts/node/render-solidity/renderWorld.ts rename to packages/world/ts/node/render-solidity/renderWorldInterface.ts index 42495ef9c6..e5e4eaee16 100644 --- a/packages/world/ts/node/render-solidity/renderWorld.ts +++ b/packages/world/ts/node/render-solidity/renderWorldInterface.ts @@ -7,7 +7,7 @@ import { } from "@latticexyz/common/codegen"; import type { RenderWorldOptions } from "./types"; -export function renderWorld(options: RenderWorldOptions) { +export function renderWorldInterface(options: RenderWorldOptions) { const { interfaceName, storeImportPath, worldImportPath, imports } = options; const baseImports: AbsoluteImportDatum[] = interfaceName === "IBaseWorld" diff --git a/packages/world/ts/node/render-solidity/worldgen.ts b/packages/world/ts/node/render-solidity/worldgen.ts index 0bb8672393..a65d63ed8e 100644 --- a/packages/world/ts/node/render-solidity/worldgen.ts +++ b/packages/world/ts/node/render-solidity/worldgen.ts @@ -3,7 +3,7 @@ import path from "path"; import { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum } from "@latticexyz/common/codegen"; import { StoreConfig } from "@latticexyz/store"; import { renderSystemInterface } from "./renderSystemInterface"; -import { renderWorld } from "./renderWorld"; +import { renderWorldInterface } from "./renderWorldInterface"; import { resolveWorldConfig } from "../../config/resolveWorldConfig"; import { WorldConfig } from "../../config/types"; @@ -64,7 +64,7 @@ export async function worldgen( } // render IWorld - const output = renderWorld({ + const output = renderWorldInterface({ interfaceName: config.worldInterfaceName, imports: systemInterfaceImports, storeImportPath: config.storeImportPath,