@latticexyz/store-indexer 2.0.0-main-3f8124e0 → 2.0.0-main-9a7c9009
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/sqlite/createIndexer.ts +11 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@latticexyz/store-indexer",
|
3
|
-
"version": "2.0.0-main-
|
3
|
+
"version": "2.0.0-main-9a7c9009",
|
4
4
|
"description": "Minimal Typescript indexer for Store",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -25,10 +25,10 @@
|
|
25
25
|
"superjson": "^1.12.4",
|
26
26
|
"viem": "1.3.1",
|
27
27
|
"zod": "^3.21.4",
|
28
|
-
"@latticexyz/block-logs-stream": "2.0.0-main-
|
29
|
-
"@latticexyz/common": "2.0.0-main-
|
30
|
-
"@latticexyz/store": "2.0.0-main-
|
31
|
-
"@latticexyz/store-sync": "2.0.0-main-
|
28
|
+
"@latticexyz/block-logs-stream": "2.0.0-main-9a7c9009",
|
29
|
+
"@latticexyz/common": "2.0.0-main-9a7c9009",
|
30
|
+
"@latticexyz/store": "2.0.0-main-9a7c9009",
|
31
|
+
"@latticexyz/store-sync": "2.0.0-main-9a7c9009"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
34
34
|
"@types/better-sqlite3": "^7.6.4",
|
@@ -54,9 +54,13 @@ export async function createIndexer({
|
|
54
54
|
map((block) => block.number)
|
55
55
|
);
|
56
56
|
|
57
|
+
let latestBlockNumber: bigint | null = null;
|
57
58
|
const blockLogs$ = latestBlockNumber$.pipe(
|
58
|
-
tap((
|
59
|
-
|
59
|
+
tap((blockNumber) => {
|
60
|
+
latestBlockNumber = blockNumber;
|
61
|
+
debug("latest block number", blockNumber);
|
62
|
+
}),
|
63
|
+
map((blockNumber) => ({ startBlock, endBlock: blockNumber })),
|
60
64
|
blockRangeToLogs({
|
61
65
|
publicClient,
|
62
66
|
events: storeEventsAbi,
|
@@ -68,11 +72,16 @@ export async function createIndexer({
|
|
68
72
|
mergeMap(({ toBlock, logs }) => from(groupLogsByBlockNumber(logs, toBlock)))
|
69
73
|
);
|
70
74
|
|
75
|
+
let lastBlockNumberProcessed: bigint | null = null;
|
71
76
|
const sub = blockLogs$
|
72
77
|
.pipe(
|
73
78
|
concatMap(blockLogsToStorage(await sqliteStorage({ database, publicClient }))),
|
74
79
|
tap(({ blockNumber, operations }) => {
|
80
|
+
lastBlockNumberProcessed = blockNumber;
|
75
81
|
debug("stored", operations.length, "operations for block", blockNumber);
|
82
|
+
if (latestBlockNumber === lastBlockNumberProcessed) {
|
83
|
+
debug("all caught up");
|
84
|
+
}
|
76
85
|
})
|
77
86
|
)
|
78
87
|
.subscribe();
|