-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(store-sync): create table registration logs from indexer records (#…
- Loading branch information
Showing
8 changed files
with
91 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/store-sync": patch | ||
--- | ||
|
||
`createStoreSync` now correctly creates table registration logs from indexer records. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from "./common"; | ||
export * from "./createStoreSync"; | ||
export * from "./internalTableIds"; | ||
export * from "./SyncStep"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable max-len */ | ||
import { describe, it, expect } from "vitest"; | ||
import { tableToLog } from "./tableToLog"; | ||
import { storeTables } from "./common"; | ||
import { flattenSchema } from "./flattenSchema"; | ||
|
||
describe("tableToLog", () => { | ||
it("should convert a table object to table registration log", async () => { | ||
expect( | ||
tableToLog({ | ||
address: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c", | ||
tableId: storeTables.Tables.tableId, | ||
namespace: storeTables.Tables.namespace, | ||
name: storeTables.Tables.name, | ||
keySchema: flattenSchema(storeTables.Tables.keySchema), | ||
valueSchema: flattenSchema(storeTables.Tables.valueSchema), | ||
}) | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c", | ||
"args": { | ||
"dynamicData": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000077461626c654964000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000b6669656c644c61796f757400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096b6579536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b76616c7565536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012616269456e636f6465644b65794e616d657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014616269456e636f6465644669656c644e616d6573000000000000000000000000", | ||
"encodedLengths": "0x000000000000000000000000000000000000022000000000a0000000000002c0", | ||
"keyTuple": [ | ||
"0x746273746f72650000000000000000005461626c657300000000000000000000", | ||
], | ||
"staticData": "0x0060030220202000000000000000000000000000000000000000000000000000002001005f000000000000000000000000000000000000000000000000000000006003025f5f5fc4c40000000000000000000000000000000000000000000000", | ||
"tableId": "0x746273746f72650000000000000000005461626c657300000000000000000000", | ||
}, | ||
"eventName": "Store_SetRecord", | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
encodeKey, | ||
encodeValueArgs, | ||
keySchemaToHex, | ||
valueSchemaToFieldLayoutHex, | ||
valueSchemaToHex, | ||
} from "@latticexyz/protocol-parser"; | ||
import { encodeAbiParameters, parseAbiParameters } from "viem"; | ||
import { StorageAdapterLog, Table, storeTables } from "./common"; | ||
import { flattenSchema } from "./flattenSchema"; | ||
|
||
export function tableToLog(table: Table): StorageAdapterLog & { eventName: "Store_SetRecord" } { | ||
return { | ||
eventName: "Store_SetRecord", | ||
address: table.address, | ||
args: { | ||
tableId: storeTables.Tables.tableId, | ||
keyTuple: encodeKey(flattenSchema(storeTables.Tables.keySchema), { tableId: table.tableId }), | ||
...encodeValueArgs(flattenSchema(storeTables.Tables.valueSchema), { | ||
fieldLayout: valueSchemaToFieldLayoutHex(table.valueSchema), | ||
keySchema: keySchemaToHex(table.keySchema), | ||
valueSchema: valueSchemaToHex(table.valueSchema), | ||
abiEncodedKeyNames: encodeAbiParameters(parseAbiParameters("string[]"), [Object.keys(table.keySchema)]), | ||
abiEncodedFieldNames: encodeAbiParameters(parseAbiParameters("string[]"), [Object.keys(table.valueSchema)]), | ||
}), | ||
}, | ||
}; | ||
} |