@sentio/sdk 2.59.5-rc.1 → 2.60.0-rc.10

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 (226) 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/aptos/aptos-processor.d.ts +1 -0
  6. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  7. package/lib/aptos/aptos-processor.js +11 -3
  8. package/lib/aptos/aptos-processor.js.map +1 -1
  9. package/lib/aptos/builtin/0x1.d.ts +211 -0
  10. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  11. package/lib/aptos/builtin/0x1.js +328 -1
  12. package/lib/aptos/builtin/0x1.js.map +1 -1
  13. package/lib/aptos/builtin/0x3.js +1 -1
  14. package/lib/aptos/builtin/0x3.js.map +1 -1
  15. package/lib/aptos/builtin/0x4.js +1 -1
  16. package/lib/aptos/builtin/0x4.js.map +1 -1
  17. package/lib/btc/btc-plugin.d.ts +5 -8
  18. package/lib/btc/btc-plugin.d.ts.map +1 -1
  19. package/lib/btc/btc-plugin.js +22 -14
  20. package/lib/btc/btc-plugin.js.map +1 -1
  21. package/lib/core/core-plugin.d.ts +3 -1
  22. package/lib/core/core-plugin.d.ts.map +1 -1
  23. package/lib/core/core-plugin.js +13 -0
  24. package/lib/core/core-plugin.js.map +1 -1
  25. package/lib/core/handler-options.d.ts +6 -0
  26. package/lib/core/handler-options.d.ts.map +1 -1
  27. package/lib/core/handler-options.js.map +1 -1
  28. package/lib/core/handler-register.d.ts +18 -0
  29. package/lib/core/handler-register.d.ts.map +1 -0
  30. package/lib/core/handler-register.js +62 -0
  31. package/lib/core/handler-register.js.map +1 -0
  32. package/lib/cosmos/cosmos-plugin.d.ts +5 -7
  33. package/lib/cosmos/cosmos-plugin.d.ts.map +1 -1
  34. package/lib/cosmos/cosmos-plugin.js +18 -10
  35. package/lib/cosmos/cosmos-plugin.js.map +1 -1
  36. package/lib/eth/base-processor.d.ts +3 -1
  37. package/lib/eth/base-processor.d.ts.map +1 -1
  38. package/lib/eth/base-processor.js +26 -0
  39. package/lib/eth/base-processor.js.map +1 -1
  40. package/lib/eth/eth-plugin.d.ts +5 -40
  41. package/lib/eth/eth-plugin.d.ts.map +1 -1
  42. package/lib/eth/eth-plugin.js +86 -120
  43. package/lib/eth/eth-plugin.js.map +1 -1
  44. package/lib/eth/eth.d.ts.map +1 -1
  45. package/lib/eth/eth.js +30 -24
  46. package/lib/eth/eth.js.map +1 -1
  47. package/lib/fuel/fuel-plugin.d.ts +5 -9
  48. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  49. package/lib/fuel/fuel-plugin.js +26 -18
  50. package/lib/fuel/fuel-plugin.js.map +1 -1
  51. package/lib/iota/builtin/0x1.d.ts +817 -0
  52. package/lib/iota/builtin/0x1.d.ts.map +1 -0
  53. package/lib/iota/builtin/0x1.js +4385 -0
  54. package/lib/iota/builtin/0x1.js.map +1 -0
  55. package/lib/iota/builtin/0x2.d.ts +4529 -0
  56. package/lib/iota/builtin/0x2.d.ts.map +1 -0
  57. package/lib/iota/builtin/0x2.js +17109 -0
  58. package/lib/iota/builtin/0x2.js.map +1 -0
  59. package/lib/iota/builtin/0x3.d.ts +2293 -0
  60. package/lib/iota/builtin/0x3.d.ts.map +1 -0
  61. package/lib/iota/builtin/0x3.js +6522 -0
  62. package/lib/iota/builtin/0x3.js.map +1 -0
  63. package/lib/iota/builtin/index.d.ts +4 -0
  64. package/lib/iota/builtin/index.d.ts.map +1 -0
  65. package/lib/iota/builtin/index.js +7 -0
  66. package/lib/iota/builtin/index.js.map +1 -0
  67. package/lib/iota/codegen/codegen.d.ts +2 -0
  68. package/lib/iota/codegen/codegen.d.ts.map +1 -0
  69. package/lib/iota/codegen/codegen.js +94 -0
  70. package/lib/iota/codegen/codegen.js.map +1 -0
  71. package/lib/iota/codegen/index.d.ts +2 -0
  72. package/lib/iota/codegen/index.d.ts.map +1 -0
  73. package/lib/iota/codegen/index.js +2 -0
  74. package/lib/iota/codegen/index.js.map +1 -0
  75. package/lib/iota/codegen/run.d.ts +2 -0
  76. package/lib/iota/codegen/run.d.ts.map +1 -0
  77. package/lib/iota/codegen/run.js +12 -0
  78. package/lib/iota/codegen/run.js.map +1 -0
  79. package/lib/iota/context.d.ts +50 -0
  80. package/lib/iota/context.d.ts.map +1 -0
  81. package/lib/iota/context.js +134 -0
  82. package/lib/iota/context.js.map +1 -0
  83. package/lib/iota/ext/coin.d.ts +17 -0
  84. package/lib/iota/ext/coin.d.ts.map +1 -0
  85. package/lib/iota/ext/coin.js +532 -0
  86. package/lib/iota/ext/coin.js.map +1 -0
  87. package/lib/iota/ext/index.d.ts +3 -0
  88. package/lib/iota/ext/index.d.ts.map +1 -0
  89. package/lib/iota/ext/index.js +3 -0
  90. package/lib/iota/ext/index.js.map +1 -0
  91. package/lib/iota/ext/move-dex.d.ts +19 -0
  92. package/lib/iota/ext/move-dex.d.ts.map +1 -0
  93. package/lib/iota/ext/move-dex.js +24 -0
  94. package/lib/iota/ext/move-dex.js.map +1 -0
  95. package/lib/iota/index.d.ts +11 -0
  96. package/lib/iota/index.d.ts.map +1 -0
  97. package/lib/iota/index.js +12 -0
  98. package/lib/iota/index.js.map +1 -0
  99. package/lib/iota/iota-object-processor-template.d.ts +44 -0
  100. package/lib/iota/iota-object-processor-template.d.ts.map +1 -0
  101. package/lib/iota/iota-object-processor-template.js +171 -0
  102. package/lib/iota/iota-object-processor-template.js.map +1 -0
  103. package/lib/iota/iota-object-processor.d.ts +83 -0
  104. package/lib/iota/iota-object-processor.d.ts.map +1 -0
  105. package/lib/iota/iota-object-processor.js +193 -0
  106. package/lib/iota/iota-object-processor.js.map +1 -0
  107. package/lib/iota/iota-plugin-part.d.ts +12 -0
  108. package/lib/iota/iota-plugin-part.d.ts.map +1 -0
  109. package/lib/iota/iota-plugin-part.js +178 -0
  110. package/lib/iota/iota-plugin-part.js.map +1 -0
  111. package/lib/iota/iota-plugin.d.ts +3 -0
  112. package/lib/iota/iota-plugin.d.ts.map +1 -0
  113. package/lib/iota/iota-plugin.js +4 -0
  114. package/lib/iota/iota-plugin.js.map +1 -0
  115. package/lib/iota/iota-processor.d.ts +47 -0
  116. package/lib/iota/iota-processor.d.ts.map +1 -0
  117. package/lib/iota/iota-processor.js +223 -0
  118. package/lib/iota/iota-processor.js.map +1 -0
  119. package/lib/iota/models.d.ts +12 -0
  120. package/lib/iota/models.d.ts.map +1 -0
  121. package/lib/iota/models.js +2 -0
  122. package/lib/iota/models.js.map +1 -0
  123. package/lib/iota/move-coder.d.ts +4 -0
  124. package/lib/iota/move-coder.d.ts.map +1 -0
  125. package/lib/iota/move-coder.js +12 -0
  126. package/lib/iota/move-coder.js.map +1 -0
  127. package/lib/iota/network.d.ts +10 -0
  128. package/lib/iota/network.d.ts.map +1 -0
  129. package/lib/iota/network.js +24 -0
  130. package/lib/iota/network.js.map +1 -0
  131. package/lib/iota/utils.d.ts +3 -0
  132. package/lib/iota/utils.d.ts.map +1 -0
  133. package/lib/iota/utils.js +41 -0
  134. package/lib/iota/utils.js.map +1 -0
  135. package/lib/solana/solana-plugin.d.ts +3 -2
  136. package/lib/solana/solana-plugin.d.ts.map +1 -1
  137. package/lib/solana/solana-plugin.js +11 -1
  138. package/lib/solana/solana-plugin.js.map +1 -1
  139. package/lib/stark/starknet-plugin.d.ts +5 -7
  140. package/lib/stark/starknet-plugin.d.ts.map +1 -1
  141. package/lib/stark/starknet-plugin.js +18 -10
  142. package/lib/stark/starknet-plugin.js.map +1 -1
  143. package/lib/store/schema.d.ts.map +1 -1
  144. package/lib/store/schema.js +1 -0
  145. package/lib/store/schema.js.map +1 -1
  146. package/lib/sui/builtin/0x2.d.ts +73 -0
  147. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  148. package/lib/sui/builtin/0x2.js +237 -1
  149. package/lib/sui/builtin/0x2.js.map +1 -1
  150. package/lib/sui/builtin/0x3.d.ts +2 -0
  151. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  152. package/lib/sui/builtin/0x3.js +21 -1
  153. package/lib/sui/builtin/0x3.js.map +1 -1
  154. package/lib/sui/network.d.ts.map +1 -1
  155. package/lib/sui/network.js +0 -3
  156. package/lib/sui/network.js.map +1 -1
  157. package/lib/sui/sui-plugin-part.d.ts +12 -0
  158. package/lib/sui/sui-plugin-part.d.ts.map +1 -0
  159. package/lib/sui/sui-plugin-part.js +178 -0
  160. package/lib/sui/sui-plugin-part.js.map +1 -0
  161. package/lib/sui/sui-plugin.d.ts +9 -10
  162. package/lib/sui/sui-plugin.d.ts.map +1 -1
  163. package/lib/sui/sui-plugin.js +30 -164
  164. package/lib/sui/sui-plugin.js.map +1 -1
  165. package/lib/testing/iota-facet.d.ts +14 -0
  166. package/lib/testing/iota-facet.d.ts.map +1 -0
  167. package/lib/testing/iota-facet.js +124 -0
  168. package/lib/testing/iota-facet.js.map +1 -0
  169. package/lib/testing/test-processor-server.d.ts +2 -0
  170. package/lib/testing/test-processor-server.d.ts.map +1 -1
  171. package/lib/testing/test-processor-server.js +3 -0
  172. package/lib/testing/test-processor-server.js.map +1 -1
  173. package/package.json +21 -9
  174. package/src/aptos/abis/0x1.json +1040 -45
  175. package/src/aptos/abis/0x3.json +2 -2
  176. package/src/aptos/abis/0x4.json +17 -17
  177. package/src/aptos/aptos-plugin.ts +55 -44
  178. package/src/aptos/aptos-processor.ts +15 -3
  179. package/src/aptos/builtin/0x1.ts +615 -1
  180. package/src/aptos/builtin/0x3.ts +1 -1
  181. package/src/aptos/builtin/0x4.ts +1 -1
  182. package/src/btc/btc-plugin.ts +33 -32
  183. package/src/core/core-plugin.ts +16 -2
  184. package/src/core/handler-options.ts +7 -0
  185. package/src/core/handler-register.ts +79 -0
  186. package/src/cosmos/cosmos-plugin.ts +24 -20
  187. package/src/eth/base-processor.ts +43 -1
  188. package/src/eth/eth-plugin.ts +111 -185
  189. package/src/eth/eth.ts +31 -26
  190. package/src/fuel/fuel-plugin.ts +43 -44
  191. package/src/iota/abis/0x1.json +4213 -0
  192. package/src/iota/abis/0x2.json +26692 -0
  193. package/src/iota/abis/0x3.json +10598 -0
  194. package/src/iota/builtin/0x1.ts +6292 -0
  195. package/src/iota/builtin/0x2.ts +26198 -0
  196. package/src/iota/builtin/0x3.ts +11144 -0
  197. package/src/iota/builtin/index.ts +6 -0
  198. package/src/iota/codegen/codegen.ts +118 -0
  199. package/src/iota/codegen/index.ts +1 -0
  200. package/src/iota/codegen/run.ts +13 -0
  201. package/src/iota/context.ts +200 -0
  202. package/src/iota/ext/coin.ts +565 -0
  203. package/src/iota/ext/index.ts +2 -0
  204. package/src/iota/ext/move-dex.ts +52 -0
  205. package/src/iota/index.ts +29 -0
  206. package/src/iota/iota-object-processor-template.ts +277 -0
  207. package/src/iota/iota-object-processor.ts +386 -0
  208. package/src/iota/iota-plugin-part.ts +211 -0
  209. package/src/iota/iota-plugin.ts +2 -0
  210. package/src/iota/iota-processor.ts +339 -0
  211. package/src/iota/models.ts +14 -0
  212. package/src/iota/move-coder.ts +15 -0
  213. package/src/iota/network.ts +27 -0
  214. package/src/iota/utils.ts +52 -0
  215. package/src/solana/solana-plugin.ts +20 -2
  216. package/src/stark/starknet-plugin.ts +24 -20
  217. package/src/store/schema.ts +1 -0
  218. package/src/sui/abis/0x2.json +269 -0
  219. package/src/sui/abis/0x3.json +29 -0
  220. package/src/sui/builtin/0x2.ts +367 -1
  221. package/src/sui/builtin/0x3.ts +29 -1
  222. package/src/sui/network.ts +0 -3
  223. package/src/sui/sui-plugin-part.ts +211 -0
  224. package/src/sui/sui-plugin.ts +51 -211
  225. package/src/testing/iota-facet.ts +143 -0
  226. package/src/testing/test-processor-server.ts +3 -0
@@ -1,10 +1,9 @@
1
1
  import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import {
3
3
  ContractConfig,
4
- Data_BTCBlock,
5
- Data_BTCTransaction,
6
4
  DataBinding,
7
5
  HandlerType,
6
+ InitResponse,
8
7
  ProcessConfigResponse,
9
8
  ProcessResult,
10
9
  ProcessStreamResponse_Partitions,
@@ -13,31 +12,31 @@ import {
13
12
 
14
13
  import { ServerError, Status } from 'nice-grpc'
15
14
  import { PartitionHandlerManager } from '../core/index.js'
15
+ import { HandlerRegister } from '../core/handler-register.js'
16
16
  import { TemplateInstanceState } from '../core/template.js'
17
17
  import { BTCProcessorState } from './btc-processor.js'
18
18
  import { filters2Proto, TransactionFilter } from './filter.js'
19
19
 
20
- interface Handlers {
21
- txHandlers: ((trace: Data_BTCTransaction) => Promise<ProcessResult>)[]
22
- blockHandlers: ((trace: Data_BTCBlock) => Promise<ProcessResult>)[]
23
- }
24
-
25
20
  export class BTCPlugin extends Plugin {
26
21
  name: string = 'BTCPlugin'
27
- handlers: Handlers = {
28
- txHandlers: [],
29
- blockHandlers: []
30
- }
31
-
22
+ handlerRegister = new HandlerRegister()
32
23
  partitionManager = new PartitionHandlerManager()
33
24
 
34
- async configure(config: ProcessConfigResponse) {
35
- const handlers: Handlers = {
36
- txHandlers: [],
37
- blockHandlers: []
25
+ async init(config: InitResponse) {
26
+ for (const aptosProcessor of BTCProcessorState.INSTANCE.getValues()) {
27
+ const chainId = aptosProcessor.config.chainId
28
+ config.chainIds.push(chainId)
38
29
  }
30
+ }
31
+
32
+ async configure(config: ProcessConfigResponse, forChainId?: string) {
33
+ this.handlerRegister.clear(forChainId as any)
39
34
 
40
35
  for (const processor of BTCProcessorState.INSTANCE.getValues()) {
36
+ const chainId = processor.config.chainId
37
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
38
+ continue
39
+ }
41
40
  const contractConfig = ContractConfig.fromPartial({
42
41
  processorType: USER_PROCESSOR,
43
42
  contract: {
@@ -50,7 +49,7 @@ export class BTCPlugin extends Plugin {
50
49
  endBlock: processor.config.endBlock
51
50
  })
52
51
  for (const callHandler of processor.callHandlers) {
53
- const handlerId = handlers.txHandlers.push(callHandler.handler) - 1
52
+ const handlerId = this.handlerRegister.register(callHandler.handler, chainId)
54
53
  this.partitionManager.registerPartitionHandler(
55
54
  HandlerType.BTC_TRANSACTION,
56
55
  handlerId,
@@ -78,7 +77,7 @@ export class BTCPlugin extends Plugin {
78
77
  }
79
78
 
80
79
  for (const blockHandler of processor.blockHandlers) {
81
- const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
80
+ const handlerId = this.handlerRegister.register(blockHandler.handler, chainId)
82
81
  this.partitionManager.registerPartitionHandler(HandlerType.BTC_BLOCK, handlerId, blockHandler.partitionHandler)
83
82
  contractConfig.intervalConfigs.push({
84
83
  slot: 0,
@@ -100,8 +99,6 @@ export class BTCPlugin extends Plugin {
100
99
  // Finish up a contract
101
100
  config.contractConfigs.push(contractConfig)
102
101
  }
103
-
104
- this.handlers = handlers
105
102
  }
106
103
 
107
104
  supportedHandlers = [HandlerType.BTC_TRANSACTION, HandlerType.BTC_BLOCK]
@@ -161,12 +158,14 @@ export class BTCPlugin extends Plugin {
161
158
  const result = binding.data?.btcTransaction
162
159
 
163
160
  for (const handlerId of binding.handlerIds) {
164
- const promise = this.handlers.txHandlers[handlerId](binding.data?.btcTransaction).catch((e) => {
165
- throw new ServerError(
166
- Status.INTERNAL,
167
- 'error processing transaction: ' + JSON.stringify(result) + '\n' + errorString(e)
168
- )
169
- })
161
+ const promise = this.handlerRegister
162
+ .getHandlerById(handlerId)(binding.data?.btcTransaction)
163
+ .catch((e: any) => {
164
+ throw new ServerError(
165
+ Status.INTERNAL,
166
+ 'error processing transaction: ' + JSON.stringify(result) + '\n' + errorString(e)
167
+ )
168
+ })
170
169
  if (GLOBAL_CONFIG.execution.sequential) {
171
170
  await promise
172
171
  }
@@ -184,12 +183,14 @@ export class BTCPlugin extends Plugin {
184
183
 
185
184
  const promises: Promise<ProcessResult>[] = []
186
185
  for (const handlerId of request.handlerIds) {
187
- const promise = this.handlers.blockHandlers[handlerId](block).catch((e) => {
188
- throw new ServerError(
189
- Status.INTERNAL,
190
- 'error processing block: ' + JSON.stringify(block) + '\n' + errorString(e)
191
- )
192
- })
186
+ const promise = this.handlerRegister
187
+ .getHandlerById(handlerId)(block)
188
+ .catch((e: any) => {
189
+ throw new ServerError(
190
+ Status.INTERNAL,
191
+ 'error processing block: ' + JSON.stringify(block) + '\n' + errorString(e)
192
+ )
193
+ })
193
194
  if (GLOBAL_CONFIG.execution.sequential) {
194
195
  await promise
195
196
  }
@@ -1,5 +1,5 @@
1
1
  import { Plugin, PluginManager } from '@sentio/runtime'
2
- import { ProcessConfigResponse } from '@sentio/protos'
2
+ import { InitResponse, ProcessConfigResponse } from '@sentio/protos'
3
3
 
4
4
  import { MetricState, MetricStateNew } from './meter.js'
5
5
  import { ExporterState } from './exporter.js'
@@ -14,6 +14,14 @@ export class CorePlugin extends Plugin {
14
14
  // This syntax is to copy values instead of using references
15
15
  config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]
16
16
 
17
+ this.initStartupConfig(config)
18
+ }
19
+
20
+ async init(config: InitResponse): Promise<void> {
21
+ this.initStartupConfig(config)
22
+ }
23
+
24
+ initStartupConfig(config: InitResponse | ProcessConfigResponse): void {
17
25
  for (const metric of MetricState.INSTANCE.getValues()) {
18
26
  config.metricConfigs.push({
19
27
  ...metric.config
@@ -24,7 +32,6 @@ export class CorePlugin extends Plugin {
24
32
  ...metric.config
25
33
  })
26
34
  }
27
-
28
35
  for (const event of EventLoggerState.INSTANCE.getValues()) {
29
36
  config.eventLogConfigs.push({
30
37
  ...event.config
@@ -45,6 +52,13 @@ export class CorePlugin extends Plugin {
45
52
  .join('\n\n')
46
53
  }
47
54
  }
55
+ if (DatabaseSchemaState.INSTANCE.getValues().length > 0) {
56
+ config.dbSchema = {
57
+ gqlSchema: DatabaseSchemaState.INSTANCE.getValues()
58
+ .map((e) => e.source)
59
+ .join('\n\n')
60
+ }
61
+ }
48
62
  }
49
63
  }
50
64
 
@@ -15,6 +15,13 @@ export type HandlerOptions<F, D> = Partial<F> & {
15
15
  * Can be a static string or a function that computes the key from the data.
16
16
  */
17
17
  partitionKey?: string | PartitionHandler<D>
18
+
19
+ /**
20
+ * Optional whether to skip decoding
21
+ * By default the processor will do decoding (e.g. replace string number to bigint, byte array to base64, etc),
22
+ * however in some case you might skip the decoding (meaning no data_decoded field) and only access the raw data field
23
+ */
24
+ skipDecoding?: boolean
18
25
  }
19
26
 
20
27
  /**
@@ -0,0 +1,79 @@
1
+ import { ServerError, Status } from 'nice-grpc'
2
+ import { ChainId } from '@sentio/chain'
3
+ import { ProcessResult } from '@sentio/protos'
4
+
5
+ export type HandlerFunction = (...args: any[]) => Promise<ProcessResult>
6
+
7
+ interface HandlerEntry {
8
+ id: number
9
+ handler: HandlerFunction
10
+ chainId: ChainId | string
11
+ }
12
+
13
+ const chainToNumber: Map<string, number> = new Map()
14
+ const numberToChain: Map<number, string> = new Map()
15
+
16
+ for (const chainId of Object.values(ChainId)) {
17
+ const num = chainToNumber.size + 1
18
+ chainToNumber.set(chainId, num)
19
+ numberToChain.set(num, chainId)
20
+ }
21
+
22
+ const MAX_HANDLER_PER_CHAIN = 1000000 // Maximum handlers per chain
23
+
24
+ export class HandlerRegister {
25
+ private handlerByChain: Map<number, HandlerEntry[]> = new Map()
26
+ private handlers: Map<number, HandlerEntry> = new Map()
27
+
28
+ /**
29
+ * Register a handler function with chain ID and handle type
30
+ * @returns handler ID
31
+ */
32
+ register(handler: HandlerFunction, chainId: ChainId | string): number {
33
+ const chainNum = chainToNumber.get(chainId) || 0
34
+ const entries = this.handlerByChain.get(chainNum) || []
35
+
36
+ const len = entries.length
37
+ const id = chainNum * MAX_HANDLER_PER_CHAIN + len + 1 // Use the first 32 bits for chain ID, next bits for index
38
+
39
+ const entry: HandlerEntry = {
40
+ id,
41
+ handler,
42
+ chainId
43
+ }
44
+ entries.push(entry)
45
+ this.handlerByChain.set(chainNum, entries)
46
+ this.handlers.set(id, entry)
47
+
48
+ return id
49
+ }
50
+
51
+ /**
52
+ * Get handler function by ID
53
+ */
54
+ getHandlerById(id: number): HandlerFunction {
55
+ const entry = this.handlers.get(id)
56
+ if (!entry) {
57
+ throw new ServerError(Status.INTERNAL, `Handler with ID ${id} not found.`)
58
+ }
59
+ return entry.handler
60
+ }
61
+
62
+ clear(chainId?: ChainId): void {
63
+ if (chainId) {
64
+ const chainNum = chainToNumber.get(chainId)
65
+ if (chainNum !== undefined) {
66
+ const chainHandlers = this.handlerByChain.get(chainNum)
67
+ if (chainHandlers) {
68
+ for (const entry of chainHandlers) {
69
+ this.handlers.delete(entry.id)
70
+ }
71
+ }
72
+ this.handlerByChain.delete(chainNum)
73
+ }
74
+ } else {
75
+ this.handlerByChain.clear()
76
+ this.handlers.clear()
77
+ }
78
+ }
79
+ }
@@ -1,33 +1,37 @@
1
1
  import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import {
3
3
  ContractConfig,
4
- Data_CosmosCall,
5
4
  DataBinding,
6
5
  HandlerType,
6
+ InitResponse,
7
7
  ProcessConfigResponse,
8
8
  ProcessResult,
9
9
  StartRequest
10
10
  } from '@sentio/protos'
11
11
  import { ServerError, Status } from 'nice-grpc'
12
12
  import { TemplateInstanceState } from '../core/template.js'
13
+ import { HandlerRegister } from '../core/handler-register.js'
13
14
  import { CosmosProcessorState } from './types.js'
14
15
 
15
- interface Handlers {
16
- callHandlers: ((trace: Data_CosmosCall) => Promise<ProcessResult>)[]
17
- }
18
-
19
16
  export class CosmosPlugin extends Plugin {
20
17
  name: string = 'CosmosPlugin'
21
- handlers: Handlers = {
22
- callHandlers: []
23
- }
18
+ handlerRegister = new HandlerRegister()
24
19
 
25
- async configure(config: ProcessConfigResponse) {
26
- const handlers: Handlers = {
27
- callHandlers: []
20
+ async init(config: InitResponse) {
21
+ for (const aptosProcessor of CosmosProcessorState.INSTANCE.getValues()) {
22
+ const chainId = aptosProcessor.config.chainId
23
+ config.chainIds.push(chainId)
28
24
  }
25
+ }
26
+
27
+ async configure(config: ProcessConfigResponse, forChainId?: string) {
28
+ this.handlerRegister.clear(forChainId as any)
29
29
 
30
30
  for (const processor of CosmosProcessorState.INSTANCE.getValues()) {
31
+ const chainId = processor.config.chainId
32
+ if (forChainId !== undefined && forChainId !== chainId.toString()) {
33
+ continue
34
+ }
31
35
  const contractConfig = ContractConfig.fromPartial({
32
36
  processorType: USER_PROCESSOR,
33
37
  contract: {
@@ -41,7 +45,7 @@ export class CosmosPlugin extends Plugin {
41
45
  })
42
46
 
43
47
  for (const callHandler of processor.callHandlers) {
44
- const handlerId = handlers.callHandlers.push(callHandler.handler) - 1
48
+ const handlerId = this.handlerRegister.register(callHandler.handler, chainId)
45
49
 
46
50
  contractConfig.cosmosLogConfigs.push({
47
51
  handlerId,
@@ -53,8 +57,6 @@ export class CosmosPlugin extends Plugin {
53
57
  // Finish up a contract
54
58
  config.contractConfigs.push(contractConfig)
55
59
  }
56
-
57
- this.handlers = handlers
58
60
  }
59
61
 
60
62
  supportedHandlers = [HandlerType.COSMOS_CALL]
@@ -83,12 +85,14 @@ export class CosmosPlugin extends Plugin {
83
85
  const promises: Promise<ProcessResult>[] = []
84
86
 
85
87
  for (const handlerId of binding.handlerIds) {
86
- const promise = this.handlers.callHandlers[handlerId](call).catch((e) => {
87
- throw new ServerError(
88
- Status.INTERNAL,
89
- 'error processing transaction: ' + JSON.stringify(call.transaction) + '\n' + errorString(e)
90
- )
91
- })
88
+ const promise = this.handlerRegister
89
+ .getHandlerById(handlerId)(call)
90
+ .catch((e) => {
91
+ throw new ServerError(
92
+ Status.INTERNAL,
93
+ 'error processing transaction: ' + JSON.stringify(call.transaction) + '\n' + errorString(e)
94
+ )
95
+ })
92
96
  if (GLOBAL_CONFIG.execution.sequential) {
93
97
  await promise
94
98
  }
@@ -1,4 +1,4 @@
1
- import { BaseContract, DeferredTopicFilter, LogDescription, TransactionResponseParams } from 'ethers'
1
+ import { BaseContract, DeferredTopicFilter, LogDescription, LogParams, TransactionResponseParams } from 'ethers'
2
2
 
3
3
  import { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js'
4
4
  import {
@@ -93,6 +93,7 @@ export class GlobalProcessor {
93
93
  blockHandlers: BlockHandler[] = proxyHandlers([])
94
94
  transactionHandler: TransactionHandler[] = proxyHandlers([])
95
95
  traceHandlers: TraceHandler[] = proxyHandlers([])
96
+ eventHandlers: EventsHandler[] = []
96
97
 
97
98
  static bind(config: Omit<BindOptions, 'address'>): GlobalProcessor {
98
99
  const processor = new GlobalProcessor(config)
@@ -333,6 +334,47 @@ export class GlobalProcessor {
333
334
  return this
334
335
  }
335
336
 
337
+ public onEvent(
338
+ handler: (rawLog: LogParams, ctx: GlobalContext) => PromiseOrVoid,
339
+ filter?: AddressOrTypeEventFilter | AddressOrTypeEventFilter[],
340
+ handlerOptions?: HandlerOptions<EthFetchConfig, TypedEvent>
341
+ ): this {
342
+ let _filters: AddressOrTypeEventFilter[] = []
343
+
344
+ if (Array.isArray(filter)) {
345
+ _filters = filter
346
+ } else if (filter) {
347
+ _filters.push(filter)
348
+ }
349
+ const chainId = this.getChainId()
350
+
351
+ this.eventHandlers.push({
352
+ filters: _filters,
353
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
354
+ handlerName: getHandlerName(),
355
+ handler: async function (data) {
356
+ const { log, block, transaction, transactionReceipt } = formatEthData(data)
357
+ if (!log) {
358
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')
359
+ }
360
+ const ctx = new GlobalContext(
361
+ chainId,
362
+ transaction?.to || '*',
363
+ data.timestamp,
364
+ block,
365
+ log,
366
+ undefined,
367
+ transaction,
368
+ transactionReceipt
369
+ )
370
+
371
+ await handler(log, ctx)
372
+ return ctx.stopAndGetResult()
373
+ }
374
+ })
375
+ return this
376
+ }
377
+
336
378
  public onTrace(
337
379
  signatures: string | string[],
338
380
  handler: (trace: Trace, ctx: GlobalContext) => PromiseOrVoid,