@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
@@ -2,12 +2,9 @@ import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR
2
2
  import {
3
3
  AccountConfig,
4
4
  ContractConfig,
5
- Data_SuiCall,
6
- Data_SuiEvent,
7
- Data_SuiObject,
8
- Data_SuiObjectChange,
9
5
  DataBinding,
10
6
  HandlerType,
7
+ InitResponse,
11
8
  MoveCallHandlerConfig,
12
9
  MoveEventHandlerConfig,
13
10
  MoveResourceChangeConfig,
@@ -19,6 +16,7 @@ import {
19
16
 
20
17
  import { ServerError, Status } from 'nice-grpc'
21
18
  import { PartitionHandlerManager } from '../core/index.js'
19
+ import { HandlerRegister } from '../core/handler-register.js'
22
20
 
23
21
  import { SuiProcessorState } from './sui-processor.js'
24
22
  import { SuiAccountProcessorState, SuiAddressProcessor } from './sui-object-processor.js'
@@ -31,22 +29,9 @@ import {
31
29
  import { SuiNetwork } from './network.js'
32
30
  import { SuiContext } from './context.js'
33
31
 
34
- interface Handlers {
35
- suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]
36
- suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]
37
- suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]
38
- suiObjectChangeHandlers: ((object: Data_SuiObjectChange) => Promise<ProcessResult>)[]
39
- }
40
-
41
32
  export class SuiPlugin extends Plugin {
42
33
  name: string = 'SuiPlugin'
43
- handlers: Handlers = {
44
- suiCallHandlers: [],
45
- suiEventHandlers: [],
46
- suiObjectHandlers: [],
47
- suiObjectChangeHandlers: []
48
- }
49
-
34
+ handlerRegister = new HandlerRegister()
50
35
  partitionManager = new PartitionHandlerManager()
51
36
  async start(request: StartRequest): Promise<void> {
52
37
  await initCoinList()
@@ -76,14 +61,21 @@ export class SuiPlugin extends Plugin {
76
61
  }
77
62
  }
78
63
 
79
- async configure(config: ProcessConfigResponse) {
80
- const handlers: Handlers = {
81
- suiCallHandlers: [],
82
- suiEventHandlers: [],
83
- suiObjectHandlers: [],
84
- suiObjectChangeHandlers: []
64
+ async init(config: InitResponse) {
65
+ for (const state of [SuiProcessorState.INSTANCE, SuiAccountProcessorState.INSTANCE]) {
66
+ for (const suiProcessor of state.getValues()) {
67
+ config.chainIds.push(suiProcessor.config.network)
68
+ }
85
69
  }
70
+ }
71
+
72
+ async configure(config: ProcessConfigResponse, forChainId?: string) {
73
+ this.handlerRegister.clear(forChainId as any)
86
74
  for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
75
+ const chainId = suiProcessor.config.network
76
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
77
+ continue
78
+ }
87
79
  const contractConfig = ContractConfig.fromPartial({
88
80
  transactionConfig: [],
89
81
  processorType: USER_PROCESSOR,
@@ -97,7 +89,7 @@ export class SuiPlugin extends Plugin {
97
89
  endBlock: suiProcessor.config.endCheckpoint
98
90
  })
99
91
  for (const handler of suiProcessor.eventHandlers) {
100
- const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1
92
+ const handlerId = this.handlerRegister.register(handler.handler, chainId)
101
93
  this.partitionManager.registerPartitionHandler(HandlerType.SUI_EVENT, handlerId, handler.partitionHandler)
102
94
  const eventHandlerConfig: MoveEventHandlerConfig = {
103
95
  filters: handler.filters.map((f) => {
@@ -114,7 +106,7 @@ export class SuiPlugin extends Plugin {
114
106
  contractConfig.moveEventConfigs.push(eventHandlerConfig)
115
107
  }
116
108
  for (const handler of suiProcessor.callHandlers) {
117
- const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1
109
+ const handlerId = this.handlerRegister.register(handler.handler, chainId)
118
110
  this.partitionManager.registerPartitionHandler(HandlerType.SUI_CALL, handlerId, handler.partitionHandler)
119
111
  const functionHandlerConfig: MoveCallHandlerConfig = {
120
112
  filters: handler.filters.map((filter) => {
@@ -135,7 +127,7 @@ export class SuiPlugin extends Plugin {
135
127
  }
136
128
  // deprecated, use objectType processor instead
137
129
  for (const handler of suiProcessor.objectChangeHandlers) {
138
- const handlerId = handlers.suiObjectChangeHandlers.push(handler.handler) - 1
130
+ const handlerId = this.handlerRegister.register(handler.handler, chainId)
139
131
  const objectChangeHandler: MoveResourceChangeConfig = {
140
132
  type: handler.type,
141
133
  handlerId,
@@ -148,6 +140,10 @@ export class SuiPlugin extends Plugin {
148
140
  }
149
141
 
150
142
  for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {
143
+ const chainId = processor.getChainId()
144
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
145
+ continue
146
+ }
151
147
  const accountConfig = AccountConfig.fromPartial({
152
148
  address: processor.config.address,
153
149
  chainId: processor.getChainId(),
@@ -156,7 +152,7 @@ export class SuiPlugin extends Plugin {
156
152
  })
157
153
 
158
154
  for (const handler of processor.objectChangeHandlers) {
159
- const handlerId = handlers.suiObjectChangeHandlers.push(handler.handler) - 1
155
+ const handlerId = this.handlerRegister.register(handler.handler, chainId)
160
156
  const objectChangeHandler: MoveResourceChangeConfig = {
161
157
  type: handler.type,
162
158
  handlerId,
@@ -167,7 +163,7 @@ export class SuiPlugin extends Plugin {
167
163
  }
168
164
 
169
165
  for (const handler of processor.objectHandlers) {
170
- const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1
166
+ const handlerId = this.handlerRegister.register(handler.handler, chainId)
171
167
 
172
168
  accountConfig.moveIntervalConfigs.push({
173
169
  intervalConfig: {
@@ -188,7 +184,7 @@ export class SuiPlugin extends Plugin {
188
184
 
189
185
  if (processor instanceof SuiAddressProcessor) {
190
186
  for (const handler of processor.callHandlers) {
191
- const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1
187
+ const handlerId = this.handlerRegister.register(handler.handler, chainId)
192
188
  const functionHandlerConfig: MoveCallHandlerConfig = {
193
189
  filters: handler.filters.map((filter) => {
194
190
  return {
@@ -210,7 +206,6 @@ export class SuiPlugin extends Plugin {
210
206
 
211
207
  config.accountConfigs.push(accountConfig)
212
208
  }
213
- this.handlers = handlers
214
209
  }
215
210
 
216
211
  supportedHandlers = [
@@ -284,12 +279,14 @@ export class SuiPlugin extends Plugin {
284
279
 
285
280
  for (const handlerId of binding.handlerIds) {
286
281
  promises.push(
287
- this.handlers.suiEventHandlers[handlerId](event).catch((e) => {
288
- throw new ServerError(
289
- Status.INTERNAL,
290
- 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
291
- )
292
- })
282
+ this.handlerRegister
283
+ .getHandlerById(handlerId)(event)
284
+ .catch((e: any) => {
285
+ throw new ServerError(
286
+ Status.INTERNAL,
287
+ 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
288
+ )
289
+ })
293
290
  )
294
291
  }
295
292
  return mergeProcessResults(await Promise.all(promises))
@@ -303,9 +300,14 @@ export class SuiPlugin extends Plugin {
303
300
 
304
301
  const promises: Promise<ProcessResult>[] = []
305
302
  for (const handlerId of binding.handlerIds) {
306
- const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {
307
- throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
308
- })
303
+ const promise = this.handlerRegister
304
+ .getHandlerById(handlerId)(call)
305
+ .catch((e: any) => {
306
+ throw new ServerError(
307
+ Status.INTERNAL,
308
+ 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e)
309
+ )
310
+ })
309
311
  promises.push(promise)
310
312
  }
311
313
  return mergeProcessResults(await Promise.all(promises))
@@ -320,12 +322,14 @@ export class SuiPlugin extends Plugin {
320
322
  const promises: Promise<ProcessResult>[] = []
321
323
  for (const handlerId of binding.handlerIds) {
322
324
  promises.push(
323
- this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {
324
- throw new ServerError(
325
- Status.INTERNAL,
326
- 'error processing object: ' + JSON.stringify(object) + '\n' + errorString(e)
327
- )
328
- })
325
+ this.handlerRegister
326
+ .getHandlerById(handlerId)(object)
327
+ .catch((e: any) => {
328
+ throw new ServerError(
329
+ Status.INTERNAL,
330
+ 'error processing object: ' + JSON.stringify(object) + '\n' + errorString(e)
331
+ )
332
+ })
329
333
  )
330
334
  }
331
335
  return mergeProcessResults(await Promise.all(promises))
@@ -340,12 +344,14 @@ export class SuiPlugin extends Plugin {
340
344
  const promises: Promise<ProcessResult>[] = []
341
345
  for (const handlerId of binding.handlerIds) {
342
346
  promises.push(
343
- this.handlers.suiObjectChangeHandlers[handlerId](objectChange).catch((e) => {
344
- throw new ServerError(
345
- Status.INTERNAL,
346
- 'error processing object change: ' + JSON.stringify(objectChange) + '\n' + errorString(e)
347
- )
348
- })
347
+ this.handlerRegister
348
+ .getHandlerById(handlerId)(objectChange)
349
+ .catch((e: any) => {
350
+ throw new ServerError(
351
+ Status.INTERNAL,
352
+ 'error processing object change: ' + JSON.stringify(objectChange) + '\n' + errorString(e)
353
+ )
354
+ })
349
355
  )
350
356
  }
351
357
  return mergeProcessResults(await Promise.all(promises))