@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
@@ -8,6 +8,7 @@ import { FuelBlock, FuelLog, FuelTransaction } from './types.js'
8
8
  import { DEFAULT_FUEL_FETCH_CONFIG, FuelFetchConfig } from './transaction.js'
9
9
  import { FuelProcessor, FuelProcessorConfig, getOptionsSignature } from './fuel-processor.js'
10
10
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
11
+ import { HandlerOptions } from '../core/index.js'
11
12
 
12
13
  export class FuelProcessorTemplateProcessorState extends ListStateStorage<FuelBaseProcessorTemplate<Contract>> {
13
14
  static INSTANCE = new FuelProcessorTemplateProcessorState()
@@ -21,6 +22,7 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
21
22
  handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid
22
23
  blockInterval?: HandleInterval
23
24
  timeIntervalInMinutes?: HandleInterval
25
+ handlerOptions?: HandlerOptions<object, FuelBlock>
24
26
  // fetchConfig?: FuelFetchConfig
25
27
  }[] = []
26
28
 
@@ -28,13 +30,14 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
28
30
  logIdFilter: string | string[]
29
31
  handlerName: string
30
32
  handler: (logs: FuelLog<any>, ctx: FuelContractContext<TContract>) => PromiseOrVoid
33
+ handlerOptions?: HandlerOptions<object, FuelLog<any>>
31
34
  // fetchConfig?: FuelFetchConfig
32
35
  }[] = []
33
36
 
34
37
  transactionHandlers: {
35
38
  handlerName: string
36
39
  handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid
37
- fetchConfig: FuelFetchConfig
40
+ handlerOptions?: HandlerOptions<FuelFetchConfig, FuelTransaction>
38
41
  }[] = []
39
42
 
40
43
  constructor() {
@@ -62,13 +65,13 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
62
65
  const processor = this.bindInternal({ ...options, chainId: ctx.chainId })
63
66
 
64
67
  for (const eh of this.logHandlers) {
65
- processor.onLog(eh.logIdFilter, eh.handler, eh.handlerName)
68
+ processor.onLog(eh.logIdFilter, eh.handler, eh.handlerOptions, eh.handlerName)
66
69
  }
67
70
  for (const bh of this.blockHandlers) {
68
- processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.handlerName)
71
+ processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.handlerOptions, bh.handlerName)
69
72
  }
70
73
  for (const th of this.transactionHandlers) {
71
- processor.onTransaction(th.handler, undefined, th.handlerName)
74
+ processor.onTransaction(th.handler, th.handlerOptions, th.handlerName)
72
75
  }
73
76
 
74
77
  const instance: TemplateInstance = {
@@ -94,13 +97,15 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
94
97
 
95
98
  protected onLog<T>(
96
99
  logIdFilter: string | string[],
97
- handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid
100
+ handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
101
+ handlerOptions: HandlerOptions<object, FuelLog<T>> = {}
98
102
  // fetchConfig?: Partial<FuelFetchConfig>
99
103
  ) {
100
104
  this.logHandlers.push({
101
105
  logIdFilter,
102
106
  handlerName: getHandlerName(),
103
- handler
107
+ handler,
108
+ handlerOptions
104
109
  // fetchConfig: { ...fetchConfig}
105
110
  })
106
111
  return this
@@ -140,14 +145,16 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
140
145
  public onInterval(
141
146
  handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
142
147
  timeInterval: HandleInterval | undefined,
143
- blockInterval: HandleInterval | undefined
148
+ blockInterval: HandleInterval | undefined,
149
+ handlerOptions: HandlerOptions<object, FuelBlock> = {}
144
150
  // fetchConfig?: FuelFetchConfig
145
151
  ) {
146
152
  this.blockHandlers.push({
147
153
  handlerName: getHandlerName(),
148
154
  handler,
149
155
  timeIntervalInMinutes: timeInterval,
150
- blockInterval
156
+ blockInterval,
157
+ handlerOptions
151
158
  // fetchConfig: { ...fetchConfig }
152
159
  })
153
160
  return this
@@ -155,12 +162,12 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
155
162
 
156
163
  protected onTransaction(
157
164
  handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
158
- config: FuelFetchConfig = DEFAULT_FUEL_FETCH_CONFIG
165
+ handlerOptions: HandlerOptions<FuelFetchConfig, FuelTransaction> = DEFAULT_FUEL_FETCH_CONFIG
159
166
  ) {
160
167
  this.transactionHandlers.push({
161
168
  handlerName: getHandlerName(),
162
169
  handler,
163
- fetchConfig: config
170
+ handlerOptions
164
171
  })
165
172
  return this
166
173
  }
@@ -27,7 +27,7 @@ import {
27
27
  FuelTransaction,
28
28
  ReceiptHandler
29
29
  } from './types.js'
30
- import { PromiseOrVoid } from '../core/index.js'
30
+ import { PromiseOrVoid, HandlerOptions } from '../core/index.js'
31
31
  import { ServerError, Status } from 'nice-grpc'
32
32
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
33
33
 
@@ -88,7 +88,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
88
88
 
89
89
  public onTransaction(
90
90
  handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
91
- config: FuelFetchConfig = DEFAULT_FUEL_FETCH_CONFIG,
91
+ handlerOptions?: HandlerOptions<FuelFetchConfig, FuelTransaction>,
92
92
  handlerName = getHandlerName()
93
93
  ) {
94
94
  const callHandler = {
@@ -115,7 +115,21 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
115
115
  },
116
116
  fetchConfig: {
117
117
  filters: [],
118
- ...config
118
+ ...handlerOptions
119
+ },
120
+ partitionHandler: async (call: Data_FuelTransaction): Promise<string | undefined> => {
121
+ const p = handlerOptions?.partitionKey
122
+ if (!p) return undefined
123
+ if (typeof p === 'function') {
124
+ const abiMap = this.config.abi
125
+ ? {
126
+ [this.config.address]: this.config.abi
127
+ }
128
+ : {}
129
+ const tx = await decodeFuelTransactionWithAbi(call.transaction, abiMap, this.provider)
130
+ return p(tx)
131
+ }
132
+ return p
119
133
  }
120
134
  }
121
135
  this.txHandlers.push(callHandler)
@@ -198,6 +212,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
198
212
  public onLog<T>(
199
213
  logIdFilter: string | string[],
200
214
  handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
215
+ handlerOptions?: HandlerOptions<object, FuelLog<T>>,
201
216
  handlerName = getHandlerName()
202
217
  ) {
203
218
  const logIds = new Set(Array.isArray(logIdFilter) ? logIdFilter : [logIdFilter])
@@ -236,6 +251,25 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
236
251
  log: {
237
252
  logIds: Array.from(logIds)
238
253
  }
254
+ },
255
+ partitionHandler: async (data: Data_FuelReceipt): Promise<string | undefined> => {
256
+ const p = handlerOptions?.partitionKey
257
+ if (!p) return undefined
258
+ if (typeof p === 'function') {
259
+ try {
260
+ const tx = await decodeFuelTransaction(data.transaction, this.provider)
261
+ const index = Number(data.receiptIndex)
262
+ const receipt = tx.receipts[index]
263
+ const log = decodeLog(receipt, this.config.abi)
264
+ if (log) {
265
+ return p({ receiptIndex: index, ...log })
266
+ }
267
+ } catch (e) {
268
+ console.error(e)
269
+ }
270
+ return undefined
271
+ }
272
+ return p
239
273
  }
240
274
  } as ReceiptHandler
241
275
  this.receiptHandlers.push(logHandler)
@@ -247,7 +281,8 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
247
281
  */
248
282
  public onTransfer(
249
283
  filter: ContractTransferFilter,
250
- handler: (transfer: ReceiptTransfer | ReceiptTransferOut, ctx: FuelContractContext<TContract>) => PromiseOrVoid
284
+ handler: (transfer: ReceiptTransfer | ReceiptTransferOut, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
285
+ handlerOptions?: HandlerOptions<object, ReceiptTransfer | ReceiptTransferOut>
251
286
  ) {
252
287
  const { from, to, assetId } = filter
253
288
  const h = {
@@ -280,6 +315,22 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
280
315
  to,
281
316
  assetId
282
317
  }
318
+ },
319
+ partitionHandler: async (data: Data_FuelReceipt): Promise<string | undefined> => {
320
+ const p = handlerOptions?.partitionKey
321
+ if (!p) return undefined
322
+ if (typeof p === 'function') {
323
+ try {
324
+ const tx = await decodeFuelTransaction(data.transaction, this.provider)
325
+ const index = Number(data.receiptIndex)
326
+ const receipt = tx.receipts[index] as ReceiptTransfer | ReceiptTransferOut
327
+ return p(receipt)
328
+ } catch (e) {
329
+ console.error(e)
330
+ }
331
+ return undefined
332
+ }
333
+ return p
283
334
  }
284
335
  } as ReceiptHandler
285
336
  this.receiptHandlers.push(h)
@@ -290,8 +341,8 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
290
341
  handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
291
342
  timeInterval: HandleInterval | undefined,
292
343
  blockInterval: HandleInterval | undefined,
344
+ handlerOptions?: HandlerOptions<object, FuelBlock>,
293
345
  handlerName = getHandlerName()
294
- // fetchConfig: Partial<FuelFetchConfig> | undefined
295
346
  ): this {
296
347
  if (timeInterval) {
297
348
  if (timeInterval.backfillInterval < timeInterval.recentInterval) {
@@ -338,6 +389,31 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
338
389
  )
339
390
  await handler(block, ctx)
340
391
  return ctx.stopAndGetResult()
392
+ },
393
+ partitionHandler: async (data: Data_FuelBlock): Promise<string | undefined> => {
394
+ const p = handlerOptions?.partitionKey
395
+ if (!p) return undefined
396
+ if (typeof p === 'function') {
397
+ const header = data.block
398
+ if (!header) return undefined
399
+ const block: FuelBlock = {
400
+ id: header.id,
401
+ height: bn(header.height),
402
+ time: header.time,
403
+ header: {
404
+ applicationHash: header.applicationHash,
405
+ daHeight: bn(header.daHeight),
406
+ eventInboxRoot: header.eventInboxRoot,
407
+ messageOutboxRoot: header.messageOutboxRoot,
408
+ prevRoot: header.prevRoot,
409
+ stateTransitionBytecodeVersion: header.stateTransitionBytecodeVersion,
410
+ transactionsCount: header.transactionsCount,
411
+ transactionsRoot: header.transactionsRoot
412
+ }
413
+ }
414
+ return p(block)
415
+ }
416
+ return p
341
417
  }
342
418
  })
343
419
  return this
@@ -346,8 +422,8 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
346
422
  public onBlockInterval(
347
423
  handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
348
424
  blockInterval = 250,
349
- backfillBlockInterval = 1000
350
- // fetchConfig?: Partial<FuelFetchConfig>
425
+ backfillBlockInterval = 1000,
426
+ handlerOptions?: HandlerOptions<object, FuelBlock>
351
427
  ): this {
352
428
  return this.onInterval(
353
429
  handler,
@@ -355,22 +431,22 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
355
431
  {
356
432
  recentInterval: blockInterval,
357
433
  backfillInterval: backfillBlockInterval
358
- }
359
- // fetchConfig,
434
+ },
435
+ handlerOptions
360
436
  )
361
437
  }
362
438
 
363
439
  public onTimeInterval(
364
440
  handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
365
441
  timeIntervalInMinutes = 60,
366
- backfillTimeIntervalInMinutes = 240
367
- // fetchConfig?: Partial<FuelFetchConfig>,
442
+ backfillTimeIntervalInMinutes = 240,
443
+ handlerOptions?: HandlerOptions<object, FuelBlock>
368
444
  ): this {
369
445
  return this.onInterval(
370
446
  handler,
371
447
  { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
372
- undefined
373
- // fetchConfig
448
+ undefined,
449
+ handlerOptions
374
450
  )
375
451
  }
376
452
  }
package/src/fuel/types.ts CHANGED
@@ -29,12 +29,14 @@ export type CallHandler<T> = {
29
29
  handler: (call: T) => Promise<ProcessResult>
30
30
  fetchConfig?: Partial<FuelCallHandlerConfig>
31
31
  assetConfig?: Partial<FuelAssetHandlerConfig>
32
+ partitionHandler?: (call: T) => Promise<string | undefined>
32
33
  }
33
34
 
34
35
  export type ReceiptHandler = {
35
36
  handlerName: string
36
37
  handler: (receipt: Data_FuelReceipt) => Promise<ProcessResult>
37
38
  receiptConfig?: Partial<FuelReceiptHandlerConfig>
39
+ partitionHandler?: (receipt: Data_FuelReceipt) => Promise<string | undefined>
38
40
  }
39
41
 
40
42
  export type BlockHandler = {
@@ -43,6 +45,7 @@ export type BlockHandler = {
43
45
  handler: (block: Data_FuelBlock) => Promise<ProcessResult>
44
46
  handlerName: string
45
47
  fetchConfig?: Partial<OnIntervalConfig>
48
+ partitionHandler?: (block: Data_FuelBlock) => Promise<string | undefined>
46
49
  }
47
50
 
48
51
  export interface FuelLog<T> {
@@ -46,6 +46,7 @@ export class CallHandler<T> {
46
46
  handlerName: string
47
47
  handler: (call: T) => Promise<ProcessResult>
48
48
  fetchConfig: MoveFetchConfig
49
+ partitionHandler?: (call: T) => Promise<string | undefined>
49
50
  }
50
51
 
51
52
  export class ObjectChangeHandler<T> {
@@ -58,6 +59,7 @@ export class ResourceChangeHandler<T> {
58
59
  handlerName: string
59
60
  handler: (call: T) => Promise<ProcessResult>
60
61
  type: string
62
+ partitionHandler?: (call: T) => Promise<string | undefined>
61
63
  }
62
64
 
63
65
  export class ResourceIntervalHandler {
@@ -67,6 +69,7 @@ export class ResourceIntervalHandler {
67
69
  handler: (resource: Data_AptResource) => Promise<ProcessResult>
68
70
  handlerName: string
69
71
  fetchConfig: MoveAccountFetchConfig
72
+ partitionHandler?: (resource: Data_AptResource) => Promise<string | undefined>
70
73
  }
71
74
 
72
75
  export class TransactionIntervalHandler {
@@ -75,4 +78,5 @@ export class TransactionIntervalHandler {
75
78
  handler: (tx: Data_AptCall) => Promise<ProcessResult>
76
79
  handlerName: string
77
80
  fetchConfig: MoveFetchConfig
81
+ partitionHandler?: (tx: Data_AptCall) => Promise<string | undefined>
78
82
  }
@@ -96,12 +96,12 @@ export abstract class SharedNetworkCodegen<NetworkType, ModuleTypes, StructType>
96
96
 
97
97
  const camelFuncName = upperFirst(camel(func.name))
98
98
  const source = `
99
- onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: Partial<MoveFetchConfig>): ${moduleName} {
99
+ onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, handlerOptions?: HandlerOptions<MoveFetchConfig, ${moduleName}.${camelFuncName}Payload>): ${moduleName} {
100
100
  this.onEntryFunctionCall(func, {
101
101
  ...filter,
102
102
  function: '${module.name}::${func.name}'
103
103
  },
104
- fetchConfig)
104
+ handlerOptions)
105
105
  return this
106
106
  }`
107
107
 
@@ -113,8 +113,8 @@ export abstract class SharedNetworkCodegen<NetworkType, ModuleTypes, StructType>
113
113
  const source = `
114
114
  onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${
115
115
  this.PREFIX
116
- }Context) => void, fetchConfig?: Partial<MoveFetchConfig>, eventFilter?: Omit<EventFilter, "type"|"account">): ${moduleName} {
117
- this.onMoveEvent(func, {...eventFilter ?? {}, type: '${module.name}::${struct.name}' }, fetchConfig)
116
+ }Context) => void, handlerOptions?: HandlerOptions<MoveFetchConfig, ${moduleName}.${normalizeToJSName(struct.name)}Instance>, eventFilter?: Omit<EventFilter, "type"|"account">): ${moduleName} {
117
+ this.onMoveEvent(func, {...eventFilter ?? {}, type: '${module.name}::${struct.name}' }, handlerOptions)
118
118
  return this
119
119
  }`
120
120
  return source
@@ -123,6 +123,7 @@ onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.nam
123
123
  generateImports() {
124
124
  return `
125
125
  import { CallFilter, MoveFetchConfig, EventFilter } from "@sentio/sdk/move"
126
+ import { HandlerOptions } from "@sentio/sdk"
126
127
  import {
127
128
  ${this.PREFIX}BindOptions, ${this.PREFIX}BaseProcessor,
128
129
  ${this.PREFIX}Network, TypedFunctionPayload,
@@ -5,6 +5,7 @@ import { SolanaBindOptions } from './solana-options.js'
5
5
  import { ListStateStorage } from '@sentio/runtime'
6
6
  import { Labels } from '../core/index.js'
7
7
  import { SolanaChainId } from '@sentio/chain'
8
+ import { HandlerOptions } from '../core/handler-options.js'
8
9
 
9
10
  type IndexConfigure = {
10
11
  startSlot: bigint
@@ -17,12 +18,17 @@ export interface InstructionCoder {
17
18
 
18
19
  export type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void
19
20
 
21
+ export interface InstructionHandlerEntry {
22
+ handler: SolanaInstructionHandler
23
+ handlerOptions?: HandlerOptions<object, Instruction>
24
+ }
25
+
20
26
  export class SolanaProcessorState extends ListStateStorage<SolanaBaseProcessor> {
21
27
  static INSTANCE: SolanaProcessorState = new SolanaProcessorState()
22
28
  }
23
29
 
24
30
  export class SolanaBaseProcessor {
25
- public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()
31
+ public instructionHandlerMap: Map<string, InstructionHandlerEntry> = new Map()
26
32
  address: string
27
33
  endpoint: string
28
34
  contractName: string
@@ -61,8 +67,12 @@ export class SolanaBaseProcessor {
61
67
  SolanaProcessorState.INSTANCE.addValue(this)
62
68
  }
63
69
 
64
- public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {
65
- this.instructionHandlerMap.set(instructionName, handler)
70
+ public onInstruction(
71
+ instructionName: string,
72
+ handler: SolanaInstructionHandler,
73
+ handlerOptions?: HandlerOptions<object, Instruction>
74
+ ) {
75
+ this.instructionHandlerMap.set(instructionName, { handler, handlerOptions })
66
76
  return this
67
77
  }
68
78
 
@@ -78,21 +88,33 @@ export class SolanaBaseProcessor {
78
88
  return null
79
89
  }
80
90
 
81
- public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {
91
+ public getInstructionHandler(parsedInstruction: Instruction): InstructionHandlerEntry | undefined {
82
92
  return this.instructionHandlerMap.get(parsedInstruction.name)
83
93
  }
84
94
 
85
95
  public async handleInstruction(
86
96
  parsedInstruction: Instruction,
87
97
  accounts: string[],
88
- handler: SolanaInstructionHandler,
98
+ handlerEntry: InstructionHandlerEntry,
89
99
  slot: bigint
90
100
  ): Promise<ProcessResult> {
91
101
  const ctx = new SolanaContext(this.contractName, this.network, this.address, slot, this.baseLabels)
92
- await handler(parsedInstruction, ctx, accounts)
102
+ await handlerEntry.handler(parsedInstruction, ctx, accounts)
93
103
  return ctx.stopAndGetResult()
94
104
  }
95
105
 
106
+ public async getPartitionKey(
107
+ parsedInstruction: Instruction,
108
+ handlerEntry: InstructionHandlerEntry
109
+ ): Promise<string | undefined> {
110
+ const p = handlerEntry.handlerOptions?.partitionKey
111
+ if (!p) return undefined
112
+ if (typeof p === 'function') {
113
+ return p(parsedInstruction)
114
+ }
115
+ return p
116
+ }
117
+
96
118
  public startSlot(startSlot: bigint | number) {
97
119
  this.config.startSlot = BigInt(startSlot)
98
120
  return this
@@ -7,6 +7,7 @@ import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
7
7
  import { StarknetProcessorConfig } from './types.js'
8
8
  import { StarknetContractView } from './contract.js'
9
9
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
10
+ import { HandlerOptions } from '../core/handler-options.js'
10
11
 
11
12
  export class StarknetProcessor {
12
13
  callHandlers: CallHandler<Data_StarknetEvent>[] = []
@@ -42,7 +43,8 @@ export class StarknetProcessor {
42
43
 
43
44
  public onEvent(
44
45
  event: string | string[],
45
- handler: (events: StarknetEvent<ParsedEvent>, ctx: StarknetContext<StarknetContractView>) => void | Promise<void>
46
+ handler: (events: StarknetEvent<ParsedEvent>, ctx: StarknetContext<StarknetContractView>) => void | Promise<void>,
47
+ handlerOptions?: HandlerOptions<object, StarknetEvent<ParsedEvent>>
46
48
  ) {
47
49
  const eventFilter = Array.isArray(event) ? event : [event]
48
50
  if (!this.config.abi) {
@@ -86,7 +88,30 @@ export class StarknetProcessor {
86
88
  return ProcessResult.fromPartial({})
87
89
  }
88
90
  },
89
- eventFilter
91
+ eventFilter,
92
+ partitionHandler: async (call: Data_StarknetEvent): Promise<string | undefined> => {
93
+ const p = handlerOptions?.partitionKey
94
+ if (!p) return undefined
95
+ if (typeof p === 'function') {
96
+ try {
97
+ const eventData = [call.result] as any[]
98
+ const abiEvents = events.getAbiEvents(abi)
99
+ const abiStructs = CallData.getAbiStruct(abi)
100
+ const abiEnums = CallData.getAbiEnum(abi)
101
+ const parsedEvents = events.parseEvents(eventData, abiEvents, abiStructs, abiEnums)
102
+ if (parsedEvents.length > 0) {
103
+ const { from_address, transaction_hash } = call.result!
104
+ const e = new StarknetEvent(from_address, transaction_hash, parsedEvents[0])
105
+ return p(e)
106
+ }
107
+ return undefined
108
+ } catch (e) {
109
+ console.error(e)
110
+ return undefined
111
+ }
112
+ }
113
+ return p
114
+ }
90
115
  }
91
116
  this.callHandlers.push(callHandler)
92
117
  return this
@@ -97,6 +122,7 @@ export type CallHandler<T> = {
97
122
  handlerName: string
98
123
  handler: (call: T) => Promise<ProcessResult>
99
124
  eventFilter?: string[]
125
+ partitionHandler?: (call: T) => Promise<string | undefined>
100
126
  }
101
127
 
102
128
  function getRpcEndpoint(chainId: StarknetChainId | string) {
@@ -36,6 +36,7 @@ import {
36
36
  } from "@typemove/sui";
37
37
 
38
38
  import { CallFilter, MoveFetchConfig, EventFilter } from "@sentio/sdk/move";
39
+ import { HandlerOptions } from "@sentio/sdk";
39
40
  import {
40
41
  SuiBindOptions,
41
42
  SuiBaseProcessor,
@@ -722,13 +723,16 @@ export class bit_vector extends SuiBaseProcessor {
722
723
 
723
724
  onEventBitVector(
724
725
  func: (event: bit_vector.BitVectorInstance, ctx: SuiContext) => void,
725
- fetchConfig?: Partial<MoveFetchConfig>,
726
+ handlerOptions?: HandlerOptions<
727
+ MoveFetchConfig,
728
+ bit_vector.BitVectorInstance
729
+ >,
726
730
  eventFilter?: Omit<EventFilter, "type" | "account">,
727
731
  ): bit_vector {
728
732
  this.onMoveEvent(
729
733
  func,
730
734
  { ...(eventFilter ?? {}), type: "bit_vector::BitVector" },
731
- fetchConfig,
735
+ handlerOptions,
732
736
  );
733
737
  return this;
734
738
  }
@@ -1066,13 +1070,16 @@ export class fixed_point32 extends SuiBaseProcessor {
1066
1070
 
1067
1071
  onEventFixedPoint32(
1068
1072
  func: (event: fixed_point32.FixedPoint32Instance, ctx: SuiContext) => void,
1069
- fetchConfig?: Partial<MoveFetchConfig>,
1073
+ handlerOptions?: HandlerOptions<
1074
+ MoveFetchConfig,
1075
+ fixed_point32.FixedPoint32Instance
1076
+ >,
1070
1077
  eventFilter?: Omit<EventFilter, "type" | "account">,
1071
1078
  ): fixed_point32 {
1072
1079
  this.onMoveEvent(
1073
1080
  func,
1074
1081
  { ...(eventFilter ?? {}), type: "fixed_point32::FixedPoint32" },
1075
- fetchConfig,
1082
+ handlerOptions,
1076
1083
  );
1077
1084
  return this;
1078
1085
  }
@@ -2003,13 +2010,13 @@ export class string$ extends SuiBaseProcessor {
2003
2010
 
2004
2011
  onEventString(
2005
2012
  func: (event: string$.StringInstance, ctx: SuiContext) => void,
2006
- fetchConfig?: Partial<MoveFetchConfig>,
2013
+ handlerOptions?: HandlerOptions<MoveFetchConfig, string$.StringInstance>,
2007
2014
  eventFilter?: Omit<EventFilter, "type" | "account">,
2008
2015
  ): string$ {
2009
2016
  this.onMoveEvent(
2010
2017
  func,
2011
2018
  { ...(eventFilter ?? {}), type: "string::String" },
2012
- fetchConfig,
2019
+ handlerOptions,
2013
2020
  );
2014
2021
  return this;
2015
2022
  }
@@ -2509,13 +2516,16 @@ export class type_name extends SuiBaseProcessor {
2509
2516
 
2510
2517
  onEventTypeName(
2511
2518
  func: (event: type_name.TypeNameInstance, ctx: SuiContext) => void,
2512
- fetchConfig?: Partial<MoveFetchConfig>,
2519
+ handlerOptions?: HandlerOptions<
2520
+ MoveFetchConfig,
2521
+ type_name.TypeNameInstance
2522
+ >,
2513
2523
  eventFilter?: Omit<EventFilter, "type" | "account">,
2514
2524
  ): type_name {
2515
2525
  this.onMoveEvent(
2516
2526
  func,
2517
2527
  { ...(eventFilter ?? {}), type: "type_name::TypeName" },
2518
- fetchConfig,
2528
+ handlerOptions,
2519
2529
  );
2520
2530
  return this;
2521
2531
  }
@@ -4578,13 +4588,13 @@ export class uq32_32 extends SuiBaseProcessor {
4578
4588
 
4579
4589
  onEventUQ32_32(
4580
4590
  func: (event: uq32_32.UQ32_32Instance, ctx: SuiContext) => void,
4581
- fetchConfig?: Partial<MoveFetchConfig>,
4591
+ handlerOptions?: HandlerOptions<MoveFetchConfig, uq32_32.UQ32_32Instance>,
4582
4592
  eventFilter?: Omit<EventFilter, "type" | "account">,
4583
4593
  ): uq32_32 {
4584
4594
  this.onMoveEvent(
4585
4595
  func,
4586
4596
  { ...(eventFilter ?? {}), type: "uq32_32::UQ32_32" },
4587
- fetchConfig,
4597
+ handlerOptions,
4588
4598
  );
4589
4599
  return this;
4590
4600
  }
@@ -5092,13 +5102,13 @@ export class uq64_64 extends SuiBaseProcessor {
5092
5102
 
5093
5103
  onEventUQ64_64(
5094
5104
  func: (event: uq64_64.UQ64_64Instance, ctx: SuiContext) => void,
5095
- fetchConfig?: Partial<MoveFetchConfig>,
5105
+ handlerOptions?: HandlerOptions<MoveFetchConfig, uq64_64.UQ64_64Instance>,
5096
5106
  eventFilter?: Omit<EventFilter, "type" | "account">,
5097
5107
  ): uq64_64 {
5098
5108
  this.onMoveEvent(
5099
5109
  func,
5100
5110
  { ...(eventFilter ?? {}), type: "uq64_64::UQ64_64" },
5101
- fetchConfig,
5111
+ handlerOptions,
5102
5112
  );
5103
5113
  return this;
5104
5114
  }