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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/lib/builtin/index.d.ts +0 -2
  2. package/lib/builtin/index.js +1 -3
  3. package/lib/builtin/index.js.map +1 -1
  4. package/lib/core/eth-plugin.js +12 -15
  5. package/lib/core/eth-plugin.js.map +1 -1
  6. package/lib/core/index.d.ts +0 -4
  7. package/lib/core/index.js +1 -9
  8. package/lib/core/index.js.map +1 -1
  9. package/lib/core/sui-plugin.js +1 -1
  10. package/lib/core/sui-plugin.js.map +1 -1
  11. package/lib/index.d.ts +1 -1
  12. package/lib/index.js +3 -14
  13. package/lib/index.js.map +1 -1
  14. package/lib/service.d.ts +0 -4
  15. package/lib/service.js +40 -71
  16. package/lib/service.js.map +1 -1
  17. package/package.json +10 -20
  18. package/src/builtin/index.ts +1 -4
  19. package/src/core/eth-plugin.ts +5 -8
  20. package/src/core/index.ts +0 -5
  21. package/src/core/sui-plugin.ts +2 -2
  22. package/src/index.ts +3 -1
  23. package/src/service.ts +13 -71
  24. package/lib/aptos/api.d.ts +0 -2
  25. package/lib/aptos/api.js +0 -14
  26. package/lib/aptos/api.js.map +0 -1
  27. package/lib/aptos/aptos-plugin.d.ts +0 -14
  28. package/lib/aptos/aptos-plugin.js +0 -185
  29. package/lib/aptos/aptos-plugin.js.map +0 -1
  30. package/lib/aptos/aptos-processor.d.ts +0 -75
  31. package/lib/aptos/aptos-processor.js +0 -193
  32. package/lib/aptos/aptos-processor.js.map +0 -1
  33. package/lib/aptos/context.d.ts +0 -22
  34. package/lib/aptos/context.js +0 -65
  35. package/lib/aptos/context.js.map +0 -1
  36. package/lib/aptos/index.d.ts +0 -9
  37. package/lib/aptos/index.js +0 -34
  38. package/lib/aptos/index.js.map +0 -1
  39. package/lib/aptos/models.d.ts +0 -23
  40. package/lib/aptos/models.js +0 -3
  41. package/lib/aptos/models.js.map +0 -1
  42. package/lib/aptos/network.d.ts +0 -14
  43. package/lib/aptos/network.js +0 -46
  44. package/lib/aptos/network.js.map +0 -1
  45. package/lib/aptos/runtime.d.ts +0 -2
  46. package/lib/aptos/runtime.js +0 -16
  47. package/lib/aptos/runtime.js.map +0 -1
  48. package/lib/aptos/type-registry.d.ts +0 -21
  49. package/lib/aptos/type-registry.js +0 -156
  50. package/lib/aptos/type-registry.js.map +0 -1
  51. package/lib/aptos/types.d.ts +0 -9
  52. package/lib/aptos/types.js +0 -135
  53. package/lib/aptos/types.js.map +0 -1
  54. package/lib/aptos/types.test.d.ts +0 -1
  55. package/lib/aptos/types.test.js.map +0 -1
  56. package/lib/aptos/utils.d.ts +0 -7
  57. package/lib/aptos/utils.js +0 -27
  58. package/lib/aptos/utils.js.map +0 -1
  59. package/lib/aptos-codegen/codegen.d.ts +0 -23
  60. package/lib/aptos-codegen/codegen.js +0 -364
  61. package/lib/aptos-codegen/codegen.js.map +0 -1
  62. package/lib/aptos-codegen/typegen.d.ts +0 -17
  63. package/lib/aptos-codegen/typegen.js +0 -142
  64. package/lib/aptos-codegen/typegen.js.map +0 -1
  65. package/lib/builtin/aptos/0x1.d.ts +0 -1913
  66. package/lib/builtin/aptos/0x1.js +0 -2748
  67. package/lib/builtin/aptos/0x1.js.map +0 -1
  68. package/lib/builtin/aptos/0x3.d.ts +0 -482
  69. package/lib/builtin/aptos/0x3.js +0 -526
  70. package/lib/builtin/aptos/0x3.js.map +0 -1
  71. package/lib/builtin/aptos/index.d.ts +0 -2
  72. package/lib/builtin/aptos/index.js +0 -29
  73. package/lib/builtin/aptos/index.js.map +0 -1
  74. package/lib/builtin/solana/index.d.ts +0 -2
  75. package/lib/builtin/solana/index.js +0 -19
  76. package/lib/builtin/solana/index.js.map +0 -1
  77. package/lib/builtin/solana/spl-token-processor.d.ts +0 -39
  78. package/lib/builtin/solana/spl-token-processor.js +0 -258
  79. package/lib/builtin/solana/spl-token-processor.js.map +0 -1
  80. package/lib/builtin/solana/types.d.ts +0 -427
  81. package/lib/builtin/solana/types.js +0 -203
  82. package/lib/builtin/solana/types.js.map +0 -1
  83. package/lib/builtin/solana/wormhole-processor.d.ts +0 -12
  84. package/lib/builtin/solana/wormhole-processor.js +0 -268
  85. package/lib/builtin/solana/wormhole-processor.js.map +0 -1
  86. package/lib/core/solana-context.d.ts +0 -11
  87. package/lib/core/solana-context.js +0 -34
  88. package/lib/core/solana-context.js.map +0 -1
  89. package/lib/core/solana-options.d.ts +0 -8
  90. package/lib/core/solana-options.js +0 -13
  91. package/lib/core/solana-options.js.map +0 -1
  92. package/lib/core/solana-plugin.d.ts +0 -9
  93. package/lib/core/solana-plugin.js +0 -79
  94. package/lib/core/solana-plugin.js.map +0 -1
  95. package/lib/core/solana-processor.d.ts +0 -40
  96. package/lib/core/solana-processor.js +0 -80
  97. package/lib/core/solana-processor.js.map +0 -1
  98. package/lib/solana-codegen/codegen.d.ts +0 -1
  99. package/lib/solana-codegen/codegen.js +0 -124
  100. package/lib/solana-codegen/codegen.js.map +0 -1
  101. package/lib/test-abi-code-gen.d.ts +0 -2
  102. package/lib/test-abi-code-gen.js +0 -20
  103. package/lib/test-abi-code-gen.js.map +0 -1
  104. package/src/abis/aptos/0x1.json +0 -9205
  105. package/src/abis/aptos/0x3.json +0 -1515
  106. package/src/aptos/api.ts +0 -11
  107. package/src/aptos/aptos-plugin.ts +0 -216
  108. package/src/aptos/aptos-processor.ts +0 -305
  109. package/src/aptos/context.ts +0 -74
  110. package/src/aptos/index.ts +0 -10
  111. package/src/aptos/models.ts +0 -34
  112. package/src/aptos/network.ts +0 -42
  113. package/src/aptos/runtime.ts +0 -13
  114. package/src/aptos/type-registry.ts +0 -187
  115. package/src/aptos/types.ts +0 -149
  116. package/src/aptos/utils.ts +0 -26
  117. package/src/aptos-codegen/codegen.ts +0 -428
  118. package/src/aptos-codegen/tsconfig.json +0 -9
  119. package/src/aptos-codegen/typegen.ts +0 -153
  120. package/src/builtin/aptos/0x1.ts +0 -4210
  121. package/src/builtin/aptos/0x3.ts +0 -888
  122. package/src/builtin/aptos/index.ts +0 -2
  123. package/src/builtin/solana/index.ts +0 -2
  124. package/src/builtin/solana/spl-token-processor.ts +0 -298
  125. package/src/builtin/solana/types.ts +0 -279
  126. package/src/builtin/solana/wormhole-processor.ts +0 -269
  127. package/src/core/solana-context.ts +0 -34
  128. package/src/core/solana-options.ts +0 -8
  129. package/src/core/solana-plugin.ts +0 -97
  130. package/src/core/solana-processor.ts +0 -102
  131. package/src/solana-codegen/codegen.ts +0 -129
  132. package/src/test-abi-code-gen.ts +0 -16
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.37.0-rc.2",
4
+ "version": "1.37.0-rc.4",
5
5
  "scripts": {
6
6
  "compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
7
7
  "compile": "tsc -p . && cp src/utils/*.csv lib/utils",
@@ -13,27 +13,16 @@
13
13
  "ts-start": "ts-node --files src/processor-runner.ts ./src/anyswap/src/processor.ts",
14
14
  "test": "jest",
15
15
  "test-nocache": "yarn jest --clearCache && yarn jest",
16
- "gen": "yarn compile_target && yarn gen_bultin_evm && yarn gen_bultin_others && yarn gen_test_abi",
17
- "gen_test_abi": "ts-node src/test-abi-code-gen.ts src/tests/abis src/tests/types",
18
- "gen_bultin_evm": "typechain --target lib/target-ethers-sentio --out-dir src/builtin/internal 'src/abis/*.json'",
19
- "gen_bultin_others": "ts-node src/test-abi-code-gen.ts src/abis src/builtin",
20
- "docs": "typedoc --options typedoc.json"
16
+ "gen": "yarn compile_target && yarn gen_bultin_evm",
17
+ "gen_bultin_evm": "typechain --target lib/target-ethers-sentio --out-dir src/builtin/internal 'src/abis/*.json'"
21
18
  },
22
19
  "dependencies": {
23
- "@dao-xyz/borsh": "^4.0.7",
24
20
  "@ethersproject/providers": "~5.7.0",
25
- "@project-serum/anchor": "^0.26.0",
26
- "@sentio/base": "^1.37.0-rc.2",
21
+ "@sentio/base": "^1.37.0-rc.4",
27
22
  "@sentio/cli": "^1.0.0",
28
- "@sentio/protos": "^1.37.0-rc.2",
29
- "@solana/web3.js": "^1.47.3",
23
+ "@sentio/protos": "^1.37.0-rc.4",
30
24
  "@typechain/ethers-v5": "^10.0.0",
31
- "@types/bn.js": "^5.1.0",
32
- "@types/bs58": "^4.0.1",
33
- "aptos-sdk": "npm:aptos@^1.3.17",
34
25
  "bignumber.js": "^9.1.0",
35
- "bn.js": "^5.2.1",
36
- "bs58": "^5.0.0",
37
26
  "command-line-args": "^5.2.1",
38
27
  "command-line-usage": "^6.1.3",
39
28
  "csv-parse": "^5.3.0",
@@ -52,15 +41,13 @@
52
41
  "@grpc/grpc-js": "1.7.3"
53
42
  },
54
43
  "devDependencies": {
55
- "@types/chai": "^4.3.1",
56
44
  "@types/command-line-args": "^5.2.0",
57
45
  "@types/command-line-usage": "^5.0.2",
58
46
  "@types/expect": "^24.3.0",
59
47
  "@types/fs-extra": "^9.0.13",
60
48
  "@types/google-protobuf": "^3.15.6",
61
49
  "@types/js-yaml": "^4.0.5",
62
- "@types/node": "^18.0.4",
63
- "typedoc": "^0.23.15"
50
+ "@types/node": "^18.0.4"
64
51
  },
65
52
  "bin": {
66
53
  "processor-runner": "./lib/processor-runner.js"
@@ -76,5 +63,8 @@
76
63
  "engines": {
77
64
  "node": ">=16"
78
65
  },
79
- "gitHead": "e7a7edd814d7afe33acd279e7770e9533827e1d7"
66
+ "typedoc": {
67
+ "entryPoint": "./src/index.ts"
68
+ },
69
+ "gitHead": "034f733c9beb56eba8b1c3944f7a055cd18968e2"
80
70
  }
@@ -1,7 +1,4 @@
1
1
  export * as eacaggregatorproxy from './eacaggregatorproxy'
2
2
  export * as erc20 from './erc20'
3
3
  export * as erc20bytes from './erc20bytes'
4
- export * as weth9 from './weth9'
5
- export * as solana from './solana'
6
-
7
- export * as aptos from 'builtin/aptos'
4
+ export * as weth9 from './weth9'
@@ -9,7 +9,7 @@ import {
9
9
  ProcessConfigResponse,
10
10
  ProcessResult,
11
11
  } from '@sentio/protos'
12
- import { DEFAULT_MAX_BLOCK, errorString, mergeProcessResults, USER_PROCESSOR, Utf8ArrayToStr } from '../service'
12
+ import { errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/base'
13
13
 
14
14
  import { ServerError, Status } from 'nice-grpc'
15
15
  import { Block, Log } from '@ethersproject/abstract-provider'
@@ -43,7 +43,7 @@ export class EthPlugin implements Plugin {
43
43
  logConfigs: [],
44
44
  traceConfigs: [],
45
45
  startBlock: processor.config.startBlock,
46
- endBlock: DEFAULT_MAX_BLOCK,
46
+ endBlock: 0n,
47
47
  instructionConfig: undefined,
48
48
  aptosEventConfigs: [],
49
49
  aptosCallConfigs: [],
@@ -185,8 +185,7 @@ export class EthPlugin implements Plugin {
185
185
  if (request.data.ethLog) {
186
186
  log = request.data.ethLog.log as Log
187
187
  } else {
188
- const jsonString = Utf8ArrayToStr(request.data.raw)
189
- log = JSON.parse(jsonString)
188
+ throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
190
189
  }
191
190
 
192
191
  for (const handlerId of request.handlerIds) {
@@ -208,8 +207,7 @@ export class EthPlugin implements Plugin {
208
207
  if (binding.data.ethTrace?.trace) {
209
208
  trace = binding.data.ethTrace.trace as Trace
210
209
  } else {
211
- const jsonString = Utf8ArrayToStr(binding.data.raw)
212
- trace = JSON.parse(jsonString)
210
+ throw new ServerError(Status.INVALID_ARGUMENT, "Trace can't be null")
213
211
  }
214
212
 
215
213
  const promises: Promise<ProcessResult>[] = []
@@ -235,8 +233,7 @@ export class EthPlugin implements Plugin {
235
233
  if (binding.data.ethBlock?.block) {
236
234
  block = binding.data.ethBlock.block as Block
237
235
  } else {
238
- const jsonString = Utf8ArrayToStr(binding.data.raw)
239
- block = JSON.parse(jsonString)
236
+ throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
240
237
  }
241
238
 
242
239
  const promises: Promise<ProcessResult>[] = []
package/src/core/index.ts CHANGED
@@ -11,12 +11,7 @@ export { GenericProcessor } from './generic-processor'
11
11
  export { BaseProcessorTemplate } from './base-processor-template'
12
12
  export { SuiBaseProcessor, SuiBindOptions } from './sui-processor'
13
13
 
14
- export { SolanaContext } from './solana-context'
15
- export { SolanaBindOptions } from './solana-options'
16
- export { SolanaBaseProcessor } from './solana-processor'
17
-
18
14
  export type { TypedCallTrace, Trace } from './trace'
19
15
 
20
16
  export { EthPlugin } from './eth-plugin'
21
- export { SolanaPlugin } from './solana-plugin'
22
17
  export { SuiPlugin } from './sui-plugin'
@@ -1,7 +1,7 @@
1
1
  import { Plugin, PluginManager } from '@sentio/base'
2
2
  import { ContractConfig, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos'
3
3
 
4
- import { DEFAULT_MAX_BLOCK, USER_PROCESSOR } from '../service'
4
+ import { USER_PROCESSOR } from '../service'
5
5
 
6
6
  import { ServerError, Status } from 'nice-grpc'
7
7
 
@@ -25,7 +25,7 @@ export class SuiPlugin implements Plugin {
25
25
  intervalConfigs: [],
26
26
  traceConfigs: [],
27
27
  startBlock: suiProcessor.config.startSeqNumber,
28
- endBlock: DEFAULT_MAX_BLOCK,
28
+ endBlock: 0n,
29
29
  instructionConfig: undefined,
30
30
  aptosEventConfigs: [],
31
31
  aptosCallConfigs: [],
package/src/index.ts CHANGED
@@ -8,4 +8,6 @@ export * from '@sentio/protos'
8
8
 
9
9
  export * from './core'
10
10
 
11
- export * as aptos from './aptos'
11
+ export * from './utils/chain'
12
+
13
+ // export * from './api'
package/src/service.ts CHANGED
@@ -22,13 +22,12 @@ import { ProcessorTemplateProcessorState, TemplateInstanceState } from './core/b
22
22
  // (Long.prototype as any).toBigInt = function() {
23
23
  // return BigInt(this.toString())
24
24
  // };
25
- import { PluginManager } from '@sentio/base'
25
+ import { errorString, mergeProcessResults, PluginManager } from '@sentio/base'
26
+ import * as console from 'console'
26
27
  ;(BigInt.prototype as any).toJSON = function () {
27
28
  return this.toString()
28
29
  }
29
30
 
30
- export const DEFAULT_MAX_BLOCK = 0n
31
-
32
31
  export const USER_PROCESSOR = 'user_processor'
33
32
 
34
33
  export class ProcessorServiceImpl implements ProcessorServiceImplementation {
@@ -93,16 +92,17 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
93
92
  }
94
93
 
95
94
  try {
96
- try {
97
- require('./core/eth-plugin')
98
- require('./core/sui-plugin')
99
- require('./aptos/aptos-plugin')
100
- require('./core/solana-plugin')
101
- } catch (e) {
102
- require('@sentio/sdk/lib/core/eth-plugin')
103
- require('@sentio/sdk/lib/core/sui-plugin')
104
- require('@sentio/sdk/lib/aptos/aptos-plugin')
105
- require('@sentio/sdk/lib/core/solana-plugin')
95
+ for (const plugin of [
96
+ '@sentio/sdk/lib/core/eth-plugin',
97
+ '@sentio/sdk/lib/core/sui-plugin',
98
+ '@sentio/sdk/lib/aptos/aptos-plugin',
99
+ '@sentio/sdk-solana/lib/solana-plugin',
100
+ ]) {
101
+ try {
102
+ require(plugin)
103
+ } catch (e) {
104
+ console.error('Failed to load plugin: ', plugin)
105
+ }
106
106
  }
107
107
 
108
108
  this.loader()
@@ -186,60 +186,6 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
186
186
  }
187
187
  }
188
188
 
189
- // https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript
190
- /* eslint-disable */
191
- export function Utf8ArrayToStr(array: Uint8Array) {
192
- let out, i, len, c
193
- let char2, char3
194
-
195
- out = ''
196
- len = array.length
197
- i = 0
198
- while (i < len) {
199
- c = array[i++]
200
- switch (c >> 4) {
201
- case 0:
202
- case 1:
203
- case 2:
204
- case 3:
205
- case 4:
206
- case 5:
207
- case 6:
208
- case 7:
209
- // 0xxxxxxx
210
- out += String.fromCharCode(c)
211
- break
212
- case 12:
213
- case 13:
214
- // 110x xxxx 10xx xxxx
215
- char2 = array[i++]
216
- out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f))
217
- break
218
- case 14:
219
- // 1110 xxxx 10xx xxxx 10xx xxxx
220
- char2 = array[i++]
221
- char3 = array[i++]
222
- out += String.fromCharCode(((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0))
223
- break
224
- }
225
- }
226
-
227
- return out
228
- }
229
-
230
- export function mergeProcessResults(results: ProcessResult[]): ProcessResult {
231
- const res = ProcessResult.fromPartial({})
232
-
233
- for (const r of results) {
234
- res.counters = res.counters.concat(r.counters)
235
- res.gauges = res.gauges.concat(r.gauges)
236
- res.logs = res.logs.concat(r.logs)
237
- res.events = res.events.concat(r.events)
238
- res.exports = res.exports.concat(r.exports)
239
- }
240
- return res
241
- }
242
-
243
189
  function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
244
190
  for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {
245
191
  list.forEach((e) => {
@@ -249,7 +195,3 @@ function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
249
195
  })
250
196
  }
251
197
  }
252
-
253
- export function errorString(e: Error): string {
254
- return e.stack || e.message
255
- }
@@ -1,2 +0,0 @@
1
- import { AptosQueryClient } from '@sentio/protos/lib/chainquery/protos/chainquery';
2
- export declare function getChainQueryClient(address?: string): AptosQueryClient;
package/lib/aptos/api.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChainQueryClient = void 0;
4
- const chainquery_1 = require("@sentio/protos/lib/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
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/aptos/api.ts"],"names":[],"mappings":";;;AAAA,gFAAwG;AACxG,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 '@sentio/protos/lib/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,14 +0,0 @@
1
- import { Plugin } from '@sentio/base';
2
- import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos';
3
- export declare class AptosPlugin implements Plugin {
4
- name: string;
5
- private aptosEventHandlers;
6
- private aptosCallHandlers;
7
- private aptosResourceHandlers;
8
- configure(config: ProcessConfigResponse): void;
9
- supportedHandlers: HandlerType[];
10
- processBinding(request: DataBinding): Promise<ProcessResult>;
11
- processAptosEvent(binding: DataBinding): Promise<ProcessResult>;
12
- processAptosResource(binding: DataBinding): Promise<ProcessResult>;
13
- processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult>;
14
- }
@@ -1,185 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AptosPlugin = void 0;
4
- const base_1 = require("@sentio/base");
5
- const protos_1 = require("@sentio/protos");
6
- const service_1 = require("../service");
7
- const nice_grpc_1 = require("nice-grpc");
8
- const aptos_processor_1 = require("./aptos-processor");
9
- class AptosPlugin {
10
- name = 'AptosPlugin';
11
- aptosEventHandlers = [];
12
- aptosCallHandlers = [];
13
- aptosResourceHandlers = [];
14
- configure(config) {
15
- for (const aptosProcessor of aptos_processor_1.AptosProcessorState.INSTANCE.getValues()) {
16
- const contractConfig = {
17
- processorType: service_1.USER_PROCESSOR,
18
- contract: {
19
- name: aptosProcessor.moduleName,
20
- chainId: aptosProcessor.getChainId(),
21
- address: aptosProcessor.config.address,
22
- abi: '',
23
- },
24
- intervalConfigs: [],
25
- logConfigs: [],
26
- traceConfigs: [],
27
- startBlock: aptosProcessor.config.startVersion,
28
- endBlock: service_1.DEFAULT_MAX_BLOCK,
29
- instructionConfig: undefined,
30
- aptosEventConfigs: [],
31
- aptosCallConfigs: [],
32
- };
33
- // 1. Prepare event handlers
34
- for (const handler of aptosProcessor.eventHandlers) {
35
- const handlerId = this.aptosEventHandlers.push(handler.handler) - 1;
36
- const eventHandlerConfig = {
37
- filters: handler.filters.map((f) => {
38
- return {
39
- type: f.type,
40
- account: f.account || '',
41
- };
42
- }),
43
- handlerId,
44
- };
45
- contractConfig.aptosEventConfigs.push(eventHandlerConfig);
46
- }
47
- // 2. Prepare function handlers
48
- for (const handler of aptosProcessor.callHandlers) {
49
- const handlerId = this.aptosCallHandlers.push(handler.handler) - 1;
50
- const functionHandlerConfig = {
51
- filters: handler.filters.map((filter) => {
52
- return {
53
- function: filter.function,
54
- typeArguments: filter.typeArguments || [],
55
- withTypeArguments: filter.typeArguments ? true : false,
56
- includeFailed: filter.includeFailed || false,
57
- };
58
- }),
59
- handlerId,
60
- };
61
- contractConfig.aptosCallConfigs.push(functionHandlerConfig);
62
- }
63
- config.contractConfigs.push(contractConfig);
64
- }
65
- for (const aptosProcessor of aptos_processor_1.AptosAccountProcessorState.INSTANCE.getValues()) {
66
- const accountConfig = {
67
- address: aptosProcessor.config.address,
68
- chainId: aptosProcessor.getChainId(),
69
- startBlock: aptosProcessor.config.startVersion,
70
- aptosIntervalConfigs: [],
71
- intervalConfigs: [],
72
- logConfigs: [],
73
- };
74
- for (const handler of aptosProcessor.resourcesHandlers) {
75
- const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1;
76
- accountConfig.aptosIntervalConfigs.push({
77
- intervalConfig: {
78
- handlerId: handlerId,
79
- minutes: 0,
80
- minutesInterval: handler.timeIntervalInMinutes,
81
- slot: 0,
82
- slotInterval: handler.versionInterval,
83
- },
84
- type: handler.type || '',
85
- });
86
- }
87
- config.accountConfigs.push(accountConfig);
88
- }
89
- }
90
- supportedHandlers = [protos_1.HandlerType.APT_CALL, protos_1.HandlerType.APT_RESOURCE, protos_1.HandlerType.APT_EVENT];
91
- processBinding(request) {
92
- switch (request.handlerType) {
93
- case protos_1.HandlerType.APT_CALL:
94
- return this.processAptosFunctionCall(request);
95
- case protos_1.HandlerType.APT_EVENT:
96
- return this.processAptosEvent(request);
97
- case protos_1.HandlerType.APT_RESOURCE:
98
- return this.processAptosResource(request);
99
- // case HandlerType.INSTRUCTION:
100
- // return this.processInstruction(request)
101
- default:
102
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
103
- }
104
- }
105
- async processAptosEvent(binding) {
106
- if (!binding.data) {
107
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
108
- }
109
- const promises = [];
110
- let event;
111
- if (binding.data.aptEvent?.event) {
112
- event = binding.data.aptEvent?.event;
113
- }
114
- else {
115
- const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
116
- event = JSON.parse(jsonString);
117
- }
118
- for (const handlerId of binding.handlerIds) {
119
- // only support aptos event for now
120
- promises.push(this.aptosEventHandlers[handlerId](event).catch((e) => {
121
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing event: ' + JSON.stringify(event) + '\n' + (0, service_1.errorString)(e));
122
- }));
123
- }
124
- return (0, service_1.mergeProcessResults)(await Promise.all(promises));
125
- }
126
- async processAptosResource(binding) {
127
- if (!binding.data) {
128
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
129
- }
130
- const resource = {
131
- resources: [],
132
- version: 0n,
133
- timestamp: 0,
134
- };
135
- if (binding.data.aptResource?.resources) {
136
- if (binding.data.aptResource.timestampMicros > Number.MAX_SAFE_INTEGER) {
137
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'timestamp is too large');
138
- }
139
- resource.timestamp = Number(binding.data.aptResource.timestampMicros);
140
- resource.version = binding.data.aptResource.version;
141
- resource.resources = binding.data.aptResource.resources;
142
- }
143
- else {
144
- const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
145
- const json = JSON.parse(jsonString);
146
- if (BigInt(json.timestamp) > Number.MAX_SAFE_INTEGER) {
147
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'timestamp is too large');
148
- }
149
- resource.timestamp = parseInt(json.timestamp);
150
- resource.version = BigInt(json.version);
151
- }
152
- const promises = [];
153
- for (const handlerId of binding.handlerIds) {
154
- promises.push(this.aptosResourceHandlers[handlerId](resource).catch((e) => {
155
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing event: ' + JSON.stringify(resource) + '\n' + (0, service_1.errorString)(e));
156
- }));
157
- }
158
- return (0, service_1.mergeProcessResults)(await Promise.all(promises));
159
- }
160
- async processAptosFunctionCall(binding) {
161
- if (!binding.data) {
162
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
163
- }
164
- let call;
165
- if (binding.data.aptCall?.call) {
166
- call = binding.data.aptCall?.call;
167
- }
168
- else {
169
- const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
170
- call = JSON.parse(jsonString);
171
- }
172
- const promises = [];
173
- for (const handlerId of binding.handlerIds) {
174
- // only support aptos call for now
175
- const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {
176
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + (0, service_1.errorString)(e));
177
- });
178
- promises.push(promise);
179
- }
180
- return (0, service_1.mergeProcessResults)(await Promise.all(promises));
181
- }
182
- }
183
- exports.AptosPlugin = AptosPlugin;
184
- base_1.PluginManager.INSTANCE.register(new AptosPlugin());
185
- //# sourceMappingURL=aptos-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AACpD,2CASuB;AAEvB,wCAAgH;AAEhH,yCAA+C;AAG/C,uDAAoH;AAEpH,MAAa,WAAW;IACtB,IAAI,GAAW,aAAa,CAAA;IAEpB,kBAAkB,GAA+C,EAAE,CAAA;IACnE,iBAAiB,GAA8C,EAAE,CAAA;IACjE,qBAAqB,GAC3B,EAAE,CAAA;IAEJ,SAAS,CAAC,MAA6B;QACrC,KAAK,MAAM,cAAc,IAAI,qCAAmB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACrE,MAAM,cAAc,GAAmB;gBACrC,aAAa,EAAE,wBAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,cAAc,CAAC,UAAU;oBAC/B,OAAO,EAAE,cAAc,CAAC,UAAU,EAAE;oBACpC,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,OAAO;oBACtC,GAAG,EAAE,EAAE;iBACR;gBACD,eAAe,EAAE,EAAE;gBACnB,UAAU,EAAE,EAAE;gBACd,YAAY,EAAE,EAAE;gBAChB,UAAU,EAAE,cAAc,CAAC,MAAM,CAAC,YAAY;gBAC9C,QAAQ,EAAE,2BAAiB;gBAC3B,iBAAiB,EAAE,SAAS;gBAC5B,iBAAiB,EAAE,EAAE;gBACrB,gBAAgB,EAAE,EAAE;aACrB,CAAA;YACD,4BAA4B;YAC5B,KAAK,MAAM,OAAO,IAAI,cAAc,CAAC,aAAa,EAAE;gBACl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AC,kBAAM,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAA,qBAAW,EAAC,CAAC,CAAC,CAAC,CAAA;YAClH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,IAAA,6BAAmB,EAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAlMD,kCAkMC;AAED,oBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager } from '@sentio/base'\nimport {\n AccountConfig,\n AptosCallHandlerConfig,\n AptosEventHandlerConfig,\n ContractConfig,\n DataBinding,\n HandlerType,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\n\nimport { DEFAULT_MAX_BLOCK, errorString, mergeProcessResults, USER_PROCESSOR, Utf8ArrayToStr } from '../service'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { MoveResource, Transaction_UserTransaction } from 'aptos-sdk/src/generated'\nimport { AptosAccountProcessorState, AptosProcessorState, MoveResourcesWithVersionPayload } from './aptos-processor'\n\nexport class AptosPlugin implements Plugin {\n name: string = 'AptosPlugin'\n\n private aptosEventHandlers: ((event: any) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: any) => Promise<ProcessResult>)[] = []\n private aptosResourceHandlers: ((resourceWithVersion: MoveResourcesWithVersionPayload) => Promise<ProcessResult>)[] =\n []\n\n configure(config: ProcessConfigResponse): void {\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: aptosProcessor.config.address,\n abi: '',\n },\n intervalConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: aptosProcessor.config.startVersion,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\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: AptosEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n handlerId,\n }\n contractConfig.aptosEventConfigs.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: AptosCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: filter.typeArguments ? true : false,\n includeFailed: filter.includeFailed || false,\n }\n }),\n handlerId,\n }\n contractConfig.aptosCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig: AccountConfig = {\n address: aptosProcessor.config.address,\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n aptosIntervalConfigs: [],\n intervalConfigs: [],\n logConfigs: [],\n }\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\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 config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n 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 // case HandlerType.INSTRUCTION:\n // return this.processInstruction(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) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n let event: Transaction_UserTransaction\n if (binding.data.aptEvent?.event) {\n event = binding.data.aptEvent?.event as Transaction_UserTransaction\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n event = JSON.parse(jsonString)\n }\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) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n\n const resource: MoveResourcesWithVersionPayload = {\n resources: [],\n version: 0n,\n timestamp: 0,\n }\n if (binding.data.aptResource?.resources) {\n if (binding.data.aptResource.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n resource.timestamp = Number(binding.data.aptResource.timestampMicros)\n resource.version = binding.data.aptResource.version\n resource.resources = binding.data.aptResource.resources as MoveResource[]\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n const json = JSON.parse(jsonString)\n if (BigInt(json.timestamp) > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n resource.timestamp = parseInt(json.timestamp)\n resource.version = BigInt(json.version)\n }\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 event: ' + 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) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n let call: Transaction_UserTransaction\n if (binding.data.aptCall?.call) {\n call = binding.data.aptCall?.call as Transaction_UserTransaction\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n call = JSON.parse(jsonString)\n }\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,75 +0,0 @@
1
- import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated';
2
- import { TypeRegistry } from './type-registry';
3
- import { AptosBindOptions, AptosNetwork } from './network';
4
- import { AptosContext, AptosResourceContext } from './context';
5
- import { EventInstance } from './models';
6
- import { ListStateStorage } from '@sentio/base';
7
- import { HandleInterval, ProcessResult } from '@sentio/protos';
8
- declare type IndexConfigure = {
9
- address: string;
10
- network: AptosNetwork;
11
- startVersion: bigint;
12
- };
13
- export interface EventFilter {
14
- type: string;
15
- account?: string;
16
- }
17
- export interface FunctionNameAndCallFilter extends CallFilter {
18
- function: string;
19
- }
20
- export interface CallFilter {
21
- includeFailed?: boolean;
22
- typeArguments?: string[];
23
- }
24
- export interface ArgumentsFilter {
25
- arguments?: string[];
26
- }
27
- declare class EventHandler {
28
- filters: EventFilter[];
29
- handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>;
30
- }
31
- declare class CallHandler {
32
- filters: FunctionNameAndCallFilter[];
33
- handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>;
34
- }
35
- export declare class MoveResourcesWithVersionPayload {
36
- resources: MoveResource[];
37
- version: bigint;
38
- timestamp: number;
39
- }
40
- declare class ResourceHandlder {
41
- type?: string;
42
- versionInterval?: HandleInterval;
43
- timeIntervalInMinutes?: HandleInterval;
44
- handler: (resource: MoveResourcesWithVersionPayload) => Promise<ProcessResult>;
45
- }
46
- export declare class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {
47
- static INSTANCE: AptosProcessorState;
48
- }
49
- export declare class AptosBaseProcessor {
50
- readonly moduleName: string;
51
- config: IndexConfigure;
52
- eventHandlers: EventHandler[];
53
- callHandlers: CallHandler[];
54
- constructor(moduleName: string, options: AptosBindOptions);
55
- onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void, includedFailed?: boolean): AptosBaseProcessor;
56
- onEvent(handler: (event: EventInstance, ctx: AptosContext) => void, filter: EventFilter | EventFilter[]): AptosBaseProcessor;
57
- onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]): AptosBaseProcessor;
58
- getChainId(): string;
59
- loadTypes(registry: TypeRegistry): void;
60
- protected loadTypesInternal(registry: TypeRegistry): void;
61
- }
62
- export declare class AptosAccountProcessorState extends ListStateStorage<AptosAccountProcessor> {
63
- static INSTANCE: AptosAccountProcessorState;
64
- }
65
- export declare class AptosAccountProcessor {
66
- config: IndexConfigure;
67
- resourcesHandlers: ResourceHandlder[];
68
- static bind(options: AptosBindOptions): AptosAccountProcessor;
69
- protected constructor(options: AptosBindOptions);
70
- getChainId(): string;
71
- private onInterval;
72
- onTimeInterval(handler: (resources: MoveResource[], ctx: AptosResourceContext) => void, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
73
- onVersionInterval(handler: (resources: MoveResource[], ctx: AptosResourceContext) => void, versionInterval?: number, backfillVersionInterval?: number, typePrefix?: string): this;
74
- }
75
- export {};