@sentio/sdk 1.19.3 → 1.19.5
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-processor.d.ts +40 -0
- package/lib/aptos/aptos-processor.js +126 -0
- package/lib/aptos/aptos-processor.js.map +1 -0
- package/lib/aptos/bind-options.d.ts +11 -0
- package/lib/aptos/bind-options.js +17 -0
- package/lib/aptos/bind-options.js.map +1 -0
- package/lib/aptos/context.d.ts +12 -0
- package/lib/aptos/context.js +33 -0
- package/lib/aptos/context.js.map +1 -0
- package/lib/aptos/index.d.ts +5 -0
- package/lib/aptos/index.js +11 -0
- package/lib/aptos/index.js.map +1 -0
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +1 -1
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/bind-options.d.ts +0 -2
- package/lib/core/bind-options.js +1 -4
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +10 -10
- package/lib/core/context.js +65 -11
- package/lib/core/context.js.map +1 -1
- package/lib/core/generic-processor.test.js +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/index.d.ts +1 -2
- package/lib/core/index.js +1 -4
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +6 -3
- package/lib/core/logger.js +15 -9
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +1 -1
- package/lib/core/metadata.js +3 -79
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +1 -1
- package/lib/core/meter.js +2 -2
- package/lib/core/meter.js.map +1 -1
- package/lib/core/numberish.d.ts +1 -1
- package/lib/core/numberish.js +7 -7
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/numberish.test.js.map +1 -1
- package/lib/core/solana-processor.d.ts +1 -1
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/gen/index.d.ts +1 -0
- package/lib/gen/index.js +18 -0
- package/lib/gen/index.js.map +1 -0
- package/lib/gen/processor/protos/processor.d.ts +165 -163
- package/lib/gen/processor/protos/processor.js +455 -482
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +15 -2
- package/lib/index.js.map +1 -1
- package/lib/processor-state.d.ts +2 -1
- package/lib/processor-state.js.map +1 -1
- package/lib/service.d.ts +13 -7
- package/lib/service.js +133 -44
- package/lib/service.js.map +1 -1
- package/lib/testing/metric-utils.d.ts +1 -1
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +16 -15
- package/lib/testing/test-processor-server.js +19 -14
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +2 -2
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/tests/aptos.test.js +44 -12
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/erc20.test.js +1 -1
- package/lib/tests/erc20.test.js.map +1 -1
- package/lib/tests/logger.test.js +1 -1
- package/lib/tests/logger.test.js.map +1 -1
- package/lib/tests/souffl3.js +16 -4
- package/lib/tests/souffl3.js.map +1 -1
- package/lib/utils/chain.d.ts +1 -0
- package/lib/utils/chain.js +3 -1
- package/lib/utils/chain.js.map +1 -1
- package/lib/utils/erc20.test.js +0 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/package.json +3 -5
- package/src/aptos/aptos-processor.ts +156 -0
- package/src/aptos/bind-options.ts +15 -0
- package/src/aptos/context.ts +35 -0
- package/src/aptos/index.ts +8 -0
- package/src/core/base-processor-template.ts +1 -1
- package/src/core/base-processor.ts +1 -1
- package/src/core/bind-options.ts +0 -1
- package/src/core/context.ts +74 -15
- package/src/core/generic-processor.test.ts +1 -1
- package/src/core/index.ts +2 -2
- package/src/core/logger.ts +13 -5
- package/src/core/metadata.ts +4 -76
- package/src/core/meter.ts +1 -1
- package/src/core/numberish.test.ts +1 -1
- package/src/core/numberish.ts +1 -1
- package/src/core/solana-processor.ts +1 -1
- package/src/core/sui-processor.ts +1 -1
- package/src/gen/index.ts +1 -0
- package/src/gen/processor/protos/processor.ts +606 -650
- package/src/index.ts +4 -1
- package/src/processor-state.ts +3 -1
- package/src/service.ts +153 -61
- package/src/testing/metric-utils.ts +2 -2
- package/src/testing/test-processor-server.ts +31 -33
- package/src/testing/test-provider.ts +1 -1
- package/src/tests/aptos.test.ts +47 -11
- package/src/tests/erc20.test.ts +1 -1
- package/src/tests/logger.test.ts +1 -1
- package/src/tests/souffl3.ts +30 -12
- package/src/utils/chain.ts +2 -0
- package/src/utils/erc20.test.ts +1 -4
- package/lib/core/aptos-processor.d.ts +0 -22
- package/lib/core/aptos-processor.js +0 -67
- package/lib/core/aptos-processor.js.map +0 -1
- package/src/core/aptos-processor.ts +0 -77
package/src/index.ts
CHANGED
|
@@ -7,5 +7,8 @@ export { EthersError } from './error'
|
|
|
7
7
|
|
|
8
8
|
export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'
|
|
9
9
|
|
|
10
|
-
export * from './gen
|
|
10
|
+
export * from './gen'
|
|
11
|
+
|
|
11
12
|
export * from './core'
|
|
13
|
+
|
|
14
|
+
export * as aptos from './aptos'
|
package/src/processor-state.ts
CHANGED
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
BaseProcessorTemplate,
|
|
6
6
|
SolanaBaseProcessor,
|
|
7
7
|
SuiBaseProcessor,
|
|
8
|
-
AptosBaseProcessor,
|
|
9
8
|
} from './core'
|
|
9
|
+
|
|
10
|
+
import { AptosBaseProcessor } from './aptos'
|
|
11
|
+
|
|
10
12
|
import { BaseContract } from 'ethers'
|
|
11
13
|
import { TemplateInstance } from './gen/processor/protos/processor'
|
|
12
14
|
import { Provider } from '@ethersproject/providers'
|
package/src/service.ts
CHANGED
|
@@ -3,29 +3,26 @@ import { CallContext, ServerError, Status } from 'nice-grpc'
|
|
|
3
3
|
import { APTOS_TESTNET_ID, SOL_MAINMET_ID, SUI_DEVNET_ID } from './utils/chain'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
AptosCallHandlerConfig,
|
|
7
|
+
AptosEventHandlerConfig,
|
|
6
8
|
BlockBinding,
|
|
7
9
|
ContractConfig,
|
|
10
|
+
DataBinding,
|
|
8
11
|
HandlerType,
|
|
9
12
|
LogFilter,
|
|
10
13
|
LogHandlerConfig,
|
|
11
|
-
|
|
14
|
+
ProcessBindingResponse,
|
|
15
|
+
ProcessBindingsRequest,
|
|
12
16
|
ProcessBlocksRequest,
|
|
13
|
-
ProcessBlocksResponse,
|
|
14
17
|
ProcessConfigRequest,
|
|
15
18
|
ProcessConfigResponse,
|
|
16
19
|
ProcessInstructionsRequest,
|
|
17
|
-
ProcessInstructionsResponse,
|
|
18
|
-
ProcessLogsRequest,
|
|
19
|
-
ProcessLogsResponse,
|
|
20
20
|
ProcessorServiceImplementation,
|
|
21
|
-
|
|
22
|
-
ProcessTracesResponse,
|
|
21
|
+
ProcessResult,
|
|
23
22
|
ProcessTransactionsRequest,
|
|
24
|
-
ProcessTransactionsResponse,
|
|
25
23
|
StartRequest,
|
|
26
24
|
TemplateInstance,
|
|
27
|
-
|
|
28
|
-
} from './gen/processor/protos/processor'
|
|
25
|
+
} from './gen'
|
|
29
26
|
|
|
30
27
|
import { Empty } from './gen/google/protobuf/empty'
|
|
31
28
|
import Long from 'long'
|
|
@@ -40,6 +37,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
40
37
|
private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []
|
|
41
38
|
private traceHandlers: ((trace: Trace) => Promise<ProcessResult>)[] = []
|
|
42
39
|
private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []
|
|
40
|
+
private aptosEventHandlers: ((event: any) => Promise<ProcessResult>)[] = []
|
|
41
|
+
private aptosCallHandlers: ((func: any) => Promise<ProcessResult>)[] = []
|
|
43
42
|
|
|
44
43
|
// map from chain id to list of processors
|
|
45
44
|
// private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()
|
|
@@ -98,6 +97,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
98
97
|
startBlock: processor.config.startBlock,
|
|
99
98
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
100
99
|
instructionConfig: undefined,
|
|
100
|
+
aptosEventConfigs: [],
|
|
101
|
+
aptosCallConfigs: [],
|
|
101
102
|
}
|
|
102
103
|
if (processor.config.endBlock) {
|
|
103
104
|
contractConfig.endBlock = processor.config.endBlock
|
|
@@ -106,6 +107,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
106
107
|
// Step 1. Prepare all the block handlers
|
|
107
108
|
for (const blockHandler of processor.blockHandlers) {
|
|
108
109
|
const handlerId = this.blockHandlers.push(blockHandler) - 1
|
|
110
|
+
// TODO wrap the block handler into one
|
|
111
|
+
|
|
109
112
|
contractConfig.blockConfigs.push({
|
|
110
113
|
handlerId: handlerId,
|
|
111
114
|
})
|
|
@@ -161,7 +164,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
161
164
|
processorType: USER_PROCESSOR,
|
|
162
165
|
contract: {
|
|
163
166
|
name: solanaProcessor.contractName,
|
|
164
|
-
chainId: SOL_MAINMET_ID,
|
|
167
|
+
chainId: SOL_MAINMET_ID,
|
|
165
168
|
address: solanaProcessor.address,
|
|
166
169
|
abi: '',
|
|
167
170
|
},
|
|
@@ -175,6 +178,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
175
178
|
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
176
179
|
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
177
180
|
},
|
|
181
|
+
aptosEventConfigs: [],
|
|
182
|
+
aptosCallConfigs: [],
|
|
178
183
|
}
|
|
179
184
|
this.contractConfigs.push(contractConfig)
|
|
180
185
|
}
|
|
@@ -195,6 +200,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
195
200
|
startBlock: suiProcessor.config.startSeqNumber,
|
|
196
201
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
197
202
|
instructionConfig: undefined,
|
|
203
|
+
aptosEventConfigs: [],
|
|
204
|
+
aptosCallConfigs: [],
|
|
198
205
|
}
|
|
199
206
|
this.contractConfigs.push(contractConfig)
|
|
200
207
|
}
|
|
@@ -206,15 +213,42 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
206
213
|
contract: {
|
|
207
214
|
name: aptosProcessor.name,
|
|
208
215
|
chainId: APTOS_TESTNET_ID,
|
|
209
|
-
address: aptosProcessor.address,
|
|
216
|
+
address: aptosProcessor.config.address,
|
|
210
217
|
abi: '',
|
|
211
218
|
},
|
|
212
219
|
blockConfigs: [],
|
|
213
220
|
logConfigs: [],
|
|
214
221
|
traceConfigs: [],
|
|
215
|
-
startBlock: aptosProcessor.config.
|
|
222
|
+
startBlock: aptosProcessor.config.startVersion,
|
|
216
223
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
217
224
|
instructionConfig: undefined,
|
|
225
|
+
aptosEventConfigs: [],
|
|
226
|
+
aptosCallConfigs: [],
|
|
227
|
+
}
|
|
228
|
+
// 1. Prepare event handlers
|
|
229
|
+
for (const handler of aptosProcessor.eventHandlers) {
|
|
230
|
+
const handlerId = this.aptosEventHandlers.push(handler.handler) - 1
|
|
231
|
+
const eventHandlerConfig: AptosEventHandlerConfig = {
|
|
232
|
+
filters: handler.filters,
|
|
233
|
+
handlerId,
|
|
234
|
+
}
|
|
235
|
+
contractConfig.aptosEventConfigs.push(eventHandlerConfig)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 2. Prepare function handlers
|
|
239
|
+
for (const handler of aptosProcessor.callHandlers) {
|
|
240
|
+
const handlerId = this.aptosCallHandlers.push(handler.handler) - 1
|
|
241
|
+
const functionHandlerConfig: AptosCallHandlerConfig = {
|
|
242
|
+
filters: handler.filters.map((filter) => {
|
|
243
|
+
return {
|
|
244
|
+
function: filter.function,
|
|
245
|
+
typeArguments: filter.typeArguments ?? [],
|
|
246
|
+
withTypeArguments: filter.typeArguments ? true : false,
|
|
247
|
+
}
|
|
248
|
+
}),
|
|
249
|
+
handlerId,
|
|
250
|
+
}
|
|
251
|
+
contractConfig.aptosCallConfigs.push(functionHandlerConfig)
|
|
218
252
|
}
|
|
219
253
|
this.contractConfigs.push(contractConfig)
|
|
220
254
|
}
|
|
@@ -264,21 +298,55 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
264
298
|
return {}
|
|
265
299
|
}
|
|
266
300
|
|
|
267
|
-
async
|
|
301
|
+
async processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse> {
|
|
302
|
+
if (!this.started) {
|
|
303
|
+
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const promises = request.bindings.map((binding) => this.processBinding(binding))
|
|
307
|
+
const result = mergeProcessResults(await Promise.all(promises))
|
|
308
|
+
|
|
309
|
+
let updated = false
|
|
310
|
+
if (
|
|
311
|
+
global.PROCESSOR_STATE.templatesInstances &&
|
|
312
|
+
this.templateInstances.length != global.PROCESSOR_STATE.templatesInstances.length
|
|
313
|
+
) {
|
|
314
|
+
await this.configure()
|
|
315
|
+
updated = true
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return {
|
|
319
|
+
result,
|
|
320
|
+
configUpdated: updated,
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult> {
|
|
325
|
+
switch (request.handlerType) {
|
|
326
|
+
case HandlerType.APT_CALL:
|
|
327
|
+
return this.processAptosFunctionCall(request)
|
|
328
|
+
case HandlerType.APT_EVENT:
|
|
329
|
+
return this.processAptosEvent(request)
|
|
330
|
+
default:
|
|
331
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async processLogs(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse> {
|
|
268
336
|
if (!this.started) {
|
|
269
337
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
270
338
|
}
|
|
271
339
|
|
|
272
340
|
const promises: Promise<ProcessResult>[] = []
|
|
273
|
-
for (const l of request.
|
|
274
|
-
if (!l.
|
|
341
|
+
for (const l of request.bindings) {
|
|
342
|
+
if (!l.data) {
|
|
275
343
|
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
276
344
|
}
|
|
277
345
|
// const jsonString = Buffer.from(l.log.raw.buffer).toString("utf-8")
|
|
278
346
|
// const jsonString = String.fromCharCode.apply(null, l.log.raw)
|
|
279
347
|
|
|
280
348
|
try {
|
|
281
|
-
const jsonString = Utf8ArrayToStr(l.
|
|
349
|
+
const jsonString = Utf8ArrayToStr(l.data.raw)
|
|
282
350
|
const log: Log = JSON.parse(jsonString)
|
|
283
351
|
const handler = this.eventHandlers[l.handlerId]
|
|
284
352
|
const promise = handler(log).catch((e) => {
|
|
@@ -302,7 +370,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
302
370
|
updated = true
|
|
303
371
|
}
|
|
304
372
|
|
|
305
|
-
recordRuntimeInfo(result, HandlerType.
|
|
373
|
+
recordRuntimeInfo(result, HandlerType.ETH_LOG)
|
|
306
374
|
return {
|
|
307
375
|
result,
|
|
308
376
|
configUpdated: updated,
|
|
@@ -312,16 +380,12 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
312
380
|
async processTransactions(
|
|
313
381
|
request: ProcessTransactionsRequest,
|
|
314
382
|
context: CallContext
|
|
315
|
-
): Promise<
|
|
383
|
+
): Promise<ProcessBindingResponse> {
|
|
316
384
|
if (!this.started) {
|
|
317
385
|
throw new ServerError(Status.UNAVAILABLE, 'Service not started.')
|
|
318
386
|
}
|
|
319
387
|
|
|
320
|
-
const result
|
|
321
|
-
gauges: [],
|
|
322
|
-
counters: [],
|
|
323
|
-
logs: [],
|
|
324
|
-
}
|
|
388
|
+
const result = ProcessResult.fromPartial({})
|
|
325
389
|
|
|
326
390
|
if (request.chainId.toLowerCase().startsWith('sui') && global.PROCESSOR_STATE.suiProcessors) {
|
|
327
391
|
const processorPromises: Promise<void>[] = []
|
|
@@ -346,50 +410,47 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
346
410
|
await Promise.all(processorPromises)
|
|
347
411
|
}
|
|
348
412
|
|
|
349
|
-
if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
413
|
+
// if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
|
|
414
|
+
// const processorPromises: Promise<void>[] = []
|
|
415
|
+
// for (const txn of request.transactions) {
|
|
416
|
+
// processorPromises.push(
|
|
417
|
+
// new Promise((resolve, _) => {
|
|
418
|
+
// for (const processor of global.PROCESSOR_STATE.aptosProcessors) {
|
|
419
|
+
// if (processor.address === txn.programAccountId!) {
|
|
420
|
+
// const res = processor.handleTransaction(
|
|
421
|
+
// JSON.parse(new TextDecoder().decode(txn.raw)),
|
|
422
|
+
// txn.slot ?? Long.fromNumber(0)
|
|
423
|
+
// )
|
|
424
|
+
// if (res) {
|
|
425
|
+
// res.gauges.forEach((g) => result.gauges.push(g))
|
|
426
|
+
// res.counters.forEach((c) => result.counters.push(c))
|
|
427
|
+
// res.logs.forEach((l) => result.logs.push(l))
|
|
428
|
+
// }
|
|
429
|
+
// }
|
|
430
|
+
// }
|
|
431
|
+
// resolve()
|
|
432
|
+
// })
|
|
433
|
+
// )
|
|
434
|
+
// }
|
|
435
|
+
// await Promise.all(processorPromises)
|
|
436
|
+
// }
|
|
373
437
|
|
|
374
438
|
recordRuntimeInfo(result, HandlerType.TRANSACTION)
|
|
375
439
|
return {
|
|
376
440
|
result,
|
|
441
|
+
configUpdated: false,
|
|
377
442
|
}
|
|
378
443
|
}
|
|
379
444
|
|
|
380
445
|
async processInstructions(
|
|
381
446
|
request: ProcessInstructionsRequest,
|
|
382
447
|
context: CallContext
|
|
383
|
-
): Promise<
|
|
448
|
+
): Promise<ProcessBindingResponse> {
|
|
384
449
|
if (!this.started) {
|
|
385
450
|
throw new ServerError(Status.UNAVAILABLE, 'Service not started.')
|
|
386
451
|
}
|
|
387
452
|
|
|
388
|
-
const result
|
|
389
|
-
gauges: [],
|
|
390
|
-
counters: [],
|
|
391
|
-
logs: [],
|
|
392
|
-
}
|
|
453
|
+
const result = ProcessResult.fromPartial({})
|
|
393
454
|
|
|
394
455
|
// Only have instruction handlers for solana processors
|
|
395
456
|
if (global.PROCESSOR_STATE.solanaProcessors) {
|
|
@@ -436,10 +497,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
436
497
|
recordRuntimeInfo(result, HandlerType.INSTRUCTION)
|
|
437
498
|
return {
|
|
438
499
|
result,
|
|
500
|
+
configUpdated: false,
|
|
439
501
|
}
|
|
440
502
|
}
|
|
441
503
|
|
|
442
|
-
async processBlocks(request: ProcessBlocksRequest, context: CallContext): Promise<
|
|
504
|
+
async processBlocks(request: ProcessBlocksRequest, context: CallContext): Promise<ProcessBindingResponse> {
|
|
443
505
|
if (!this.started) {
|
|
444
506
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
445
507
|
}
|
|
@@ -450,6 +512,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
450
512
|
recordRuntimeInfo(result, HandlerType.BLOCK)
|
|
451
513
|
return {
|
|
452
514
|
result,
|
|
515
|
+
configUpdated: false,
|
|
453
516
|
}
|
|
454
517
|
}
|
|
455
518
|
|
|
@@ -471,31 +534,60 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
471
534
|
return mergeProcessResults(await Promise.all(promises))
|
|
472
535
|
}
|
|
473
536
|
|
|
474
|
-
async processTraces(request:
|
|
537
|
+
async processTraces(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse> {
|
|
475
538
|
if (!this.started) {
|
|
476
539
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
477
540
|
}
|
|
478
541
|
|
|
479
|
-
const promises = request.
|
|
542
|
+
const promises = request.bindings.map((binding) => this.processTrace(binding))
|
|
480
543
|
const result = mergeProcessResults(await Promise.all(promises))
|
|
481
544
|
|
|
482
|
-
recordRuntimeInfo(result, HandlerType.
|
|
545
|
+
recordRuntimeInfo(result, HandlerType.ETH_TRACE)
|
|
483
546
|
return {
|
|
484
547
|
result,
|
|
548
|
+
configUpdated: false,
|
|
485
549
|
}
|
|
486
550
|
}
|
|
487
551
|
|
|
488
|
-
async processTrace(binding:
|
|
489
|
-
if (!binding.
|
|
552
|
+
async processTrace(binding: DataBinding): Promise<ProcessResult> {
|
|
553
|
+
if (!binding.data) {
|
|
490
554
|
throw new ServerError(Status.INVALID_ARGUMENT, "Trace can't be empty")
|
|
491
555
|
}
|
|
492
|
-
const jsonString = Utf8ArrayToStr(binding.
|
|
556
|
+
const jsonString = Utf8ArrayToStr(binding.data.raw)
|
|
493
557
|
const trace: Trace = JSON.parse(jsonString)
|
|
494
558
|
|
|
495
559
|
return this.traceHandlers[binding.handlerId](trace).catch((e) => {
|
|
496
560
|
throw new ServerError(Status.INTERNAL, 'error processing trace: ' + jsonString + '\n' + errorString(e))
|
|
497
561
|
})
|
|
498
562
|
}
|
|
563
|
+
|
|
564
|
+
async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {
|
|
565
|
+
if (!binding.data) {
|
|
566
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
|
|
567
|
+
}
|
|
568
|
+
const jsonString = Utf8ArrayToStr(binding.data.raw)
|
|
569
|
+
const event = JSON.parse(jsonString)
|
|
570
|
+
// only support aptos event for now
|
|
571
|
+
const result = await this.aptosEventHandlers[binding.handlerId](event).catch((e) => {
|
|
572
|
+
throw new ServerError(Status.INTERNAL, 'error processing event: ' + jsonString + '\n' + errorString(e))
|
|
573
|
+
})
|
|
574
|
+
recordRuntimeInfo(result, HandlerType.APT_EVENT)
|
|
575
|
+
return result
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {
|
|
579
|
+
if (!binding.data) {
|
|
580
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
|
|
581
|
+
}
|
|
582
|
+
const jsonString = Utf8ArrayToStr(binding.data.raw)
|
|
583
|
+
const call = JSON.parse(jsonString)
|
|
584
|
+
// only support aptos call for now
|
|
585
|
+
const result = await this.aptosCallHandlers[binding.handlerId](call).catch((e) => {
|
|
586
|
+
throw new ServerError(Status.INTERNAL, 'error processing call: ' + jsonString + '\n' + errorString(e))
|
|
587
|
+
})
|
|
588
|
+
recordRuntimeInfo(result, HandlerType.APT_CALL)
|
|
589
|
+
return result
|
|
590
|
+
}
|
|
499
591
|
}
|
|
500
592
|
|
|
501
593
|
// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepPartial } from '../gen/builtin'
|
|
2
|
-
import {
|
|
3
|
-
import { Numberish } from '../core'
|
|
2
|
+
import { MetricValue, ProcessResult } from '../gen'
|
|
3
|
+
import { Numberish, BigDecimal } from '../core'
|
|
4
4
|
import { BigNumber } from 'ethers'
|
|
5
5
|
|
|
6
6
|
export function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined {
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BlockBinding,
|
|
3
3
|
ContractConfig,
|
|
4
|
-
|
|
4
|
+
DataBinding,
|
|
5
|
+
HandlerType,
|
|
6
|
+
ProcessBindingResponse,
|
|
7
|
+
ProcessBindingsRequest,
|
|
5
8
|
ProcessBlocksRequest,
|
|
6
|
-
ProcessBlocksResponse,
|
|
7
9
|
ProcessConfigRequest,
|
|
8
10
|
ProcessConfigResponse,
|
|
9
11
|
ProcessInstructionsRequest,
|
|
10
|
-
ProcessInstructionsResponse,
|
|
11
|
-
ProcessLogsRequest,
|
|
12
|
-
ProcessLogsResponse,
|
|
13
12
|
ProcessorServiceImpl,
|
|
14
13
|
ProcessorServiceImplementation,
|
|
15
14
|
ProcessorState,
|
|
16
|
-
ProcessTracesRequest,
|
|
17
|
-
ProcessTracesResponse,
|
|
18
15
|
ProcessTransactionsRequest,
|
|
19
|
-
ProcessTransactionsResponse,
|
|
20
16
|
setProvider,
|
|
21
17
|
StartRequest,
|
|
22
|
-
|
|
18
|
+
Trace,
|
|
23
19
|
} from '@sentio/sdk'
|
|
24
20
|
import { CallContext } from 'nice-grpc-common'
|
|
25
21
|
import { Empty } from '../gen/google/protobuf/empty'
|
|
@@ -28,9 +24,8 @@ import { CHAIN_MAP } from '../utils/chain'
|
|
|
28
24
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
29
25
|
import Long from 'long'
|
|
30
26
|
import { getNetwork, Networkish } from '@ethersproject/providers'
|
|
31
|
-
import { Trace } from '@sentio/sdk'
|
|
32
27
|
|
|
33
|
-
const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
28
|
+
export const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
34
29
|
|
|
35
30
|
function cleanTest() {
|
|
36
31
|
global.PROCESSOR_STATE = new ProcessorState()
|
|
@@ -71,37 +66,31 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
71
66
|
return this.service.getConfig(request, context)
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
processBlocks(request: ProcessBlocksRequest, context = TEST_CONTEXT): Promise<
|
|
69
|
+
processBlocks(request: ProcessBlocksRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
75
70
|
return this.service.processBlocks(request, context)
|
|
76
71
|
}
|
|
77
72
|
|
|
78
|
-
processInstructions(
|
|
79
|
-
request: ProcessInstructionsRequest,
|
|
80
|
-
context = TEST_CONTEXT
|
|
81
|
-
): Promise<ProcessInstructionsResponse> {
|
|
73
|
+
processInstructions(request: ProcessInstructionsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
82
74
|
return this.service.processInstructions(request, context)
|
|
83
75
|
}
|
|
84
76
|
|
|
85
|
-
processLogs(request:
|
|
77
|
+
processLogs(request: ProcessBindingsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
86
78
|
return this.service.processLogs(request, context)
|
|
87
79
|
}
|
|
88
80
|
|
|
89
|
-
processTraces(request:
|
|
81
|
+
processTraces(request: ProcessBindingsRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
90
82
|
return this.service.processTraces(request, context)
|
|
91
83
|
}
|
|
92
84
|
|
|
93
|
-
processTransactions(
|
|
94
|
-
request: ProcessTransactionsRequest,
|
|
95
|
-
context = TEST_CONTEXT
|
|
96
|
-
): Promise<ProcessTransactionsResponse> {
|
|
85
|
+
processTransactions(request: ProcessTransactionsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
97
86
|
return this.service.processTransactions(request, context)
|
|
98
87
|
}
|
|
99
88
|
|
|
100
|
-
testTrace(trace: Trace, network: Networkish = 1): Promise<
|
|
89
|
+
testTrace(trace: Trace, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
101
90
|
return this.testTraces([trace], network)
|
|
102
91
|
}
|
|
103
92
|
|
|
104
|
-
testTraces(traces: Trace[], network: Networkish = 1): Promise<
|
|
93
|
+
testTraces(traces: Trace[], network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
105
94
|
const bindings = []
|
|
106
95
|
for (const trace of traces) {
|
|
107
96
|
const binding = this.buildTraceBinding(trace, network)
|
|
@@ -111,11 +100,11 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
111
100
|
bindings.push(binding)
|
|
112
101
|
}
|
|
113
102
|
return this.processTraces({
|
|
114
|
-
|
|
103
|
+
bindings: bindings,
|
|
115
104
|
})
|
|
116
105
|
}
|
|
117
106
|
|
|
118
|
-
buildTraceBinding(trace: Trace, network: Networkish = 1):
|
|
107
|
+
buildTraceBinding(trace: Trace, network: Networkish = 1): DataBinding | undefined {
|
|
119
108
|
if (trace.type !== 'call' || !trace.action.input) {
|
|
120
109
|
throw Error('Invalid test trace: ' + JSON.stringify(trace))
|
|
121
110
|
}
|
|
@@ -131,10 +120,11 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
131
120
|
for (const config of contract.traceConfigs) {
|
|
132
121
|
if (config.signature == signature) {
|
|
133
122
|
return {
|
|
134
|
-
|
|
123
|
+
data: {
|
|
135
124
|
raw: toBytes(trace),
|
|
136
125
|
},
|
|
137
126
|
handlerId: config.handlerId,
|
|
127
|
+
handlerType: HandlerType.ETH_TRACE,
|
|
138
128
|
}
|
|
139
129
|
}
|
|
140
130
|
}
|
|
@@ -142,11 +132,11 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
142
132
|
return undefined
|
|
143
133
|
}
|
|
144
134
|
|
|
145
|
-
testLog(log: Log, network: Networkish = 1): Promise<
|
|
135
|
+
testLog(log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
146
136
|
return this.testLogs([log], network)
|
|
147
137
|
}
|
|
148
138
|
|
|
149
|
-
testLogs(logs: Log[], network: Networkish = 1): Promise<
|
|
139
|
+
testLogs(logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
150
140
|
const bindings = []
|
|
151
141
|
for (const log of logs) {
|
|
152
142
|
const binding = this.buildLogBinding(log, network)
|
|
@@ -156,11 +146,11 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
156
146
|
bindings.push(binding)
|
|
157
147
|
}
|
|
158
148
|
return this.processLogs({
|
|
159
|
-
|
|
149
|
+
bindings: bindings,
|
|
160
150
|
})
|
|
161
151
|
}
|
|
162
152
|
|
|
163
|
-
buildLogBinding(log: Log, network: Networkish = 1):
|
|
153
|
+
buildLogBinding(log: Log, network: Networkish = 1): DataBinding | undefined {
|
|
164
154
|
for (const contract of this.contractConfig) {
|
|
165
155
|
if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {
|
|
166
156
|
continue
|
|
@@ -191,10 +181,11 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
191
181
|
}
|
|
192
182
|
if (match) {
|
|
193
183
|
return {
|
|
194
|
-
|
|
184
|
+
data: {
|
|
195
185
|
raw: toBytes(log),
|
|
196
186
|
},
|
|
197
187
|
handlerId: config.handlerId,
|
|
188
|
+
handlerType: HandlerType.ETH_LOG,
|
|
198
189
|
}
|
|
199
190
|
}
|
|
200
191
|
}
|
|
@@ -203,7 +194,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
203
194
|
return undefined
|
|
204
195
|
}
|
|
205
196
|
|
|
206
|
-
testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<
|
|
197
|
+
testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
207
198
|
return this.testBlocks([block], network)
|
|
208
199
|
}
|
|
209
200
|
|
|
@@ -246,6 +237,13 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
246
237
|
}
|
|
247
238
|
return binding
|
|
248
239
|
}
|
|
240
|
+
|
|
241
|
+
processBindings(
|
|
242
|
+
request: ProcessBindingsRequest,
|
|
243
|
+
context: CallContext = TEST_CONTEXT
|
|
244
|
+
): Promise<ProcessBindingResponse> {
|
|
245
|
+
return this.service.processBindings(request, context)
|
|
246
|
+
}
|
|
249
247
|
}
|
|
250
248
|
|
|
251
249
|
function toBytes(obj: any): Uint8Array {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainConfig } from '../chain-config'
|
|
2
2
|
import { CHAIN_MAP } from '../utils/chain'
|
|
3
|
-
import { setProvider } from '
|
|
3
|
+
import { setProvider } from '../provider'
|
|
4
4
|
|
|
5
5
|
export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): boolean {
|
|
6
6
|
const dummyConfig: Record<string, ChainConfig> = {}
|