@sentio/sdk 2.59.5-rc.1 → 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.
- 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/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-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/btc/btc-plugin.ts +33 -32
- package/src/core/core-plugin.ts +11 -2
- 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
@@ -1,11 +1,12 @@
|
|
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
|
AccountConfig,
|
5
6
|
ContractConfig,
|
6
|
-
Data_AptCall,
|
7
7
|
DataBinding,
|
8
8
|
HandlerType,
|
9
|
+
InitResponse,
|
9
10
|
MoveCallHandlerConfig,
|
10
11
|
MoveEventHandlerConfig,
|
11
12
|
MoveOwnerType,
|
@@ -27,26 +28,21 @@ import {
|
|
27
28
|
AptosResourceProcessorTemplateState
|
28
29
|
} from './aptos-resource-processor-template.js'
|
29
30
|
import { AptosNetwork } from './network.js'
|
30
|
-
import {
|
31
|
-
|
32
|
-
interface Handlers {
|
33
|
-
aptosEventHandlers: ((event: AptEvent) => Promise<ProcessResult>)[]
|
34
|
-
aptosCallHandlers: ((func: AptCall) => Promise<ProcessResult>)[]
|
35
|
-
aptosResourceHandlers: ((resourceWithVersion: AptResource) => Promise<ProcessResult>)[]
|
36
|
-
aptosTransactionIntervalHandlers: ((txn: Data_AptCall) => Promise<ProcessResult>)[]
|
37
|
-
}
|
31
|
+
import { AptCall, AptEvent, AptResource } from './data.js'
|
38
32
|
|
39
33
|
export class AptosPlugin extends Plugin {
|
40
34
|
name: string = 'AptosPlugin'
|
41
|
-
|
42
|
-
aptosEventHandlers: [],
|
43
|
-
aptosCallHandlers: [],
|
44
|
-
aptosResourceHandlers: [],
|
45
|
-
aptosTransactionIntervalHandlers: []
|
46
|
-
}
|
47
|
-
|
35
|
+
handlerRegister = new HandlerRegister()
|
48
36
|
partitionManager = new PartitionHandlerManager()
|
49
37
|
|
38
|
+
async init(config: InitResponse) {
|
39
|
+
for (const state of [AptosProcessorState.INSTANCE, AptosResourceProcessorState.INSTANCE]) {
|
40
|
+
for (const aptosProcessor of state.getValues()) {
|
41
|
+
config.chainIds.push(aptosProcessor.getChainId())
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
50
46
|
async start(request: StartRequest) {
|
51
47
|
await initTokenList()
|
52
48
|
|
@@ -72,14 +68,13 @@ export class AptosPlugin extends Plugin {
|
|
72
68
|
}
|
73
69
|
}
|
74
70
|
|
75
|
-
async configure(config: ProcessConfigResponse) {
|
76
|
-
|
77
|
-
aptosTransactionIntervalHandlers: [],
|
78
|
-
aptosEventHandlers: [],
|
79
|
-
aptosCallHandlers: [],
|
80
|
-
aptosResourceHandlers: []
|
81
|
-
}
|
71
|
+
async configure(config: ProcessConfigResponse, forChainId?: string) {
|
72
|
+
this.handlerRegister.clear(forChainId as any)
|
82
73
|
for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
|
74
|
+
const chainId = aptosProcessor.getChainId()
|
75
|
+
if (forChainId !== undefined && forChainId !== chainId.toString()) {
|
76
|
+
continue
|
77
|
+
}
|
83
78
|
const contractConfig = ContractConfig.fromPartial({
|
84
79
|
processorType: USER_PROCESSOR,
|
85
80
|
contract: {
|
@@ -93,7 +88,7 @@ export class AptosPlugin extends Plugin {
|
|
93
88
|
})
|
94
89
|
// 1. Prepare event handlers
|
95
90
|
for (const handler of aptosProcessor.eventHandlers) {
|
96
|
-
const handlerId =
|
91
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
97
92
|
this.partitionManager.registerPartitionHandler(HandlerType.APT_EVENT, handlerId, handler.partitionHandler)
|
98
93
|
const eventHandlerConfig: MoveEventHandlerConfig = {
|
99
94
|
filters: handler.filters.map((f) => {
|
@@ -112,7 +107,7 @@ export class AptosPlugin extends Plugin {
|
|
112
107
|
|
113
108
|
// 2. Prepare function handlers
|
114
109
|
for (const handler of aptosProcessor.callHandlers) {
|
115
|
-
const handlerId =
|
110
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
116
111
|
this.partitionManager.registerPartitionHandler(HandlerType.APT_CALL, handlerId, handler.partitionHandler)
|
117
112
|
const functionHandlerConfig: MoveCallHandlerConfig = {
|
118
113
|
filters: handler.filters.map((filter) => {
|
@@ -137,6 +132,10 @@ export class AptosPlugin extends Plugin {
|
|
137
132
|
|
138
133
|
// Prepare resource handlers
|
139
134
|
for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
|
135
|
+
const chainId = aptosProcessor.getChainId()
|
136
|
+
if (forChainId !== undefined && forChainId !== chainId.toString()) {
|
137
|
+
continue
|
138
|
+
}
|
140
139
|
const accountConfig = AccountConfig.fromPartial({
|
141
140
|
address: aptosProcessor.config.address,
|
142
141
|
chainId: aptosProcessor.getChainId(),
|
@@ -144,7 +143,7 @@ export class AptosPlugin extends Plugin {
|
|
144
143
|
endBlock: aptosProcessor.config.endVersion
|
145
144
|
})
|
146
145
|
for (const handler of aptosProcessor.resourceChangeHandlers) {
|
147
|
-
const handlerId =
|
146
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
148
147
|
this.partitionManager.registerPartitionHandler(HandlerType.APT_RESOURCE, handlerId, handler.partitionHandler)
|
149
148
|
accountConfig.moveResourceChangeConfigs.push({
|
150
149
|
handlerId: handlerId,
|
@@ -156,7 +155,7 @@ export class AptosPlugin extends Plugin {
|
|
156
155
|
|
157
156
|
// Prepare interval handlers
|
158
157
|
for (const handler of aptosProcessor.transactionIntervalHandlers) {
|
159
|
-
const handlerId =
|
158
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
160
159
|
this.partitionManager.registerPartitionHandler(HandlerType.APT_CALL, handlerId, handler.partitionHandler)
|
161
160
|
accountConfig.moveIntervalConfigs.push({
|
162
161
|
intervalConfig: {
|
@@ -179,6 +178,10 @@ export class AptosPlugin extends Plugin {
|
|
179
178
|
}
|
180
179
|
|
181
180
|
for (const aptosProcessor of AptosResourceProcessorState.INSTANCE.getValues()) {
|
181
|
+
const chainId = aptosProcessor.getChainId()
|
182
|
+
if (forChainId !== undefined && forChainId !== chainId.toString()) {
|
183
|
+
continue
|
184
|
+
}
|
182
185
|
const accountConfig = AccountConfig.fromPartial({
|
183
186
|
address: aptosProcessor.config.address,
|
184
187
|
chainId: aptosProcessor.getChainId(),
|
@@ -186,7 +189,7 @@ export class AptosPlugin extends Plugin {
|
|
186
189
|
endBlock: aptosProcessor.config.endVersion
|
187
190
|
})
|
188
191
|
for (const handler of aptosProcessor.resourceIntervalHandlers) {
|
189
|
-
const handlerId =
|
192
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
190
193
|
this.partitionManager.registerPartitionHandler(HandlerType.APT_RESOURCE, handlerId, handler.partitionHandler)
|
191
194
|
if (handler.timeIntervalInMinutes || handler.versionInterval) {
|
192
195
|
accountConfig.moveIntervalConfigs.push({
|
@@ -216,7 +219,6 @@ export class AptosPlugin extends Plugin {
|
|
216
219
|
}
|
217
220
|
config.accountConfigs.push(accountConfig)
|
218
221
|
}
|
219
|
-
this.handlers = handlers
|
220
222
|
}
|
221
223
|
|
222
224
|
supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]
|
@@ -276,12 +278,14 @@ export class AptosPlugin extends Plugin {
|
|
276
278
|
const event = new AptEvent(binding.data.aptEvent)
|
277
279
|
|
278
280
|
for (const handlerId of binding.handlerIds) {
|
279
|
-
const promise = this.
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
281
|
+
const promise = this.handlerRegister
|
282
|
+
.getHandlerById(handlerId)(event)
|
283
|
+
.catch((e: any) => {
|
284
|
+
throw new ServerError(
|
285
|
+
Status.INTERNAL,
|
286
|
+
'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
|
287
|
+
)
|
288
|
+
})
|
285
289
|
if (GLOBAL_CONFIG.execution.sequential) {
|
286
290
|
await promise
|
287
291
|
}
|
@@ -298,12 +302,14 @@ export class AptosPlugin extends Plugin {
|
|
298
302
|
|
299
303
|
const promises: Promise<ProcessResult>[] = []
|
300
304
|
for (const handlerId of binding.handlerIds) {
|
301
|
-
const promise = this.
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
305
|
+
const promise = this.handlerRegister
|
306
|
+
.getHandlerById(handlerId)(resource)
|
307
|
+
.catch((e: any) => {
|
308
|
+
throw new ServerError(
|
309
|
+
Status.INTERNAL,
|
310
|
+
'error processing resource: ' + JSON.stringify(resource) + '\n' + errorString(e)
|
311
|
+
)
|
312
|
+
})
|
307
313
|
if (GLOBAL_CONFIG.execution.sequential) {
|
308
314
|
await promise
|
309
315
|
}
|
@@ -321,9 +327,14 @@ export class AptosPlugin extends Plugin {
|
|
321
327
|
const promises: Promise<ProcessResult>[] = []
|
322
328
|
for (const handlerId of binding.handlerIds) {
|
323
329
|
// only support aptos call for now
|
324
|
-
const promise = this.
|
325
|
-
|
326
|
-
|
330
|
+
const promise = this.handlerRegister
|
331
|
+
.getHandlerById(handlerId)(call)
|
332
|
+
.catch((e: any) => {
|
333
|
+
throw new ServerError(
|
334
|
+
Status.INTERNAL,
|
335
|
+
'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e)
|
336
|
+
)
|
337
|
+
})
|
327
338
|
if (GLOBAL_CONFIG.execution.sequential) {
|
328
339
|
await promise
|
329
340
|
}
|
package/src/btc/btc-plugin.ts
CHANGED
@@ -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
|
-
|
28
|
-
txHandlers: [],
|
29
|
-
blockHandlers: []
|
30
|
-
}
|
31
|
-
|
22
|
+
handlerRegister = new HandlerRegister()
|
32
23
|
partitionManager = new PartitionHandlerManager()
|
33
24
|
|
34
|
-
async
|
35
|
-
const
|
36
|
-
|
37
|
-
|
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 =
|
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 =
|
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.
|
165
|
-
|
166
|
-
|
167
|
-
|
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.
|
188
|
-
|
189
|
-
|
190
|
-
|
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
|
}
|
package/src/core/core-plugin.ts
CHANGED
@@ -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'
|
@@ -24,7 +24,6 @@ export class CorePlugin extends Plugin {
|
|
24
24
|
...metric.config
|
25
25
|
})
|
26
26
|
}
|
27
|
-
|
28
27
|
for (const event of EventLoggerState.INSTANCE.getValues()) {
|
29
28
|
config.eventLogConfigs.push({
|
30
29
|
...event.config
|
@@ -46,6 +45,16 @@ export class CorePlugin extends Plugin {
|
|
46
45
|
}
|
47
46
|
}
|
48
47
|
}
|
48
|
+
|
49
|
+
async init(config: InitResponse): Promise<void> {
|
50
|
+
if (DatabaseSchemaState.INSTANCE.getValues().length > 0) {
|
51
|
+
config.dbSchema = {
|
52
|
+
gqlSchema: DatabaseSchemaState.INSTANCE.getValues()
|
53
|
+
.map((e) => e.source)
|
54
|
+
.join('\n\n')
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
49
58
|
}
|
50
59
|
|
51
60
|
PluginManager.INSTANCE.register(new CorePlugin())
|
@@ -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
|
}
|