@sentio/sdk 1.28.0 → 1.29.0

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 (101) hide show
  1. package/lib/aptos/api.d.ts +2 -0
  2. package/lib/aptos/api.js +14 -0
  3. package/lib/aptos/api.js.map +1 -0
  4. package/lib/aptos/aptos-processor.d.ts +5 -4
  5. package/lib/aptos/aptos-processor.js +8 -9
  6. package/lib/aptos/aptos-processor.js.map +1 -1
  7. package/lib/aptos/context.d.ts +3 -2
  8. package/lib/aptos/context.js +3 -3
  9. package/lib/aptos/context.js.map +1 -1
  10. package/lib/aptos/index.d.ts +3 -2
  11. package/lib/aptos/index.js +18 -3
  12. package/lib/aptos/index.js.map +1 -1
  13. package/lib/aptos/models.d.ts +23 -0
  14. package/lib/aptos/models.js +3 -0
  15. package/lib/aptos/models.js.map +1 -0
  16. package/lib/aptos/type-registry.d.ts +21 -0
  17. package/lib/aptos/type-registry.js +156 -0
  18. package/lib/aptos/type-registry.js.map +1 -0
  19. package/lib/aptos/types.d.ts +1 -33
  20. package/lib/aptos/types.js +49 -142
  21. package/lib/aptos/types.js.map +1 -1
  22. package/lib/aptos/types.test.js.map +1 -1
  23. package/lib/aptos/utils.d.ts +0 -2
  24. package/lib/aptos/utils.js +1 -8
  25. package/lib/aptos/utils.js.map +1 -1
  26. package/lib/aptos-codegen/codegen.js +2 -1
  27. package/lib/aptos-codegen/codegen.js.map +1 -1
  28. package/lib/aptos-codegen/typegen.d.ts +0 -1
  29. package/lib/aptos-codegen/typegen.js +3 -61
  30. package/lib/aptos-codegen/typegen.js.map +1 -1
  31. package/lib/cli/upload.js +2 -1
  32. package/lib/cli/upload.js.map +1 -1
  33. package/lib/core/base-context.d.ts +12 -0
  34. package/lib/core/base-context.js +25 -0
  35. package/lib/core/base-context.js.map +1 -0
  36. package/lib/core/base-processor.d.ts +1 -2
  37. package/lib/core/base-processor.js.map +1 -1
  38. package/lib/core/context.d.ts +2 -11
  39. package/lib/core/context.js +5 -24
  40. package/lib/core/context.js.map +1 -1
  41. package/lib/core/event-tracker.d.ts +1 -1
  42. package/lib/core/event-tracker.js +2 -2
  43. package/lib/core/event-tracker.js.map +1 -1
  44. package/lib/core/exporter.d.ts +1 -1
  45. package/lib/core/exporter.js.map +1 -1
  46. package/lib/core/generic-processor.test.js.map +1 -1
  47. package/lib/core/logger.d.ts +1 -1
  48. package/lib/core/logger.js.map +1 -1
  49. package/lib/core/meter.d.ts +1 -1
  50. package/lib/core/meter.js.map +1 -1
  51. package/lib/endpoints.d.ts +6 -0
  52. package/lib/endpoints.js +11 -0
  53. package/lib/endpoints.js.map +1 -0
  54. package/lib/processor-runner.js +6 -0
  55. package/lib/processor-runner.js.map +1 -1
  56. package/lib/processor-state.d.ts +2 -6
  57. package/lib/processor-state.js +0 -2
  58. package/lib/processor-state.js.map +1 -1
  59. package/lib/provider.js +5 -5
  60. package/lib/provider.js.map +1 -1
  61. package/lib/testing/test-processor-server.d.ts +4 -1
  62. package/lib/testing/test-processor-server.js +15 -7
  63. package/lib/testing/test-processor-server.js.map +1 -1
  64. package/lib/utils/conversion.d.ts +2 -1
  65. package/lib/utils/conversion.js +3 -3
  66. package/lib/utils/conversion.js.map +1 -1
  67. package/lib/utils/dex-price.test.js.map +1 -1
  68. package/lib/utils/erc20.test.js.map +1 -1
  69. package/lib/utils/price.d.ts +9 -1
  70. package/lib/utils/price.js +49 -1
  71. package/lib/utils/price.js.map +1 -1
  72. package/lib/utils/token.d.ts +1 -1
  73. package/lib/utils/token.js +2 -2
  74. package/lib/utils/token.js.map +1 -1
  75. package/package.json +5 -2
  76. package/src/aptos/api.ts +11 -0
  77. package/src/aptos/aptos-processor.ts +7 -10
  78. package/src/aptos/context.ts +3 -3
  79. package/src/aptos/index.ts +3 -2
  80. package/src/aptos/models.ts +34 -0
  81. package/src/aptos/type-registry.ts +187 -0
  82. package/src/aptos/types.ts +53 -199
  83. package/src/aptos/utils.ts +0 -9
  84. package/src/aptos-codegen/codegen.ts +2 -1
  85. package/src/aptos-codegen/typegen.ts +1 -67
  86. package/src/cli/upload.ts +2 -1
  87. package/src/core/base-context.ts +28 -0
  88. package/src/core/base-processor.ts +1 -2
  89. package/src/core/context.ts +2 -26
  90. package/src/core/event-tracker.ts +2 -2
  91. package/src/core/exporter.ts +1 -1
  92. package/src/core/logger.ts +1 -1
  93. package/src/core/meter.ts +1 -1
  94. package/src/endpoints.ts +9 -0
  95. package/src/processor-runner.ts +6 -0
  96. package/src/processor-state.ts +2 -7
  97. package/src/provider.ts +5 -5
  98. package/src/testing/test-processor-server.ts +10 -6
  99. package/src/utils/conversion.ts +2 -1
  100. package/src/utils/price.ts +51 -1
  101. package/src/utils/token.ts +1 -1
@@ -0,0 +1,2 @@
1
+ import { AptosQueryClient } from '../gen/chainquery/protos/chainquery';
2
+ export declare function getChainQueryClient(address?: string): AptosQueryClient;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChainQueryClient = void 0;
4
+ const chainquery_1 = require("../gen/chainquery/protos/chainquery");
5
+ const nice_grpc_1 = require("nice-grpc");
6
+ function getChainQueryClient(address) {
7
+ if (!address) {
8
+ address = global.ENDPOINTS.chainQueryAPI;
9
+ }
10
+ const channel = (0, nice_grpc_1.createChannel)(address);
11
+ return (0, nice_grpc_1.createClient)(chainquery_1.AptosQueryDefinition, channel);
12
+ }
13
+ exports.getChainQueryClient = getChainQueryClient;
14
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/aptos/api.ts"],"names":[],"mappings":";;;AAAA,oEAA4F;AAC5F,yCAAuD;AAEvD,SAAgB,mBAAmB,CAAC,OAAgB;IAClD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,aAAa,CAAA;KACzC;IACD,MAAM,OAAO,GAAG,IAAA,yBAAa,EAAC,OAAO,CAAC,CAAA;IAEtC,OAAO,IAAA,wBAAY,EAAC,iCAAoB,EAAE,OAAO,CAAC,CAAA;AACpD,CAAC;AAPD,kDAOC","sourcesContent":["import { AptosQueryClient, AptosQueryDefinition } from '../gen/chainquery/protos/chainquery'\nimport { createChannel, createClient } from 'nice-grpc'\n\nexport function getChainQueryClient(address?: string): AptosQueryClient {\n if (!address) {\n address = global.ENDPOINTS.chainQueryAPI\n }\n const channel = createChannel(address)\n\n return createClient(AptosQueryDefinition, channel)\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import { ProcessResult } from '../gen';
2
- import { AptosBindOptions, AptosContext, AptosNetwork, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload, TypeRegistry } from '.';
3
- import { EventInstance } from './types';
4
- import { MoveResource } from 'aptos-sdk/src/generated';
5
- import { AptosResourceContext } from './context';
2
+ import { TypeRegistry } from './type-registry';
3
+ import { AptosBindOptions, AptosNetwork } from './network';
4
+ import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated';
5
+ import { AptosContext, AptosResourceContext } from './context';
6
+ import { EventInstance } from './models';
6
7
  declare type IndexConfigure = {
7
8
  address: string;
8
9
  network: AptosNetwork;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AptosAccountProcessor = exports.AptosBaseProcessor = exports.MoveResourcesWithVersionPayload = void 0;
4
- const _1 = require(".");
5
- const types_1 = require("./types");
4
+ const type_registry_1 = require("./type-registry");
6
5
  const network_1 = require("./network");
7
6
  const context_1 = require("./context");
8
7
  class EventHandler {
@@ -34,7 +33,7 @@ class AptosBaseProcessor {
34
33
  this.moduleName = moduleName;
35
34
  this.config = configure(options);
36
35
  global.PROCESSOR_STATE.aptosProcessors.push(this);
37
- this.loadTypes(types_1.TYPE_REGISTRY);
36
+ this.loadTypes(type_registry_1.TYPE_REGISTRY);
38
37
  }
39
38
  // getABI(): MoveModule | undefined {
40
39
  // return undefined
@@ -46,7 +45,7 @@ class AptosBaseProcessor {
46
45
  const processor = this;
47
46
  this.callHandlers.push({
48
47
  handler: async function (tx) {
49
- const ctx = new _1.AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(tx.version), tx);
48
+ const ctx = new context_1.AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(tx.version), tx);
50
49
  if (tx) {
51
50
  await handler(tx, ctx);
52
51
  }
@@ -70,13 +69,13 @@ class AptosBaseProcessor {
70
69
  const processor = this;
71
70
  this.eventHandlers.push({
72
71
  handler: async function (txn) {
73
- const ctx = new _1.AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(txn.version), txn);
72
+ const ctx = new context_1.AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(txn.version), txn);
74
73
  if (txn && txn.events) {
75
74
  const events = txn.events;
76
75
  txn.events = [];
77
76
  for (const evt of events) {
78
77
  const eventInstance = evt;
79
- const decoded = types_1.TYPE_REGISTRY.decodeEvent(eventInstance);
78
+ const decoded = type_registry_1.TYPE_REGISTRY.decodeEvent(eventInstance);
80
79
  await handler(decoded || eventInstance, ctx);
81
80
  }
82
81
  }
@@ -100,10 +99,10 @@ class AptosBaseProcessor {
100
99
  const processor = this;
101
100
  this.callHandlers.push({
102
101
  handler: async function (tx) {
103
- const ctx = new _1.AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(tx.version), tx);
102
+ const ctx = new context_1.AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(tx.version), tx);
104
103
  if (tx) {
105
104
  const payload = tx.payload;
106
- const decoded = types_1.TYPE_REGISTRY.decodeFunctionPayload(payload);
105
+ const decoded = type_registry_1.TYPE_REGISTRY.decodeFunctionPayload(payload);
107
106
  await handler(decoded, ctx);
108
107
  }
109
108
  return ctx.getProcessResult();
@@ -176,7 +175,7 @@ function configure(options) {
176
175
  return {
177
176
  startVersion: startVersion,
178
177
  address: options.address,
179
- network: options.network || _1.AptosNetwork.MAIN_NET,
178
+ network: options.network || network_1.AptosNetwork.MAIN_NET,
180
179
  };
181
180
  }
182
181
  //# sourceMappingURL=aptos-processor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;AACA,wBAOU;AAEV,mCAAsD;AACtD,uCAAsC;AAEtC,uCAAgD;AA6BhD,MAAM,YAAY;IAChB,OAAO,CAAe;IACtB,OAAO,CAAgE;CACxE;AAED,MAAM,WAAW;IACf,OAAO,CAA6B;IACpC,OAAO,CAA+D;CACvE;AAED,MAAa,+BAA+B;IAC1C,SAAS,CAAgB;IACzB,OAAO,CAAQ;IACf,SAAS,CAAQ;CAClB;AAJD,0EAIC;AAED,MAAM,gBAAgB;IACpB,IAAI,CAAS;IACb,eAAe,CAAS;IACxB,qBAAqB,CAAS;IAC9B,OAAO,CAAuE;CAC/E;AAED,MAAa,kBAAkB;IACpB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IACtB,aAAa,GAAmB,EAAE,CAAA;IAClC,YAAY,GAAkB,EAAE,CAAA;IAEhC,YAAY,UAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;QAChC,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,SAAS,CAAC,qBAAa,CAAC,CAAA;IAC/B,CAAC;IAED,qCAAqC;IACrC,qBAAqB;IACrB,IAAI;IAEG,aAAa,CAClB,OAA8E,EAC9E,cAAc,GAAG,KAAK;QAEtB,sCAAsC;QACtC,qCAAqC;QACrC,4DAA4D;QAC5D,MAAM,SAAS,GAAG,IAAI,CAAA;QACtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YACrB,OAAO,EAAE,KAAK,WAAW,EAAE;gBACzB,MAAM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AC,GAAG,CAAC,OAAO,CAAC,EACnB,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CACxB,CAAA;gBACD,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;gBACjC,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;YACD,qBAAqB,EAAE,YAAY;YACnC,eAAe,EAAE,eAAe;YAChC,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,cAAc,CACnB,OAAuE,EACvE,qBAAqB,GAAG,EAAE,EAC1B,IAAa;QAEb,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;IACzE,CAAC;IAEM,iBAAiB,CACtB,OAAuE,EACvE,eAAe,GAAG,MAAM,EACxB,UAAmB;QAEnB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,CAAC,CAAA;IACzE,CAAC;CACF;AA3DD,sDA2DC;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAI,YAAY,GAAG,EAAE,CAAA;IACrB,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;QACtC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YAC5C,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SAC5C;aAAM;YACL,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,eAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { ProcessResult } from '../gen'\nimport {\n AptosBindOptions,\n AptosContext,\n AptosNetwork,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n TypeRegistry,\n} from '.'\n\nimport { EventInstance, TYPE_REGISTRY } from './types'\nimport { getChainId } from './network'\nimport { MoveResource } from 'aptos-sdk/src/generated'\nimport { AptosResourceContext } from './context'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\n// TODO extends ArgumentsFilter\nexport interface EventFilter {\n type: string\n account?: string\n}\n\nexport interface FunctionNameAndCallFilter extends CallFilter {\n function: string\n}\n\n// TODO extends ArgumentsFilter\nexport interface CallFilter {\n includeFailed?: boolean\n typeArguments?: string[]\n}\n\nexport interface ArgumentsFilter {\n arguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: FunctionNameAndCallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class MoveResourcesWithVersionPayload {\n resources: MoveResource[]\n version: string\n timestamp: string\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: number\n timeIntervalInMinutes?: number\n handler: (resource: MoveResourcesWithVersionPayload) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n this.loadTypes(TYPE_REGISTRY)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void,\n includedFailed = false\n ): AptosBaseProcessor {\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx\n )\n if (tx) {\n await handler(tx, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n })\n return this\n }\n\n public onEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[]\n ): AptosBaseProcessor {\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (txn) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn\n )\n if (txn && txn.events) {\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const eventInstance = evt as EventInstance\n const decoded = TYPE_REGISTRY.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]\n ): AptosBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = TYPE_REGISTRY.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: TypeRegistry) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: TypeRegistry) {\n // should be override by subclass\n console.log('')\n }\n}\n\nexport class AptosAccountProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosAccountProcessor {\n return new AptosAccountProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n global.PROCESSOR_STATE.aptosAccountProcessors.push(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n timeInterval: number | undefined,\n versionInterval: number | undefined,\n type: string | undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (arg) {\n const ctx = new AptosResourceContext(\n processor.config.network,\n processor.config.address,\n BigInt(arg.version),\n parseInt(arg.timestamp)\n )\n await handler(arg.resources, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n timeIntervalInMinutes = 60,\n type?: string\n ) {\n return this.onInterval(handler, timeIntervalInMinutes, undefined, type)\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n versionInterval = 100000,\n typePrefix?: string\n ) {\n return this.onInterval(handler, undefined, versionInterval, typePrefix)\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
1
+ {"version":3,"file":"aptos-processor.js","sourceR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,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;YACD,qBAAqB,EAAE,YAAY;YACnC,eAAe,EAAE,eAAe;YAChC,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,cAAc,CACnB,OAAuE,EACvE,qBAAqB,GAAG,EAAE,EAC1B,IAAa;QAEb,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;IACzE,CAAC;IAEM,iBAAiB,CACtB,OAAuE,EACvE,eAAe,GAAG,MAAM,EACxB,UAAmB;QAEnB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,CAAC,CAAA;IACzE,CAAC;CACF;AA3DD,sDA2DC;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAI,YAAY,GAAG,EAAE,CAAA;IACrB,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;QACtC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YAC5C,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SAC5C;aAAM;YACL,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,sBAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { ProcessResult } from '../gen'\n\nimport { TYPE_REGISTRY, TypeRegistry } from './type-registry'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network'\nimport {\n MoveResource,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n} from 'aptos-sdk/src/generated'\nimport { AptosContext, AptosResourceContext } from './context'\nimport { EventInstance } from './models'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\n// TODO extends ArgumentsFilter\nexport interface EventFilter {\n type: string\n account?: string\n}\n\nexport interface FunctionNameAndCallFilter extends CallFilter {\n function: string\n}\n\n// TODO extends ArgumentsFilter\nexport interface CallFilter {\n includeFailed?: boolean\n typeArguments?: string[]\n}\n\nexport interface ArgumentsFilter {\n arguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: FunctionNameAndCallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class MoveResourcesWithVersionPayload {\n resources: MoveResource[]\n version: string\n timestamp: string\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: number\n timeIntervalInMinutes?: number\n handler: (resource: MoveResourcesWithVersionPayload) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n this.loadTypes(TYPE_REGISTRY)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void,\n includedFailed = false\n ): AptosBaseProcessor {\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx\n )\n if (tx) {\n await handler(tx, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n })\n return this\n }\n\n public onEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[]\n ): AptosBaseProcessor {\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (txn) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn\n )\n if (txn && txn.events) {\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const eventInstance = evt as EventInstance\n const decoded = TYPE_REGISTRY.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]\n ): AptosBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = TYPE_REGISTRY.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: TypeRegistry) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: TypeRegistry) {\n // should be override by subclass\n console.log('')\n }\n}\n\nexport class AptosAccountProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosAccountProcessor {\n return new AptosAccountProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n global.PROCESSOR_STATE.aptosAccountProcessors.push(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n timeInterval: number | undefined,\n versionInterval: number | undefined,\n type: string | undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (arg) {\n const ctx = new AptosResourceContext(\n processor.config.network,\n processor.config.address,\n BigInt(arg.version),\n parseInt(arg.timestamp)\n )\n await handler(arg.resources, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n timeIntervalInMinutes = 60,\n type?: string\n ) {\n return this.onInterval(handler, timeIntervalInMinutes, undefined, type)\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n versionInterval = 100000,\n typePrefix?: string\n ) {\n return this.onInterval(handler, undefined, versionInterval, typePrefix)\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  import { DataDescriptor, RecordMetaData } from '../gen';
2
2
  import { Labels } from '../core/metadata';
3
- import { BaseContext } from '../core/context';
4
- import { AptosNetwork, Transaction_UserTransaction } from './';
3
+ import { BaseContext } from '../core/base-context';
4
+ import { Transaction_UserTransaction } from 'aptos-sdk/src/generated';
5
+ import { AptosNetwork } from './network';
5
6
  export declare class AptosContext extends BaseContext {
6
7
  address: string;
7
8
  network: AptosNetwork;
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AptosResourceContext = exports.AptosContext = void 0;
7
7
  const long_1 = __importDefault(require("long"));
8
8
  const meter_1 = require("../core/meter");
9
- const context_1 = require("../core/context");
9
+ const base_context_1 = require("../core/base-context");
10
10
  const network_1 = require("./network");
11
- class AptosContext extends context_1.BaseContext {
11
+ class AptosContext extends base_context_1.BaseContext {
12
12
  address;
13
13
  network;
14
14
  moduleName;
@@ -40,7 +40,7 @@ class AptosContext extends context_1.BaseContext {
40
40
  }
41
41
  }
42
42
  exports.AptosContext = AptosContext;
43
- class AptosResourceContext extends context_1.BaseContext {
43
+ class AptosResourceContext extends base_context_1.BaseContext {
44
44
  address;
45
45
  network;
46
46
  version;
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAGvB,yCAA+C;AAC/C,6CAA6C;AAE7C,uCAAsC;AAEtC,MAAa,YAAa,SAAQ,qBAAW;IAC3C,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAQ;IACf,WAAW,CAA6B;IAExC,YACE,UAAkB,EAClB,OAAqB,EACrB,OAAe,EACf,OAAe,EACf,WAAyC;QAEzC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,WAAW,CAAC,UAA0B,EAAE,MAAc;QACpD,O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I,EAAE,UAAU,CAAC,IAAI;YACrB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AA5BD,oDA4BC","sourcesContent":["import Long from 'long'\nimport { DataDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/context'\nimport { AptosNetwork, Transaction_UserTransaction } from './'\nimport { getChainId } from './network'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: bigint\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: bigint,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: Long.fromString(this.version.toString()),\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: getChainId(this.network),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class AptosResourceContext extends BaseContext {\n address: string\n network: AptosNetwork\n version: bigint\n timestampInMicros: number\n\n constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {\n super()\n this.address = address\n this.network = network\n this.version = version\n this.timestampInMicros = timestampInMicros\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'resources',\n blockNumber: Long.fromString(this.version.toString()),\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: getChainId(this.network),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";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AAyB;QAC5F,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED,WAAW,CAAC,UAA0B,EAAE,MAAc;QACpD,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,cAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrD,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAA,oBAAU,EAAC,IAAI,CAAC,OAAO,CAAC;YACjC,cAAc,EAAE,UAAU;YAC1B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AA5BD,oDA4BC","sourcesContent":["import Long from 'long'\nimport { DataDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/base-context'\nimport { Transaction_UserTransaction } from 'aptos-sdk/src/generated'\nimport { AptosNetwork, getChainId } from './network'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: bigint\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: bigint,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: Long.fromString(this.version.toString()),\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: getChainId(this.network),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class AptosResourceContext extends BaseContext {\n address: string\n network: AptosNetwork\n version: bigint\n timestampInMicros: number\n\n constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {\n super()\n this.address = address\n this.network = network\n this.version = version\n this.timestampInMicros = timestampInMicros\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'resources',\n blockNumber: Long.fromString(this.version.toString()),\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: getChainId(this.network),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated';
2
- export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload } from './types';
3
- export { TYPE_REGISTRY, TypeRegistry } from './types';
2
+ export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models';
3
+ export { TYPE_REGISTRY, TypeRegistry } from './type-registry';
4
4
  export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor';
5
5
  export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor';
6
6
  export { AptosContext, AptosResourceContext } from './context';
7
7
  export { AptosBindOptions, AptosNetwork, getRpcClient } from './network';
8
+ export * from './api';
@@ -1,9 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.getRpcClient = exports.AptosNetwork = exports.AptosBindOptions = exports.AptosResourceContext = exports.AptosContext = exports.AptosAccountProcessor = exports.AptosBaseProcessor = exports.TypeRegistry = exports.TYPE_REGISTRY = void 0;
4
- var types_1 = require("./types");
5
- Object.defineProperty(exports, "TYPE_REGISTRY", { enumerable: true, get: function () { return types_1.TYPE_REGISTRY; } });
6
- Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return types_1.TypeRegistry; } });
18
+ var type_registry_1 = require("./type-registry");
19
+ Object.defineProperty(exports, "TYPE_REGISTRY", { enumerable: true, get: function () { return type_registry_1.TYPE_REGISTRY; } });
20
+ Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return type_registry_1.TypeRegistry; } });
7
21
  var aptos_processor_1 = require("./aptos-processor");
8
22
  Object.defineProperty(exports, "AptosBaseProcessor", { enumerable: true, get: function () { return aptos_processor_1.AptosBaseProcessor; } });
9
23
  Object.defineProperty(exports, "AptosAccountProcessor", { enumerable: true, get: function () { return aptos_processor_1.AptosAccountProcessor; } });
@@ -14,4 +28,5 @@ var network_1 = require("./network");
14
28
  Object.defineProperty(exports, "AptosBindOptions", { enumerable: true, get: function () { return network_1.AptosBindOptions; } });
15
29
  Object.defineProperty(exports, "AptosNetwork", { enumerable: true, get: function () { return network_1.AptosNetwork; } });
16
30
  Object.defineProperty(exports, "getRpcClient", { enumerable: true, get: function () { return network_1.getRpcClient; } });
31
+ __exportStar(require("./api"), exports);
17
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;AAEA,iCAAqD;AAA5C,sGAAA,aAAa,OAAA;AAAE,qGAAA,YAAY,OAAA;AAEpC,qDAA6E;AAApE,qHAAA,kBAAkB,OAAA;AAAE,wHAAA,qBAAqB,OAAA;AAClD,qCAA8D;AAArD,uGAAA,YAAY,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAC3C,qCAAwE;AAA/D,2GAAA,gBAAgB,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,uGAAA,YAAY,OAAA","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'\nexport type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload } from './types'\nexport { TYPE_REGISTRY, TypeRegistry } from './types'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'\nexport { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'\nexport { AptosContext, AptosResourceContext } from './context'\nexport { AptosBindOptions, AptosNetwork, getRpcClient } from './network'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,iDAA6D;AAApD,8GAAA,aAAa,OAAA;AAAE,6GAAA,YAAY,OAAA;AAEpC,qDAA6E;AAApE,qHAAA,kBAAkB,OAAA;AAAE,wHAAA,qBAAqB,OAAA;AAClD,qCAA8D;AAArD,uGAAA,YAAY,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAC3C,qCAAwE;AAA/D,2GAAA,gBAAgB,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,uGAAA,YAAY,OAAA;AACrD,wCAAqB","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'\nexport type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models'\nexport { TYPE_REGISTRY, TypeRegistry } from './type-registry'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'\nexport { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'\nexport { AptosContext, AptosResourceContext } from './context'\nexport { AptosBindOptions, AptosNetwork, getRpcClient } from './network'\nexport * from './api'\n"]}
@@ -0,0 +1,23 @@
1
+ import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated';
2
+ export declare type EventInstance = Event & {
3
+ version: string;
4
+ };
5
+ export declare type TypedEventInstance<T> = EventInstance & {
6
+ data_typed: T;
7
+ type_arguments: string[];
8
+ };
9
+ export declare type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
10
+ arguments_typed: T;
11
+ };
12
+ export declare type TypedMoveResource<T> = MoveResource & {
13
+ data_typed: T;
14
+ type_arguments: string[];
15
+ };
16
+ export interface StructWithTag {
17
+ type: string;
18
+ data: any;
19
+ }
20
+ export interface StructWithType<T> extends StructWithTag {
21
+ data_typed: T;
22
+ type_arguments: string[];
23
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/aptos/models.ts"],"names":[],"mappings":"","sourcesContent":["import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance & {\n // Typed data converted from ABI\n // undefined if there is converting error, usually because the ABI/data\n // mismatch\n data_typed: T\n\n type_arguments: string[]\n}\n\n// Don't use intermedidate type to make IDE happier\nexport type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n arguments_typed: T\n}\n\nexport type TypedMoveResource<T> = MoveResource & {\n data_typed: T\n type_arguments: string[]\n}\n\nexport interface StructWithTag {\n type: string\n data: any\n}\n\nexport interface StructWithType<T> extends StructWithTag {\n data_typed: T\n type_arguments: string[]\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { Event, MoveFunction, MoveModule, MoveResource, MoveStruct, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated';
2
+ import { TypeDescriptor } from './types';
3
+ import { TypedEventInstance, TypedMoveResource } from './models';
4
+ export declare class TypeRegistry {
5
+ moduleMapping: Map<string, MoveModule>;
6
+ typeMapping: Map<string, MoveStruct>;
7
+ funcMapping: Map<string, MoveFunction>;
8
+ contains(account: string, name: string): boolean;
9
+ load(module: MoveModule): void;
10
+ getMoveStruct(type: string): MoveStruct;
11
+ getMoveFunction(type: string): MoveFunction;
12
+ decode(data: any, type: TypeDescriptor): any;
13
+ decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined;
14
+ filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[];
15
+ decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined;
16
+ filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[];
17
+ private filterAndDecodeInternal;
18
+ private decodedInternal;
19
+ decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload;
20
+ }
21
+ export declare const TYPE_REGISTRY: TypeRegistry;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TYPE_REGISTRY = exports.TypeRegistry = void 0;
4
+ const utils_1 = require("./utils");
5
+ const types_1 = require("./types");
6
+ class TypeRegistry {
7
+ moduleMapping = new Map();
8
+ typeMapping = new Map();
9
+ funcMapping = new Map();
10
+ contains(account, name) {
11
+ return this.moduleMapping.has(account + '::' + name);
12
+ }
13
+ load(module) {
14
+ if (this.contains(module.address, module.name)) {
15
+ return;
16
+ }
17
+ this.moduleMapping.set((0, utils_1.moduleQname)(module), module);
18
+ for (const struct of module.structs) {
19
+ // TODO move to util
20
+ const key = [module.address, module.name, struct.name].join(utils_1.SPLITTER);
21
+ this.typeMapping.set(key, struct);
22
+ }
23
+ for (const func of module.exposed_functions) {
24
+ if (!func.is_entry) {
25
+ continue;
26
+ }
27
+ const key = [module.address, module.name, func.name].join(utils_1.SPLITTER);
28
+ this.funcMapping.set(key, func);
29
+ }
30
+ }
31
+ getMoveStruct(type) {
32
+ const struct = this.typeMapping.get(type);
33
+ if (!struct) {
34
+ throw new Error('Failed to load type' + type);
35
+ }
36
+ return struct;
37
+ }
38
+ getMoveFunction(type) {
39
+ const func = this.funcMapping.get(type);
40
+ if (!func) {
41
+ throw new Error('Failed to load function' + type);
42
+ }
43
+ return func;
44
+ }
45
+ decode(data, type) {
46
+ // process simple type
47
+ if (type.qname.startsWith('&')) {
48
+ return data;
49
+ }
50
+ switch (type.qname) {
51
+ case 'signer': // TODO check this
52
+ case 'address':
53
+ case '0x1::string::String':
54
+ case 'bool':
55
+ case 'u8':
56
+ case 'u16':
57
+ case 'u32':
58
+ return data;
59
+ case 'u64':
60
+ case 'u128':
61
+ return BigInt(data);
62
+ }
63
+ // process vector
64
+ if (type.qname === utils_1.VECTOR_STR) {
65
+ // vector<u8> as hex string
66
+ if (type.typeArgs[0].qname === 'u8') {
67
+ return data;
68
+ }
69
+ const res = [];
70
+ for (const entry of data) {
71
+ res.push(this.decode(entry, type.typeArgs[0]));
72
+ }
73
+ return res;
74
+ }
75
+ // Process complex type
76
+ const struct = this.getMoveStruct(type.qname);
77
+ const typeCtx = new Map();
78
+ for (const [idx, typeArg] of type.typeArgs.entries()) {
79
+ typeCtx.set('T' + idx, typeArg);
80
+ }
81
+ const typedData = {};
82
+ for (const field of struct.fields) {
83
+ let filedType = (0, types_1.parseMoveType)(field.type);
84
+ filedType = filedType.applyTypeArgs(typeCtx);
85
+ const value = this.decode(data[field.name], filedType);
86
+ typedData[field.name] = value;
87
+ }
88
+ return typedData;
89
+ }
90
+ decodeEvent(event) {
91
+ return this.decodedInternal(event);
92
+ }
93
+ filterAndDecodeEvents(typeQname, resources) {
94
+ return this.filterAndDecodeInternal(typeQname, resources);
95
+ }
96
+ decodeResource(res) {
97
+ return this.decodedInternal(res);
98
+ }
99
+ filterAndDecodeResources(typeQname, resources) {
100
+ return this.filterAndDecodeInternal(typeQname, resources);
101
+ }
102
+ filterAndDecodeInternal(typeQname, structs) {
103
+ if (!structs) {
104
+ return [];
105
+ }
106
+ const results = [];
107
+ for (const resource of structs) {
108
+ if (resource.type.split('<')[0] !== typeQname) {
109
+ continue;
110
+ }
111
+ const result = this.decodedInternal(resource);
112
+ if (result) {
113
+ results.push(result);
114
+ }
115
+ }
116
+ return results;
117
+ }
118
+ decodedInternal(typeStruct) {
119
+ const registry = exports.TYPE_REGISTRY;
120
+ // this.loadTypes(registry)
121
+ // TODO check if module is not loaded
122
+ const typeDescriptor = (0, types_1.parseMoveType)(typeStruct.type);
123
+ const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature());
124
+ let dataTyped = undefined;
125
+ try {
126
+ dataTyped = registry.decode(typeStruct.data, typeDescriptor);
127
+ }
128
+ catch (e) {
129
+ console.error('Decoding error for ', JSON.stringify(typeStruct), e);
130
+ return undefined;
131
+ }
132
+ return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments };
133
+ }
134
+ decodeFunctionPayload(payload) {
135
+ const registry = exports.TYPE_REGISTRY;
136
+ // this.loadTypes(registry)
137
+ const argumentsTyped = [];
138
+ try {
139
+ const func = registry.getMoveFunction(payload.function);
140
+ const params = (0, utils_1.getMeaningfulFunctionParams)(func);
141
+ for (const [idx, arg] of payload.arguments.entries()) {
142
+ // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
143
+ const argType = (0, types_1.parseMoveType)(params[idx]);
144
+ argumentsTyped.push(registry.decode(arg, argType));
145
+ }
146
+ }
147
+ catch (e) {
148
+ console.error('Decoding error for ', JSON.stringify(payload), e);
149
+ return payload;
150
+ }
151
+ return { ...payload, arguments_typed: argumentsTyped };
152
+ }
153
+ }
154
+ exports.TypeRegistry = TypeRegistry;
155
+ exports.TYPE_REGISTRY = new TypeRegistry();
156
+ //# sourceMappingURL=type-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-registry.js","sourceRoot":"","sources":["../../src/aptos/type-registry.ts"],"names":[],"mappings":";;;AAQA,mCAAwF;AACxF,mCAAuD;AASvD,MAAa,YAAY;IACvB,aAAa,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC7C,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC3C,WAAW,GAAG,IAAI,GAAG,EAAwB,CAAA;IAE7C,QAAQ,CAAC,OAAe,EAAE,IAAY;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,CAAC,MAAkB;QACrB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE;YAC9C,OAAM;SACP;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAA,mBAAW,EAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;QAEnD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,oBAAoB;YACpB,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,gBAAQ,CAAC,CAAA;YACrE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;SAClC;QAED,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,iBAAiB,EAAE;YAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAClB,SAAQ;aACT;YACD,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM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qB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;YACnE,OAAO,SAAS,CAAA;SACjB;QACD,OAAO,EAAE,GAAG,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAuB,CAAA;IACrG,CAAC;IAED,qBAAqB,CAAC,OAAgD;QACpE,MAAM,QAAQ,GAAG,qBAAa,CAAA;QAC9B,2BAA2B;QAC3B,MAAM,cAAc,GAAU,EAAE,CAAA;QAEhC,IAAI;YACF,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACvD,MAAM,MAAM,GAAG,IAAA,mCAA2B,EAAC,IAAI,CAAC,CAAA;YAChD,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE;gBACpD,sGAAsG;gBACtG,MAAM,OAAO,GAAG,IAAA,qBAAa,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC1C,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;aACnD;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;YAChE,OAAO,OAAO,CAAA;SACf;QAED,OAAO,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAoC,CAAA;IAC1F,CAAC;CACF;AAtKD,oCAsKC;AAEY,QAAA,aAAa,GAAG,IAAI,YAAY,EAAE,CAAA","sourcesContent":["import {\n Event,\n MoveFunction,\n MoveModule,\n MoveResource,\n MoveStruct,\n TransactionPayload_EntryFunctionPayload,\n} from 'aptos-sdk/src/generated'\nimport { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils'\nimport { parseMoveType, TypeDescriptor } from './types'\nimport {\n TypedEventInstance,\n TypedMoveResource,\n StructWithTag,\n StructWithType,\n TypedEntryFunctionPayload,\n} from './models'\n\nexport class TypeRegistry {\n moduleMapping = new Map<string, MoveModule>()\n typeMapping = new Map<string, MoveStruct>()\n funcMapping = new Map<string, MoveFunction>()\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n load(module: MoveModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname(module), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [module.address, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n getMoveStruct(type: string): MoveStruct {\n const struct = this.typeMapping.get(type)\n if (!struct) {\n throw new Error('Failed to load type' + type)\n }\n return struct\n }\n\n getMoveFunction(type: string): MoveFunction {\n const func = this.funcMapping.get(type)\n if (!func) {\n throw new Error('Failed to load function' + type)\n }\n return func\n }\n\n decode(data: any, type: TypeDescriptor): any {\n // process simple type\n if (type.qname.startsWith('&')) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n return data\n case 'u64':\n case 'u128':\n return BigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.decode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = parseMoveType(field.type)\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = this.decode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {\n return this.decodedInternal<T>(event) as TypedEventInstance<T>\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]\n }\n decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {\n return this.decodedInternal<T>(res)\n }\n filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources)\n }\n\n private filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag[]): StructWithType<T>[] {\n if (!structs) {\n return []\n }\n const results: StructWithType<T>[] = []\n for (const resource of structs) {\n if (resource.type.split('<')[0] !== typeQname) {\n continue\n }\n const result = this.decodedInternal(resource)\n if (result) {\n results.push(result as StructWithType<T>)\n }\n }\n return results\n }\n\n private decodedInternal<T>(typeStruct: StructWithTag): StructWithType<T> | undefined {\n const registry = TYPE_REGISTRY\n // this.loadTypes(registry)\n // TODO check if module is not loaded\n\n const typeDescriptor = parseMoveType(typeStruct.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = registry.decode(typeStruct.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(typeStruct), e)\n return undefined\n }\n return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments } as StructWithType<T>\n }\n\n decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {\n const registry = TYPE_REGISTRY\n // this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const func = registry.getMoveFunction(payload.function)\n const params = getMeaningfulFunctionParams(func)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = parseMoveType(params[idx])\n argumentsTyped.push(registry.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload), e)\n return payload\n }\n\n return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>\n }\n}\n\nexport const TYPE_REGISTRY = new TypeRegistry()\n"]}
@@ -1,18 +1,3 @@
1
- import { Event, MoveFunction, MoveModule, MoveStruct, TransactionPayload_EntryFunctionPayload, MoveResource } from 'aptos-sdk/src/generated';
2
- export declare type EventInstance = Event & {
3
- version: string;
4
- };
5
- export declare type TypedEventInstance<T> = EventInstance & {
6
- data_typed: T;
7
- type_arguments: string[];
8
- };
9
- export declare type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
10
- arguments_typed: T;
11
- };
12
- export declare type TypedMoveResource<T> = MoveResource & {
13
- data_typed: T;
14
- type_arguments: string[];
15
- };
16
1
  export declare class TypeDescriptor {
17
2
  qname: string;
18
3
  typeArgs: TypeDescriptor[];
@@ -21,21 +6,4 @@ export declare class TypeDescriptor {
21
6
  applyTypeArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor;
22
7
  dependedTypes(): string[];
23
8
  }
24
- export declare class TypeRegistry {
25
- moduleMapping: Map<string, MoveModule>;
26
- typeMapping: Map<string, MoveStruct>;
27
- funcMapping: Map<string, MoveFunction>;
28
- contains(account: string, name: string): boolean;
29
- load(module: MoveModule): void;
30
- getMoveStruct(type: string): MoveStruct;
31
- getMoveFunction(type: string): MoveFunction;
32
- decode(data: any, type: TypeDescriptor): any;
33
- decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined;
34
- filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[];
35
- decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined;
36
- filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[];
37
- private filterAndDecodeInternal;
38
- private decodedInternal;
39
- decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload;
40
- }
41
- export declare const TYPE_REGISTRY: TypeRegistry;
9
+ export declare function parseMoveType(type: string): TypeDescriptor;