@hugomrdias/foxer 0.1.9 → 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.
Files changed (55) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +71 -1
  3. package/dist/config/env.d.ts +1 -1
  4. package/dist/config/env.d.ts.map +1 -1
  5. package/dist/config/env.js +2 -2
  6. package/dist/config/env.js.map +1 -1
  7. package/dist/db/actions/blocks.d.ts +9 -6
  8. package/dist/db/actions/blocks.d.ts.map +1 -1
  9. package/dist/db/actions/blocks.js +39 -43
  10. package/dist/db/actions/blocks.js.map +1 -1
  11. package/dist/db/client.d.ts +1 -1
  12. package/dist/db/client.d.ts.map +1 -1
  13. package/dist/db/client.js +5 -1
  14. package/dist/db/client.js.map +1 -1
  15. package/dist/db/column-types.d.ts +2 -2
  16. package/dist/db/column-types.d.ts.map +1 -1
  17. package/dist/db/column-types.js +11 -3
  18. package/dist/db/column-types.js.map +1 -1
  19. package/dist/db/schema/blocks.d.ts +16 -16
  20. package/dist/db/schema/index.d.ts +44 -44
  21. package/dist/db/schema/transactions.d.ts +6 -6
  22. package/dist/db/schema/transactions.d.ts.map +1 -1
  23. package/dist/db/schema/transactions.js +3 -1
  24. package/dist/db/schema/transactions.js.map +1 -1
  25. package/dist/hooks/registry.d.ts +3 -3
  26. package/dist/hooks/registry.d.ts.map +1 -1
  27. package/dist/indexer/backfill.d.ts.map +1 -1
  28. package/dist/indexer/backfill.js +19 -12
  29. package/dist/indexer/backfill.js.map +1 -1
  30. package/dist/indexer/process-block.d.ts +4 -4
  31. package/dist/indexer/process-block.d.ts.map +1 -1
  32. package/dist/indexer/process-block.js +4 -29
  33. package/dist/indexer/process-block.js.map +1 -1
  34. package/dist/indexer/queue-block.d.ts.map +1 -1
  35. package/dist/indexer/queue-block.js +19 -1
  36. package/dist/indexer/queue-block.js.map +1 -1
  37. package/dist/indexer/reorg.d.ts +2 -2
  38. package/dist/indexer/reorg.d.ts.map +1 -1
  39. package/dist/rpc/get-logs.js +1 -1
  40. package/dist/rpc/get-logs.js.map +1 -1
  41. package/dist/types.d.ts +2 -0
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +11 -9
  44. package/src/config/env.ts +2 -2
  45. package/src/db/actions/blocks.ts +51 -51
  46. package/src/db/client.ts +5 -1
  47. package/src/db/column-types.ts +17 -6
  48. package/src/db/schema/transactions.ts +3 -1
  49. package/src/hooks/registry.ts +3 -3
  50. package/src/indexer/backfill.ts +28 -10
  51. package/src/indexer/process-block.ts +10 -39
  52. package/src/indexer/queue-block.ts +24 -1
  53. package/src/indexer/reorg.ts +2 -2
  54. package/src/rpc/get-logs.ts +1 -1
  55. package/src/types.ts +2 -0
@@ -5,6 +5,8 @@ import { filterContracts, type InternalConfig } from '../config/config.ts'
5
5
  import type { Database } from '../db/client.ts'
6
6
  import type { relations, schema } from '../db/schema/index.ts'
7
7
  import type { HookRegistry } from '../hooks/registry.ts'
8
+ import { safeGetBlock } from '../rpc/get-block.ts'
9
+ import type { EncodedBlock, EncodedTransaction } from '../types.ts'
8
10
  import { startClock } from '../utils/timer.ts'
9
11
  import { processBlock } from './process-block.ts'
10
12
 
@@ -34,15 +36,36 @@ export async function queueBlock(args: QueueBlockArgs): Promise<void> {
34
36
  const endClock = startClock()
35
37
  try {
36
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
+
37
58
  const result = await processBlock({
38
59
  logger,
39
60
  config,
40
61
  db,
41
62
  client,
42
63
  registry,
43
- blockNumber,
44
64
  type: 'live',
45
65
  contracts,
66
+ block,
67
+ transactionsMap,
68
+ logs: logsResult,
46
69
  })
47
70
 
48
71
  if (result.status === 'reorg') {
@@ -3,7 +3,7 @@ import type { PublicClient } from 'viem'
3
3
  import { deleteBlocksFrom } from '../db/actions/blocks.ts'
4
4
  import type { Database } from '../db/client.ts'
5
5
  import { safeGetBlock } from '../rpc/get-block.ts'
6
- import type { EncodedBlockWithTransactions } from '../types'
6
+ import type { EncodedBlock } from '../types'
7
7
  import { hashEquals } from '../utils/hash.ts'
8
8
  import type { Logger } from '../utils/logger.ts'
9
9
  import { startClock } from '../utils/timer.ts'
@@ -16,7 +16,7 @@ export async function ensureParentContinuity(args: {
16
16
  logger: Logger
17
17
  db: Database
18
18
  client: PublicClient
19
- block: EncodedBlockWithTransactions
19
+ block: EncodedBlock
20
20
  }): Promise<bigint | null> {
21
21
  const { logger, db, client, block } = args
22
22
  if (block.number === 0n) return null
@@ -30,7 +30,7 @@ export async function getLogsInRange(args: {
30
30
  }
31
31
  logger.trace(
32
32
  {
33
- logs: logsByBlock.size,
33
+ logs: logs.length,
34
34
  duration: endClock(),
35
35
  },
36
36
  'get logs'
package/src/types.ts CHANGED
@@ -31,3 +31,5 @@ export type EncodedBlockWithTransactions = Simplify<
31
31
  transactions: EncodedTransaction[]
32
32
  }
33
33
  >
34
+ export type TransactionsMap = Map<`0x${string}`, EncodedTransaction>
35
+ export type BlocksMap = Map<bigint, EncodedBlock>