@sentio/sdk 2.59.0-rc.23 → 2.59.0-rc.25

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 (205) hide show
  1. package/lib/aptos/aptos-plugin.d.ts +6 -5
  2. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  3. package/lib/aptos/aptos-plugin.js +31 -33
  4. package/lib/aptos/aptos-plugin.js.map +1 -1
  5. package/lib/aptos/aptos-processor.d.ts +19 -19
  6. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  7. package/lib/aptos/aptos-processor.js +95 -44
  8. package/lib/aptos/aptos-processor.js.map +1 -1
  9. package/lib/aptos/aptos-resource-processor-template.d.ts +5 -4
  10. package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
  11. package/lib/aptos/aptos-resource-processor-template.js +8 -8
  12. package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
  13. package/lib/aptos/builtin/0x1.d.ts +333 -332
  14. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  15. package/lib/aptos/builtin/0x1.js +664 -664
  16. package/lib/aptos/builtin/0x1.js.map +1 -1
  17. package/lib/aptos/builtin/0x3.d.ts +66 -65
  18. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  19. package/lib/aptos/builtin/0x3.js +130 -130
  20. package/lib/aptos/builtin/0x3.js.map +1 -1
  21. package/lib/aptos/builtin/0x4.d.ts +29 -28
  22. package/lib/aptos/builtin/0x4.d.ts.map +1 -1
  23. package/lib/aptos/builtin/0x4.js +56 -56
  24. package/lib/aptos/builtin/0x4.js.map +1 -1
  25. package/lib/aptos/codegen/codegen.js +27 -0
  26. package/lib/aptos/codegen/codegen.js.map +1 -1
  27. package/lib/aptos/data.d.ts +28 -3
  28. package/lib/aptos/data.d.ts.map +1 -1
  29. package/lib/aptos/data.js +61 -0
  30. package/lib/aptos/data.js.map +1 -1
  31. package/lib/aptos/index.d.ts +1 -0
  32. package/lib/aptos/index.d.ts.map +1 -1
  33. package/lib/aptos/index.js.map +1 -1
  34. package/lib/aptos/models.d.ts +1 -0
  35. package/lib/aptos/models.d.ts.map +1 -1
  36. package/lib/btc/btc-plugin.d.ts +4 -1
  37. package/lib/btc/btc-plugin.d.ts.map +1 -1
  38. package/lib/btc/btc-plugin.js +27 -0
  39. package/lib/btc/btc-plugin.js.map +1 -1
  40. package/lib/btc/btc-processor.d.ts +6 -5
  41. package/lib/btc/btc-processor.d.ts.map +1 -1
  42. package/lib/btc/btc-processor.js +35 -9
  43. package/lib/btc/btc-processor.js.map +1 -1
  44. package/lib/btc/types.d.ts +2 -1
  45. package/lib/btc/types.d.ts.map +1 -1
  46. package/lib/core/handler-options.d.ts +25 -0
  47. package/lib/core/handler-options.d.ts.map +1 -0
  48. package/lib/core/handler-options.js +21 -0
  49. package/lib/core/handler-options.js.map +1 -0
  50. package/lib/core/index.d.ts +2 -0
  51. package/lib/core/index.d.ts.map +1 -1
  52. package/lib/core/index.js +2 -0
  53. package/lib/core/index.js.map +1 -1
  54. package/lib/core/partition-handler-manager.d.ts +44 -0
  55. package/lib/core/partition-handler-manager.d.ts.map +1 -0
  56. package/lib/core/partition-handler-manager.js +76 -0
  57. package/lib/core/partition-handler-manager.js.map +1 -0
  58. package/lib/cosmos/cosmos-processor.d.ts +3 -2
  59. package/lib/cosmos/cosmos-processor.d.ts.map +1 -1
  60. package/lib/cosmos/cosmos-processor.js +11 -1
  61. package/lib/cosmos/cosmos-processor.js.map +1 -1
  62. package/lib/cosmos/types.d.ts +1 -0
  63. package/lib/cosmos/types.d.ts.map +1 -1
  64. package/lib/eth/base-processor.d.ts +18 -17
  65. package/lib/eth/base-processor.d.ts.map +1 -1
  66. package/lib/eth/base-processor.js +147 -26
  67. package/lib/eth/base-processor.js.map +1 -1
  68. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +32 -31
  69. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
  70. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +62 -62
  71. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  72. package/lib/eth/builtin/internal/erc1155-processor.d.ts +17 -16
  73. package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
  74. package/lib/eth/builtin/internal/erc1155-processor.js +32 -32
  75. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  76. package/lib/eth/builtin/internal/erc20-processor.d.ts +25 -24
  77. package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
  78. package/lib/eth/builtin/internal/erc20-processor.js +48 -48
  79. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  80. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +14 -13
  81. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
  82. package/lib/eth/builtin/internal/erc20bytes-processor.js +26 -26
  83. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  84. package/lib/eth/builtin/internal/erc721-processor.d.ts +21 -20
  85. package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
  86. package/lib/eth/builtin/internal/erc721-processor.js +40 -40
  87. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  88. package/lib/eth/builtin/internal/weth9-processor.d.ts +20 -19
  89. package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
  90. package/lib/eth/builtin/internal/weth9-processor.js +38 -38
  91. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  92. package/lib/eth/codegen/event-handler.js +2 -2
  93. package/lib/eth/codegen/event-handler.js.map +1 -1
  94. package/lib/eth/codegen/file.d.ts.map +1 -1
  95. package/lib/eth/codegen/file.js +1 -0
  96. package/lib/eth/codegen/file.js.map +1 -1
  97. package/lib/eth/codegen/functions-handler.js +2 -2
  98. package/lib/eth/codegen/functions-handler.js.map +1 -1
  99. package/lib/eth/eth-plugin.d.ts +4 -1
  100. package/lib/eth/eth-plugin.d.ts.map +1 -1
  101. package/lib/eth/eth-plugin.js +42 -1
  102. package/lib/eth/eth-plugin.js.map +1 -1
  103. package/lib/eth/eth.d.ts +2 -7
  104. package/lib/eth/eth.d.ts.map +1 -1
  105. package/lib/eth/eth.js +8 -1
  106. package/lib/eth/eth.js.map +1 -1
  107. package/lib/fuel/codegen/codegen.js +5 -5
  108. package/lib/fuel/codegen/codegen.js.map +1 -1
  109. package/lib/fuel/fuel-plugin.d.ts +4 -1
  110. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  111. package/lib/fuel/fuel-plugin.js +41 -0
  112. package/lib/fuel/fuel-plugin.js.map +1 -1
  113. package/lib/fuel/fuel-processor-template.d.ts +7 -4
  114. package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
  115. package/lib/fuel/fuel-processor-template.js +11 -9
  116. package/lib/fuel/fuel-processor-template.js.map +1 -1
  117. package/lib/fuel/fuel-processor.d.ts +7 -7
  118. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  119. package/lib/fuel/fuel-processor.js +90 -19
  120. package/lib/fuel/fuel-processor.js.map +1 -1
  121. package/lib/fuel/types.d.ts +3 -0
  122. package/lib/fuel/types.d.ts.map +1 -1
  123. package/lib/move/filter.d.ts +4 -0
  124. package/lib/move/filter.d.ts.map +1 -1
  125. package/lib/move/filter.js +4 -0
  126. package/lib/move/filter.js.map +1 -1
  127. package/lib/move/shared-network-codegen.d.ts.map +1 -1
  128. package/lib/move/shared-network-codegen.js +5 -4
  129. package/lib/move/shared-network-codegen.js.map +1 -1
  130. package/lib/solana/solana-processor.d.ts +10 -4
  131. package/lib/solana/solana-processor.d.ts.map +1 -1
  132. package/lib/solana/solana-processor.js +13 -4
  133. package/lib/solana/solana-processor.js.map +1 -1
  134. package/lib/stark/starknet-processor.d.ts +3 -1
  135. package/lib/stark/starknet-processor.d.ts.map +1 -1
  136. package/lib/stark/starknet-processor.js +27 -2
  137. package/lib/stark/starknet-processor.js.map +1 -1
  138. package/lib/sui/builtin/0x1.d.ts +7 -6
  139. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  140. package/lib/sui/builtin/0x1.js +12 -12
  141. package/lib/sui/builtin/0x1.js.map +1 -1
  142. package/lib/sui/builtin/0x2.d.ts +61 -60
  143. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  144. package/lib/sui/builtin/0x2.js +120 -120
  145. package/lib/sui/builtin/0x2.js.map +1 -1
  146. package/lib/sui/builtin/0x3.d.ts +49 -48
  147. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  148. package/lib/sui/builtin/0x3.js +96 -96
  149. package/lib/sui/builtin/0x3.js.map +1 -1
  150. package/lib/sui/models.d.ts +1 -0
  151. package/lib/sui/models.d.ts.map +1 -1
  152. package/lib/sui/sui-plugin.d.ts +6 -3
  153. package/lib/sui/sui-plugin.d.ts.map +1 -1
  154. package/lib/sui/sui-plugin.js +59 -20
  155. package/lib/sui/sui-plugin.js.map +1 -1
  156. package/lib/sui/sui-processor.d.ts +5 -4
  157. package/lib/sui/sui-processor.d.ts.map +1 -1
  158. package/lib/sui/sui-processor.js +47 -11
  159. package/lib/sui/sui-processor.js.map +1 -1
  160. package/package.json +3 -3
  161. package/src/aptos/aptos-plugin.ts +35 -39
  162. package/src/aptos/aptos-processor.ts +104 -60
  163. package/src/aptos/aptos-resource-processor-template.ts +9 -8
  164. package/src/aptos/builtin/0x1.ts +1565 -664
  165. package/src/aptos/builtin/0x3.ts +302 -130
  166. package/src/aptos/builtin/0x4.ts +123 -56
  167. package/src/aptos/codegen/codegen.ts +34 -1
  168. package/src/aptos/data.ts +78 -3
  169. package/src/aptos/index.ts +2 -0
  170. package/src/aptos/models.ts +2 -0
  171. package/src/btc/btc-plugin.ts +38 -0
  172. package/src/btc/btc-processor.ts +35 -10
  173. package/src/btc/types.ts +2 -1
  174. package/src/core/handler-options.ts +40 -0
  175. package/src/core/index.ts +5 -0
  176. package/src/core/partition-handler-manager.ts +94 -0
  177. package/src/cosmos/cosmos-processor.ts +12 -1
  178. package/src/cosmos/types.ts +1 -0
  179. package/src/eth/base-processor.ts +139 -33
  180. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +118 -62
  181. package/src/eth/builtin/internal/erc1155-processor.ts +76 -32
  182. package/src/eth/builtin/internal/erc20-processor.ts +79 -48
  183. package/src/eth/builtin/internal/erc20bytes-processor.ts +47 -26
  184. package/src/eth/builtin/internal/erc721-processor.ts +77 -40
  185. package/src/eth/builtin/internal/weth9-processor.ts +79 -38
  186. package/src/eth/codegen/event-handler.ts +2 -2
  187. package/src/eth/codegen/file.ts +1 -0
  188. package/src/eth/codegen/functions-handler.ts +2 -2
  189. package/src/eth/eth-plugin.ts +55 -3
  190. package/src/eth/eth.ts +12 -1
  191. package/src/fuel/codegen/codegen.ts +5 -5
  192. package/src/fuel/fuel-plugin.ts +56 -0
  193. package/src/fuel/fuel-processor-template.ts +17 -10
  194. package/src/fuel/fuel-processor.ts +89 -13
  195. package/src/fuel/types.ts +3 -0
  196. package/src/move/filter.ts +4 -0
  197. package/src/move/shared-network-codegen.ts +5 -4
  198. package/src/solana/solana-processor.ts +28 -6
  199. package/src/stark/starknet-processor.ts +28 -2
  200. package/src/sui/builtin/0x1.ts +22 -12
  201. package/src/sui/builtin/0x2.ts +220 -120
  202. package/src/sui/builtin/0x3.ts +241 -96
  203. package/src/sui/models.ts +2 -0
  204. package/src/sui/sui-plugin.ts +68 -22
  205. package/src/sui/sui-processor.ts +48 -11
@@ -29,7 +29,7 @@ import sha3 from 'js-sha3'
29
29
  import { ListStateStorage } from '@sentio/runtime'
30
30
  import { EthChainId } from '@sentio/chain'
31
31
  import { getHandlerName, proxyHandlers, proxyProcessor } from '../utils/metrics.js'
32
- import { ALL_ADDRESS } from '../core/index.js'
32
+ import { ALL_ADDRESS, HandlerOptions } from '../core/index.js'
33
33
  import { parseLog, decodeTrace } from './abi-decoder/index.js'
34
34
 
35
35
  export interface AddressOrTypeEventFilter extends DeferredTopicFilter {
@@ -45,7 +45,7 @@ export class EventsHandler {
45
45
  handler: (event: Data_EthLog) => Promise<ProcessResult>
46
46
  preprocessHandler?: (event: Data_EthLog, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>
47
47
  fetchConfig: EthFetchConfig
48
- partitionHandler?: (event: Data_EthLog) => string | undefined
48
+ partitionHandler?: (event: Data_EthLog) => Promise<string | undefined>
49
49
  }
50
50
 
51
51
  export class TraceHandler {
@@ -54,7 +54,7 @@ export class TraceHandler {
54
54
  handler: (trace: Data_EthTrace) => Promise<ProcessResult>
55
55
  preprocessHandler?: (event: Data_EthTrace, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>
56
56
  fetchConfig: EthFetchConfig
57
- partitionHandler?: (trace: Data_EthTrace) => string | undefined
57
+ partitionHandler?: (trace: Data_EthTrace) => Promise<string | undefined>
58
58
  }
59
59
 
60
60
  export class BlockHandler {
@@ -64,7 +64,7 @@ export class BlockHandler {
64
64
  handler: (block: Data_EthBlock) => Promise<ProcessResult>
65
65
  preprocessHandler?: (event: Data_EthBlock, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>
66
66
  fetchConfig: EthFetchConfig
67
- partitionHandler?: (block: Data_EthBlock) => string | undefined
67
+ partitionHandler?: (block: Data_EthBlock) => Promise<string | undefined>
68
68
  }
69
69
 
70
70
  export class TransactionHandler {
@@ -72,7 +72,7 @@ export class TransactionHandler {
72
72
  handlerName: string
73
73
  preprocessHandler?: (event: Data_EthTransaction, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>
74
74
  fetchConfig: EthFetchConfig
75
- partitionHandler?: (tx: Data_EthTransaction) => string | undefined
75
+ partitionHandler?: (tx: Data_EthTransaction) => Promise<string | undefined>
76
76
  }
77
77
 
78
78
  class BindInternalOptions {
@@ -128,15 +128,14 @@ export class GlobalProcessor {
128
128
  handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
129
129
  blockInterval = 250,
130
130
  backfillBlockInterval = 1000,
131
- fetchConfig?: Partial<EthFetchConfig>,
131
+ handlerOptions?: HandlerOptions<EthFetchConfig, RichBlock>,
132
132
  preprocessHandler: (
133
133
  block: RichBlock,
134
134
  ctx: GlobalContext,
135
135
  preprocessStore: {
136
136
  [k: string]: any
137
137
  }
138
- ) => Promise<PreprocessResult> = defaultPreprocessHandler,
139
- partitionHandler?: (block: Data_EthBlock) => string | undefined
138
+ ) => Promise<PreprocessResult> = defaultPreprocessHandler
140
139
  ): this {
141
140
  return this.onInterval(
142
141
  handler,
@@ -145,7 +144,7 @@ export class GlobalProcessor {
145
144
  recentInterval: blockInterval,
146
145
  backfillInterval: backfillBlockInterval
147
146
  },
148
- fetchConfig,
147
+ handlerOptions,
149
148
  preprocessHandler
150
149
  )
151
150
  }
@@ -154,7 +153,7 @@ export class GlobalProcessor {
154
153
  handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
155
154
  timeIntervalInMinutes = 60,
156
155
  backfillTimeIntervalInMinutes = 240,
157
- fetchConfig?: Partial<EthFetchConfig>,
156
+ handlerOptions?: HandlerOptions<EthFetchConfig, RichBlock>,
158
157
  preprocessHandler: (
159
158
  block: RichBlock,
160
159
  ctx: GlobalContext,
@@ -167,7 +166,7 @@ export class GlobalProcessor {
167
166
  handler,
168
167
  { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
169
168
  undefined,
170
- fetchConfig,
169
+ handlerOptions,
171
170
  preprocessHandler
172
171
  )
173
172
  }
@@ -180,7 +179,7 @@ export class GlobalProcessor {
180
179
  handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
181
180
  timeInterval: HandleInterval | undefined,
182
181
  blockInterval: HandleInterval | undefined,
183
- fetchConfig: Partial<EthFetchConfig> | undefined,
182
+ handlerOptions?: HandlerOptions<EthFetchConfig, RichBlock>,
184
183
  preprocessHandler: (
185
184
  block: RichBlock,
186
185
  ctx: GlobalContext,
@@ -242,14 +241,24 @@ export class GlobalProcessor {
242
241
  },
243
242
  timeIntervalInMinutes: timeInterval,
244
243
  blockInterval: blockInterval,
245
- fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {})
244
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
245
+ partitionHandler: async (data: Data_EthBlock): Promise<string | undefined> => {
246
+ const p = handlerOptions?.partitionKey
247
+ if (!p) return undefined
248
+ if (typeof p === 'function') {
249
+ const { block } = formatEthData(data)
250
+ if (!block) return undefined
251
+ return p(block)
252
+ }
253
+ return p
254
+ }
246
255
  })
247
256
  return this
248
257
  }
249
258
 
250
259
  public onTransaction(
251
260
  handler: (transaction: TransactionResponseParams, ctx: GlobalContext) => PromiseOrVoid,
252
- fetchConfig?: Partial<EthFetchConfig>,
261
+ handlerOptions?: HandlerOptions<EthFetchConfig, TransactionResponseParams>,
253
262
  preprocessHandler: (
254
263
  transaction: TransactionResponseParams,
255
264
  ctx: GlobalContext,
@@ -310,7 +319,16 @@ export class GlobalProcessor {
310
319
  )
311
320
  return preprocessHandler(transaction, ctx, preprocessStore)
312
321
  },
313
- fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {})
322
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
323
+ partitionHandler: async (data: Data_EthTransaction): Promise<string | undefined> => {
324
+ const p = handlerOptions?.partitionKey
325
+ if (!p) return undefined
326
+ if (typeof p === 'function') {
327
+ const { transaction } = formatEthData(data)
328
+ return p(transaction)
329
+ }
330
+ return p
331
+ }
314
332
  })
315
333
  return this
316
334
  }
@@ -318,7 +336,7 @@ export class GlobalProcessor {
318
336
  public onTrace(
319
337
  signatures: string | string[],
320
338
  handler: (trace: Trace, ctx: GlobalContext) => PromiseOrVoid,
321
- fetchConfig?: Partial<EthFetchConfig>,
339
+ handlerOptions?: HandlerOptions<EthFetchConfig, Trace>,
322
340
  preprocessHandler: (
323
341
  trace: Trace,
324
342
  ctx: GlobalContext,
@@ -341,7 +359,7 @@ export class GlobalProcessor {
341
359
 
342
360
  this.traceHandlers.push({
343
361
  signatures,
344
- fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
362
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
345
363
  handlerName: getHandlerName(),
346
364
  handler: async function (data: Data_EthTrace) {
347
365
  const { trace, block, transaction, transactionReceipt } = formatEthData(data)
@@ -381,6 +399,16 @@ export class GlobalProcessor {
381
399
  processor.config.baseLabels
382
400
  )
383
401
  return preprocessHandler(trace, ctx, preprocessStore)
402
+ },
403
+ partitionHandler: async (data: Data_EthTrace): Promise<string | undefined> => {
404
+ const p = handlerOptions?.partitionKey
405
+ if (!p) return undefined
406
+ if (typeof p === 'function') {
407
+ const { trace } = formatEthData(data)
408
+ if (!trace) return undefined
409
+ return p(trace)
410
+ }
411
+ return p
384
412
  }
385
413
  })
386
414
  return this
@@ -430,7 +458,7 @@ export abstract class BaseProcessor<
430
458
 
431
459
  public onEvent(
432
460
  handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
433
- fetchConfig?: Partial<EthFetchConfig>,
461
+ handlerOptions?: HandlerOptions<EthFetchConfig, TypedEvent>,
434
462
  preprocessHandler: (
435
463
  event: TypedEvent,
436
464
  ctx: ContractContext<TContract, TBoundContractView>,
@@ -446,13 +474,13 @@ export abstract class BaseProcessor<
446
474
  _filters.push(filter())
447
475
  }
448
476
  }
449
- return this.onEthEvent(handler, _filters, fetchConfig, preprocessHandler)
477
+ return this.onEthEvent(handler, _filters, handlerOptions, preprocessHandler)
450
478
  }
451
479
 
452
480
  protected onEthEvent(
453
481
  handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
454
482
  filter: DeferredTopicFilter | DeferredTopicFilter[],
455
- fetchConfig?: Partial<EthFetchConfig>,
483
+ handlerOptions?: HandlerOptions<EthFetchConfig, TypedEvent>,
456
484
  preprocessHandler: (
457
485
  event: TypedEvent,
458
486
  ctx: ContractContext<TContract, TBoundContractView>,
@@ -473,7 +501,7 @@ export abstract class BaseProcessor<
473
501
  const processor = this
474
502
  this.eventHandlers.push({
475
503
  filters: _filters,
476
- fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
504
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
477
505
  handlerName,
478
506
  handler: async function (data: Data_EthLog, preparedData?: PreparedData) {
479
507
  const { log, block, transaction, transactionReceipt } = formatEthData(data)
@@ -493,7 +521,7 @@ export abstract class BaseProcessor<
493
521
 
494
522
  let parsed: LogDescription | null = null
495
523
  try {
496
- parsed = await parseLog(processor, log)
524
+ parsed = await getCachedParsedLog(data, processor, log)
497
525
  } catch (e) {
498
526
  // RangeError data out-of-bounds
499
527
  if (e instanceof Error) {
@@ -558,7 +586,7 @@ export abstract class BaseProcessor<
558
586
 
559
587
  let parsed: LogDescription | null = null
560
588
  try {
561
- parsed = await parseLog(processor, log)
589
+ parsed = await getCachedParsedLog(data, processor, log)
562
590
  } catch (e) {
563
591
  // RangeError data out-of-bounds
564
592
  if (e instanceof Error) {
@@ -574,6 +602,26 @@ export abstract class BaseProcessor<
574
602
  return preprocessHandler(event, ctx, preprocessStore)
575
603
  }
576
604
  return PreprocessResult.fromPartial({})
605
+ },
606
+ partitionHandler: async (data: Data_EthLog): Promise<string | undefined> => {
607
+ const p = handlerOptions?.partitionKey
608
+ if (!p) return undefined
609
+ if (typeof p === 'function') {
610
+ const { log } = formatEthData(data)
611
+ if (!log) return undefined
612
+ let parsed: LogDescription | null = null
613
+ try {
614
+ parsed = await getCachedParsedLog(data, processor, log)
615
+ } catch (e) {
616
+ return undefined
617
+ }
618
+ if (parsed) {
619
+ const event: TypedEvent = { ...log, name: parsed.name, args: fixEmptyKey(parsed) }
620
+ return p(event)
621
+ }
622
+ return undefined
623
+ }
624
+ return p
577
625
  }
578
626
  })
579
627
  return this
@@ -583,7 +631,7 @@ export abstract class BaseProcessor<
583
631
  handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
584
632
  blockInterval = 250,
585
633
  backfillBlockInterval = 1000,
586
- fetchConfig?: Partial<EthFetchConfig>,
634
+ handlerOptions?: HandlerOptions<EthFetchConfig, RichBlock>,
587
635
  preprocessHandler: (
588
636
  block: RichBlock,
589
637
  ctx: ContractContext<TContract, TBoundContractView>,
@@ -597,7 +645,7 @@ export abstract class BaseProcessor<
597
645
  recentInterval: blockInterval,
598
646
  backfillInterval: backfillBlockInterval
599
647
  },
600
- fetchConfig,
648
+ handlerOptions,
601
649
  preprocessHandler
602
650
  )
603
651
  }
@@ -606,7 +654,7 @@ export abstract class BaseProcessor<
606
654
  handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
607
655
  timeIntervalInMinutes = 60,
608
656
  backfillTimeIntervalInMinutes = 240,
609
- fetchConfig?: Partial<EthFetchConfig>,
657
+ handlerOptions?: HandlerOptions<EthFetchConfig, RichBlock>,
610
658
  preprocessHandler: (
611
659
  block: RichBlock,
612
660
  ctx: ContractContext<TContract, TBoundContractView>,
@@ -617,7 +665,7 @@ export abstract class BaseProcessor<
617
665
  handler,
618
666
  { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
619
667
  undefined,
620
- fetchConfig,
668
+ handlerOptions,
621
669
  preprocessHandler
622
670
  )
623
671
  }
@@ -626,7 +674,7 @@ export abstract class BaseProcessor<
626
674
  handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
627
675
  timeInterval: HandleInterval | undefined,
628
676
  blockInterval: HandleInterval | undefined,
629
- fetchConfig: Partial<EthFetchConfig> | undefined,
677
+ handlerOptions?: HandlerOptions<EthFetchConfig, RichBlock>,
630
678
  preprocessHandler: (
631
679
  block: RichBlock,
632
680
  ctx: ContractContext<TContract, TBoundContractView>,
@@ -690,7 +738,17 @@ export abstract class BaseProcessor<
690
738
  },
691
739
  timeIntervalInMinutes: timeInterval,
692
740
  blockInterval: blockInterval,
693
- fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {})
741
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
742
+ partitionHandler: async (data: Data_EthBlock): Promise<string | undefined> => {
743
+ const p = handlerOptions?.partitionKey
744
+ if (!p) return undefined
745
+ if (typeof p === 'function') {
746
+ const { block } = formatEthData(data)
747
+ if (!block) return undefined
748
+ return p(block)
749
+ }
750
+ return p
751
+ }
694
752
  })
695
753
  return this
696
754
  }
@@ -698,7 +756,7 @@ export abstract class BaseProcessor<
698
756
  protected onEthTrace(
699
757
  signatures: string | string[],
700
758
  handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
701
- fetchConfig?: Partial<EthFetchConfig>,
759
+ handlerOptions?: HandlerOptions<EthFetchConfig, TypedCallTrace>,
702
760
  preprocessHandler: (
703
761
  trace: TypedCallTrace,
704
762
  ctx: ContractContext<TContract, TBoundContractView>,
@@ -715,7 +773,7 @@ export abstract class BaseProcessor<
715
773
 
716
774
  this.traceHandlers.push({
717
775
  signatures,
718
- fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
776
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
719
777
  handlerName,
720
778
  handler: async function (data: Data_EthTrace, preparedData?: PreparedData) {
721
779
  const contractView = processor.CreateBoundContractView()
@@ -805,6 +863,35 @@ export abstract class BaseProcessor<
805
863
  processor.config.baseLabels
806
864
  )
807
865
  return preprocessHandler(typedTrace, ctx, preprocessStore)
866
+ },
867
+ partitionHandler: async (data: Data_EthTrace): Promise<string | undefined> => {
868
+ const p = handlerOptions?.partitionKey
869
+ if (!p) return undefined
870
+ if (typeof p === 'function') {
871
+ const contractView = processor.CreateBoundContractView()
872
+ const contractInterface = contractView.rawContract.interface
873
+ const { trace } = formatEthData(data)
874
+ if (!trace) return undefined
875
+ const sighash = trace.action.input?.slice(0, 10)
876
+ if (!sighash) return undefined
877
+ const fragment = contractInterface.getFunction(sighash)
878
+ if (!fragment) return undefined
879
+ const typedTrace = trace as TypedCallTrace
880
+ typedTrace.name = fragment.name
881
+ typedTrace.functionSignature = fragment.format()
882
+ if (trace.action.input) {
883
+ const traceData = '0x' + trace.action.input.slice(10)
884
+ try {
885
+ typedTrace.args = await decodeTrace(processor, fragment.inputs, traceData)
886
+ } catch (e) {
887
+ if (!trace.error) {
888
+ throw e
889
+ }
890
+ }
891
+ }
892
+ return p(typedTrace)
893
+ }
894
+ return p
808
895
  }
809
896
  })
810
897
  return this
@@ -812,7 +899,7 @@ export abstract class BaseProcessor<
812
899
 
813
900
  public onTrace(
814
901
  handler: (event: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
815
- fetchConfig?: Partial<EthFetchConfig>,
902
+ handlerOptions?: HandlerOptions<EthFetchConfig, TypedCallTrace>,
816
903
  preprocessHandler: (
817
904
  trace: TypedCallTrace,
818
905
  ctx: ContractContext<TContract, TBoundContractView>,
@@ -830,6 +917,25 @@ export abstract class BaseProcessor<
830
917
  sighashes.push(sighash)
831
918
  }
832
919
  }
833
- return this.onEthTrace(sighashes, handler, fetchConfig, preprocessHandler)
920
+ return this.onEthTrace(sighashes, handler, handlerOptions, preprocessHandler)
921
+ }
922
+ }
923
+
924
+ // Helper function to get cached or parse log data
925
+ async function getCachedParsedLog(data: any, processor: any, log: any): Promise<LogDescription | null> {
926
+ // Check if parsed log is already cached on data object
927
+ if ((data as any).__parsedLog !== undefined) {
928
+ return (data as any).__parsedLog
929
+ }
930
+
931
+ try {
932
+ const parsed = await parseLog(processor, log)
933
+ // Cache the parsed result on the data object
934
+ ;(data as any).__parsedLog = parsed
935
+ return parsed
936
+ } catch (e) {
937
+ // Cache the null result to avoid retrying
938
+ ;(data as any).__parsedLog = null
939
+ throw e
834
940
  }
835
941
  }