@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/src/service.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  HandlerType,
8
8
  LogFilter,
9
9
  LogHandlerConfig,
10
- O11yResult,
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<O11yResult>)[] = []
36
- private blockHandlers: ((block: Block) => Promise<O11yResult>)[] = []
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<O11yResult>)[]>()
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: O11yResult = {
207
+ const resp: ProcessResult = {
208
208
  gauges: [],
209
209
  counters: [],
210
+ logs: [],
210
211
  }
211
212
 
212
- const promises: Promise<O11yResult>[] = []
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: O11yResult = {
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: O11yResult | null
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 = O11yResult.fromPartial({})
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<O11yResult> {
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: O11yResult = {
369
+ const resp: ProcessResult = {
368
370
  gauges: [],
369
371
  counters: [],
372
+ logs: [],
370
373
  }
371
374
 
372
- const promises: Promise<O11yResult>[] = []
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: O11yResult, handlerType: HandlerType) {
438
+ function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
436
439
  results.gauges.forEach((e) => {
437
440
  e.runtimeInfo = {
438
441
  from: handlerType,
@@ -1,4 +1,4 @@
1
- import { O11yResult } from './gen/processor/protos/processor'
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 }): O11yResult | null {
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
 
@@ -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
- const o11yRes = res.result
33
- expect(o11yRes?.counters).length(0)
34
- expect(o11yRes?.gauges).length(1)
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 = o11yRes?.gauges?.[0]
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
- const o11yRes2 = res2.result
43
- expect(o11yRes2?.counters).length(0)
44
- expect(o11yRes2?.gauges).length(1)
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 () => {
@@ -1,5 +1,5 @@
1
1
  import { DeepPartial } from '../gen/builtin'
2
- import { BigDecimal, MetricValue, O11yResult } from '@sentio/sdk'
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: O11yResult | undefined, name: string): Numberish | undefined {
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: O11yResult | undefined, name: string): Numberish | undefined {
39
+ export function firstGaugeValue(result: ProcessResult | undefined, name: string): Numberish | undefined {
40
40
  if (!result) {
41
41
  return undefined
42
42
  }