@sentio/sdk 2.59.5-rc.1 → 2.60.0-rc.2
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.
- package/lib/aptos/aptos-plugin.d.ts +5 -11
- package/lib/aptos/aptos-plugin.d.ts.map +1 -1
- package/lib/aptos/aptos-plugin.js +38 -23
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +1 -0
- package/lib/aptos/aptos-processor.d.ts.map +1 -1
- package/lib/aptos/aptos-processor.js +11 -3
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/btc/btc-plugin.d.ts +5 -8
- package/lib/btc/btc-plugin.d.ts.map +1 -1
- package/lib/btc/btc-plugin.js +22 -14
- package/lib/btc/btc-plugin.js.map +1 -1
- package/lib/core/core-plugin.d.ts +2 -1
- package/lib/core/core-plugin.d.ts.map +1 -1
- package/lib/core/core-plugin.js +9 -0
- package/lib/core/core-plugin.js.map +1 -1
- package/lib/core/handler-options.d.ts +6 -0
- package/lib/core/handler-options.d.ts.map +1 -1
- package/lib/core/handler-options.js.map +1 -1
- package/lib/core/handler-register.d.ts +18 -0
- package/lib/core/handler-register.d.ts.map +1 -0
- package/lib/core/handler-register.js +62 -0
- package/lib/core/handler-register.js.map +1 -0
- package/lib/cosmos/cosmos-plugin.d.ts +5 -7
- package/lib/cosmos/cosmos-plugin.d.ts.map +1 -1
- package/lib/cosmos/cosmos-plugin.js +18 -10
- package/lib/cosmos/cosmos-plugin.js.map +1 -1
- package/lib/eth/eth-plugin.d.ts +5 -40
- package/lib/eth/eth-plugin.d.ts.map +1 -1
- package/lib/eth/eth-plugin.js +41 -117
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/fuel/fuel-plugin.d.ts +5 -9
- package/lib/fuel/fuel-plugin.d.ts.map +1 -1
- package/lib/fuel/fuel-plugin.js +26 -18
- package/lib/fuel/fuel-plugin.js.map +1 -1
- package/lib/solana/solana-plugin.d.ts +3 -2
- package/lib/solana/solana-plugin.d.ts.map +1 -1
- package/lib/solana/solana-plugin.js +11 -1
- package/lib/solana/solana-plugin.js.map +1 -1
- package/lib/stark/starknet-plugin.d.ts +5 -7
- package/lib/stark/starknet-plugin.d.ts.map +1 -1
- package/lib/stark/starknet-plugin.js +18 -10
- package/lib/stark/starknet-plugin.js.map +1 -1
- package/lib/sui/sui-plugin.d.ts +5 -10
- package/lib/sui/sui-plugin.d.ts.map +1 -1
- package/lib/sui/sui-plugin.js +37 -24
- package/lib/sui/sui-plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/aptos/aptos-plugin.ts +55 -44
- package/src/aptos/aptos-processor.ts +15 -3
- package/src/btc/btc-plugin.ts +33 -32
- package/src/core/core-plugin.ts +11 -2
- package/src/core/handler-options.ts +7 -0
- package/src/core/handler-register.ts +79 -0
- package/src/cosmos/cosmos-plugin.ts +24 -20
- package/src/eth/eth-plugin.ts +62 -182
- package/src/fuel/fuel-plugin.ts +43 -44
- package/src/solana/solana-plugin.ts +20 -2
- package/src/stark/starknet-plugin.ts +24 -20
- package/src/sui/sui-plugin.ts +58 -52
@@ -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
|
-
|
22
|
-
callHandlers: []
|
23
|
-
}
|
18
|
+
handlerRegister = new HandlerRegister()
|
24
19
|
|
25
|
-
async
|
26
|
-
const
|
27
|
-
|
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 =
|
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.
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
}
|
package/src/eth/eth-plugin.ts
CHANGED
@@ -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 {
|
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
|
-
|
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
|
76
|
-
const
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
114
|
-
|
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
|
-
|
132
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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.
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
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.
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
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.
|
573
|
-
|
574
|
-
|
575
|
-
|
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
|
}
|