@hugomrdias/foxer 0.1.3 → 0.1.11
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/CHANGELOG.md +71 -17
- package/README.md +77 -10
- package/dist/{src/api/runner.d.ts → api/create-api.d.ts} +2 -2
- package/dist/api/create-api.d.ts.map +1 -0
- package/dist/{src/api/runner.js → api/create-api.js} +2 -2
- package/dist/api/create-api.js.map +1 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/sql-middleware.d.ts.map +1 -0
- package/dist/{src/api → api}/sql-middleware.js +3 -3
- package/dist/api/sql-middleware.js.map +1 -0
- package/dist/api/sql.d.ts.map +1 -0
- package/dist/api/sql.js.map +1 -0
- package/dist/api/sse.d.ts.map +1 -0
- package/dist/api/sse.js.map +1 -0
- package/dist/bin/create.d.ts.map +1 -0
- package/dist/{src/bin → bin}/create.js +4 -4
- package/dist/bin/create.js.map +1 -0
- package/dist/bin/dev.d.ts.map +1 -0
- package/dist/{src/bin → bin}/dev.js +9 -11
- package/dist/bin/dev.js.map +1 -0
- package/dist/bin/flags.d.ts.map +1 -0
- package/dist/{src/bin → bin}/flags.js +1 -1
- package/dist/bin/flags.js.map +1 -0
- package/dist/{src/bin → bin}/index.d.ts.map +1 -1
- package/dist/{src/bin → bin}/index.js +4 -2
- package/dist/bin/index.js.map +1 -0
- package/dist/bin/serve.d.ts +3 -0
- package/dist/bin/serve.d.ts.map +1 -0
- package/dist/bin/serve.js +53 -0
- package/dist/bin/serve.js.map +1 -0
- package/dist/bin/start.d.ts +3 -0
- package/dist/bin/start.d.ts.map +1 -0
- package/dist/bin/start.js +72 -0
- package/dist/bin/start.js.map +1 -0
- package/dist/bin/utils.d.ts.map +1 -0
- package/dist/bin/utils.js +39 -0
- package/dist/bin/utils.js.map +1 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js.map +1 -0
- package/dist/{src/config → config}/env.d.ts +1 -1
- package/dist/config/env.d.ts.map +1 -0
- package/dist/{src/config → config}/env.js +4 -3
- package/dist/config/env.js.map +1 -0
- package/dist/contants.d.ts.map +1 -0
- package/dist/contants.js.map +1 -0
- package/dist/{src/db → db}/actions/blocks.d.ts +9 -6
- package/dist/db/actions/blocks.d.ts.map +1 -0
- package/dist/{src/db → db}/actions/blocks.js +40 -44
- package/dist/db/actions/blocks.js.map +1 -0
- package/dist/db/actions/index.d.ts.map +1 -0
- package/dist/db/actions/index.js.map +1 -0
- package/dist/db/actions/transactions.d.ts.map +1 -0
- package/dist/db/actions/transactions.js.map +1 -0
- package/dist/{src/db → db}/client.d.ts +3 -3
- package/dist/db/client.d.ts.map +1 -0
- package/dist/{src/db → db}/client.js +9 -3
- package/dist/db/client.js.map +1 -0
- package/dist/{src/db → db}/column-types.d.ts +2 -2
- package/dist/db/column-types.d.ts.map +1 -0
- package/dist/{src/db → db}/column-types.js +11 -3
- package/dist/db/column-types.js.map +1 -0
- package/dist/db/encode.d.ts.map +1 -0
- package/dist/db/encode.js.map +1 -0
- package/dist/db/migrate.d.ts.map +1 -0
- package/dist/db/migrate.js.map +1 -0
- package/dist/{src/db → db}/schema/blocks.d.ts +16 -16
- package/dist/{src/db → db}/schema/blocks.d.ts.map +1 -1
- package/dist/db/schema/blocks.js.map +1 -0
- package/dist/{src/db → db}/schema/index.d.ts +44 -44
- package/dist/{src/db → db}/schema/index.d.ts.map +1 -1
- package/dist/db/schema/index.js.map +1 -0
- package/dist/{src/db → db}/schema/transactions.d.ts +6 -6
- package/dist/{src/db → db}/schema/transactions.d.ts.map +1 -1
- package/dist/{src/db → db}/schema/transactions.js +3 -1
- package/dist/db/schema/transactions.js.map +1 -0
- package/dist/db/transaction.d.ts.map +1 -0
- package/dist/db/transaction.js.map +1 -0
- package/dist/{src/hooks → hooks}/registry.d.ts +7 -3
- package/dist/hooks/registry.d.ts.map +1 -0
- package/dist/{src/hooks → hooks}/registry.js +5 -0
- package/dist/hooks/registry.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/backfill.d.ts.map +1 -0
- package/dist/{src/indexer → indexer}/backfill.js +22 -19
- package/dist/indexer/backfill.js.map +1 -0
- package/dist/{src/indexer/runner.d.ts → indexer/create-indexer.d.ts} +2 -2
- package/dist/indexer/create-indexer.d.ts.map +1 -0
- package/dist/{src/indexer/runner.js → indexer/create-indexer.js} +2 -2
- package/dist/indexer/create-indexer.js.map +1 -0
- package/dist/indexer/live.d.ts.map +1 -0
- package/dist/{src/indexer → indexer}/live.js +3 -3
- package/dist/indexer/live.js.map +1 -0
- package/dist/{src/indexer → indexer}/process-block.d.ts +4 -4
- package/dist/indexer/process-block.d.ts.map +1 -0
- package/dist/{src/indexer → indexer}/process-block.js +6 -31
- package/dist/indexer/process-block.js.map +1 -0
- package/dist/indexer/queue-block.d.ts.map +1 -0
- package/dist/{src/indexer → indexer}/queue-block.js +19 -1
- package/dist/indexer/queue-block.js.map +1 -0
- package/dist/{src/indexer → indexer}/reorg.d.ts +2 -2
- package/dist/indexer/reorg.d.ts.map +1 -0
- package/dist/indexer/reorg.js.map +1 -0
- package/dist/rpc/client.d.ts.map +1 -0
- package/dist/rpc/client.js.map +1 -0
- package/dist/rpc/get-block.d.ts.map +1 -0
- package/dist/rpc/get-block.js.map +1 -0
- package/dist/rpc/get-logs.d.ts.map +1 -0
- package/dist/{src/rpc → rpc}/get-logs.js +2 -2
- package/dist/rpc/get-logs.js.map +1 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js.map +1 -0
- package/dist/{src/types.d.ts → types.d.ts} +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/bloom.d.ts.map +1 -0
- package/dist/utils/bloom.js.map +1 -0
- package/dist/utils/build-conflict-columns.d.ts.map +1 -0
- package/dist/utils/build-conflict-columns.js.map +1 -0
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/cursor.d.ts.map +1 -0
- package/dist/utils/cursor.js.map +1 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/{src/utils → utils}/logger.js +0 -3
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/shutdown.d.ts.map +1 -0
- package/dist/{src/utils → utils}/shutdown.js +3 -2
- package/dist/utils/shutdown.js.map +1 -0
- package/dist/utils/timer.d.ts.map +1 -0
- package/dist/utils/timer.js.map +1 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/{src → utils}/types.js.map +1 -1
- package/package.json +45 -41
- package/src/api/{runner.ts → create-api.ts} +2 -1
- package/src/api/server.ts +1 -0
- package/src/api/sql-middleware.ts +4 -3
- package/src/api/sql.ts +2 -1
- package/src/bin/create.ts +7 -8
- package/src/bin/dev.ts +11 -13
- package/src/bin/flags.ts +1 -1
- package/src/bin/index.ts +6 -2
- package/src/bin/serve.ts +65 -0
- package/src/bin/start.ts +87 -0
- package/src/bin/utils.ts +22 -25
- package/src/config/config.ts +1 -0
- package/src/config/env.ts +5 -3
- package/src/db/actions/blocks.ts +53 -52
- package/src/db/actions/transactions.ts +1 -0
- package/src/db/client.ts +12 -5
- package/src/db/column-types.ts +17 -6
- package/src/db/encode.ts +1 -0
- package/src/db/migrate.ts +1 -0
- package/src/db/schema/blocks.ts +1 -0
- package/src/db/schema/transactions.ts +4 -1
- package/src/hooks/registry.ts +15 -3
- package/src/indexer/backfill.ts +31 -20
- package/src/indexer/{runner.ts → create-indexer.ts} +1 -1
- package/src/indexer/live.ts +4 -3
- package/src/indexer/process-block.ts +13 -41
- package/src/indexer/queue-block.ts +25 -1
- package/src/indexer/reorg.ts +3 -2
- package/src/rpc/client.ts +1 -0
- package/src/rpc/get-block.ts +1 -0
- package/src/rpc/get-logs.ts +3 -2
- package/src/types.ts +3 -0
- package/src/utils/logger.ts +1 -3
- package/src/utils/shutdown.ts +3 -2
- package/src/utils/types.ts +1 -0
- package/template/{package.json → package.json.tpl} +10 -8
- package/template/{pnpm-workspace.yaml → pnpm-workspace.yaml.tpl} +1 -1
- package/template/{tsconfig.json → tsconfig.json.tpl} +1 -2
- package/template/turbo.json.tpl +22 -0
- package/tsconfig.json +3 -1
- package/dist/src/api/index.d.ts.map +0 -1
- package/dist/src/api/index.js.map +0 -1
- package/dist/src/api/runner.d.ts.map +0 -1
- package/dist/src/api/runner.js.map +0 -1
- package/dist/src/api/server.d.ts.map +0 -1
- package/dist/src/api/server.js.map +0 -1
- package/dist/src/api/sql-middleware.d.ts.map +0 -1
- package/dist/src/api/sql-middleware.js.map +0 -1
- package/dist/src/api/sql.d.ts.map +0 -1
- package/dist/src/api/sql.js.map +0 -1
- package/dist/src/api/sse.d.ts.map +0 -1
- package/dist/src/api/sse.js.map +0 -1
- package/dist/src/bin/create.d.ts.map +0 -1
- package/dist/src/bin/create.js.map +0 -1
- package/dist/src/bin/dev.d.ts.map +0 -1
- package/dist/src/bin/dev.js.map +0 -1
- package/dist/src/bin/flags.d.ts.map +0 -1
- package/dist/src/bin/flags.js.map +0 -1
- package/dist/src/bin/index.js.map +0 -1
- package/dist/src/bin/utils.d.ts.map +0 -1
- package/dist/src/bin/utils.js +0 -52
- package/dist/src/bin/utils.js.map +0 -1
- package/dist/src/config/config.d.ts.map +0 -1
- package/dist/src/config/config.js.map +0 -1
- package/dist/src/config/env.d.ts.map +0 -1
- package/dist/src/config/env.js.map +0 -1
- package/dist/src/contants.d.ts.map +0 -1
- package/dist/src/contants.js.map +0 -1
- package/dist/src/db/actions/blocks.d.ts.map +0 -1
- package/dist/src/db/actions/blocks.js.map +0 -1
- package/dist/src/db/actions/index.d.ts.map +0 -1
- package/dist/src/db/actions/index.js.map +0 -1
- package/dist/src/db/actions/transactions.d.ts.map +0 -1
- package/dist/src/db/actions/transactions.js.map +0 -1
- package/dist/src/db/client.d.ts.map +0 -1
- package/dist/src/db/client.js.map +0 -1
- package/dist/src/db/column-types.d.ts.map +0 -1
- package/dist/src/db/column-types.js.map +0 -1
- package/dist/src/db/encode.d.ts.map +0 -1
- package/dist/src/db/encode.js.map +0 -1
- package/dist/src/db/migrate.d.ts.map +0 -1
- package/dist/src/db/migrate.js.map +0 -1
- package/dist/src/db/schema/blocks.js.map +0 -1
- package/dist/src/db/schema/index.js.map +0 -1
- package/dist/src/db/schema/transactions.js.map +0 -1
- package/dist/src/db/transaction.d.ts.map +0 -1
- package/dist/src/db/transaction.js.map +0 -1
- package/dist/src/hooks/registry.d.ts.map +0 -1
- package/dist/src/hooks/registry.js.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/indexer/backfill.d.ts.map +0 -1
- package/dist/src/indexer/backfill.js.map +0 -1
- package/dist/src/indexer/live.d.ts.map +0 -1
- package/dist/src/indexer/live.js.map +0 -1
- package/dist/src/indexer/process-block.d.ts.map +0 -1
- package/dist/src/indexer/process-block.js.map +0 -1
- package/dist/src/indexer/queue-block.d.ts.map +0 -1
- package/dist/src/indexer/queue-block.js.map +0 -1
- package/dist/src/indexer/reorg.d.ts.map +0 -1
- package/dist/src/indexer/reorg.js.map +0 -1
- package/dist/src/indexer/runner.d.ts.map +0 -1
- package/dist/src/indexer/runner.js.map +0 -1
- package/dist/src/rpc/client.d.ts.map +0 -1
- package/dist/src/rpc/client.js.map +0 -1
- package/dist/src/rpc/get-block.d.ts.map +0 -1
- package/dist/src/rpc/get-block.js.map +0 -1
- package/dist/src/rpc/get-logs.d.ts.map +0 -1
- package/dist/src/rpc/get-logs.js.map +0 -1
- package/dist/src/schema.d.ts.map +0 -1
- package/dist/src/schema.js.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils/bloom.d.ts.map +0 -1
- package/dist/src/utils/bloom.js.map +0 -1
- package/dist/src/utils/build-conflict-columns.d.ts.map +0 -1
- package/dist/src/utils/build-conflict-columns.js.map +0 -1
- package/dist/src/utils/common.d.ts.map +0 -1
- package/dist/src/utils/common.js.map +0 -1
- package/dist/src/utils/cursor.d.ts.map +0 -1
- package/dist/src/utils/cursor.js.map +0 -1
- package/dist/src/utils/format.d.ts.map +0 -1
- package/dist/src/utils/format.js.map +0 -1
- package/dist/src/utils/hash.d.ts.map +0 -1
- package/dist/src/utils/hash.js.map +0 -1
- package/dist/src/utils/json.d.ts.map +0 -1
- package/dist/src/utils/json.js.map +0 -1
- package/dist/src/utils/logger.d.ts.map +0 -1
- package/dist/src/utils/logger.js.map +0 -1
- package/dist/src/utils/shutdown.d.ts.map +0 -1
- package/dist/src/utils/shutdown.js.map +0 -1
- package/dist/src/utils/timer.d.ts.map +0 -1
- package/dist/src/utils/timer.js.map +0 -1
- package/dist/src/utils/types.d.ts.map +0 -1
- package/dist/src/utils/types.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/template/biome.template.json +0 -50
- /package/dist/{src/api → api}/index.d.ts +0 -0
- /package/dist/{src/api → api}/index.js +0 -0
- /package/dist/{src/api → api}/server.d.ts +0 -0
- /package/dist/{src/api → api}/server.js +0 -0
- /package/dist/{src/api → api}/sql-middleware.d.ts +0 -0
- /package/dist/{src/api → api}/sql.d.ts +0 -0
- /package/dist/{src/api → api}/sql.js +0 -0
- /package/dist/{src/api → api}/sse.d.ts +0 -0
- /package/dist/{src/api → api}/sse.js +0 -0
- /package/dist/{src/bin → bin}/create.d.ts +0 -0
- /package/dist/{src/bin → bin}/dev.d.ts +0 -0
- /package/dist/{src/bin → bin}/flags.d.ts +0 -0
- /package/dist/{src/bin → bin}/index.d.ts +0 -0
- /package/dist/{src/bin → bin}/utils.d.ts +0 -0
- /package/dist/{src/config → config}/config.d.ts +0 -0
- /package/dist/{src/config → config}/config.js +0 -0
- /package/dist/{src/contants.d.ts → contants.d.ts} +0 -0
- /package/dist/{src/contants.js → contants.js} +0 -0
- /package/dist/{src/db → db}/actions/index.d.ts +0 -0
- /package/dist/{src/db → db}/actions/index.js +0 -0
- /package/dist/{src/db → db}/actions/transactions.d.ts +0 -0
- /package/dist/{src/db → db}/actions/transactions.js +0 -0
- /package/dist/{src/db → db}/encode.d.ts +0 -0
- /package/dist/{src/db → db}/encode.js +0 -0
- /package/dist/{src/db → db}/migrate.d.ts +0 -0
- /package/dist/{src/db → db}/migrate.js +0 -0
- /package/dist/{src/db → db}/schema/blocks.js +0 -0
- /package/dist/{src/db → db}/schema/index.js +0 -0
- /package/dist/{src/db → db}/transaction.d.ts +0 -0
- /package/dist/{src/db → db}/transaction.js +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/index.js → index.js} +0 -0
- /package/dist/{src/indexer → indexer}/backfill.d.ts +0 -0
- /package/dist/{src/indexer → indexer}/live.d.ts +0 -0
- /package/dist/{src/indexer → indexer}/queue-block.d.ts +0 -0
- /package/dist/{src/indexer → indexer}/reorg.js +0 -0
- /package/dist/{src/rpc → rpc}/client.d.ts +0 -0
- /package/dist/{src/rpc → rpc}/client.js +0 -0
- /package/dist/{src/rpc → rpc}/get-block.d.ts +0 -0
- /package/dist/{src/rpc → rpc}/get-block.js +0 -0
- /package/dist/{src/rpc → rpc}/get-logs.d.ts +0 -0
- /package/dist/{src/schema.d.ts → schema.d.ts} +0 -0
- /package/dist/{src/schema.js → schema.js} +0 -0
- /package/dist/{src/types.js → types.js} +0 -0
- /package/dist/{src/utils → utils}/bloom.d.ts +0 -0
- /package/dist/{src/utils → utils}/bloom.js +0 -0
- /package/dist/{src/utils → utils}/build-conflict-columns.d.ts +0 -0
- /package/dist/{src/utils → utils}/build-conflict-columns.js +0 -0
- /package/dist/{src/utils → utils}/common.d.ts +0 -0
- /package/dist/{src/utils → utils}/common.js +0 -0
- /package/dist/{src/utils → utils}/cursor.d.ts +0 -0
- /package/dist/{src/utils → utils}/cursor.js +0 -0
- /package/dist/{src/utils → utils}/format.d.ts +0 -0
- /package/dist/{src/utils → utils}/format.js +0 -0
- /package/dist/{src/utils → utils}/hash.d.ts +0 -0
- /package/dist/{src/utils → utils}/hash.js +0 -0
- /package/dist/{src/utils → utils}/json.d.ts +0 -0
- /package/dist/{src/utils → utils}/json.js +0 -0
- /package/dist/{src/utils → utils}/logger.d.ts +0 -0
- /package/dist/{src/utils → utils}/shutdown.d.ts +0 -0
- /package/dist/{src/utils → utils}/timer.d.ts +0 -0
- /package/dist/{src/utils → utils}/timer.js +0 -0
- /package/dist/{src/utils → utils}/types.d.ts +0 -0
- /package/dist/{src/utils → utils}/types.js +0 -0
package/src/db/actions/blocks.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** biome-ignore-all lint/style/noNonNullAssertion: its ok */
|
|
2
2
|
|
|
3
|
-
import { gte } from 'drizzle-orm'
|
|
3
|
+
import { and, gte, inArray } from 'drizzle-orm'
|
|
4
4
|
import {
|
|
5
5
|
getTableConfig,
|
|
6
6
|
type PgAsyncTransaction,
|
|
@@ -8,13 +8,15 @@ import {
|
|
|
8
8
|
type PgQueryResultHKT,
|
|
9
9
|
type PgTable,
|
|
10
10
|
} from 'drizzle-orm/pg-core'
|
|
11
|
-
import type { PublicClient } from 'viem'
|
|
12
|
-
|
|
11
|
+
import type { Hash, PublicClient } from 'viem'
|
|
12
|
+
|
|
13
13
|
import { MAX_QUERY_PARAMS } from '../../contants.ts'
|
|
14
14
|
import { safeGetBlock } from '../../rpc/get-block.ts'
|
|
15
15
|
import type {
|
|
16
|
-
|
|
16
|
+
BlocksMap,
|
|
17
|
+
EncodedBlock,
|
|
17
18
|
EncodedTransaction,
|
|
19
|
+
TransactionsMap,
|
|
18
20
|
} from '../../types.ts'
|
|
19
21
|
import type { Logger } from '../../utils/logger.ts'
|
|
20
22
|
import { startClock } from '../../utils/timer.ts'
|
|
@@ -72,19 +74,20 @@ function getTablesWithBlockNumberColumn(fullSchema: Record<string, unknown>) {
|
|
|
72
74
|
*/
|
|
73
75
|
export async function cacheBlockAndTransactions(args: {
|
|
74
76
|
db: Database<typeof schema, typeof relations>
|
|
75
|
-
|
|
77
|
+
blocks: EncodedBlock[]
|
|
78
|
+
transactions: EncodedTransaction[]
|
|
76
79
|
logger: Logger
|
|
77
80
|
}): Promise<void> {
|
|
78
|
-
const { db,
|
|
81
|
+
const { db, blocks, transactions } = args
|
|
79
82
|
|
|
80
83
|
await db.transaction(async (tx) => {
|
|
81
84
|
await insertBlocksInChunks({
|
|
82
85
|
db: tx,
|
|
83
|
-
blocks
|
|
86
|
+
blocks,
|
|
84
87
|
})
|
|
85
88
|
await insertTransactionsInChunks({
|
|
86
89
|
db: tx,
|
|
87
|
-
transactions
|
|
90
|
+
transactions,
|
|
88
91
|
})
|
|
89
92
|
})
|
|
90
93
|
}
|
|
@@ -104,8 +107,8 @@ export async function getBlocksInRange(
|
|
|
104
107
|
db: Database<typeof schema, typeof relations>,
|
|
105
108
|
blockNumbers: bigint[],
|
|
106
109
|
client: PublicClient,
|
|
107
|
-
|
|
108
|
-
): Promise<
|
|
110
|
+
logsTxs: Hash[]
|
|
111
|
+
): Promise<{ blocks: BlocksMap; transactions: TransactionsMap }> {
|
|
109
112
|
const endClock = startClock()
|
|
110
113
|
const firstBlockNumber = blockNumbers[0]!
|
|
111
114
|
const lastBlockNumber = blockNumbers[blockNumbers.length - 1]!
|
|
@@ -116,74 +119,72 @@ export async function getBlocksInRange(
|
|
|
116
119
|
// contractAddresses: contracts.addresses,
|
|
117
120
|
// })
|
|
118
121
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
{
|
|
127
|
-
to: {
|
|
128
|
-
in: contracts.addresses,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
],
|
|
132
|
-
},
|
|
122
|
+
const [blocks, txs] = await Promise.all([
|
|
123
|
+
db.query.blocks.findMany({
|
|
124
|
+
where: {
|
|
125
|
+
AND: [
|
|
126
|
+
{ number: { gte: firstBlockNumber } },
|
|
127
|
+
{ number: { lte: lastBlockNumber } },
|
|
128
|
+
],
|
|
133
129
|
},
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
})
|
|
130
|
+
}),
|
|
131
|
+
db
|
|
132
|
+
.select()
|
|
133
|
+
.from(schema.transactions)
|
|
134
|
+
.where(and(inArray(schema.transactions.hash, logsTxs))),
|
|
135
|
+
])
|
|
136
|
+
|
|
137
|
+
const transactionByHash = new Map<`0x${string}`, EncodedTransaction>()
|
|
138
|
+
for (const tx of txs) {
|
|
139
|
+
transactionByHash.set(tx.hash, tx)
|
|
140
|
+
}
|
|
142
141
|
|
|
143
|
-
const blocksByNumber = new Map<bigint,
|
|
142
|
+
const blocksByNumber = new Map<bigint, EncodedBlock>()
|
|
144
143
|
const missing = new Set(blockNumbers)
|
|
145
144
|
|
|
146
|
-
for (const block of
|
|
145
|
+
for (const block of blocks) {
|
|
147
146
|
blocksByNumber.set(block.number, block)
|
|
148
147
|
missing.delete(block.number)
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
const missingBlockNumbers = [...missing]
|
|
152
|
-
const newBlocks:
|
|
151
|
+
const newBlocks: EncodedBlock[] = []
|
|
153
152
|
const newTransactions: EncodedTransaction[] = []
|
|
154
153
|
|
|
155
154
|
await Promise.all(
|
|
156
155
|
missingBlockNumbers.map(async (blockNumber) => {
|
|
157
156
|
const block = await safeGetBlock({ client, blockNumber, db })
|
|
158
|
-
const transactions = block.transactions
|
|
159
157
|
blocksByNumber.set(blockNumber, block)
|
|
160
|
-
|
|
158
|
+
const { transactions, ..._block } = block
|
|
159
|
+
newBlocks.push(_block)
|
|
160
|
+
|
|
161
161
|
if (transactions.length > 0) {
|
|
162
162
|
newTransactions.push(...transactions)
|
|
163
163
|
}
|
|
164
|
+
for (const tx of transactions) {
|
|
165
|
+
transactionByHash.set(tx.hash, tx)
|
|
166
|
+
}
|
|
164
167
|
})
|
|
165
168
|
)
|
|
166
169
|
|
|
167
|
-
await
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
await insertTransactionsInChunks({
|
|
173
|
-
db: tx,
|
|
174
|
-
transactions: newTransactions,
|
|
175
|
-
})
|
|
170
|
+
await cacheBlockAndTransactions({
|
|
171
|
+
db,
|
|
172
|
+
blocks: newBlocks,
|
|
173
|
+
transactions: newTransactions,
|
|
174
|
+
logger,
|
|
176
175
|
})
|
|
177
176
|
|
|
178
|
-
logger.
|
|
177
|
+
logger.trace(
|
|
179
178
|
{
|
|
180
|
-
blocks:
|
|
181
|
-
|
|
179
|
+
blocks: blocks.length,
|
|
180
|
+
txs: txs.length,
|
|
181
|
+
newBlocks: newBlocks.length,
|
|
182
|
+
newTxs: newTransactions.length,
|
|
182
183
|
duration: endClock(),
|
|
183
184
|
},
|
|
184
|
-
'get blocks'
|
|
185
|
+
'get blocks and txs'
|
|
185
186
|
)
|
|
186
|
-
return blocksByNumber
|
|
187
|
+
return { blocks: blocksByNumber, transactions: transactionByHash }
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
/**
|
|
@@ -191,7 +192,7 @@ export async function getBlocksInRange(
|
|
|
191
192
|
*/
|
|
192
193
|
export async function insertBlocksInChunks(args: {
|
|
193
194
|
db: PgAsyncTransaction<PgQueryResultHKT, typeof schema>
|
|
194
|
-
blocks:
|
|
195
|
+
blocks: EncodedBlock[]
|
|
195
196
|
}): Promise<void> {
|
|
196
197
|
const { db, blocks } = args
|
|
197
198
|
if (blocks.length === 0) return
|
package/src/db/client.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from 'drizzle-orm/pglite'
|
|
11
11
|
import type { AnyRelations, EmptyRelations } from 'drizzle-orm/relations'
|
|
12
12
|
import { Pool, type PoolConfig } from 'pg'
|
|
13
|
+
|
|
13
14
|
import type { DatabaseConfig } from '../config/config.ts'
|
|
14
15
|
import type { Env } from '../config/env.ts'
|
|
15
16
|
import { type relations, schema } from './schema/index.ts'
|
|
@@ -39,7 +40,7 @@ export type DatabaseContext<
|
|
|
39
40
|
$prepared: ReturnType<typeof generatePrepared>
|
|
40
41
|
}
|
|
41
42
|
driver: 'postgres'
|
|
42
|
-
|
|
43
|
+
stop: () => Promise<void>
|
|
43
44
|
}
|
|
44
45
|
| {
|
|
45
46
|
db: PgliteDatabase<TSchema, TRelations> & {
|
|
@@ -47,7 +48,7 @@ export type DatabaseContext<
|
|
|
47
48
|
$prepared: ReturnType<typeof generatePrepared>
|
|
48
49
|
}
|
|
49
50
|
driver: 'pglite'
|
|
50
|
-
|
|
51
|
+
stop: () => Promise<void>
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -80,10 +81,15 @@ export function createDatabase<
|
|
|
80
81
|
options = config.options
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
// Postgres
|
|
83
85
|
if (driver === 'postgres' && url) {
|
|
84
86
|
const pool = new Pool({
|
|
85
|
-
|
|
87
|
+
application_name: 'foxer',
|
|
88
|
+
connectionTimeoutMillis: 5_000,
|
|
89
|
+
idleTimeoutMillis: 30_000,
|
|
90
|
+
max: 10,
|
|
86
91
|
connectionString: url,
|
|
92
|
+
...options,
|
|
87
93
|
})
|
|
88
94
|
const db = drizzleNodePostgres({
|
|
89
95
|
client: pool,
|
|
@@ -101,12 +107,13 @@ export function createDatabase<
|
|
|
101
107
|
return {
|
|
102
108
|
db,
|
|
103
109
|
driver: 'postgres',
|
|
104
|
-
|
|
110
|
+
stop: async () => {
|
|
105
111
|
await pool.end()
|
|
106
112
|
},
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
115
|
|
|
116
|
+
// PGlite
|
|
110
117
|
const client = new PGlite(
|
|
111
118
|
config?.driver === 'pglite' && config.directory
|
|
112
119
|
? config.directory
|
|
@@ -128,7 +135,7 @@ export function createDatabase<
|
|
|
128
135
|
return {
|
|
129
136
|
db,
|
|
130
137
|
driver: 'pglite',
|
|
131
|
-
|
|
138
|
+
stop: async () => {
|
|
132
139
|
await client.close()
|
|
133
140
|
},
|
|
134
141
|
}
|
package/src/db/column-types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { customType } from 'drizzle-orm/pg-core'
|
|
2
|
+
import { hex as hexCodec } from 'iso-base/rfc4648'
|
|
2
3
|
import { type Address, type Hash, type Hex, stringify } from 'viem'
|
|
3
4
|
|
|
4
5
|
export const numeric78 = customType<{ data: bigint; driverData: string }>({
|
|
@@ -90,16 +91,26 @@ export const jsonb = customType<{ data: unknown; driverData: string }>({
|
|
|
90
91
|
},
|
|
91
92
|
})
|
|
92
93
|
|
|
93
|
-
export const bytea = customType<{ data: Hex; driverData:
|
|
94
|
+
export const bytea = customType<{ data: Hex; driverData: Uint8Array }>({
|
|
94
95
|
dataType() {
|
|
95
96
|
return 'bytea'
|
|
96
97
|
},
|
|
97
|
-
toDriver(value: string):
|
|
98
|
+
toDriver(value: string): Uint8Array {
|
|
98
99
|
return Buffer.from(value.slice(2), 'hex')
|
|
99
100
|
},
|
|
100
|
-
fromDriver(value:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
fromDriver(value: unknown): Hex {
|
|
102
|
+
if (typeof value === 'string') {
|
|
103
|
+
return `0x${value.slice(2)}` as Hex
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (value instanceof Buffer) {
|
|
107
|
+
return `0x${value.toString('hex')}` as Hex
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (value instanceof Uint8Array) {
|
|
111
|
+
return `0x${hexCodec.encode(value)}` as Hex
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
throw new Error('Invalid value')
|
|
104
115
|
},
|
|
105
116
|
})
|
package/src/db/encode.ts
CHANGED
package/src/db/migrate.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { migrate as migratePostgresJs } from 'drizzle-orm/node-postgres/migrator
|
|
|
2
2
|
import { getTableConfig, type PgTable } from 'drizzle-orm/pg-core'
|
|
3
3
|
import { IndexedColumn } from 'drizzle-orm/pg-core/columns/common'
|
|
4
4
|
import { migrate as migratePglite } from 'drizzle-orm/pglite/migrator'
|
|
5
|
+
|
|
5
6
|
import { FOXER_TABLES, PUBLICATION_NAME } from '../contants.ts'
|
|
6
7
|
import type { Logger } from '../utils/logger.ts'
|
|
7
8
|
import { startClock } from '../utils/timer.ts'
|
package/src/db/schema/blocks.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { index, integer, jsonb, pgEnum, pgTable } from 'drizzle-orm/pg-core'
|
|
2
2
|
import type { AccessList } from 'viem'
|
|
3
|
+
|
|
3
4
|
import { address, bigint, bytea, hash, numeric78 } from '../column-types.ts'
|
|
4
5
|
|
|
5
6
|
export const transactionTypeEnum = pgEnum('transaction_type', [
|
|
@@ -34,6 +35,8 @@ export const transactions = pgTable(
|
|
|
34
35
|
},
|
|
35
36
|
(table) => [
|
|
36
37
|
index('transactions_block_number_index').on(table.blockNumber),
|
|
37
|
-
index('
|
|
38
|
+
index('transactions_to_block_number_index')
|
|
39
|
+
.on(table.to, table.blockNumber)
|
|
40
|
+
.concurrently(),
|
|
38
41
|
]
|
|
39
42
|
)
|
package/src/hooks/registry.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { AnyRelations, EmptyRelations } from 'drizzle-orm/relations'
|
|
2
2
|
import type { GetEventArgs, Log } from 'viem'
|
|
3
|
+
|
|
4
|
+
import type { InternalConfig } from '../config/config'
|
|
3
5
|
import type { Database } from '../db/client'
|
|
4
|
-
import type {
|
|
6
|
+
import type { EncodedBlock, EncodedTransaction } from '../types'
|
|
5
7
|
import type { Logger } from '../utils/logger'
|
|
6
8
|
import type {
|
|
7
9
|
ContractAbiByEventKey,
|
|
@@ -32,7 +34,7 @@ export type DecodedEvent<
|
|
|
32
34
|
{ EnableUnion: false; IndexedOnly: false; Required: true }
|
|
33
35
|
>
|
|
34
36
|
log: Log<bigint, number, false, ContractAbiEventByEventKey<C, Event>>
|
|
35
|
-
block:
|
|
37
|
+
block: EncodedBlock
|
|
36
38
|
transaction: EncodedTransaction
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -79,7 +81,7 @@ export class HookRegistry<
|
|
|
79
81
|
{ EnableUnion: false; IndexedOnly: false; Required: true }
|
|
80
82
|
>
|
|
81
83
|
log: Log<bigint, number, false, ContractAbiEventByEventKey<C, K>>
|
|
82
|
-
block:
|
|
84
|
+
block: EncodedBlock
|
|
83
85
|
transaction: EncodedTransaction
|
|
84
86
|
context: HookContext<TSchema, TRelations>
|
|
85
87
|
}): Promise<void> {
|
|
@@ -105,3 +107,13 @@ export class HookRegistry<
|
|
|
105
107
|
})
|
|
106
108
|
}
|
|
107
109
|
}
|
|
110
|
+
|
|
111
|
+
export function createRegistry({
|
|
112
|
+
config,
|
|
113
|
+
}: {
|
|
114
|
+
config: InternalConfig
|
|
115
|
+
}): HookRegistry {
|
|
116
|
+
const registry = new HookRegistry()
|
|
117
|
+
config.hooks({ registry })
|
|
118
|
+
return registry
|
|
119
|
+
}
|
package/src/indexer/backfill.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Hash } from 'viem'
|
|
1
2
|
import { filterContracts, type InternalConfig } from '../config/config.ts'
|
|
2
3
|
import { getBlocksInRange } from '../db/actions/blocks.ts'
|
|
3
4
|
import type { Database } from '../db/client.ts'
|
|
@@ -40,7 +41,7 @@ export async function runBackfill(args: {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
const batchSize = config.batchSize
|
|
43
|
-
logger.
|
|
44
|
+
logger.info(
|
|
44
45
|
{
|
|
45
46
|
fromBlock: cursor.toString(),
|
|
46
47
|
toBlock: safeHead.toString(),
|
|
@@ -54,14 +55,6 @@ export async function runBackfill(args: {
|
|
|
54
55
|
const toBlock = windowEnd(cursor, batchSize, safeHead)
|
|
55
56
|
const windowContracts = filterContracts(config, cursor, toBlock)
|
|
56
57
|
|
|
57
|
-
logger.debug(
|
|
58
|
-
{
|
|
59
|
-
batchFromBlock: cursor.toString(),
|
|
60
|
-
batchToBlock: toBlock.toString(),
|
|
61
|
-
streamCount: windowContracts.addresses.length,
|
|
62
|
-
},
|
|
63
|
-
'processing backfill batch'
|
|
64
|
-
)
|
|
65
58
|
const batchBlockNumbers: bigint[] = []
|
|
66
59
|
let blockNumber = cursor
|
|
67
60
|
while (blockNumber <= toBlock) {
|
|
@@ -69,17 +62,30 @@ export async function runBackfill(args: {
|
|
|
69
62
|
blockNumber += 1n
|
|
70
63
|
}
|
|
71
64
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
const logsByBlock = await getLogsInRange({
|
|
66
|
+
logger,
|
|
67
|
+
client,
|
|
68
|
+
addresses: windowContracts.addresses,
|
|
69
|
+
events: windowContracts.eventAbis,
|
|
70
|
+
fromBlock: cursor,
|
|
71
|
+
toBlock,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const logsTxsSet = new Set<Hash>()
|
|
75
|
+
for (const logs of logsByBlock.values()) {
|
|
76
|
+
for (const log of logs) {
|
|
77
|
+
logsTxsSet.add(log.transactionHash)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const { blocks: blocksByNumber, transactions: transactionsMap } =
|
|
82
|
+
await getBlocksInRange(
|
|
75
83
|
logger,
|
|
84
|
+
db,
|
|
85
|
+
batchBlockNumbers,
|
|
76
86
|
client,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
fromBlock: cursor,
|
|
80
|
-
toBlock,
|
|
81
|
-
}),
|
|
82
|
-
])
|
|
87
|
+
Array.from(logsTxsSet)
|
|
88
|
+
)
|
|
83
89
|
|
|
84
90
|
let blockIndex = 0
|
|
85
91
|
|
|
@@ -89,22 +95,26 @@ export async function runBackfill(args: {
|
|
|
89
95
|
const blockNumber = batchBlockNumbers[blockIndex]
|
|
90
96
|
const prefetchedBlock = blocksByNumber.get(blockNumber)
|
|
91
97
|
|
|
98
|
+
if (!prefetchedBlock) {
|
|
99
|
+
throw new Error(`Block ${blockNumber} not found`)
|
|
100
|
+
}
|
|
101
|
+
|
|
92
102
|
await processBlock({
|
|
93
103
|
logger,
|
|
94
104
|
config,
|
|
95
105
|
db: tx,
|
|
96
106
|
client,
|
|
97
107
|
registry,
|
|
98
|
-
blockNumber,
|
|
99
108
|
logs: logsByBlock.get(blockNumber) ?? [],
|
|
100
109
|
block: prefetchedBlock,
|
|
110
|
+
transactionsMap,
|
|
101
111
|
type: 'backfill',
|
|
102
112
|
contracts: windowContracts,
|
|
103
113
|
})
|
|
104
114
|
blockIndex += 1
|
|
105
115
|
}
|
|
106
116
|
})
|
|
107
|
-
logger.
|
|
117
|
+
logger.debug(
|
|
108
118
|
{ duration: endClockBatch() },
|
|
109
119
|
'batch block and events processed'
|
|
110
120
|
)
|
|
@@ -118,6 +128,7 @@ export async function runBackfill(args: {
|
|
|
118
128
|
{
|
|
119
129
|
indexedUpTo: toBlock.toString(),
|
|
120
130
|
duration: batchElapsedMs,
|
|
131
|
+
contracts: windowContracts.addresses.length,
|
|
121
132
|
throughput: Number(blocksPerSecond.toFixed(2)),
|
|
122
133
|
},
|
|
123
134
|
'backfill batch completed'
|
|
@@ -7,7 +7,7 @@ import { runBackfill } from './backfill.ts'
|
|
|
7
7
|
import { startLiveSync } from './live.ts'
|
|
8
8
|
import { verifyRecentBlocks } from './reorg.ts'
|
|
9
9
|
|
|
10
|
-
export async function
|
|
10
|
+
export async function createIndexer(options: {
|
|
11
11
|
logger: Logger
|
|
12
12
|
db: Database<typeof schema, typeof relations>
|
|
13
13
|
registry: HookRegistry
|
package/src/indexer/live.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import PQueue from 'p-queue'
|
|
2
2
|
import type { PublicClient } from 'viem'
|
|
3
|
+
|
|
3
4
|
import type { InternalConfig } from '../config/config.ts'
|
|
4
5
|
import type { Database } from '../db/client.ts'
|
|
5
6
|
import type { relations, schema } from '../db/schema/index.ts'
|
|
@@ -25,7 +26,7 @@ export function startLiveSync(args: {
|
|
|
25
26
|
const contracts = config.contractsForLive
|
|
26
27
|
|
|
27
28
|
if (contracts.length === 0) {
|
|
28
|
-
logger.
|
|
29
|
+
logger.info(
|
|
29
30
|
'all configured contracts have endBlock set; live sync disabled'
|
|
30
31
|
)
|
|
31
32
|
return { stop: noop }
|
|
@@ -44,7 +45,7 @@ export function startLiveSync(args: {
|
|
|
44
45
|
onBlockNumber: (head) => {
|
|
45
46
|
while (nextBlockToQueue <= head) {
|
|
46
47
|
const blockNumber = nextBlockToQueue
|
|
47
|
-
pqueue.add(async () => {
|
|
48
|
+
void pqueue.add(async () => {
|
|
48
49
|
await queueBlock({
|
|
49
50
|
logger,
|
|
50
51
|
blockNumber,
|
|
@@ -67,7 +68,7 @@ export function startLiveSync(args: {
|
|
|
67
68
|
},
|
|
68
69
|
})
|
|
69
70
|
|
|
70
|
-
logger.
|
|
71
|
+
logger.info(
|
|
71
72
|
{ startBlock: nextBlockToQueue.toString() },
|
|
72
73
|
'watching latest chain head'
|
|
73
74
|
)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AbiEvent, Log, PublicClient } from 'viem'
|
|
2
|
+
|
|
2
3
|
import type { FilteredContracts, InternalConfig } from '../config/config.ts'
|
|
3
4
|
import { cacheBlockAndTransactions } from '../db/actions/blocks.ts'
|
|
4
5
|
import type { Database } from '../db/client.ts'
|
|
5
6
|
import type { relations, schema } from '../db/schema/index.ts'
|
|
6
7
|
import { withTransaction } from '../db/transaction.ts'
|
|
7
8
|
import type { HookRegistry } from '../hooks/registry.ts'
|
|
8
|
-
import {
|
|
9
|
-
import type { EncodedBlockWithTransactions, EncodedTransaction } from '../types'
|
|
9
|
+
import type { EncodedBlock, TransactionsMap } from '../types'
|
|
10
10
|
import type { Logger } from '../utils/logger.ts'
|
|
11
11
|
import { ensureParentContinuity } from './reorg.ts'
|
|
12
12
|
|
|
@@ -23,9 +23,9 @@ export async function processBlock(args: {
|
|
|
23
23
|
db: Database<typeof schema, typeof relations>
|
|
24
24
|
client: PublicClient
|
|
25
25
|
registry: HookRegistry<NonNullable<unknown>>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
logs: Log<bigint, number, false, AbiEvent>[]
|
|
27
|
+
block: EncodedBlock
|
|
28
|
+
transactionsMap: TransactionsMap
|
|
29
29
|
type: 'backfill' | 'live'
|
|
30
30
|
contracts: FilteredContracts
|
|
31
31
|
}): Promise<ProcessBlockResult> {
|
|
@@ -35,41 +35,12 @@ export async function processBlock(args: {
|
|
|
35
35
|
db,
|
|
36
36
|
client,
|
|
37
37
|
registry,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
logs
|
|
38
|
+
block,
|
|
39
|
+
transactionsMap,
|
|
40
|
+
logs,
|
|
41
41
|
type,
|
|
42
42
|
contracts,
|
|
43
43
|
} = args
|
|
44
|
-
const transactionByHash = new Map<`0x${string}`, EncodedTransaction>()
|
|
45
|
-
|
|
46
|
-
let block: EncodedBlockWithTransactions | undefined
|
|
47
|
-
let logs: Log<bigint, number, false, AbiEvent>[] | undefined
|
|
48
|
-
|
|
49
|
-
if (prefetchedBlock) {
|
|
50
|
-
block = prefetchedBlock
|
|
51
|
-
}
|
|
52
|
-
if (prefetchedLogs) {
|
|
53
|
-
logs = prefetchedLogs
|
|
54
|
-
}
|
|
55
|
-
if (!block || !logs) {
|
|
56
|
-
const [blockResult, logsResult] = await Promise.all([
|
|
57
|
-
safeGetBlock({ client, blockNumber, db }),
|
|
58
|
-
client.getLogs({
|
|
59
|
-
address: contracts.addresses,
|
|
60
|
-
events: contracts.eventAbis,
|
|
61
|
-
fromBlock: blockNumber,
|
|
62
|
-
toBlock: blockNumber,
|
|
63
|
-
}),
|
|
64
|
-
])
|
|
65
|
-
|
|
66
|
-
block = blockResult
|
|
67
|
-
logs = logsResult
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
for (const tx of block.transactions) {
|
|
71
|
-
transactionByHash.set(tx.hash, tx)
|
|
72
|
-
}
|
|
73
44
|
|
|
74
45
|
if (type === 'live') {
|
|
75
46
|
const rewindTo = await ensureParentContinuity({
|
|
@@ -87,7 +58,8 @@ export async function processBlock(args: {
|
|
|
87
58
|
if (type === 'live') {
|
|
88
59
|
await cacheBlockAndTransactions({
|
|
89
60
|
db: tx,
|
|
90
|
-
block,
|
|
61
|
+
blocks: [block],
|
|
62
|
+
transactions: Array.from(transactionsMap.values()),
|
|
91
63
|
logger,
|
|
92
64
|
})
|
|
93
65
|
}
|
|
@@ -96,7 +68,7 @@ export async function processBlock(args: {
|
|
|
96
68
|
const contractName = contracts.contractNameByAddress[log.address]
|
|
97
69
|
|
|
98
70
|
if (!contractName) {
|
|
99
|
-
logger.
|
|
71
|
+
logger.debug(
|
|
100
72
|
{ address: log.address },
|
|
101
73
|
'contract not found in contract name by address'
|
|
102
74
|
)
|
|
@@ -107,10 +79,10 @@ export async function processBlock(args: {
|
|
|
107
79
|
if (!contracts.eventNames.has(eventName)) {
|
|
108
80
|
continue
|
|
109
81
|
}
|
|
110
|
-
const transaction =
|
|
82
|
+
const transaction = transactionsMap.get(log.transactionHash)
|
|
111
83
|
|
|
112
84
|
if (!transaction) {
|
|
113
|
-
logger.
|
|
85
|
+
logger.debug(
|
|
114
86
|
{ transactionHash: log.transactionHash },
|
|
115
87
|
|
|
116
88
|
'transaction not found in block transaction list'
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Logger } from 'pino'
|
|
2
2
|
import type { PublicClient } from 'viem'
|
|
3
|
+
|
|
3
4
|
import { filterContracts, type InternalConfig } from '../config/config.ts'
|
|
4
5
|
import type { Database } from '../db/client.ts'
|
|
5
6
|
import type { relations, schema } from '../db/schema/index.ts'
|
|
6
7
|
import type { HookRegistry } from '../hooks/registry.ts'
|
|
8
|
+
import { safeGetBlock } from '../rpc/get-block.ts'
|
|
9
|
+
import type { EncodedBlock, EncodedTransaction } from '../types.ts'
|
|
7
10
|
import { startClock } from '../utils/timer.ts'
|
|
8
11
|
import { processBlock } from './process-block.ts'
|
|
9
12
|
|
|
@@ -33,15 +36,36 @@ export async function queueBlock(args: QueueBlockArgs): Promise<void> {
|
|
|
33
36
|
const endClock = startClock()
|
|
34
37
|
try {
|
|
35
38
|
const contracts = filterContracts(config, blockNumber, blockNumber)
|
|
39
|
+
|
|
40
|
+
const [blockResult, logsResult] = await Promise.all([
|
|
41
|
+
safeGetBlock({ client, blockNumber, db }),
|
|
42
|
+
client.getLogs({
|
|
43
|
+
address: contracts.addresses,
|
|
44
|
+
events: contracts.eventAbis,
|
|
45
|
+
fromBlock: blockNumber,
|
|
46
|
+
toBlock: blockNumber,
|
|
47
|
+
}),
|
|
48
|
+
])
|
|
49
|
+
|
|
50
|
+
const { transactions, ..._block } = blockResult
|
|
51
|
+
const block: EncodedBlock = _block
|
|
52
|
+
const transactionsMap = new Map<`0x${string}`, EncodedTransaction>()
|
|
53
|
+
|
|
54
|
+
for (const tx of transactions) {
|
|
55
|
+
transactionsMap.set(tx.hash, tx)
|
|
56
|
+
}
|
|
57
|
+
|
|
36
58
|
const result = await processBlock({
|
|
37
59
|
logger,
|
|
38
60
|
config,
|
|
39
61
|
db,
|
|
40
62
|
client,
|
|
41
63
|
registry,
|
|
42
|
-
blockNumber,
|
|
43
64
|
type: 'live',
|
|
44
65
|
contracts,
|
|
66
|
+
block,
|
|
67
|
+
transactionsMap,
|
|
68
|
+
logs: logsResult,
|
|
45
69
|
})
|
|
46
70
|
|
|
47
71
|
if (result.status === 'reorg') {
|