@sentio/sdk 1.8.0 → 1.8.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/base-processor.d.ts +3 -3
- package/lib/base-processor.js +3 -0
- package/lib/base-processor.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +43 -20
- package/lib/gen/processor/protos/processor.js +187 -40
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.d.ts +2 -2
- package/lib/service.js +5 -2
- package/lib/service.js.map +1 -1
- package/lib/solana-processor.d.ts +2 -2
- package/lib/solana-processor.js +1 -0
- package/lib/solana-processor.js.map +1 -1
- package/lib/test/erc20.test.js +9 -11
- package/lib/test/erc20.test.js.map +1 -1
- package/lib/test/metric-utils.d.ts +3 -3
- package/lib/test/metric-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/base-processor.ts +6 -3
- package/src/gen/processor/protos/processor.ts +226 -57
- package/src/service.ts +16 -13
- package/src/solana-processor.ts +3 -2
- package/src/test/erc20.test.ts +9 -11
- package/src/test/metric-utils.ts +3 -3
package/src/service.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
HandlerType,
|
|
8
8
|
LogFilter,
|
|
9
9
|
LogHandlerConfig,
|
|
10
|
-
|
|
10
|
+
ProcessResult,
|
|
11
11
|
ProcessBlocksRequest,
|
|
12
12
|
ProcessBlocksResponse,
|
|
13
13
|
ProcessConfigRequest,
|
|
@@ -32,11 +32,11 @@ import { TextDecoder } from 'util'
|
|
|
32
32
|
const DEFAULT_MAX_BLOCK = Long.ZERO
|
|
33
33
|
|
|
34
34
|
export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
35
|
-
private eventHandlers: ((event: Log) => Promise<
|
|
36
|
-
private blockHandlers: ((block: Block) => Promise<
|
|
35
|
+
private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []
|
|
36
|
+
private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []
|
|
37
37
|
|
|
38
38
|
// map from chain id to list of processors
|
|
39
|
-
// private blockHandlers = new Map<string, ((block: Block) => Promise<
|
|
39
|
+
// private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()
|
|
40
40
|
// private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()
|
|
41
41
|
|
|
42
42
|
private started = false
|
|
@@ -204,12 +204,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
204
204
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
const resp:
|
|
207
|
+
const resp: ProcessResult = {
|
|
208
208
|
gauges: [],
|
|
209
209
|
counters: [],
|
|
210
|
+
logs: [],
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
const promises: Promise<
|
|
213
|
+
const promises: Promise<ProcessResult>[] = []
|
|
213
214
|
for (const l of request.logBindings) {
|
|
214
215
|
if (!l.log) {
|
|
215
216
|
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
@@ -272,9 +273,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
272
273
|
throw new ServerError(Status.UNAVAILABLE, 'Service not started.')
|
|
273
274
|
}
|
|
274
275
|
|
|
275
|
-
const result:
|
|
276
|
+
const result: ProcessResult = {
|
|
276
277
|
gauges: [],
|
|
277
278
|
counters: [],
|
|
279
|
+
logs: [],
|
|
278
280
|
}
|
|
279
281
|
|
|
280
282
|
// Only have instruction handlers for solana processors
|
|
@@ -289,7 +291,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
289
291
|
new Promise((resolve, _) => {
|
|
290
292
|
for (const processor of global.PROCESSOR_STATE.solanaProcessors) {
|
|
291
293
|
if (processor.address === instruction.programAccountId) {
|
|
292
|
-
let res:
|
|
294
|
+
let res: ProcessResult | null
|
|
293
295
|
if (instruction.parsed) {
|
|
294
296
|
res = processor.handleInstruction(JSON.parse(new TextDecoder().decode(instruction.parsed)))
|
|
295
297
|
} else if (instruction.instructionData) {
|
|
@@ -343,7 +345,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
343
345
|
const promises = request.blockBindings.map((binding) => this.processBlock(binding))
|
|
344
346
|
const results = await Promise.all(promises)
|
|
345
347
|
|
|
346
|
-
const res =
|
|
348
|
+
const res = ProcessResult.fromPartial({})
|
|
347
349
|
|
|
348
350
|
for (const r of results) {
|
|
349
351
|
res.counters = res.counters.concat(r.counters)
|
|
@@ -356,7 +358,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
356
358
|
}
|
|
357
359
|
}
|
|
358
360
|
|
|
359
|
-
async processBlock(binding: BlockBinding): Promise<
|
|
361
|
+
async processBlock(binding: BlockBinding): Promise<ProcessResult> {
|
|
360
362
|
if (!binding.block) {
|
|
361
363
|
throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
|
|
362
364
|
}
|
|
@@ -364,12 +366,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
364
366
|
|
|
365
367
|
const block: Block = JSON.parse(jsonString)
|
|
366
368
|
|
|
367
|
-
const resp:
|
|
369
|
+
const resp: ProcessResult = {
|
|
368
370
|
gauges: [],
|
|
369
371
|
counters: [],
|
|
372
|
+
logs: [],
|
|
370
373
|
}
|
|
371
374
|
|
|
372
|
-
const promises: Promise<
|
|
375
|
+
const promises: Promise<ProcessResult>[] = []
|
|
373
376
|
for (const handlerId of binding.handlerIds) {
|
|
374
377
|
const promise = this.blockHandlers[handlerId](block).catch((e) => {
|
|
375
378
|
throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\n' + e.toString())
|
|
@@ -432,7 +435,7 @@ function Utf8ArrayToStr(array: Uint8Array) {
|
|
|
432
435
|
return out
|
|
433
436
|
}
|
|
434
437
|
|
|
435
|
-
function recordRuntimeInfo(results:
|
|
438
|
+
function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
|
|
436
439
|
results.gauges.forEach((e) => {
|
|
437
440
|
e.runtimeInfo = {
|
|
438
441
|
from: handlerType,
|
package/src/solana-processor.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProcessResult } from './gen/processor/protos/processor'
|
|
2
2
|
import { SolanaContext } from './context'
|
|
3
3
|
import Long from 'long'
|
|
4
4
|
import { Instruction } from '@project-serum/anchor'
|
|
@@ -54,7 +54,7 @@ export class SolanaBaseProcessor {
|
|
|
54
54
|
return this
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
public handleInstruction(ins: string | { type: string; info: any }):
|
|
57
|
+
public handleInstruction(ins: string | { type: string; info: any }): ProcessResult | null {
|
|
58
58
|
const ctx = new SolanaContext(this.address)
|
|
59
59
|
let parsedInstruction: Instruction | null = null
|
|
60
60
|
|
|
@@ -80,6 +80,7 @@ export class SolanaBaseProcessor {
|
|
|
80
80
|
return {
|
|
81
81
|
gauges: ctx.gauges,
|
|
82
82
|
counters: ctx.counters,
|
|
83
|
+
logs: [],
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
package/src/test/erc20.test.ts
CHANGED
|
@@ -28,21 +28,19 @@ describe('Test Basic Examples', () => {
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
test('Check block dispatch', async () => {
|
|
31
|
-
const res = await service.testBlock(blockData)
|
|
32
|
-
|
|
33
|
-
expect(
|
|
34
|
-
expect(
|
|
35
|
-
expect(firstGaugeValue(o11yRes, 'g1')).equals(10n)
|
|
31
|
+
const res = (await service.testBlock(blockData)).result
|
|
32
|
+
expect(res?.counters).length(0)
|
|
33
|
+
expect(res?.gauges).length(1)
|
|
34
|
+
expect(firstGaugeValue(res, 'g1')).equals(10n)
|
|
36
35
|
|
|
37
|
-
const gauge =
|
|
36
|
+
const gauge = res?.gauges?.[0]
|
|
38
37
|
expect(gauge?.metadata?.blockNumber?.toString()).equals('14373295')
|
|
39
38
|
expect(gauge?.runtimeInfo?.from).equals(HandlerType.BLOCK)
|
|
40
39
|
|
|
41
|
-
const res2 = await service.testBlock(blockData, 56)
|
|
42
|
-
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
45
|
-
expect(firstGaugeValue(o11yRes2, 'g2')).equals(20n)
|
|
40
|
+
const res2 = (await service.testBlock(blockData, 56)).result
|
|
41
|
+
expect(res2?.counters).length(0)
|
|
42
|
+
expect(res2?.gauges).length(1)
|
|
43
|
+
expect(firstGaugeValue(res2, 'g2')).equals(20n)
|
|
46
44
|
})
|
|
47
45
|
|
|
48
46
|
test('Check log dispatch', async () => {
|
package/src/test/metric-utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepPartial } from '../gen/builtin'
|
|
2
|
-
import { BigDecimal, MetricValue,
|
|
2
|
+
import { BigDecimal, MetricValue, ProcessResult } from '@sentio/sdk'
|
|
3
3
|
import { Numberish } from '../numberish'
|
|
4
4
|
import { BigNumber } from 'ethers'
|
|
5
5
|
|
|
@@ -24,7 +24,7 @@ export function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Nu
|
|
|
24
24
|
return undefined
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function firstCounterValue(result:
|
|
27
|
+
export function firstCounterValue(result: ProcessResult | undefined, name: string): Numberish | undefined {
|
|
28
28
|
if (!result) {
|
|
29
29
|
return undefined
|
|
30
30
|
}
|
|
@@ -36,7 +36,7 @@ export function firstCounterValue(result: O11yResult | undefined, name: string):
|
|
|
36
36
|
return undefined
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function firstGaugeValue(result:
|
|
39
|
+
export function firstGaugeValue(result: ProcessResult | undefined, name: string): Numberish | undefined {
|
|
40
40
|
if (!result) {
|
|
41
41
|
return undefined
|
|
42
42
|
}
|