@sentio/sdk 1.36.0-rc.3 → 1.36.0-rc.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/src/service.ts CHANGED
@@ -27,7 +27,6 @@ import {
27
27
 
28
28
  import { Empty } from './gen/google/protobuf/empty'
29
29
  import Long from 'long'
30
- import { TextDecoder } from 'util'
31
30
  import { Trace } from './core'
32
31
  import { Instruction as SolInstruction } from '@project-serum/anchor'
33
32
  import { MetricState } from './core/meter'
@@ -43,6 +42,12 @@ import { SuiProcessorState } from './core/sui-processor'
43
42
  import { SolanaProcessorState } from './core/solana-processor'
44
43
  import { ProcessorState } from './binds'
45
44
  import { ProcessorTemplateProcessorState, TemplateInstanceState } from './core/base-processor-template'
45
+ import { toBigInt } from './core/numberish'
46
+ import { MoveResource, Transaction_UserTransaction } from 'aptos-sdk/src/generated'
47
+
48
+ // (Long.prototype as any).toBigInt = function() {
49
+ // return BigInt(this.toString())
50
+ // };
46
51
  ;(BigInt.prototype as any).toJSON = function () {
47
52
  return this.toString()
48
53
  }
@@ -541,8 +546,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
541
546
  if (processor.address === instruction.programAccountId) {
542
547
  let parsedInstruction: SolInstruction | null = null
543
548
  if (instruction.parsed) {
544
- const a1 = JSON.parse(new TextDecoder().decode(instruction.parsed))
545
- parsedInstruction = processor.getParsedInstruction(a1)
549
+ parsedInstruction = processor.getParsedInstruction(instruction.parsed as { type: string; info: any })
546
550
  } else if (instruction.instructionData) {
547
551
  parsedInstruction = processor.getParsedInstruction(instruction.instructionData)
548
552
  }
@@ -610,14 +614,22 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
610
614
  throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
611
615
  }
612
616
  const promises: Promise<ProcessResult>[] = []
613
- const jsonString = Utf8ArrayToStr(binding.data.aptEvent?.data || binding.data.raw)
614
- const event = JSON.parse(jsonString)
617
+ let event: Transaction_UserTransaction
618
+ if (binding.data.aptEvent) {
619
+ event = binding.data.aptEvent?.event as Transaction_UserTransaction
620
+ } else {
621
+ const jsonString = Utf8ArrayToStr(binding.data.raw)
622
+ event = JSON.parse(jsonString)
623
+ }
615
624
 
616
625
  for (const handlerId of binding.handlerIds) {
617
626
  // only support aptos event for now
618
627
  promises.push(
619
628
  this.aptosEventHandlers[handlerId](event).catch((e) => {
620
- throw new ServerError(Status.INTERNAL, 'error processing event: ' + jsonString + '\n' + errorString(e))
629
+ throw new ServerError(
630
+ Status.INTERNAL,
631
+ 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
632
+ )
621
633
  })
622
634
  )
623
635
  }
@@ -628,13 +640,31 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
628
640
  if (!binding.data) {
629
641
  throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
630
642
  }
631
- const jsonString = Utf8ArrayToStr(binding.data.aptResource?.data || binding.data.raw)
632
- const json = JSON.parse(jsonString) as MoveResourcesWithVersionPayload
643
+
644
+ const resource: MoveResourcesWithVersionPayload = {
645
+ resources: [],
646
+ version: 0n,
647
+ timestamp: 0n,
648
+ }
649
+ if (binding.data.aptResource?.resources) {
650
+ resource.timestamp = toBigInt(binding.data.aptResource.timestampMicros)
651
+ resource.version = toBigInt(binding.data.aptResource.version)
652
+ resource.resources = binding.data.aptResource.resources as MoveResource[]
653
+ } else {
654
+ const jsonString = Utf8ArrayToStr(binding.data.raw)
655
+ const json = JSON.parse(jsonString)
656
+ resource.timestamp = toBigInt(json.timestamp)
657
+ resource.version = toBigInt(json.version)
658
+ }
659
+
633
660
  const promises: Promise<ProcessResult>[] = []
634
661
  for (const handlerId of binding.handlerIds) {
635
662
  promises.push(
636
- this.aptosResourceHandlers[handlerId](json).catch((e) => {
637
- throw new ServerError(Status.INTERNAL, 'error processing event: ' + jsonString + '\n' + errorString(e))
663
+ this.aptosResourceHandlers[handlerId](resource).catch((e) => {
664
+ throw new ServerError(
665
+ Status.INTERNAL,
666
+ 'error processing event: ' + JSON.stringify(resource) + '\n' + errorString(e)
667
+ )
638
668
  })
639
669
  )
640
670
  }
@@ -645,14 +675,19 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
645
675
  if (!binding.data) {
646
676
  throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
647
677
  }
648
- const jsonString = Utf8ArrayToStr(binding.data.aptCall?.data || binding.data.raw)
649
- const call = JSON.parse(jsonString)
678
+ let call: Transaction_UserTransaction
679
+ if (binding.data.aptCall?.call) {
680
+ call = binding.data.aptCall?.call as Transaction_UserTransaction
681
+ } else {
682
+ const jsonString = Utf8ArrayToStr(binding.data.raw)
683
+ call = JSON.parse(jsonString)
684
+ }
650
685
 
651
686
  const promises: Promise<ProcessResult>[] = []
652
687
  for (const handlerId of binding.handlerIds) {
653
688
  // only support aptos call for now
654
689
  const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {
655
- throw new ServerError(Status.INTERNAL, 'error processing call: ' + jsonString + '\n' + errorString(e))
690
+ throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
656
691
  })
657
692
  promises.push(promise)
658
693
  }