@sentio/sdk 2.59.4 → 2.60.0-rc.1

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 (51) hide show
  1. package/lib/aptos/aptos-plugin.d.ts +5 -11
  2. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  3. package/lib/aptos/aptos-plugin.js +38 -23
  4. package/lib/aptos/aptos-plugin.js.map +1 -1
  5. package/lib/btc/btc-plugin.d.ts +5 -8
  6. package/lib/btc/btc-plugin.d.ts.map +1 -1
  7. package/lib/btc/btc-plugin.js +22 -14
  8. package/lib/btc/btc-plugin.js.map +1 -1
  9. package/lib/core/core-plugin.d.ts +2 -1
  10. package/lib/core/core-plugin.d.ts.map +1 -1
  11. package/lib/core/core-plugin.js +15 -1
  12. package/lib/core/core-plugin.js.map +1 -1
  13. package/lib/core/handler-register.d.ts +18 -0
  14. package/lib/core/handler-register.d.ts.map +1 -0
  15. package/lib/core/handler-register.js +62 -0
  16. package/lib/core/handler-register.js.map +1 -0
  17. package/lib/cosmos/cosmos-plugin.d.ts +5 -7
  18. package/lib/cosmos/cosmos-plugin.d.ts.map +1 -1
  19. package/lib/cosmos/cosmos-plugin.js +18 -10
  20. package/lib/cosmos/cosmos-plugin.js.map +1 -1
  21. package/lib/eth/eth-plugin.d.ts +5 -40
  22. package/lib/eth/eth-plugin.d.ts.map +1 -1
  23. package/lib/eth/eth-plugin.js +41 -117
  24. package/lib/eth/eth-plugin.js.map +1 -1
  25. package/lib/fuel/fuel-plugin.d.ts +5 -9
  26. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  27. package/lib/fuel/fuel-plugin.js +26 -18
  28. package/lib/fuel/fuel-plugin.js.map +1 -1
  29. package/lib/solana/solana-plugin.d.ts +3 -2
  30. package/lib/solana/solana-plugin.d.ts.map +1 -1
  31. package/lib/solana/solana-plugin.js +11 -1
  32. package/lib/solana/solana-plugin.js.map +1 -1
  33. package/lib/stark/starknet-plugin.d.ts +5 -7
  34. package/lib/stark/starknet-plugin.d.ts.map +1 -1
  35. package/lib/stark/starknet-plugin.js +18 -10
  36. package/lib/stark/starknet-plugin.js.map +1 -1
  37. package/lib/sui/sui-plugin.d.ts +5 -10
  38. package/lib/sui/sui-plugin.d.ts.map +1 -1
  39. package/lib/sui/sui-plugin.js +37 -24
  40. package/lib/sui/sui-plugin.js.map +1 -1
  41. package/package.json +3 -3
  42. package/src/aptos/aptos-plugin.ts +55 -44
  43. package/src/btc/btc-plugin.ts +33 -32
  44. package/src/core/core-plugin.ts +17 -3
  45. package/src/core/handler-register.ts +79 -0
  46. package/src/cosmos/cosmos-plugin.ts +24 -20
  47. package/src/eth/eth-plugin.ts +62 -182
  48. package/src/fuel/fuel-plugin.ts +43 -44
  49. package/src/solana/solana-plugin.ts +20 -2
  50. package/src/stark/starknet-plugin.ts +24 -20
  51. package/src/sui/sui-plugin.ts +58 -52
@@ -11,12 +11,9 @@ import { PartitionHandlerManager } from '../core/index.js'
11
11
  import {
12
12
  AccountConfig,
13
13
  ContractConfig,
14
- Data_EthBlock,
15
- Data_EthLog,
16
- Data_EthTrace,
17
- Data_EthTransaction,
18
14
  DataBinding,
19
15
  HandlerType,
16
+ InitResponse,
20
17
  LogFilter,
21
18
  LogHandlerConfig,
22
19
  PreparedData,
@@ -31,67 +28,40 @@ import { ServerError, Status } from 'nice-grpc'
31
28
  import { EthProcessorState } from './binds.js'
32
29
  import { AccountProcessorState } from './account-processor-state.js'
33
30
  import { ProcessorTemplateProcessorState } from './base-processor-template.js'
34
- import { defaultPreprocessHandler, GlobalProcessorState } from './base-processor.js'
31
+ import { GlobalProcessorState } from './base-processor.js'
35
32
  import { validateAndNormalizeAddress } from './eth.js'
36
33
  import { EthChainId } from '@sentio/chain'
37
34
  import { EthContext } from './context.js'
38
35
  import { TemplateInstanceState } from '../core/template.js'
39
36
  import { timeOrBlockToBlockNumber } from '@sentio/sdk/utils'
40
-
41
- interface Handlers {
42
- eventHandlers: ((event: Data_EthLog, preparedData?: PreparedData) => Promise<ProcessResult>)[]
43
- traceHandlers: ((trace: Data_EthTrace, preparedData?: PreparedData) => Promise<ProcessResult>)[]
44
- blockHandlers: ((block: Data_EthBlock, preparedData?: PreparedData) => Promise<ProcessResult>)[]
45
- transactionHandlers: ((trace: Data_EthTransaction, preparedData?: PreparedData) => Promise<ProcessResult>)[]
46
- }
47
-
48
- interface PreprocessHandlers {
49
- eventHandlers: ((event: Data_EthLog, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>)[]
50
- traceHandlers: ((trace: Data_EthTrace, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>)[]
51
- blockHandlers: ((block: Data_EthBlock, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>)[]
52
- transactionHandlers: ((
53
- txn: Data_EthTransaction,
54
- preprocessStore: { [k: string]: any }
55
- ) => Promise<PreprocessResult>)[]
56
- }
37
+ import { HandlerRegister } from '../core/handler-register.js'
57
38
 
58
39
  export class EthPlugin extends Plugin {
59
40
  name: string = 'EthPlugin'
60
- handlers: Handlers = {
61
- blockHandlers: [],
62
- eventHandlers: [],
63
- traceHandlers: [],
64
- transactionHandlers: []
65
- }
66
- preprocessHandlers: PreprocessHandlers = {
67
- blockHandlers: [],
68
- eventHandlers: [],
69
- traceHandlers: [],
70
- transactionHandlers: []
71
- }
41
+ handlerRegister = new HandlerRegister()
72
42
 
73
43
  partitionManager = new PartitionHandlerManager()
74
44
 
75
- async configure(config: ProcessConfigResponse) {
76
- const handlers: Handlers = {
77
- blockHandlers: [],
78
- eventHandlers: [],
79
- traceHandlers: [],
80
- transactionHandlers: []
81
- }
82
- const preprocessHandlers: PreprocessHandlers = {
83
- blockHandlers: [],
84
- eventHandlers: [],
85
- traceHandlers: [],
86
- transactionHandlers: []
45
+ async init(config: InitResponse): Promise<void> {
46
+ for (const state of [EthProcessorState.INSTANCE, GlobalProcessorState.INSTANCE, AccountProcessorState.INSTANCE]) {
47
+ for (const processor of state.getValues()) {
48
+ const chainId = processor.getChainId()
49
+ config.chainIds.push(chainId)
50
+ }
87
51
  }
52
+ }
53
+
54
+ async configure(config: ProcessConfigResponse, forChainId?: string) {
55
+ this.handlerRegister.clear(forChainId as EthChainId)
88
56
 
89
57
  for (const processor of EthProcessorState.INSTANCE.getValues()) {
90
58
  // If server favor incremental update this need to change
91
59
  // Start basic config for contract
92
60
  const chainId = processor.getChainId()
93
61
  // this.processorsByChainId.set(chainId, processor)
94
-
62
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
63
+ continue
64
+ }
95
65
  const provider = getProvider(chainId)
96
66
  const startBlock = await timeOrBlockToBlockNumber(provider, processor.config.start)
97
67
  const endBlock = processor.config.end ? await timeOrBlockToBlockNumber(provider, processor.config.end) : undefined
@@ -110,8 +80,8 @@ export class EthPlugin extends Plugin {
110
80
 
111
81
  // Step 1. Prepare all the block handlers
112
82
  for (const blockHandler of processor.blockHandlers) {
113
- preprocessHandlers.blockHandlers.push(blockHandler.preprocessHandler ?? defaultPreprocessHandler)
114
- const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
83
+ const handlerId = this.handlerRegister.register(blockHandler.handler, chainId)
84
+
115
85
  this.partitionManager.registerPartitionHandler(HandlerType.ETH_BLOCK, handlerId, blockHandler.partitionHandler)
116
86
  // TODO wrap the block handler into one
117
87
 
@@ -128,8 +98,8 @@ export class EthPlugin extends Plugin {
128
98
 
129
99
  // Step 2. Prepare all trace handlers
130
100
  for (const traceHandler of processor.traceHandlers) {
131
- preprocessHandlers.traceHandlers.push(traceHandler.preprocessHandler ?? defaultPreprocessHandler)
132
- const handlerId = handlers.traceHandlers.push(traceHandler.handler) - 1
101
+ const handlerId = this.handlerRegister.register(traceHandler.handler, chainId)
102
+
133
103
  this.partitionManager.registerPartitionHandler(HandlerType.ETH_TRACE, handlerId, traceHandler.partitionHandler)
134
104
  for (const signature of traceHandler.signatures) {
135
105
  contractConfig.traceConfigs.push({
@@ -144,8 +114,7 @@ export class EthPlugin extends Plugin {
144
114
  // Step 3. Prepare all the event handlers
145
115
  for (const eventsHandler of processor.eventHandlers) {
146
116
  // associate id with filter
147
- preprocessHandlers.eventHandlers.push(eventsHandler.preprocessHandler ?? defaultPreprocessHandler)
148
- const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1
117
+ const handlerId = this.handlerRegister.register(eventsHandler.handler, chainId)
149
118
  this.partitionManager.registerPartitionHandler(HandlerType.ETH_LOG, handlerId, eventsHandler.partitionHandler)
150
119
  const logConfig: LogHandlerConfig = {
151
120
  handlerId: handlerId,
@@ -186,7 +155,9 @@ export class EthPlugin extends Plugin {
186
155
 
187
156
  for (const processor of GlobalProcessorState.INSTANCE.getValues()) {
188
157
  const chainId = processor.getChainId()
189
-
158
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
159
+ continue
160
+ }
190
161
  const provider = getProvider(chainId)
191
162
  const startBlock = await timeOrBlockToBlockNumber(provider, processor.config.start)
192
163
  const endBlock = processor.config.end ? await timeOrBlockToBlockNumber(provider, processor.config.end) : undefined
@@ -204,8 +175,7 @@ export class EthPlugin extends Plugin {
204
175
  })
205
176
 
206
177
  for (const blockHandler of processor.blockHandlers) {
207
- preprocessHandlers.blockHandlers.push(blockHandler.preprocessHandler ?? defaultPreprocessHandler)
208
- const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
178
+ const handlerId = this.handlerRegister.register(blockHandler.handler, chainId)
209
179
  contractConfig.intervalConfigs.push({
210
180
  slot: 0,
211
181
  slotInterval: blockHandler.blockInterval,
@@ -218,8 +188,7 @@ export class EthPlugin extends Plugin {
218
188
  }
219
189
 
220
190
  for (const transactionHandler of processor.transactionHandler) {
221
- preprocessHandlers.transactionHandlers.push(transactionHandler.preprocessHandler ?? defaultPreprocessHandler)
222
- const handlerId = handlers.transactionHandlers.push(transactionHandler.handler) - 1
191
+ const handlerId = this.handlerRegister.register(transactionHandler.handler, chainId)
223
192
  this.partitionManager.registerPartitionHandler(
224
193
  HandlerType.ETH_TRANSACTION,
225
194
  handlerId,
@@ -233,8 +202,7 @@ export class EthPlugin extends Plugin {
233
202
  }
234
203
 
235
204
  for (const traceHandler of processor.traceHandlers) {
236
- preprocessHandlers.traceHandlers.push(traceHandler.preprocessHandler ?? defaultPreprocessHandler)
237
- const handlerId = handlers.traceHandlers.push(traceHandler.handler) - 1
205
+ const handlerId = this.handlerRegister.register(traceHandler.handler, chainId)
238
206
  for (const signature of traceHandler.signatures) {
239
207
  contractConfig.traceConfigs.push({
240
208
  signature: signature,
@@ -249,6 +217,9 @@ export class EthPlugin extends Plugin {
249
217
 
250
218
  // part 1.b prepare EVM account processors
251
219
  for (const processor of AccountProcessorState.INSTANCE.getValues()) {
220
+ if (forChainId !== undefined && forChainId !== processor.getChainId().toString()) {
221
+ continue
222
+ }
252
223
  const accountConfig = AccountConfig.fromPartial({
253
224
  address: validateAndNormalizeAddress(processor.config.address),
254
225
  chainId: processor.getChainId().toString(),
@@ -257,8 +228,7 @@ export class EthPlugin extends Plugin {
257
228
  // TODO add interval
258
229
  for (const eventsHandler of processor.eventHandlers) {
259
230
  // associate id with filter
260
- preprocessHandlers.eventHandlers.push(eventsHandler.preprocessHandler ?? defaultPreprocessHandler)
261
- const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1
231
+ const handlerId = this.handlerRegister.register(eventsHandler.handler, processor.getChainId())
262
232
  const logConfig: LogHandlerConfig = {
263
233
  handlerId: handlerId,
264
234
  handlerName: eventsHandler.handlerName,
@@ -298,8 +268,8 @@ export class EthPlugin extends Plugin {
298
268
  config.accountConfigs.push(accountConfig)
299
269
  }
300
270
 
301
- this.handlers = handlers
302
- this.preprocessHandlers = preprocessHandlers
271
+ // this.handlers = handlers
272
+ // this.preprocessHandlers = preprocessHandlers
303
273
  }
304
274
 
305
275
  supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE, HandlerType.ETH_TRANSACTION]
@@ -320,21 +290,6 @@ export class EthPlugin extends Plugin {
320
290
  }
321
291
  }
322
292
 
323
- preprocessBinding(request: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
324
- switch (request.handlerType) {
325
- case HandlerType.ETH_LOG:
326
- return this.preprocessLog(request, preprocessStore)
327
- case HandlerType.ETH_TRACE:
328
- return this.preprocessTrace(request, preprocessStore)
329
- case HandlerType.ETH_BLOCK:
330
- return this.preprocessBlock(request, preprocessStore)
331
- case HandlerType.ETH_TRANSACTION:
332
- return this.preprocessTransaction(request, preprocessStore)
333
- default:
334
- throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
335
- }
336
- }
337
-
338
293
  async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {
339
294
  let data: any
340
295
  switch (request.handlerType) {
@@ -408,87 +363,6 @@ export class EthPlugin extends Plugin {
408
363
  return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
409
364
  }
410
365
 
411
- async preprocessLog(request: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
412
- if (!request.data?.ethLog?.log) {
413
- throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
414
- }
415
- const ethLog = request.data.ethLog
416
-
417
- const promises: Promise<PreprocessResult>[] = []
418
- for (const handlerId of request.handlerIds) {
419
- const handler = this.preprocessHandlers.eventHandlers[handlerId]
420
- const promise = handler(ethLog, preprocessStore).catch((e) => {
421
- throw new ServerError(
422
- Status.INTERNAL,
423
- 'error processing log: ' + JSON.stringify(ethLog.log) + '\n' + errorString(e)
424
- )
425
- })
426
- promises.push(promise)
427
- }
428
- return mergePreprocessResults(await Promise.all(promises))
429
- }
430
-
431
- async preprocessTrace(binding: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
432
- if (!binding.data?.ethTrace?.trace) {
433
- throw new ServerError(Status.INVALID_ARGUMENT, "Trace can't be null")
434
- }
435
- const ethTrace = binding.data.ethTrace
436
-
437
- const promises: Promise<PreprocessResult>[] = []
438
-
439
- for (const handlerId of binding.handlerIds) {
440
- const promise = this.preprocessHandlers.traceHandlers[handlerId](ethTrace, preprocessStore).catch((e) => {
441
- throw new ServerError(
442
- Status.INTERNAL,
443
- 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
444
- )
445
- })
446
- promises.push(promise)
447
- }
448
- return mergePreprocessResults(await Promise.all(promises))
449
- }
450
-
451
- async preprocessBlock(binding: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
452
- if (!binding.data?.ethBlock?.block) {
453
- throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
454
- }
455
- const ethBlock = binding.data.ethBlock
456
-
457
- const promises: Promise<PreprocessResult>[] = []
458
- for (const handlerId of binding.handlerIds) {
459
- const promise = this.preprocessHandlers.blockHandlers[handlerId](ethBlock, preprocessStore).catch((e) => {
460
- throw new ServerError(
461
- Status.INTERNAL,
462
- 'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
463
- )
464
- })
465
- promises.push(promise)
466
- }
467
- return mergePreprocessResults(await Promise.all(promises))
468
- }
469
-
470
- async preprocessTransaction(binding: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
471
- if (!binding.data?.ethTransaction?.transaction) {
472
- throw new ServerError(Status.INVALID_ARGUMENT, "transaction can't be null")
473
- }
474
- const ethTransaction = binding.data.ethTransaction
475
-
476
- const promises: Promise<PreprocessResult>[] = []
477
-
478
- for (const handlerId of binding.handlerIds) {
479
- const promise = this.preprocessHandlers.transactionHandlers[handlerId](ethTransaction, preprocessStore).catch(
480
- (e) => {
481
- throw new ServerError(
482
- Status.INTERNAL,
483
- 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
484
- )
485
- }
486
- )
487
- promises.push(promise)
488
- }
489
- return mergePreprocessResults(await Promise.all(promises))
490
- }
491
-
492
366
  async processLog(request: DataBinding, preparedData: PreparedData | undefined): Promise<ProcessResult> {
493
367
  if (!request.data?.ethLog?.log) {
494
368
  throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
@@ -497,8 +371,8 @@ export class EthPlugin extends Plugin {
497
371
 
498
372
  const promises: Promise<ProcessResult>[] = []
499
373
  for (const handlerId of request.handlerIds) {
500
- const handler = this.handlers.eventHandlers[handlerId]
501
- const promise = handler(ethLog, preparedData).catch((e) => {
374
+ const handler = this.handlerRegister.getHandlerById(handlerId)
375
+ const promise = handler(ethLog, preparedData).catch((e: any) => {
502
376
  console.error('error processing log: ', e)
503
377
  throw new ServerError(
504
378
  Status.INTERNAL,
@@ -522,13 +396,15 @@ export class EthPlugin extends Plugin {
522
396
  const promises: Promise<ProcessResult>[] = []
523
397
 
524
398
  for (const handlerId of binding.handlerIds) {
525
- const promise = this.handlers.traceHandlers[handlerId](ethTrace, preparedData).catch((e) => {
526
- console.error('error processing trace: ', e)
527
- throw new ServerError(
528
- Status.INTERNAL,
529
- 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
530
- )
531
- })
399
+ const promise = this.handlerRegister
400
+ .getHandlerById(handlerId)(ethTrace, preparedData)
401
+ .catch((e: any) => {
402
+ console.error('error processing trace: ', e)
403
+ throw new ServerError(
404
+ Status.INTERNAL,
405
+ 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
406
+ )
407
+ })
532
408
  if (GLOBAL_CONFIG.execution.sequential) {
533
409
  await promise
534
410
  }
@@ -545,13 +421,15 @@ export class EthPlugin extends Plugin {
545
421
 
546
422
  const promises: Promise<ProcessResult>[] = []
547
423
  for (const handlerId of binding.handlerIds) {
548
- const promise = this.handlers.blockHandlers[handlerId](ethBlock, preparedData).catch((e) => {
549
- console.error('error processing block: ', e)
550
- throw new ServerError(
551
- Status.INTERNAL,
552
- 'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
553
- )
554
- })
424
+ const promise = this.handlerRegister
425
+ .getHandlerById(handlerId)(ethBlock, preparedData)
426
+ .catch((e: any) => {
427
+ console.error('error processing block: ', e)
428
+ throw new ServerError(
429
+ Status.INTERNAL,
430
+ 'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
431
+ )
432
+ })
555
433
  if (GLOBAL_CONFIG.execution.sequential) {
556
434
  await promise
557
435
  }
@@ -569,12 +447,14 @@ export class EthPlugin extends Plugin {
569
447
  const promises: Promise<ProcessResult>[] = []
570
448
 
571
449
  for (const handlerId of binding.handlerIds) {
572
- const promise = this.handlers.transactionHandlers[handlerId](ethTransaction, preparedData).catch((e) => {
573
- throw new ServerError(
574
- Status.INTERNAL,
575
- 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
576
- )
577
- })
450
+ const promise = this.handlerRegister
451
+ .getHandlerById(handlerId)(ethTransaction, preparedData)
452
+ .catch((e: any) => {
453
+ throw new ServerError(
454
+ Status.INTERNAL,
455
+ 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
456
+ )
457
+ })
578
458
  if (GLOBAL_CONFIG.execution.sequential) {
579
459
  await promise
580
460
  }
@@ -1,12 +1,11 @@
1
1
  import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import { PartitionHandlerManager } from '../core/index.js'
3
+ import { HandlerRegister } from '../core/handler-register.js'
3
4
  import {
4
5
  ContractConfig,
5
- Data_FuelBlock,
6
- Data_FuelReceipt,
7
- Data_FuelTransaction,
8
6
  DataBinding,
9
7
  HandlerType,
8
+ InitResponse,
10
9
  ProcessConfigResponse,
11
10
  ProcessResult,
12
11
  ProcessStreamResponse_Partitions,
@@ -20,30 +19,26 @@ import { FuelProcessorState } from './types.js'
20
19
  import { FuelProcessor } from './fuel-processor.js'
21
20
  import { FuelGlobalProcessor } from './global-processor.js'
22
21
 
23
- interface Handlers {
24
- transactionHandlers: ((trace: Data_FuelTransaction) => Promise<ProcessResult>)[]
25
- blockHandlers: ((block: Data_FuelBlock) => Promise<ProcessResult>)[]
26
- receiptHandlers: ((log: Data_FuelReceipt) => Promise<ProcessResult>)[]
27
- }
28
-
29
22
  export class FuelPlugin extends Plugin {
30
23
  name: string = 'FuelPlugin'
31
- handlers: Handlers = {
32
- transactionHandlers: [],
33
- blockHandlers: [],
34
- receiptHandlers: []
35
- }
36
-
24
+ handlerRegister = new HandlerRegister()
37
25
  partitionManager = new PartitionHandlerManager()
38
26
 
39
- async configure(config: ProcessConfigResponse) {
40
- const handlers: Handlers = {
41
- transactionHandlers: [],
42
- blockHandlers: [],
43
- receiptHandlers: []
27
+ async init(config: InitResponse) {
28
+ for (const fuelProcessor of FuelProcessorState.INSTANCE.getValues()) {
29
+ const chainId = fuelProcessor.config.chainId
30
+ config.chainIds.push(chainId)
44
31
  }
32
+ }
33
+
34
+ async configure(config: ProcessConfigResponse, forChainId?: string) {
35
+ this.handlerRegister.clear(forChainId as any)
45
36
 
46
37
  for (const processor of FuelProcessorState.INSTANCE.getValues()) {
38
+ const chainId = processor.config.chainId
39
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
40
+ continue
41
+ }
47
42
  const processorConfig = processor.config
48
43
  const contractConfig = ContractConfig.fromPartial({
49
44
  processorType: USER_PROCESSOR,
@@ -57,7 +52,7 @@ export class FuelPlugin extends Plugin {
57
52
  endBlock: processorConfig.endBlock
58
53
  })
59
54
  for (const txHandler of processor.txHandlers) {
60
- const handlerId = handlers.transactionHandlers.push(txHandler.handler) - 1
55
+ const handlerId = this.handlerRegister.register(txHandler.handler, chainId)
61
56
  this.partitionManager.registerPartitionHandler(
62
57
  HandlerType.FUEL_TRANSACTION,
63
58
  handlerId,
@@ -90,7 +85,7 @@ export class FuelPlugin extends Plugin {
90
85
  }
91
86
 
92
87
  for (const receiptHandler of processor.receiptHandlers ?? []) {
93
- const handlerId = handlers.receiptHandlers.push(receiptHandler.handler) - 1
88
+ const handlerId = this.handlerRegister.register(receiptHandler.handler, chainId)
94
89
  this.partitionManager.registerPartitionHandler(
95
90
  HandlerType.FUEL_RECEIPT,
96
91
  handlerId,
@@ -107,7 +102,7 @@ export class FuelPlugin extends Plugin {
107
102
  }
108
103
 
109
104
  for (const blockHandler of processor.blockHandlers) {
110
- const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
105
+ const handlerId = this.handlerRegister.register(blockHandler.handler, chainId)
111
106
  this.partitionManager.registerPartitionHandler(HandlerType.FUEL_BLOCK, handlerId, blockHandler.partitionHandler)
112
107
  contractConfig.intervalConfigs.push({
113
108
  slot: 0,
@@ -123,8 +118,6 @@ export class FuelPlugin extends Plugin {
123
118
 
124
119
  config.contractConfigs.push(contractConfig)
125
120
  }
126
-
127
- this.handlers = handlers
128
121
  }
129
122
 
130
123
  supportedHandlers = [
@@ -212,12 +205,14 @@ export class FuelPlugin extends Plugin {
212
205
  const promises: Promise<ProcessResult>[] = []
213
206
 
214
207
  for (const handlerId of binding.handlerIds) {
215
- const promise = this.handlers.receiptHandlers[handlerId](receipt).catch((e) => {
216
- throw new ServerError(
217
- Status.INTERNAL,
218
- 'error processing transaction: ' + JSON.stringify(receipt) + '\n' + errorString(e)
219
- )
220
- })
208
+ const promise = this.handlerRegister
209
+ .getHandlerById(handlerId)(receipt)
210
+ .catch((e: any) => {
211
+ throw new ServerError(
212
+ Status.INTERNAL,
213
+ 'error processing transaction: ' + JSON.stringify(receipt) + '\n' + errorString(e)
214
+ )
215
+ })
221
216
  if (GLOBAL_CONFIG.execution.sequential) {
222
217
  await promise
223
218
  }
@@ -235,12 +230,14 @@ export class FuelPlugin extends Plugin {
235
230
  const promises: Promise<ProcessResult>[] = []
236
231
 
237
232
  for (const handlerId of binding.handlerIds) {
238
- const promise = this.handlers.transactionHandlers[handlerId](fuelTransaction).catch((e) => {
239
- throw new ServerError(
240
- Status.INTERNAL,
241
- 'error processing transaction: ' + JSON.stringify(fuelTransaction.transaction) + '\n' + errorString(e)
242
- )
243
- })
233
+ const promise = this.handlerRegister
234
+ .getHandlerById(handlerId)(fuelTransaction)
235
+ .catch((e: any) => {
236
+ throw new ServerError(
237
+ Status.INTERNAL,
238
+ 'error processing transaction: ' + JSON.stringify(fuelTransaction.transaction) + '\n' + errorString(e)
239
+ )
240
+ })
244
241
  if (GLOBAL_CONFIG.execution.sequential) {
245
242
  await promise
246
243
  }
@@ -257,13 +254,15 @@ export class FuelPlugin extends Plugin {
257
254
 
258
255
  const promises: Promise<ProcessResult>[] = []
259
256
  for (const handlerId of binding.handlerIds) {
260
- const promise = this.handlers.blockHandlers[handlerId](ethBlock).catch((e) => {
261
- console.error('error processing block: ', e)
262
- throw new ServerError(
263
- Status.INTERNAL,
264
- 'error processing block: ' + ethBlock.block?.height + '\n' + errorString(e)
265
- )
266
- })
257
+ const promise = this.handlerRegister
258
+ .getHandlerById(handlerId)(ethBlock)
259
+ .catch((e: any) => {
260
+ console.error('error processing block: ', e)
261
+ throw new ServerError(
262
+ Status.INTERNAL,
263
+ 'error processing block: ' + ethBlock.block?.height + '\n' + errorString(e)
264
+ )
265
+ })
267
266
  if (GLOBAL_CONFIG.execution.sequential) {
268
267
  await promise
269
268
  }
@@ -1,5 +1,12 @@
1
1
  import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
- import { ContractConfig, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos'
2
+ import {
3
+ ContractConfig,
4
+ DataBinding,
5
+ HandlerType,
6
+ InitResponse,
7
+ ProcessConfigResponse,
8
+ ProcessResult
9
+ } from '@sentio/protos'
3
10
 
4
11
  import { ServerError, Status } from 'nice-grpc'
5
12
 
@@ -9,9 +16,20 @@ import { Instruction as SolInstruction } from '@coral-xyz/anchor'
9
16
  export class SolanaPlugin extends Plugin {
10
17
  name: string = 'SolanaPlugin'
11
18
 
12
- async configure(config: ProcessConfigResponse) {
19
+ async init(config: InitResponse) {
20
+ for (const solanaProcessor of SolanaProcessorState.INSTANCE.getValues()) {
21
+ const chainId = solanaProcessor.network
22
+ config.chainIds.push(chainId)
23
+ }
24
+ }
25
+
26
+ async configure(config: ProcessConfigResponse, forChainId?: string) {
13
27
  // Part 2, prepare solana constractors
14
28
  for (const solanaProcessor of SolanaProcessorState.INSTANCE.getValues()) {
29
+ const chainId = solanaProcessor.network
30
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
31
+ continue
32
+ }
15
33
  const contractConfig = ContractConfig.fromPartial({
16
34
  processorType: USER_PROCESSOR,
17
35
  contract: {
@@ -1,9 +1,9 @@
1
1
  import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import {
3
3
  ContractConfig,
4
- Data_StarknetEvent,
5
4
  DataBinding,
6
5
  HandlerType,
6
+ InitResponse,
7
7
  ProcessConfigResponse,
8
8
  ProcessResult,
9
9
  StartRequest
@@ -11,25 +11,29 @@ import {
11
11
 
12
12
  import { ServerError, Status } from 'nice-grpc'
13
13
  import { TemplateInstanceState } from '../core/template.js'
14
+ import { HandlerRegister } from '../core/handler-register.js'
14
15
  import { StarknetProcessorState } from './starknet-processor.js'
15
16
  import { hash } from 'starknet'
16
17
 
17
- interface Handlers {
18
- callHandlers: ((trace: Data_StarknetEvent) => Promise<ProcessResult>)[]
19
- }
20
-
21
18
  export class StarknetPlugin extends Plugin {
22
19
  name: string = 'StarknetPlugin'
23
- handlers: Handlers = {
24
- callHandlers: []
25
- }
20
+ handlerRegister = new HandlerRegister()
26
21
 
27
- async configure(config: ProcessConfigResponse) {
28
- const handlers: Handlers = {
29
- callHandlers: []
22
+ async init(config: InitResponse) {
23
+ for (const solanaProcessor of StarknetProcessorState.INSTANCE.getValues()) {
24
+ const chainId = solanaProcessor.config.chainId
25
+ config.chainIds.push(chainId)
30
26
  }
27
+ }
28
+
29
+ async configure(config: ProcessConfigResponse, forChainId?: string) {
30
+ this.handlerRegister.clear(forChainId as any)
31
31
 
32
32
  for (const processor of StarknetProcessorState.INSTANCE.getValues()) {
33
+ const chainId = processor.config.chainId
34
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
35
+ continue
36
+ }
33
37
  await processor.configure()
34
38
  const contractConfig = ContractConfig.fromPartial({
35
39
  processorType: USER_PROCESSOR,
@@ -43,7 +47,7 @@ export class StarknetPlugin extends Plugin {
43
47
  endBlock: processor.config.endBlock
44
48
  })
45
49
  for (const callHandler of processor.callHandlers) {
46
- const handlerId = handlers.callHandlers.push(callHandler.handler) - 1
50
+ const handlerId = this.handlerRegister.register(callHandler.handler, chainId)
47
51
 
48
52
  if (callHandler.eventFilter) {
49
53
  contractConfig.starknetEventConfigs.push({
@@ -60,8 +64,6 @@ export class StarknetPlugin extends Plugin {
60
64
  // Finish up a contract
61
65
  config.contractConfigs.push(contractConfig)
62
66
  }
63
-
64
- this.handlers = handlers
65
67
  }
66
68
 
67
69
  supportedHandlers = [HandlerType.STARKNET_EVENT]
@@ -91,12 +93,14 @@ export class StarknetPlugin extends Plugin {
91
93
  const result = binding.data?.starknetEvents?.result
92
94
 
93
95
  for (const handlerId of binding.handlerIds) {
94
- const promise = this.handlers.callHandlers[handlerId](binding.data?.starknetEvents).catch((e) => {
95
- throw new ServerError(
96
- Status.INTERNAL,
97
- 'error processing transaction: ' + JSON.stringify(result) + '\n' + errorString(e)
98
- )
99
- })
96
+ const promise = this.handlerRegister
97
+ .getHandlerById(handlerId)(binding.data?.starknetEvents)
98
+ .catch((e: any) => {
99
+ throw new ServerError(
100
+ Status.INTERNAL,
101
+ 'error processing transaction: ' + JSON.stringify(result) + '\n' + errorString(e)
102
+ )
103
+ })
100
104
  if (GLOBAL_CONFIG.execution.sequential) {
101
105
  await promise
102
106
  }