@sentio/sdk 1.36.0-rc.2 → 1.36.0-rc.4

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