@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
@@ -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,
@@ -244,11 +212,61 @@ export class EthPlugin extends Plugin {
244
212
  })
245
213
  }
246
214
  }
215
+
216
+ for (const eventsHandler of processor.eventHandlers) {
217
+ // associate id with filter
218
+ const handlerId = this.handlerRegister.register(eventsHandler.handler, processor.getChainId())
219
+ const logConfig: LogHandlerConfig = {
220
+ handlerId: handlerId,
221
+ handlerName: eventsHandler.handlerName,
222
+ filters: [],
223
+ fetchConfig: eventsHandler.fetchConfig
224
+ }
225
+
226
+ if (!eventsHandler.filters || eventsHandler.filters.length === 0) {
227
+ // if no filter, then we assume all logs
228
+ logConfig.filters.push({
229
+ topics: []
230
+ })
231
+ } else {
232
+ for (const filter of eventsHandler.filters) {
233
+ const topics = await filter.getTopicFilter()
234
+ // if (!filter.topics) {
235
+ // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
236
+ // }
237
+ let address = undefined
238
+ if (filter.address) {
239
+ address = filter.address.toString()
240
+ }
241
+ const logFilter: LogFilter = {
242
+ addressType: filter.addressType,
243
+ address: address && validateAndNormalizeAddress(address),
244
+ topics: []
245
+ }
246
+
247
+ for (const ts of topics) {
248
+ let hashes: string[] = []
249
+ if (Array.isArray(ts)) {
250
+ hashes = hashes.concat(ts)
251
+ } else if (ts) {
252
+ hashes.push(ts)
253
+ }
254
+ logFilter.topics.push({ hashes: hashes })
255
+ }
256
+ logConfig.filters.push(logFilter)
257
+ }
258
+ }
259
+ contractConfig.logConfigs.push(logConfig)
260
+ }
261
+
247
262
  config.contractConfigs.push(contractConfig)
248
263
  }
249
264
 
250
265
  // part 1.b prepare EVM account processors
251
266
  for (const processor of AccountProcessorState.INSTANCE.getValues()) {
267
+ if (forChainId !== undefined && forChainId !== processor.getChainId().toString()) {
268
+ continue
269
+ }
252
270
  const accountConfig = AccountConfig.fromPartial({
253
271
  address: validateAndNormalizeAddress(processor.config.address),
254
272
  chainId: processor.getChainId().toString(),
@@ -257,8 +275,7 @@ export class EthPlugin extends Plugin {
257
275
  // TODO add interval
258
276
  for (const eventsHandler of processor.eventHandlers) {
259
277
  // associate id with filter
260
- preprocessHandlers.eventHandlers.push(eventsHandler.preprocessHandler ?? defaultPreprocessHandler)
261
- const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1
278
+ const handlerId = this.handlerRegister.register(eventsHandler.handler, processor.getChainId())
262
279
  const logConfig: LogHandlerConfig = {
263
280
  handlerId: handlerId,
264
281
  handlerName: eventsHandler.handlerName,
@@ -268,9 +285,7 @@ export class EthPlugin extends Plugin {
268
285
 
269
286
  for (const filter of eventsHandler.filters) {
270
287
  const topics = await filter.getTopicFilter()
271
- // if (!filter.topics) {
272
- // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
273
- // }
288
+
274
289
  let address = undefined
275
290
  if (filter.address) {
276
291
  address = filter.address.toString()
@@ -292,14 +307,15 @@ export class EthPlugin extends Plugin {
292
307
  }
293
308
  logConfig.filters.push(logFilter)
294
309
  }
310
+
295
311
  accountConfig.logConfigs.push(logConfig)
296
312
  }
297
313
 
298
314
  config.accountConfigs.push(accountConfig)
299
315
  }
300
316
 
301
- this.handlers = handlers
302
- this.preprocessHandlers = preprocessHandlers
317
+ // this.handlers = handlers
318
+ // this.preprocessHandlers = preprocessHandlers
303
319
  }
304
320
 
305
321
  supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE, HandlerType.ETH_TRANSACTION]
@@ -320,21 +336,6 @@ export class EthPlugin extends Plugin {
320
336
  }
321
337
  }
322
338
 
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
339
  async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {
339
340
  let data: any
340
341
  switch (request.handlerType) {
@@ -408,87 +409,6 @@ export class EthPlugin extends Plugin {
408
409
  return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
409
410
  }
410
411
 
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
412
  async processLog(request: DataBinding, preparedData: PreparedData | undefined): Promise<ProcessResult> {
493
413
  if (!request.data?.ethLog?.log) {
494
414
  throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
@@ -497,8 +417,8 @@ export class EthPlugin extends Plugin {
497
417
 
498
418
  const promises: Promise<ProcessResult>[] = []
499
419
  for (const handlerId of request.handlerIds) {
500
- const handler = this.handlers.eventHandlers[handlerId]
501
- const promise = handler(ethLog, preparedData).catch((e) => {
420
+ const handler = this.handlerRegister.getHandlerById(handlerId)
421
+ const promise = handler(ethLog, preparedData).catch((e: any) => {
502
422
  console.error('error processing log: ', e)
503
423
  throw new ServerError(
504
424
  Status.INTERNAL,
@@ -522,13 +442,15 @@ export class EthPlugin extends Plugin {
522
442
  const promises: Promise<ProcessResult>[] = []
523
443
 
524
444
  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
- })
445
+ const promise = this.handlerRegister
446
+ .getHandlerById(handlerId)(ethTrace, preparedData)
447
+ .catch((e: any) => {
448
+ console.error('error processing trace: ', e)
449
+ throw new ServerError(
450
+ Status.INTERNAL,
451
+ 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
452
+ )
453
+ })
532
454
  if (GLOBAL_CONFIG.execution.sequential) {
533
455
  await promise
534
456
  }
@@ -545,13 +467,15 @@ export class EthPlugin extends Plugin {
545
467
 
546
468
  const promises: Promise<ProcessResult>[] = []
547
469
  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
- })
470
+ const promise = this.handlerRegister
471
+ .getHandlerById(handlerId)(ethBlock, preparedData)
472
+ .catch((e: any) => {
473
+ console.error('error processing block: ', e)
474
+ throw new ServerError(
475
+ Status.INTERNAL,
476
+ 'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
477
+ )
478
+ })
555
479
  if (GLOBAL_CONFIG.execution.sequential) {
556
480
  await promise
557
481
  }
@@ -569,12 +493,14 @@ export class EthPlugin extends Plugin {
569
493
  const promises: Promise<ProcessResult>[] = []
570
494
 
571
495
  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
- })
496
+ const promise = this.handlerRegister
497
+ .getHandlerById(handlerId)(ethTransaction, preparedData)
498
+ .catch((e: any) => {
499
+ throw new ServerError(
500
+ Status.INTERNAL,
501
+ 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
502
+ )
503
+ })
578
504
  if (GLOBAL_CONFIG.execution.sequential) {
579
505
  await promise
580
506
  }
package/src/eth/eth.ts CHANGED
@@ -150,34 +150,39 @@ export function formatEthData(data: {
150
150
  return data.__formattedEthData
151
151
  }
152
152
 
153
- const log = data.log ? formatLog(data.log) : undefined
154
- if (data.block && !data.block.transactions) {
155
- data.block.transactions = []
156
- }
157
- const block = data.block ? formatRichBlock(data.block) : undefined
158
- const trace = data.trace ? (data.trace as Trace) : undefined
159
- let transaction = undefined
160
- if (data.transaction) {
161
- if (!data.transaction.v) {
162
- data.transaction.v = '0x1c'
163
- data.transaction.r = '0x88ff6cf0fefd94db46111149ae4bfc179e9b94721fffd821d38d16464b3f71d0'
164
- data.transaction.s = '0x45e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a'
153
+ try {
154
+ const log = data.log ? formatLog(data.log) : undefined
155
+ if (data.block && !data.block.transactions) {
156
+ data.block.transactions = []
157
+ }
158
+ const block = data.block ? formatRichBlock(data.block) : undefined
159
+ const trace = data.trace ? (data.trace as Trace) : undefined
160
+ let transaction = undefined
161
+ if (data.transaction) {
162
+ if (!data.transaction.v) {
163
+ data.transaction.v = '0x1c'
164
+ data.transaction.r = '0x88ff6cf0fefd94db46111149ae4bfc179e9b94721fffd821d38d16464b3f71d0'
165
+ data.transaction.s = '0x45e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a'
166
+ }
167
+ transaction = formatTransactionResponse(data.transaction)
168
+ }
169
+ const transactionReceipt = data.transactionReceipt ? formatTransactionReceipt(data.transactionReceipt) : undefined
170
+
171
+ const result = {
172
+ log,
173
+ block,
174
+ trace,
175
+ transaction,
176
+ transactionReceipt
165
177
  }
166
- transaction = formatTransactionResponse(data.transaction)
167
- }
168
- const transactionReceipt = data.transactionReceipt ? formatTransactionReceipt(data.transactionReceipt) : undefined
169
-
170
- const result = {
171
- log,
172
- block,
173
- trace,
174
- transaction,
175
- transactionReceipt
176
- }
177
178
 
178
- // Cache the result on the input data object
179
- data.__formattedEthData = result
180
- return result
179
+ // Cache the result on the input data object
180
+ data.__formattedEthData = result
181
+ return result
182
+ } catch (e) {
183
+ console.error('Error formatting eth data', e)
184
+ return data
185
+ }
181
186
  }
182
187
 
183
188
  export function formatRichBlock(block: RichBlock): RichBlock {
@@ -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
  }