@sentio/sdk 2.12.3 → 2.13.0-rc.10

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 (145) hide show
  1. package/lib/aptos/aptos-chain-adapter.d.ts +14 -0
  2. package/lib/aptos/aptos-chain-adapter.js +69 -0
  3. package/lib/aptos/aptos-chain-adapter.js.map +1 -0
  4. package/lib/aptos/aptos-plugin.js +2 -0
  5. package/lib/aptos/aptos-plugin.js.map +1 -1
  6. package/lib/aptos/aptos-processor.d.ts +7 -7
  7. package/lib/aptos/aptos-processor.js +27 -26
  8. package/lib/aptos/aptos-processor.js.map +1 -1
  9. package/lib/aptos/builtin/0x1.d.ts +1244 -599
  10. package/lib/aptos/builtin/0x1.js +1939 -1458
  11. package/lib/aptos/builtin/0x1.js.map +1 -1
  12. package/lib/aptos/builtin/0x3.d.ts +241 -118
  13. package/lib/aptos/builtin/0x3.js +373 -333
  14. package/lib/aptos/builtin/0x3.js.map +1 -1
  15. package/lib/aptos/codegen/codegen.d.ts +1 -1
  16. package/lib/aptos/codegen/codegen.js +6 -47
  17. package/lib/aptos/codegen/codegen.js.map +1 -1
  18. package/lib/aptos/codegen/run.js +1 -1
  19. package/lib/aptos/codegen/run.js.map +1 -1
  20. package/lib/aptos/context.d.ts +5 -1
  21. package/lib/aptos/context.js +9 -2
  22. package/lib/aptos/context.js.map +1 -1
  23. package/lib/aptos/ext/aptos-dex.d.ts +2 -1
  24. package/lib/aptos/ext/aptos-dex.js +1 -2
  25. package/lib/aptos/ext/aptos-dex.js.map +1 -1
  26. package/lib/aptos/index.d.ts +1 -0
  27. package/lib/aptos/index.js +1 -0
  28. package/lib/aptos/index.js.map +1 -1
  29. package/lib/aptos/models.d.ts +3 -11
  30. package/lib/aptos/models.js.map +1 -1
  31. package/lib/aptos/module-client.js +1 -1
  32. package/lib/aptos/module-client.js.map +1 -1
  33. package/lib/aptos/move-coder.d.ts +10 -10
  34. package/lib/aptos/move-coder.js +37 -18
  35. package/lib/aptos/move-coder.js.map +1 -1
  36. package/lib/eth/base-processor-template.d.ts +4 -3
  37. package/lib/eth/base-processor-template.js +7 -7
  38. package/lib/eth/base-processor-template.js.map +1 -1
  39. package/lib/eth/base-processor.d.ts +9 -8
  40. package/lib/eth/base-processor.js +13 -11
  41. package/lib/eth/base-processor.js.map +1 -1
  42. package/lib/eth/eth-plugin.js +2 -0
  43. package/lib/eth/eth-plugin.js.map +1 -1
  44. package/lib/eth/eth.d.ts +7 -2
  45. package/lib/eth/eth.js +8 -1
  46. package/lib/eth/eth.js.map +1 -1
  47. package/lib/move/abstract-codegen.d.ts +11 -11
  48. package/lib/move/abstract-codegen.js +60 -23
  49. package/lib/move/abstract-codegen.js.map +1 -1
  50. package/lib/move/abstract-move-coder.d.ts +19 -25
  51. package/lib/move/abstract-move-coder.js +74 -51
  52. package/lib/move/abstract-move-coder.js.map +1 -1
  53. package/lib/move/chain-adapter.d.ts +11 -0
  54. package/lib/move/chain-adapter.js +3 -0
  55. package/lib/move/chain-adapter.js.map +1 -0
  56. package/lib/move/index.d.ts +1 -0
  57. package/lib/move/index.js +1 -0
  58. package/lib/move/index.js.map +1 -1
  59. package/lib/move/types.d.ts +28 -1
  60. package/lib/move/types.js +65 -16
  61. package/lib/move/types.js.map +1 -1
  62. package/lib/sui/builtin/0x1.d.ts +37 -18
  63. package/lib/sui/builtin/0x1.js +58 -32
  64. package/lib/sui/builtin/0x1.js.map +1 -1
  65. package/lib/sui/builtin/0x2.d.ts +299 -149
  66. package/lib/sui/builtin/0x2.js +463 -322
  67. package/lib/sui/builtin/0x2.js.map +1 -1
  68. package/lib/sui/builtin/0x3.d.ts +169 -94
  69. package/lib/sui/builtin/0x3.js +229 -272
  70. package/lib/sui/builtin/0x3.js.map +1 -1
  71. package/lib/sui/codegen/codegen.d.ts +1 -1
  72. package/lib/sui/codegen/codegen.js +10 -36
  73. package/lib/sui/codegen/codegen.js.map +1 -1
  74. package/lib/sui/codegen/run.js +1 -1
  75. package/lib/sui/codegen/run.js.map +1 -1
  76. package/lib/sui/context.d.ts +5 -1
  77. package/lib/sui/context.js +8 -1
  78. package/lib/sui/context.js.map +1 -1
  79. package/lib/sui/index.d.ts +1 -0
  80. package/lib/sui/index.js +1 -0
  81. package/lib/sui/index.js.map +1 -1
  82. package/lib/sui/models.d.ts +3 -11
  83. package/lib/sui/models.js.map +1 -1
  84. package/lib/sui/move-coder.d.ts +15 -15
  85. package/lib/sui/move-coder.js +43 -39
  86. package/lib/sui/move-coder.js.map +1 -1
  87. package/lib/sui/sui-chain-adapter.d.ts +14 -0
  88. package/lib/sui/sui-chain-adapter.js +69 -0
  89. package/lib/sui/sui-chain-adapter.js.map +1 -0
  90. package/lib/sui/sui-plugin.js +1 -0
  91. package/lib/sui/sui-plugin.js.map +1 -1
  92. package/lib/sui/sui-processor.d.ts +8 -5
  93. package/lib/sui/sui-processor.js +23 -14
  94. package/lib/sui/sui-processor.js.map +1 -1
  95. package/lib/sui/utils.d.ts +0 -2
  96. package/lib/sui/utils.js +0 -6
  97. package/lib/sui/utils.js.map +1 -1
  98. package/lib/testing/aptos-facet.d.ts +2 -2
  99. package/lib/testing/aptos-facet.js +14 -21
  100. package/lib/testing/aptos-facet.js.map +1 -1
  101. package/lib/testing/sui-facet.d.ts +2 -2
  102. package/lib/testing/sui-facet.js +16 -26
  103. package/lib/testing/sui-facet.js.map +1 -1
  104. package/package.json +4 -4
  105. package/src/aptos/aptos-chain-adapter.ts +81 -0
  106. package/src/aptos/aptos-plugin.ts +2 -0
  107. package/src/aptos/aptos-processor.ts +58 -43
  108. package/src/aptos/builtin/0x1.ts +2858 -616
  109. package/src/aptos/builtin/0x3.ts +543 -120
  110. package/src/aptos/codegen/codegen.ts +13 -57
  111. package/src/aptos/codegen/run.ts +1 -1
  112. package/src/aptos/context.ts +10 -2
  113. package/src/aptos/ext/aptos-dex.ts +4 -12
  114. package/src/aptos/index.ts +2 -0
  115. package/src/aptos/models.ts +3 -13
  116. package/src/aptos/module-client.ts +1 -1
  117. package/src/aptos/move-coder.ts +48 -25
  118. package/src/eth/base-processor-template.ts +20 -10
  119. package/src/eth/base-processor.ts +45 -25
  120. package/src/eth/eth-plugin.ts +2 -0
  121. package/src/eth/eth.ts +15 -2
  122. package/src/move/abstract-codegen.ts +75 -38
  123. package/src/move/abstract-move-coder.ts +87 -75
  124. package/src/move/chain-adapter.ts +17 -0
  125. package/src/move/index.ts +1 -0
  126. package/src/move/types.ts +83 -17
  127. package/src/sui/builtin/0x1.ts +75 -20
  128. package/src/sui/builtin/0x2.ts +694 -150
  129. package/src/sui/builtin/0x3.ts +360 -95
  130. package/src/sui/codegen/codegen.ts +17 -43
  131. package/src/sui/codegen/run.ts +1 -1
  132. package/src/sui/context.ts +9 -1
  133. package/src/sui/index.ts +1 -0
  134. package/src/sui/models.ts +3 -13
  135. package/src/sui/move-coder.ts +58 -53
  136. package/src/sui/sui-chain-adapter.ts +86 -0
  137. package/src/sui/sui-plugin.ts +1 -0
  138. package/src/sui/sui-processor.ts +41 -28
  139. package/src/sui/utils.ts +0 -8
  140. package/src/testing/aptos-facet.ts +13 -27
  141. package/src/testing/sui-facet.ts +15 -30
  142. package/lib/aptos/utils.d.ts +0 -2
  143. package/lib/aptos/utils.js +0 -10
  144. package/lib/aptos/utils.js.map +0 -1
  145. package/src/aptos/utils.ts +0 -11
@@ -0,0 +1,14 @@
1
+ import { ChainAdapter, TypeDescriptor } from '../move/index.js';
2
+ import { Event, MoveModuleBytecode, MoveResource } from './move-types.js';
3
+ import { AptosNetwork } from './network.js';
4
+ import { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js';
5
+ export declare class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
6
+ static INSTANCE: AptosChainAdapter;
7
+ fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]>;
8
+ fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode>;
9
+ toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[];
10
+ getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
11
+ getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>;
12
+ getType(data: Event | MoveResource): string;
13
+ getData(data: Event | MoveResource): any;
14
+ }
@@ -0,0 +1,69 @@
1
+ import { ChainAdapter, moduleQname, SPLITTER } from '../move/index.js';
2
+ import { toInternalModule } from './move-types.js';
3
+ import { AptosNetwork } from './network.js';
4
+ import { AptosClient } from 'aptos-sdk';
5
+ class AptosChainAdapter extends ChainAdapter {
6
+ static INSTANCE = new AptosChainAdapter();
7
+ async fetchModules(account, network) {
8
+ const client = getRpcClient(network);
9
+ return await client.getAccountModules(account);
10
+ }
11
+ async fetchModule(account, module, network) {
12
+ const client = getRpcClient(network);
13
+ return await client.getAccountModule(account, module);
14
+ }
15
+ toInternalModules(modules) {
16
+ return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []));
17
+ }
18
+ getMeaningfulFunctionParams(params) {
19
+ if (params.length === 0) {
20
+ return params;
21
+ }
22
+ if (params[0].qname === 'signer' && params[0].reference) {
23
+ params = params.slice(1);
24
+ }
25
+ return params;
26
+ }
27
+ getEventStructs(module) {
28
+ const qname = moduleQname(module);
29
+ const structMap = new Map();
30
+ const eventMap = new Map();
31
+ for (const struct of module.structs) {
32
+ structMap.set(qname + SPLITTER + struct.name, struct);
33
+ }
34
+ for (const struct of module.structs) {
35
+ for (const field of struct.fields) {
36
+ const t = field.type;
37
+ if (t.qname === '0x1::event::EventHandle') {
38
+ const event = t.typeArgs[0].qname;
39
+ const eventStruct = structMap.get(event);
40
+ if (eventStruct) {
41
+ eventMap.set(event, eventStruct);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ return eventMap;
47
+ }
48
+ getType(data) {
49
+ return data.type;
50
+ }
51
+ getData(data) {
52
+ if ('data' in data && 'type' in data) {
53
+ return data.data;
54
+ }
55
+ return data;
56
+ }
57
+ }
58
+ export { AptosChainAdapter };
59
+ function getRpcClient(network) {
60
+ return new AptosClient(getRpcEndpoint(network));
61
+ }
62
+ function getRpcEndpoint(network) {
63
+ switch (network) {
64
+ case AptosNetwork.TEST_NET:
65
+ return 'https://testnet.aptoslabs.com/';
66
+ }
67
+ return 'https://mainnet.aptoslabs.com/';
68
+ }
69
+ //# sourceMappingURL=aptos-chain-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aptos-chain-adapter.js","sourceRoot":"","sources":["../../src/aptos/aptos-chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AACtF,OAAO,EAA2C,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAa,iBAAkB,SAAQ,YAAoE;IACzG,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;IAEzC,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,OAAqB;QACvD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QACpC,OAAO,MAAM,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,MAAc,EAAE,OAAqB;QACtE,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QACpC,OAAO,MAAM,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACvD,CAAC;IAED,iBAAiB,CAAC,OAA6B;QAC7C,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,E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,IAAI,CAAA;IAClB,CAAC;IAED,OAAO,CAAC,IAA0B;QAChC,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,EAAE;YACpC,OAAO,IAAI,CAAC,IAAI,CAAA;SACjB;QACD,OAAO,IAAI,CAAA;IACb,CAAC;;SA7DU,iBAAiB;AAgE9B,SAAS,YAAY,CAAC,OAAqB;IACzC,OAAO,IAAI,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,cAAc,CAAC,OAAqB;IAC3C,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,gCAAgC,CAAA;KAC1C;IACD,OAAO,gCAAgC,CAAA;AACzC,CAAC","sourcesContent":["import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { Event, MoveModuleBytecode, MoveResource, toInternalModule } from './move-types.js'\nimport { AptosNetwork } from './network.js'\nimport { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'\nimport { AptosClient } from 'aptos-sdk'\n\nexport class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n static INSTANCE = new AptosChainAdapter()\n\n async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {\n const client = getRpcClient(network)\n return await client.getAccountModules(account)\n }\n\n async fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode> {\n const client = getRpcClient(network)\n return await client.getAccountModule(account, module)\n }\n\n toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {\n return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n if (params.length === 0) {\n return params\n }\n if (params[0].qname === 'signer' && params[0].reference) {\n params = params.slice(1)\n }\n return params\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, InternalMoveStruct>()\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = field.type\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n }\n\n getType(data: Event | MoveResource): string {\n return data.type\n }\n\n getData(data: Event | MoveResource) {\n if ('data' in data && 'type' in data) {\n return data.data\n }\n return data\n }\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n"]}
@@ -73,6 +73,7 @@ export class AptosPlugin extends Plugin {
73
73
  minutesInterval: handler.timeIntervalInMinutes,
74
74
  slot: 0,
75
75
  slotInterval: handler.versionInterval,
76
+ fetchConfig: undefined,
76
77
  },
77
78
  type: handler.type || '',
78
79
  });
@@ -83,6 +84,7 @@ export class AptosPlugin extends Plugin {
83
84
  minutesInterval: handler.timeIntervalInMinutes,
84
85
  slot: 0,
85
86
  slotInterval: handler.versionInterval,
87
+ fetchConfig: undefined,
86
88
  },
87
89
  type: handler.type || '',
88
90
  ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,EAMX,8BAA8B,GAC/B,MAAM,gBAAgB,CAAA;AAEvB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CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n MoveOnIntervalConfig_OwnerType,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\n\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n\n private aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[] = []\n private aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[] = []\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: aptosProcessor.config.address,\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\n })\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = this.aptosEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = this.aptosCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: aptosProcessor.config.address,\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\n // TODO move to only use moveIntervalConfigs\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n })\n\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosFunctionCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n case HandlerType.APT_RESOURCE:\n return this.processAptosResource(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.aptosEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosResource(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing resource: ' + JSON.stringify(resource) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new AptosPlugin())\n"]}
1
+ {"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,O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C,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n MoveOnIntervalConfig_OwnerType,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\n\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n\n private aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[] = []\n private aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[] = []\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: aptosProcessor.config.address,\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\n })\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = this.aptosEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = this.aptosCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: aptosProcessor.config.address,\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\n // TODO move to only use moveIntervalConfigs\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n })\n\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosFunctionCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n case HandlerType.APT_RESOURCE:\n return this.processAptosResource(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.aptosEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosResource(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing resource: ' + JSON.stringify(resource) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new AptosPlugin())\n"]}
@@ -6,6 +6,7 @@ import { EventInstance } from './models.js';
6
6
  import { ListStateStorage } from '@sentio/runtime';
7
7
  import { MoveFetchConfig, Data_AptResource, HandleInterval, ProcessResult, Data_AptEvent, Data_AptCall } from '@sentio/protos';
8
8
  import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js';
9
+ import { PromiseOrVoid } from '../core/index.js';
9
10
  type IndexConfigure = {
10
11
  address: string;
11
12
  network: AptosNetwork;
@@ -25,13 +26,12 @@ export declare class AptosBaseProcessor {
25
26
  config: IndexConfigure;
26
27
  eventHandlers: EventHandler<Data_AptEvent>[];
27
28
  callHandlers: CallHandler<Data_AptCall>[];
29
+ coder: MoveCoder;
28
30
  constructor(moduleName: string, options: AptosBindOptions);
29
- onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void, includedFailed?: boolean, fetchConfig?: MoveFetchConfig): this;
30
- onMoveEvent(handler: (event: EventInstance, ctx: AptosContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: MoveFetchConfig): this;
31
- onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: MoveFetchConfig): this;
31
+ onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid, includedFailed?: boolean, fetchConfig?: Partial<MoveFetchConfig>): this;
32
+ onMoveEvent(handler: (event: EventInstance, ctx: AptosContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: Partial<MoveFetchConfig>): this;
33
+ onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: Partial<MoveFetchConfig>): this;
32
34
  getChainId(): string;
33
- loadTypes(registry: MoveCoder): void;
34
- protected loadTypesInternal(registry: MoveCoder): void;
35
35
  }
36
36
  export declare class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {
37
37
  static INSTANCE: AptosAccountProcessorState;
@@ -43,7 +43,7 @@ export declare class AptosResourcesProcessor {
43
43
  protected constructor(options: AptosBindOptions);
44
44
  getChainId(): string;
45
45
  private onInterval;
46
- onTimeInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
47
- onVersionInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void, versionInterval?: number, backfillVersionInterval?: number, typePrefix?: string): this;
46
+ onTimeInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
47
+ onVersionInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid, versionInterval?: number, backfillVersionInterval?: number, typePrefix?: string): this;
48
48
  }
49
49
  export {};
@@ -1,9 +1,14 @@
1
- import { MOVE_CODER } from './move-coder.js';
1
+ import { defaultMoveCoder } from './move-coder.js';
2
2
  import { AptosNetwork, getChainId } from './network.js';
3
3
  import { AptosContext, AptosResourcesContext } from './context.js';
4
- import { ListStateStorage } from '@sentio/runtime';
4
+ import { ListStateStorage, mergeProcessResults } from '@sentio/runtime';
5
5
  import { MoveFetchConfig, } from '@sentio/protos';
6
6
  import { ServerError, Status } from 'nice-grpc';
7
+ import { parseMoveType } from '../move/index.js';
8
+ const DEFAULT_FETCH_CONFIG = {
9
+ resourceChanges: false,
10
+ allEvents: true,
11
+ };
7
12
  class ResourceHandlder {
8
13
  type;
9
14
  versionInterval;
@@ -19,17 +24,19 @@ export class AptosBaseProcessor {
19
24
  config;
20
25
  eventHandlers = [];
21
26
  callHandlers = [];
27
+ coder;
22
28
  constructor(moduleName, options) {
23
29
  this.moduleName = moduleName;
24
30
  this.config = configure(options);
25
31
  AptosProcessorState.INSTANCE.addValue(this);
26
- this.loadTypes(MOVE_CODER);
32
+ this.coder = defaultMoveCoder(this.config.network);
33
+ // this.loadTypes(this.coder)
27
34
  }
28
35
  // getABI(): MoveModule | undefined {
29
36
  // return undefined
30
37
  // }
31
38
  onTransaction(handler, includedFailed = false, fetchConfig) {
32
- const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({});
39
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig });
33
40
  // const address = this.config.address
34
41
  // const moduleName = this.moduleName
35
42
  const processor = this;
@@ -39,7 +46,7 @@ export class AptosBaseProcessor {
39
46
  throw new ServerError(Status.INVALID_ARGUMENT, 'call is null');
40
47
  }
41
48
  const call = data.transaction;
42
- const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(data.transaction.version), call);
49
+ const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(data.transaction.version), call, 0);
43
50
  await handler(call, ctx);
44
51
  return ctx.getProcessResult();
45
52
  },
@@ -50,16 +57,16 @@ export class AptosBaseProcessor {
50
57
  }
51
58
  onMoveEvent(handler, filter, fetchConfig) {
52
59
  let _filters = [];
53
- const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({});
60
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig });
54
61
  if (Array.isArray(filter)) {
55
62
  _filters = filter;
56
63
  }
57
64
  else {
58
65
  _filters.push(filter);
59
66
  }
60
- // const address = this.config.address
61
67
  // const moduleName = this.moduleName
62
68
  const processor = this;
69
+ const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type));
63
70
  this.eventHandlers.push({
64
71
  handler: async function (data) {
65
72
  if (!data.transaction) {
@@ -69,15 +76,19 @@ export class AptosBaseProcessor {
69
76
  if (!txn.events.length) {
70
77
  throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions');
71
78
  }
72
- const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(txn.version), txn);
73
- const events = txn.events;
74
- txn.events = [];
75
- for (const evt of events) {
79
+ const processResults = [];
80
+ for (const [idx, evt] of txn.events.entries()) {
81
+ const typeQname = parseMoveType(evt.type).qname;
82
+ if (!allEventType.has(typeQname)) {
83
+ continue;
84
+ }
85
+ const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(txn.version), txn, idx);
76
86
  const eventInstance = evt;
77
- const decoded = MOVE_CODER.decodeEvent(eventInstance);
87
+ const decoded = await processor.coder.decodeEvent(eventInstance);
78
88
  await handler(decoded || eventInstance, ctx);
89
+ processResults.push(ctx.getProcessResult());
79
90
  }
80
- return ctx.getProcessResult();
91
+ return mergeProcessResults(processResults);
81
92
  },
82
93
  filters: _filters,
83
94
  fetchConfig: _fetchConfig,
@@ -86,7 +97,7 @@ export class AptosBaseProcessor {
86
97
  }
87
98
  onEntryFunctionCall(handler, filter, fetchConfig) {
88
99
  let _filters = [];
89
- const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({});
100
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig });
90
101
  if (Array.isArray(filter)) {
91
102
  _filters = filter;
92
103
  }
@@ -102,10 +113,10 @@ export class AptosBaseProcessor {
102
113
  throw new ServerError(Status.INVALID_ARGUMENT, 'call is null');
103
114
  }
104
115
  const tx = data.transaction;
105
- const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(tx.version), tx);
116
+ const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(tx.version), tx, 0);
106
117
  if (tx) {
107
118
  const payload = tx.payload;
108
- const decoded = MOVE_CODER.decodeFunctionPayload(payload);
119
+ const decoded = await processor.coder.decodeFunctionPayload(payload);
109
120
  await handler(decoded, ctx);
110
121
  }
111
122
  return ctx.getProcessResult();
@@ -118,16 +129,6 @@ export class AptosBaseProcessor {
118
129
  getChainId() {
119
130
  return getChainId(this.config.network);
120
131
  }
121
- loadTypes(registry) {
122
- if (registry.contains(this.config.address, this.moduleName)) {
123
- return;
124
- }
125
- this.loadTypesInternal(registry);
126
- }
127
- loadTypesInternal(registry) {
128
- // should be override by subclass
129
- console.log('');
130
- }
131
132
  }
132
133
  class AptosAccountProcessorState extends ListStateStorage {
133
134
  static INSTANCE = new AptosAccountProcessorState();
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAU/C,MAAM,gBAAgB;IACpB,IAAI,CAAS;IACb,eAAe,CAAiB;IAChC,qBAAqB,CAAiB;IACtC,OAAO,CAAwD;CAChE;AAED,MAAa,mBAAoB,SAAQ,gBAAoC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,mBAAmB,EAAE,CAAA;;SADhC,mBAAmB;AAIhC,MAAM,OAAO,kBAAkB;IACpB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IACtB,aAAa,GAAkC,EAAE,CAAA;IACjD,YAAY,GAAgC,EAAE,CAAA;IAE9C,YAAY,UAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;QAChC,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC3C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAC5B,CAAC;IAED,qCAAqC;IACrC,qBAAqB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AAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nimport { MOVE_CODER, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourcesContext } from './context.js'\nimport { EventInstance } from './models.js'\nimport { ListStateStorage } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.loadTypes(MOVE_CODER)\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 fetchConfig?: MoveFetchConfig\n ): this {\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: MoveFetchConfig\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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 const processor = this\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn\n )\n\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const eventInstance = evt as EventInstance\n const decoded = MOVE_CODER.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: MoveFetchConfig\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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 const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as Transaction_UserTransaction\n\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 = MOVE_CODER.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: MoveCoder) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: MoveCoder) {\n // should be override by subclass\n console.log('')\n }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosResourcesProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosResourcesProcessor {\n return new AptosResourcesProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourcesContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], 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: AptosResourcesContext) => void,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\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","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AA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AC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourcesContext } from './context.js'\nimport { EventInstance } from './models.js'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { PromiseOrVoid } from '../core/index.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n coder: MoveCoder\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n // this.loadTypes(this.coder)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid,\n includedFailed = false,\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call,\n 0\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of txn.events.entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn,\n idx\n )\n const eventInstance = evt as EventInstance\n const decoded = await processor.coder.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\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 const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as Transaction_UserTransaction\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx,\n 0\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = await processor.coder.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n // loadTypes(registry: MoveCoder) {\n // if (registry.contains(this.config.address, this.moduleName)) {\n // return\n // }\n // this.loadTypesInternal(registry)\n // }\n //\n // protected loadTypesInternal(registry: MoveCoder) {\n // // should be override by subclass\n // console.log('')\n // }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosResourcesProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosResourcesProcessor {\n return new AptosResourcesProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourcesContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], 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: AptosResourcesContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\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"]}