@sentio/sdk 2.59.0-rc.3 → 2.59.0-rc.31

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 (286) hide show
  1. package/lib/aptos/api.d.ts +1 -0
  2. package/lib/aptos/api.d.ts.map +1 -1
  3. package/lib/aptos/api.js +13 -1
  4. package/lib/aptos/api.js.map +1 -1
  5. package/lib/aptos/aptos-plugin.d.ts +8 -4
  6. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  7. package/lib/aptos/aptos-plugin.js +51 -8
  8. package/lib/aptos/aptos-plugin.js.map +1 -1
  9. package/lib/aptos/aptos-processor.d.ts +21 -19
  10. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  11. package/lib/aptos/aptos-processor.js +102 -50
  12. package/lib/aptos/aptos-processor.js.map +1 -1
  13. package/lib/aptos/aptos-resource-processor-template.d.ts +5 -4
  14. package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
  15. package/lib/aptos/aptos-resource-processor-template.js +8 -8
  16. package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
  17. package/lib/aptos/builtin/0x1.d.ts +803 -317
  18. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  19. package/lib/aptos/builtin/0x1.js +1458 -635
  20. package/lib/aptos/builtin/0x1.js.map +1 -1
  21. package/lib/aptos/builtin/0x3.d.ts +66 -65
  22. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  23. package/lib/aptos/builtin/0x3.js +131 -131
  24. package/lib/aptos/builtin/0x3.js.map +1 -1
  25. package/lib/aptos/builtin/0x4.d.ts +29 -28
  26. package/lib/aptos/builtin/0x4.d.ts.map +1 -1
  27. package/lib/aptos/builtin/0x4.js +57 -57
  28. package/lib/aptos/builtin/0x4.js.map +1 -1
  29. package/lib/aptos/codegen/codegen.js +31 -4
  30. package/lib/aptos/codegen/codegen.js.map +1 -1
  31. package/lib/aptos/data.d.ts +45 -0
  32. package/lib/aptos/data.d.ts.map +1 -0
  33. package/lib/aptos/data.js +99 -0
  34. package/lib/aptos/data.js.map +1 -0
  35. package/lib/aptos/index.d.ts +1 -0
  36. package/lib/aptos/index.d.ts.map +1 -1
  37. package/lib/aptos/index.js.map +1 -1
  38. package/lib/aptos/models.d.ts +1 -0
  39. package/lib/aptos/models.d.ts.map +1 -1
  40. package/lib/aptos/move-coder.d.ts +8 -2
  41. package/lib/aptos/move-coder.d.ts.map +1 -1
  42. package/lib/aptos/move-coder.js +84 -1
  43. package/lib/aptos/move-coder.js.map +1 -1
  44. package/lib/aptos/network.d.ts +1 -0
  45. package/lib/aptos/network.d.ts.map +1 -1
  46. package/lib/aptos/network.js +1 -0
  47. package/lib/aptos/network.js.map +1 -1
  48. package/lib/btc/btc-plugin.d.ts +4 -1
  49. package/lib/btc/btc-plugin.d.ts.map +1 -1
  50. package/lib/btc/btc-plugin.js +27 -0
  51. package/lib/btc/btc-plugin.js.map +1 -1
  52. package/lib/btc/btc-processor.d.ts +6 -5
  53. package/lib/btc/btc-processor.d.ts.map +1 -1
  54. package/lib/btc/btc-processor.js +35 -9
  55. package/lib/btc/btc-processor.js.map +1 -1
  56. package/lib/btc/types.d.ts +2 -1
  57. package/lib/btc/types.d.ts.map +1 -1
  58. package/lib/core/base-context.d.ts +4 -2
  59. package/lib/core/base-context.d.ts.map +1 -1
  60. package/lib/core/base-context.js +8 -3
  61. package/lib/core/base-context.js.map +1 -1
  62. package/lib/core/event-logger.d.ts +5 -0
  63. package/lib/core/event-logger.d.ts.map +1 -1
  64. package/lib/core/event-logger.js +36 -1
  65. package/lib/core/event-logger.js.map +1 -1
  66. package/lib/core/handler-options.d.ts +25 -0
  67. package/lib/core/handler-options.d.ts.map +1 -0
  68. package/lib/core/handler-options.js +21 -0
  69. package/lib/core/handler-options.js.map +1 -0
  70. package/lib/core/index.d.ts +3 -1
  71. package/lib/core/index.d.ts.map +1 -1
  72. package/lib/core/index.js +3 -1
  73. package/lib/core/index.js.map +1 -1
  74. package/lib/core/meter.d.ts +45 -2
  75. package/lib/core/meter.d.ts.map +1 -1
  76. package/lib/core/meter.js +124 -2
  77. package/lib/core/meter.js.map +1 -1
  78. package/lib/core/numberish.d.ts +2 -1
  79. package/lib/core/numberish.d.ts.map +1 -1
  80. package/lib/core/numberish.js +35 -1
  81. package/lib/core/numberish.js.map +1 -1
  82. package/lib/core/partition-handler-manager.d.ts +44 -0
  83. package/lib/core/partition-handler-manager.d.ts.map +1 -0
  84. package/lib/core/partition-handler-manager.js +76 -0
  85. package/lib/core/partition-handler-manager.js.map +1 -0
  86. package/lib/cosmos/cosmos-processor.d.ts +3 -2
  87. package/lib/cosmos/cosmos-processor.d.ts.map +1 -1
  88. package/lib/cosmos/cosmos-processor.js +11 -1
  89. package/lib/cosmos/cosmos-processor.js.map +1 -1
  90. package/lib/cosmos/types.d.ts +1 -0
  91. package/lib/cosmos/types.d.ts.map +1 -1
  92. package/lib/eth/base-processor.d.ts +23 -17
  93. package/lib/eth/base-processor.d.ts.map +1 -1
  94. package/lib/eth/base-processor.js +173 -34
  95. package/lib/eth/base-processor.js.map +1 -1
  96. package/lib/eth/bind-options.d.ts +6 -0
  97. package/lib/eth/bind-options.d.ts.map +1 -1
  98. package/lib/eth/bind-options.js +2 -0
  99. package/lib/eth/bind-options.js.map +1 -1
  100. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +32 -31
  101. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
  102. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +62 -62
  103. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  104. package/lib/eth/builtin/internal/erc1155-processor.d.ts +17 -16
  105. package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
  106. package/lib/eth/builtin/internal/erc1155-processor.js +32 -32
  107. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  108. package/lib/eth/builtin/internal/erc20-processor.d.ts +25 -24
  109. package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
  110. package/lib/eth/builtin/internal/erc20-processor.js +48 -48
  111. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  112. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +14 -13
  113. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
  114. package/lib/eth/builtin/internal/erc20bytes-processor.js +26 -26
  115. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  116. package/lib/eth/builtin/internal/erc721-processor.d.ts +21 -20
  117. package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
  118. package/lib/eth/builtin/internal/erc721-processor.js +40 -40
  119. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  120. package/lib/eth/builtin/internal/weth9-processor.d.ts +20 -19
  121. package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
  122. package/lib/eth/builtin/internal/weth9-processor.js +38 -38
  123. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  124. package/lib/eth/codegen/event-handler.js +2 -2
  125. package/lib/eth/codegen/event-handler.js.map +1 -1
  126. package/lib/eth/codegen/file.d.ts.map +1 -1
  127. package/lib/eth/codegen/file.js +1 -0
  128. package/lib/eth/codegen/file.js.map +1 -1
  129. package/lib/eth/codegen/functions-handler.js +2 -2
  130. package/lib/eth/codegen/functions-handler.js.map +1 -1
  131. package/lib/eth/eth-plugin.d.ts +5 -1
  132. package/lib/eth/eth-plugin.d.ts.map +1 -1
  133. package/lib/eth/eth-plugin.js +53 -5
  134. package/lib/eth/eth-plugin.js.map +1 -1
  135. package/lib/eth/eth.d.ts +2 -7
  136. package/lib/eth/eth.d.ts.map +1 -1
  137. package/lib/eth/eth.js +8 -1
  138. package/lib/eth/eth.js.map +1 -1
  139. package/lib/fuel/codegen/codegen.js +5 -5
  140. package/lib/fuel/codegen/codegen.js.map +1 -1
  141. package/lib/fuel/fuel-plugin.d.ts +4 -1
  142. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  143. package/lib/fuel/fuel-plugin.js +41 -0
  144. package/lib/fuel/fuel-plugin.js.map +1 -1
  145. package/lib/fuel/fuel-processor-template.d.ts +7 -4
  146. package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
  147. package/lib/fuel/fuel-processor-template.js +11 -9
  148. package/lib/fuel/fuel-processor-template.js.map +1 -1
  149. package/lib/fuel/fuel-processor.d.ts +7 -7
  150. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  151. package/lib/fuel/fuel-processor.js +91 -28
  152. package/lib/fuel/fuel-processor.js.map +1 -1
  153. package/lib/fuel/types.d.ts +3 -0
  154. package/lib/fuel/types.d.ts.map +1 -1
  155. package/lib/move/filter.d.ts +5 -0
  156. package/lib/move/filter.d.ts.map +1 -1
  157. package/lib/move/filter.js +5 -0
  158. package/lib/move/filter.js.map +1 -1
  159. package/lib/move/shared-network-codegen.d.ts.map +1 -1
  160. package/lib/move/shared-network-codegen.js +5 -4
  161. package/lib/move/shared-network-codegen.js.map +1 -1
  162. package/lib/solana/solana-processor.d.ts +10 -4
  163. package/lib/solana/solana-processor.d.ts.map +1 -1
  164. package/lib/solana/solana-processor.js +13 -4
  165. package/lib/solana/solana-processor.js.map +1 -1
  166. package/lib/stark/starknet-processor.d.ts +3 -1
  167. package/lib/stark/starknet-processor.d.ts.map +1 -1
  168. package/lib/stark/starknet-processor.js +32 -14
  169. package/lib/stark/starknet-processor.js.map +1 -1
  170. package/lib/store/codegen.d.ts.map +1 -1
  171. package/lib/store/codegen.js +36 -2
  172. package/lib/store/codegen.js.map +1 -1
  173. package/lib/store/schema.d.ts.map +1 -1
  174. package/lib/store/schema.js +3 -1
  175. package/lib/store/schema.js.map +1 -1
  176. package/lib/store/store.d.ts +4 -3
  177. package/lib/store/store.d.ts.map +1 -1
  178. package/lib/store/store.js +41 -1
  179. package/lib/store/store.js.map +1 -1
  180. package/lib/store/types.d.ts +20 -1
  181. package/lib/store/types.d.ts.map +1 -1
  182. package/lib/store/types.js +22 -0
  183. package/lib/store/types.js.map +1 -1
  184. package/lib/sui/builtin/0x1.d.ts +11 -6
  185. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  186. package/lib/sui/builtin/0x1.js +13 -13
  187. package/lib/sui/builtin/0x1.js.map +1 -1
  188. package/lib/sui/builtin/0x2.d.ts +123 -59
  189. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  190. package/lib/sui/builtin/0x2.js +397 -119
  191. package/lib/sui/builtin/0x2.js.map +1 -1
  192. package/lib/sui/builtin/0x3.d.ts +89 -61
  193. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  194. package/lib/sui/builtin/0x3.js +222 -104
  195. package/lib/sui/builtin/0x3.js.map +1 -1
  196. package/lib/sui/models.d.ts +1 -0
  197. package/lib/sui/models.d.ts.map +1 -1
  198. package/lib/sui/sui-object-processor-template.js +1 -1
  199. package/lib/sui/sui-object-processor-template.js.map +1 -1
  200. package/lib/sui/sui-object-processor.d.ts +2 -0
  201. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  202. package/lib/sui/sui-object-processor.js +4 -0
  203. package/lib/sui/sui-object-processor.js.map +1 -1
  204. package/lib/sui/sui-plugin.d.ts +6 -3
  205. package/lib/sui/sui-plugin.d.ts.map +1 -1
  206. package/lib/sui/sui-plugin.js +68 -24
  207. package/lib/sui/sui-plugin.js.map +1 -1
  208. package/lib/sui/sui-processor.d.ts +6 -4
  209. package/lib/sui/sui-processor.d.ts.map +1 -1
  210. package/lib/sui/sui-processor.js +48 -11
  211. package/lib/sui/sui-processor.js.map +1 -1
  212. package/lib/testing/eth-facet.d.ts +2 -1
  213. package/lib/testing/eth-facet.d.ts.map +1 -1
  214. package/lib/testing/eth-facet.js.map +1 -1
  215. package/lib/utils/block.d.ts +2 -0
  216. package/lib/utils/block.d.ts.map +1 -1
  217. package/lib/utils/block.js +13 -0
  218. package/lib/utils/block.js.map +1 -1
  219. package/package.json +9 -8
  220. package/src/aptos/abis/0x1.json +9650 -5284
  221. package/src/aptos/abis/0x3.json +13 -13
  222. package/src/aptos/abis/0x4.json +42 -42
  223. package/src/aptos/api.ts +13 -1
  224. package/src/aptos/aptos-plugin.ts +62 -13
  225. package/src/aptos/aptos-processor.ts +114 -74
  226. package/src/aptos/aptos-resource-processor-template.ts +9 -8
  227. package/src/aptos/builtin/0x1.ts +3105 -705
  228. package/src/aptos/builtin/0x3.ts +304 -131
  229. package/src/aptos/builtin/0x4.ts +125 -57
  230. package/src/aptos/codegen/codegen.ts +40 -5
  231. package/src/aptos/data.ts +123 -0
  232. package/src/aptos/index.ts +2 -0
  233. package/src/aptos/models.ts +2 -0
  234. package/src/aptos/move-coder.ts +96 -3
  235. package/src/aptos/network.ts +1 -0
  236. package/src/btc/btc-plugin.ts +38 -0
  237. package/src/btc/btc-processor.ts +35 -10
  238. package/src/btc/types.ts +2 -1
  239. package/src/core/base-context.ts +8 -3
  240. package/src/core/event-logger.ts +45 -1
  241. package/src/core/handler-options.ts +40 -0
  242. package/src/core/index.ts +17 -1
  243. package/src/core/meter.ts +159 -4
  244. package/src/core/numberish.ts +34 -1
  245. package/src/core/partition-handler-manager.ts +94 -0
  246. package/src/cosmos/cosmos-processor.ts +12 -1
  247. package/src/cosmos/types.ts +1 -0
  248. package/src/eth/base-processor.ts +163 -41
  249. package/src/eth/bind-options.ts +7 -0
  250. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +118 -62
  251. package/src/eth/builtin/internal/erc1155-processor.ts +76 -32
  252. package/src/eth/builtin/internal/erc20-processor.ts +79 -48
  253. package/src/eth/builtin/internal/erc20bytes-processor.ts +47 -26
  254. package/src/eth/builtin/internal/erc721-processor.ts +77 -40
  255. package/src/eth/builtin/internal/weth9-processor.ts +79 -38
  256. package/src/eth/codegen/event-handler.ts +2 -2
  257. package/src/eth/codegen/file.ts +1 -0
  258. package/src/eth/codegen/functions-handler.ts +2 -2
  259. package/src/eth/eth-plugin.ts +76 -10
  260. package/src/eth/eth.ts +12 -1
  261. package/src/fuel/codegen/codegen.ts +5 -5
  262. package/src/fuel/fuel-plugin.ts +56 -0
  263. package/src/fuel/fuel-processor-template.ts +17 -10
  264. package/src/fuel/fuel-processor.ts +90 -22
  265. package/src/fuel/types.ts +3 -0
  266. package/src/move/filter.ts +5 -0
  267. package/src/move/shared-network-codegen.ts +5 -4
  268. package/src/solana/solana-processor.ts +28 -6
  269. package/src/stark/starknet-processor.ts +31 -13
  270. package/src/store/codegen.ts +50 -2
  271. package/src/store/schema.ts +3 -1
  272. package/src/store/store.ts +57 -4
  273. package/src/store/types.ts +30 -1
  274. package/src/sui/abis/0x1.json +8 -0
  275. package/src/sui/abis/0x2.json +437 -0
  276. package/src/sui/abis/0x3.json +116 -5
  277. package/src/sui/builtin/0x1.ts +28 -13
  278. package/src/sui/builtin/0x2.ts +631 -119
  279. package/src/sui/builtin/0x3.ts +450 -116
  280. package/src/sui/models.ts +2 -0
  281. package/src/sui/sui-object-processor-template.ts +1 -1
  282. package/src/sui/sui-object-processor.ts +6 -0
  283. package/src/sui/sui-plugin.ts +77 -26
  284. package/src/sui/sui-processor.ts +50 -11
  285. package/src/testing/eth-facet.ts +2 -1
  286. package/src/utils/block.ts +15 -0
package/src/aptos/api.ts CHANGED
@@ -14,6 +14,9 @@ import { AptosBaseContext } from './context.js'
14
14
  import { TypeDescriptor } from '@typemove/move'
15
15
  import { defaultMoveCoderForClient } from './move-coder.js'
16
16
 
17
+ // Sentinel value to indicate "latest" ledger version
18
+ export const LATEST_LEDGER_VERSION = Number.MAX_SAFE_INTEGER
19
+
17
20
  // Aptos Client inherit [[ Aptos ]] and add getTypedAccountResource method with could get resource and
18
21
  // decode it to the specified type
19
22
  export class RichAptosClient extends Aptos {
@@ -45,12 +48,21 @@ export class RichAptosClientWithContext extends RichAptosClient {
45
48
  }
46
49
 
47
50
  private transformArgs<T extends { options?: LedgerVersionArg }>(args: T): T {
48
- if (!args.options?.ledgerVersion) {
51
+ // Check if ledgerVersion was explicitly provided
52
+ if (!args.options || !('ledgerVersion' in args.options)) {
53
+ // No ledgerVersion specified at all - use context version
49
54
  args.options = {
50
55
  ...args.options,
51
56
  ledgerVersion: this.ctx.version
52
57
  }
58
+ } else if (args.options.ledgerVersion === LATEST_LEDGER_VERSION) {
59
+ // Explicitly requested latest state using sentinel value
60
+ args.options = {
61
+ ...args.options,
62
+ ledgerVersion: undefined // This tells Aptos SDK to use latest
63
+ }
53
64
  }
65
+ // Otherwise, use the provided ledgerVersion as-is
54
66
  return args
55
67
  }
56
68
 
@@ -1,10 +1,9 @@
1
1
  import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
+ import { PartitionHandlerManager } from '../core/index.js'
2
3
  import {
3
4
  AccountConfig,
4
5
  ContractConfig,
5
6
  Data_AptCall,
6
- Data_AptEvent,
7
- Data_AptResource,
8
7
  DataBinding,
9
8
  HandlerType,
10
9
  MoveCallHandlerConfig,
@@ -12,6 +11,7 @@ import {
12
11
  MoveOwnerType,
13
12
  ProcessConfigResponse,
14
13
  ProcessResult,
14
+ ProcessStreamResponse_Partitions,
15
15
  StartRequest
16
16
  } from '@sentio/protos'
17
17
 
@@ -27,13 +27,15 @@ import {
27
27
  AptosResourceProcessorTemplateState
28
28
  } from './aptos-resource-processor-template.js'
29
29
  import { AptosNetwork } from './network.js'
30
+ import { AptEvent, AptCall, AptResource } from './data.js'
30
31
 
31
32
  interface Handlers {
32
- aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[]
33
- aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[]
34
- aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[]
33
+ aptosEventHandlers: ((event: AptEvent) => Promise<ProcessResult>)[]
34
+ aptosCallHandlers: ((func: AptCall) => Promise<ProcessResult>)[]
35
+ aptosResourceHandlers: ((resourceWithVersion: AptResource) => Promise<ProcessResult>)[]
35
36
  aptosTransactionIntervalHandlers: ((txn: Data_AptCall) => Promise<ProcessResult>)[]
36
37
  }
38
+
37
39
  export class AptosPlugin extends Plugin {
38
40
  name: string = 'AptosPlugin'
39
41
  handlers: Handlers = {
@@ -43,6 +45,8 @@ export class AptosPlugin extends Plugin {
43
45
  aptosTransactionIntervalHandlers: []
44
46
  }
45
47
 
48
+ partitionManager = new PartitionHandlerManager()
49
+
46
50
  async start(request: StartRequest) {
47
51
  await initTokenList()
48
52
 
@@ -60,6 +64,7 @@ export class AptosPlugin extends Plugin {
60
64
  address: instance.contract?.address || '',
61
65
  network: <AptosNetwork>instance.contract?.chainId || AptosNetwork.MAIN_NET,
62
66
  startVersion: instance.startBlock || 0n,
67
+ endVersion: instance.endBlock,
63
68
  baseLabels: instance.baseLabels
64
69
  },
65
70
  NoopContext
@@ -83,11 +88,13 @@ export class AptosPlugin extends Plugin {
83
88
  address: aptosProcessor.config.address,
84
89
  abi: ''
85
90
  },
86
- startBlock: aptosProcessor.config.startVersion
91
+ startBlock: aptosProcessor.config.startVersion,
92
+ endBlock: aptosProcessor.config.endVersion
87
93
  })
88
94
  // 1. Prepare event handlers
89
95
  for (const handler of aptosProcessor.eventHandlers) {
90
96
  const handlerId = handlers.aptosEventHandlers.push(handler.handler) - 1
97
+ this.partitionManager.registerPartitionHandler(HandlerType.APT_EVENT, handlerId, handler.partitionHandler)
91
98
  const eventHandlerConfig: MoveEventHandlerConfig = {
92
99
  filters: handler.filters.map((f) => {
93
100
  return {
@@ -106,6 +113,7 @@ export class AptosPlugin extends Plugin {
106
113
  // 2. Prepare function handlers
107
114
  for (const handler of aptosProcessor.callHandlers) {
108
115
  const handlerId = handlers.aptosCallHandlers.push(handler.handler) - 1
116
+ this.partitionManager.registerPartitionHandler(HandlerType.APT_CALL, handlerId, handler.partitionHandler)
109
117
  const functionHandlerConfig: MoveCallHandlerConfig = {
110
118
  filters: handler.filters.map((filter) => {
111
119
  return {
@@ -132,20 +140,24 @@ export class AptosPlugin extends Plugin {
132
140
  const accountConfig = AccountConfig.fromPartial({
133
141
  address: aptosProcessor.config.address,
134
142
  chainId: aptosProcessor.getChainId(),
135
- startBlock: aptosProcessor.config.startVersion
143
+ startBlock: aptosProcessor.config.startVersion,
144
+ endBlock: aptosProcessor.config.endVersion
136
145
  })
137
146
  for (const handler of aptosProcessor.resourceChangeHandlers) {
138
147
  const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
148
+ this.partitionManager.registerPartitionHandler(HandlerType.APT_RESOURCE, handlerId, handler.partitionHandler)
139
149
  accountConfig.moveResourceChangeConfigs.push({
140
150
  handlerId: handlerId,
141
151
  handlerName: handler.handlerName,
142
- type: handler.type
152
+ type: handler.type,
153
+ includeDeleted: false
143
154
  })
144
155
  }
145
156
 
146
157
  // Prepare interval handlers
147
158
  for (const handler of aptosProcessor.transactionIntervalHandlers) {
148
159
  const handlerId = handlers.aptosTransactionIntervalHandlers.push(handler.handler) - 1
160
+ this.partitionManager.registerPartitionHandler(HandlerType.APT_CALL, handlerId, handler.partitionHandler)
149
161
  accountConfig.moveIntervalConfigs.push({
150
162
  intervalConfig: {
151
163
  handlerId: handlerId,
@@ -170,10 +182,12 @@ export class AptosPlugin extends Plugin {
170
182
  const accountConfig = AccountConfig.fromPartial({
171
183
  address: aptosProcessor.config.address,
172
184
  chainId: aptosProcessor.getChainId(),
173
- startBlock: aptosProcessor.config.startVersion
185
+ startBlock: aptosProcessor.config.startVersion,
186
+ endBlock: aptosProcessor.config.endVersion
174
187
  })
175
188
  for (const handler of aptosProcessor.resourceIntervalHandlers) {
176
189
  const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
190
+ this.partitionManager.registerPartitionHandler(HandlerType.APT_RESOURCE, handlerId, handler.partitionHandler)
177
191
  if (handler.timeIntervalInMinutes || handler.versionInterval) {
178
192
  accountConfig.moveIntervalConfigs.push({
179
193
  intervalConfig: {
@@ -195,7 +209,8 @@ export class AptosPlugin extends Plugin {
195
209
  accountConfig.moveResourceChangeConfigs.push({
196
210
  handlerId,
197
211
  handlerName: handler.handlerName,
198
- type: handler.type
212
+ type: handler.type,
213
+ includeDeleted: false
199
214
  })
200
215
  }
201
216
  }
@@ -219,12 +234,46 @@ export class AptosPlugin extends Plugin {
219
234
  }
220
235
  }
221
236
 
237
+ async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {
238
+ let data: any
239
+ switch (request.handlerType) {
240
+ case HandlerType.APT_EVENT:
241
+ if (!request.data?.aptEvent) {
242
+ throw new ServerError(Status.INVALID_ARGUMENT, "aptEvent can't be empty")
243
+ }
244
+ data = new AptEvent(request.data.aptEvent)
245
+ break
246
+ case HandlerType.APT_CALL:
247
+ if (!request.data?.aptCall) {
248
+ throw new ServerError(Status.INVALID_ARGUMENT, "aptCall can't be empty")
249
+ }
250
+ data = new AptCall(request.data.aptCall)
251
+ break
252
+ case HandlerType.APT_RESOURCE:
253
+ if (!request.data?.aptResource) {
254
+ throw new ServerError(Status.INVALID_ARGUMENT, "aptResource can't be empty")
255
+ }
256
+ data = new AptResource(request.data.aptResource)
257
+ break
258
+ default:
259
+ throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
260
+ }
261
+ const partitions = await this.partitionManager.processPartitionForHandlerType(
262
+ request.handlerType,
263
+ request.handlerIds,
264
+ data
265
+ )
266
+ return {
267
+ partitions
268
+ }
269
+ }
270
+
222
271
  async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {
223
272
  if (!binding.data?.aptEvent) {
224
273
  throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
225
274
  }
226
275
  const promises: Promise<ProcessResult>[] = []
227
- const event = binding.data.aptEvent
276
+ const event = new AptEvent(binding.data.aptEvent)
228
277
 
229
278
  for (const handlerId of binding.handlerIds) {
230
279
  const promise = this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {
@@ -245,7 +294,7 @@ export class AptosPlugin extends Plugin {
245
294
  if (!binding.data?.aptResource) {
246
295
  throw new ServerError(Status.INVALID_ARGUMENT, "Resource can't be empty")
247
296
  }
248
- const resource = binding.data.aptResource
297
+ const resource = new AptResource(binding.data.aptResource)
249
298
 
250
299
  const promises: Promise<ProcessResult>[] = []
251
300
  for (const handlerId of binding.handlerIds) {
@@ -267,7 +316,7 @@ export class AptosPlugin extends Plugin {
267
316
  if (!binding.data?.aptCall) {
268
317
  throw new ServerError(Status.INVALID_ARGUMENT, "Call can't be empty")
269
318
  }
270
- const call = binding.data.aptCall
319
+ const call = new AptCall(binding.data.aptCall)
271
320
 
272
321
  const promises: Promise<ProcessResult>[] = []
273
322
  for (const handlerId of binding.handlerIds) {
@@ -1,25 +1,17 @@
1
1
  import { defaultMoveCoder, MoveCoder } from './index.js'
2
2
 
3
3
  import {
4
+ EntryFunctionPayloadResponse,
4
5
  Event,
5
6
  MoveResource,
6
7
  UserTransactionResponse,
7
- EntryFunctionPayloadResponse,
8
- MultisigPayloadResponse,
9
8
  WriteSetChangeWriteResource
10
9
  } from '@aptos-labs/ts-sdk'
11
10
 
12
11
  import { AptosBindOptions, AptosNetwork } from './network.js'
13
12
  import { AptosContext, AptosResourcesContext, AptosTransactionContext } from './context.js'
14
13
  import { ListStateStorage } from '@sentio/runtime'
15
- import {
16
- MoveFetchConfig,
17
- Data_AptResource,
18
- HandleInterval,
19
- Data_AptEvent,
20
- Data_AptCall,
21
- MoveAccountFetchConfig
22
- } from '@sentio/protos'
14
+ import { Data_AptResource, HandleInterval, MoveAccountFetchConfig, MoveFetchConfig } from '@sentio/protos'
23
15
  import { ServerError, Status } from 'nice-grpc'
24
16
  import {
25
17
  accountTypeString,
@@ -33,10 +25,11 @@ import {
33
25
  TransactionIntervalHandler
34
26
  } from '../move/index.js'
35
27
  import { ALL_ADDRESS, Labels, PromiseOrVoid } from '../core/index.js'
36
- import { TypeDescriptor, matchType, NestedDecodedStruct } from '@typemove/move'
37
- import { decodeResourceChange, ResourceChange } from '@typemove/aptos'
38
- import { GeneralTransactionResponse } from './models.js'
28
+ import { matchType, NestedDecodedStruct, TypeDescriptor } from '@typemove/move'
29
+ import { ResourceChange } from '@typemove/aptos'
30
+ import { GeneralTransactionResponse, HandlerOptions } from './models.js'
39
31
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
32
+ import { AptCall, AptEvent, AptResource } from './data.js'
40
33
 
41
34
  const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
42
35
  resourceChanges: false,
@@ -54,6 +47,7 @@ type IndexConfigure = {
54
47
  address: string
55
48
  network: AptosNetwork
56
49
  startVersion: bigint
50
+ endVersion?: bigint
57
51
  baseLabels?: Labels
58
52
  // endSeqNumber?: Long
59
53
  }
@@ -65,9 +59,9 @@ export class AptosProcessorState extends ListStateStorage<AptosTransactionProces
65
59
  export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT extends AptosTransactionContext<T>> {
66
60
  readonly moduleName: string
67
61
  config: IndexConfigure
68
- eventHandlers: EventHandler<Data_AptEvent>[] = []
69
- callHandlers: CallHandler<Data_AptCall>[] = []
70
- resourceChangeHandlers: ResourceChangeHandler<Data_AptResource>[] = []
62
+ eventHandlers: EventHandler<AptEvent>[] = []
63
+ callHandlers: CallHandler<AptCall>[] = []
64
+ resourceChangeHandlers: ResourceChangeHandler<AptResource>[] = []
71
65
  transactionIntervalHandlers: TransactionIntervalHandler[] = []
72
66
  coder: MoveCoder
73
67
 
@@ -84,10 +78,10 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
84
78
  protected onMoveEvent(
85
79
  handler: (event: Event, ctx: AptosContext) => PromiseOrVoid,
86
80
  filter: EventFilter | EventFilter[],
87
- fetchConfig?: Partial<MoveFetchConfig>
81
+ handlerOptions?: HandlerOptions<MoveFetchConfig, Event>
88
82
  ): this {
89
83
  let _filters: EventFilter[] = []
90
- const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
84
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handlerOptions })
91
85
 
92
86
  if (Array.isArray(filter)) {
93
87
  _filters = filter
@@ -105,12 +99,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
105
99
  if (!data.rawTransaction) {
106
100
  throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')
107
101
  }
108
- const txn = JSON.parse(data.rawTransaction) as UserTransactionResponse
109
- if (txn.events == null) {
110
- txn.events = []
111
- }
112
-
113
- const evt = JSON.parse(data.rawEvent)
102
+ const txn = data.transaction
114
103
 
115
104
  const ctx = new AptosContext(
116
105
  processor.moduleName,
@@ -122,13 +111,21 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
122
111
  processor.config.baseLabels
123
112
  )
124
113
 
125
- const decoded = await processor.coder.decodeEvent<any>(evt)
126
- await handler(decoded || evt, ctx)
127
-
114
+ const decoded = await data.decodeEvent(processor.coder)
115
+ await handler(decoded || data.event, ctx)
128
116
  return ctx.stopAndGetResult()
129
117
  },
130
118
  filters: _filters,
131
- fetchConfig: _fetchConfig
119
+ fetchConfig: _fetchConfig,
120
+ partitionHandler: async (data: AptEvent): Promise<string | undefined> => {
121
+ const p = handlerOptions?.partitionKey
122
+ if (!p) return undefined
123
+ if (typeof p === 'function') {
124
+ const decoded = await data.decodeEvent(processor.coder)
125
+ return p(decoded || data.event)
126
+ }
127
+ return p
128
+ }
132
129
  })
133
130
  return this
134
131
  }
@@ -136,10 +133,10 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
136
133
  protected onEntryFunctionCall(
137
134
  handler: (call: EntryFunctionPayloadResponse, ctx: AptosContext) => PromiseOrVoid,
138
135
  filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],
139
- fetchConfig?: Partial<MoveFetchConfig>
136
+ handlerOptions?: HandlerOptions<MoveFetchConfig, EntryFunctionPayloadResponse>
140
137
  ): this {
141
138
  let _filters: FunctionNameAndCallFilter[] = []
142
- const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
139
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handlerOptions })
143
140
 
144
141
  if (Array.isArray(filter)) {
145
142
  _filters = filter
@@ -157,7 +154,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
157
154
  if (!data.rawTransaction) {
158
155
  throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')
159
156
  }
160
- const tx = JSON.parse(data.rawTransaction) as UserTransactionResponse
157
+ const tx = data.transaction
161
158
 
162
159
  const ctx = new AptosContext(
163
160
  processor.moduleName,
@@ -169,18 +166,22 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
169
166
  processor.config.baseLabels
170
167
  )
171
168
  if (tx) {
172
- let payload = tx.payload
173
- if (payload.type === 'multisig_payload') {
174
- payload = (payload as MultisigPayloadResponse).transaction_payload ?? payload
175
- }
176
-
177
- const decoded = await processor.coder.decodeFunctionPayload(payload as EntryFunctionPayloadResponse)
169
+ const decoded = await data.decodeCall(processor.coder)
178
170
  await handler(decoded, ctx)
179
171
  }
180
172
  return ctx.stopAndGetResult()
181
173
  },
182
174
  filters: _filters,
183
- fetchConfig: _fetchConfig
175
+ fetchConfig: _fetchConfig,
176
+ partitionHandler: async (data: AptCall): Promise<string | undefined> => {
177
+ const p = handlerOptions?.partitionKey
178
+ if (!p) return undefined
179
+ if (typeof p === 'function') {
180
+ const decoded = await data.decodeCall(processor.coder)
181
+ return p(decoded)
182
+ }
183
+ return p
184
+ }
184
185
  })
185
186
  return this
186
187
  }
@@ -191,9 +192,9 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
191
192
  includeFailed?: boolean
192
193
  sender?: string
193
194
  },
194
- fetchConfig?: Partial<MoveFetchConfig>
195
+ handleOptions?: HandlerOptions<MoveFetchConfig, UserTransactionResponse>
195
196
  ): this {
196
- const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
197
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handleOptions })
197
198
 
198
199
  const processor = this
199
200
  const filter: FunctionNameAndCallFilter = { function: '', includeFailed: transactionFilter?.includeFailed }
@@ -210,10 +211,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
210
211
  if (!data.rawTransaction) {
211
212
  throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')
212
213
  }
213
- const call = JSON.parse(data.rawTransaction) as UserTransactionResponse
214
- if (call.events == null) {
215
- call.events = []
216
- }
214
+ const call = data.transaction
217
215
  const ctx = new AptosContext(
218
216
  processor.moduleName,
219
217
  processor.config.network,
@@ -227,19 +225,31 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
227
225
  return ctx.stopAndGetResult()
228
226
  },
229
227
  filters: [filter],
230
- fetchConfig: _fetchConfig
228
+ fetchConfig: _fetchConfig,
229
+ partitionHandler: async (data: AptCall): Promise<string | undefined> => {
230
+ const p = handleOptions?.partitionKey
231
+ if (!p) return undefined
232
+ if (typeof p === 'function') {
233
+ return p(data.transaction)
234
+ }
235
+ return p
236
+ }
231
237
  })
232
238
  return this
233
239
  }
234
240
 
235
- public onEvent(handler: (event: Event, ctx: AptosContext) => void, fetchConfig?: Partial<MoveFetchConfig>): this {
236
- this.onMoveEvent(handler, { type: '' }, fetchConfig)
241
+ public onEvent(
242
+ handler: (event: Event, ctx: AptosContext) => void,
243
+ handlerOptions?: HandlerOptions<MoveFetchConfig, Event>
244
+ ): this {
245
+ this.onMoveEvent(handler, { type: '' }, handlerOptions)
237
246
  return this
238
247
  }
239
248
 
240
249
  public onResourceChange<T>(
241
250
  handler: (changes: ResourceChange<T>[], ctx: AptosResourcesContext) => PromiseOrVoid,
242
- typeDesc: TypeDescriptor<T> | string
251
+ typeDesc: TypeDescriptor<T> | string,
252
+ handlerOptions?: HandlerOptions<object, ResourceChange<T>[]>
243
253
  ): this {
244
254
  if (typeof typeDesc === 'string') {
245
255
  typeDesc = parseMoveType(typeDesc)
@@ -254,6 +264,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
254
264
  if (!data.rawResources || !data.version) {
255
265
  throw new ServerError(Status.INVALID_ARGUMENT, 'resource is null')
256
266
  }
267
+ const aptResource = new AptResource(data)
257
268
  const timestamp = Number(data.timestampMicros)
258
269
  const ctx = new AptosResourcesContext(
259
270
  processor.config.network,
@@ -262,10 +273,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
262
273
  timestamp,
263
274
  processor.config.baseLabels
264
275
  )
265
- let resources = await decodeResourceChange<T>(
266
- data.rawResources.map((r) => JSON.parse(r)),
267
- ctx.coder
268
- )
276
+ let resources = await aptResource.decodeResources<T>(processor.coder)
269
277
 
270
278
  if (hasAny) {
271
279
  resources = resources.filter((r) => {
@@ -279,7 +287,16 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
279
287
  }
280
288
  return ctx.stopAndGetResult()
281
289
  },
282
- type: hasAny ? typeDesc.qname : typeDesc.getNormalizedSignature()
290
+ type: hasAny ? typeDesc.qname : typeDesc.getNormalizedSignature(),
291
+ partitionHandler: async (data): Promise<string | undefined> => {
292
+ const p = handlerOptions?.partitionKey
293
+ if (!p) return undefined
294
+ if (typeof p === 'function') {
295
+ const resources = await data.decodeResources<T>(processor.coder)
296
+ return p(resources)
297
+ }
298
+ return p
299
+ }
283
300
  })
284
301
  return this
285
302
  }
@@ -288,7 +305,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
288
305
  handler: (transaction: T, ctx: CT) => PromiseOrVoid,
289
306
  timeInterval: HandleInterval | undefined,
290
307
  versionInterval: HandleInterval | undefined,
291
- fetchConfig: Partial<MoveFetchConfig> | undefined
308
+ handlerOptions?: HandlerOptions<MoveFetchConfig, T>
292
309
  ): this {
293
310
  const processor = this
294
311
  this.transactionIntervalHandlers.push({
@@ -317,7 +334,16 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
317
334
  },
318
335
  timeIntervalInMinutes: timeInterval,
319
336
  versionInterval: versionInterval,
320
- fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig }
337
+ fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...handlerOptions },
338
+ partitionHandler: async (data): Promise<string | undefined> => {
339
+ const p = handlerOptions?.partitionKey
340
+ if (!p) return undefined
341
+ if (typeof p === 'function') {
342
+ const transaction = JSON.parse(data.rawTransaction) as T
343
+ return p(transaction)
344
+ }
345
+ return p
346
+ }
321
347
  })
322
348
  return this
323
349
  }
@@ -326,7 +352,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
326
352
  handler: (transaction: T, ctx: CT) => PromiseOrVoid,
327
353
  timeIntervalInMinutes = 60,
328
354
  backfillTimeIntervalInMinutes = 240,
329
- fetchConfig?: Partial<MoveFetchConfig>
355
+ handlerOptions?: HandlerOptions<MoveFetchConfig, T>
330
356
  ): this {
331
357
  return this.onInterval(
332
358
  handler,
@@ -335,7 +361,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
335
361
  backfillInterval: backfillTimeIntervalInMinutes
336
362
  },
337
363
  undefined,
338
- fetchConfig
364
+ handlerOptions
339
365
  )
340
366
  }
341
367
 
@@ -343,13 +369,13 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
343
369
  handler: (transaction: T, context: CT) => PromiseOrVoid,
344
370
  versionInterval = 100000,
345
371
  backfillVersionInterval = 400000,
346
- fetchConfig?: Partial<MoveFetchConfig>
372
+ handlerOptions?: HandlerOptions<MoveFetchConfig, T>
347
373
  ): this {
348
374
  return this.onInterval(
349
375
  handler,
350
376
  undefined,
351
377
  { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },
352
- fetchConfig
378
+ handlerOptions
353
379
  )
354
380
  }
355
381
 
@@ -376,6 +402,7 @@ export class AptosModulesProcessor extends AptosTransactionProcessor<
376
402
 
377
403
  export class AptosGlobalProcessor {
378
404
  private baseProcessor
405
+
379
406
  private constructor(options: AptosBindOptions) {
380
407
  this.baseProcessor = new AptosTransactionProcessor('*', options)
381
408
  return proxyProcessor(this)
@@ -404,9 +431,9 @@ export class AptosGlobalProcessor {
404
431
  ) => PromiseOrVoid,
405
432
  timeIntervalInMinutes = 60,
406
433
  backfillTimeIntervalInMinutes = 240,
407
- fetchConfig?: Partial<MoveFetchConfig>
434
+ handlerOptions?: HandlerOptions<MoveFetchConfig, GeneralTransactionResponse>
408
435
  ): this {
409
- this.baseProcessor.onTimeInterval(handler, timeIntervalInMinutes, backfillTimeIntervalInMinutes, fetchConfig)
436
+ this.baseProcessor.onTimeInterval(handler, timeIntervalInMinutes, backfillTimeIntervalInMinutes, handlerOptions)
410
437
  return this
411
438
  }
412
439
 
@@ -417,9 +444,9 @@ export class AptosGlobalProcessor {
417
444
  ) => PromiseOrVoid,
418
445
  versionInterval = 100000,
419
446
  backfillVersionInterval = 400000,
420
- fetchConfig?: Partial<MoveFetchConfig>
447
+ handlerOptions?: HandlerOptions<MoveFetchConfig, GeneralTransactionResponse>
421
448
  ): this {
422
- this.baseProcessor.onVersionInterval(handler, versionInterval, backfillVersionInterval, fetchConfig)
449
+ this.baseProcessor.onVersionInterval(handler, versionInterval, backfillVersionInterval, handlerOptions)
423
450
  return this
424
451
  }
425
452
  }
@@ -453,7 +480,7 @@ export class AptosResourcesProcessor {
453
480
  timeInterval: HandleInterval | undefined,
454
481
  versionInterval: HandleInterval | undefined,
455
482
  type: string | undefined,
456
- fetchConfig: Partial<MoveAccountFetchConfig> | undefined,
483
+ handlerOptions?: HandlerOptions<MoveAccountFetchConfig, MoveResource[]>,
457
484
  handlerName = getHandlerName()
458
485
  ): this {
459
486
  const processor = this
@@ -463,6 +490,7 @@ export class AptosResourcesProcessor {
463
490
  if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {
464
491
  throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')
465
492
  }
493
+ const aptResource = new AptResource(data)
466
494
  const timestamp = Number(data.timestampMicros)
467
495
 
468
496
  const ctx = new AptosResourcesContext(
@@ -472,13 +500,22 @@ export class AptosResourcesProcessor {
472
500
  timestamp,
473
501
  processor.config.baseLabels
474
502
  )
475
- await handler(data.rawResources.map((r) => JSON.parse(r)) as MoveResource[], ctx)
503
+ await handler(aptResource.resources, ctx)
476
504
  return ctx.stopAndGetResult()
477
505
  },
478
506
  timeIntervalInMinutes: timeInterval,
479
507
  versionInterval: versionInterval,
480
508
  type: type,
481
- fetchConfig: { ...DEFAULT_RESOURCE_FETCH_CONFIG, ...fetchConfig }
509
+ fetchConfig: { ...DEFAULT_RESOURCE_FETCH_CONFIG, ...handlerOptions },
510
+ partitionHandler: async (data: Data_AptResource): Promise<string | undefined> => {
511
+ const p = handlerOptions?.partitionKey
512
+ if (!p) return undefined
513
+ if (typeof p === 'function') {
514
+ const aptResource = new AptResource(data)
515
+ return p(aptResource.resources)
516
+ }
517
+ return p
518
+ }
482
519
  })
483
520
  return this
484
521
  }
@@ -488,7 +525,7 @@ export class AptosResourcesProcessor {
488
525
  timeIntervalInMinutes = 60,
489
526
  backfillTimeIntervalInMinutes = 240,
490
527
  type?: string,
491
- fetchConfig?: Partial<MoveAccountFetchConfig>
528
+ handlerOptions?: HandlerOptions<MoveAccountFetchConfig, MoveResource[]>
492
529
  ): this {
493
530
  return this.onInterval(
494
531
  handler,
@@ -498,7 +535,7 @@ export class AptosResourcesProcessor {
498
535
  },
499
536
  undefined,
500
537
  type,
501
- fetchConfig
538
+ handlerOptions
502
539
  )
503
540
  }
504
541
 
@@ -507,14 +544,14 @@ export class AptosResourcesProcessor {
507
544
  versionInterval = 100000,
508
545
  backfillVersionInterval = 400000,
509
546
  typePrefix?: string,
510
- fetchConfig?: Partial<MoveAccountFetchConfig>
547
+ handlerOptions?: HandlerOptions<MoveAccountFetchConfig, MoveResource[]>
511
548
  ): this {
512
549
  return this.onInterval(
513
550
  handler,
514
551
  undefined,
515
552
  { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },
516
553
  typePrefix,
517
- fetchConfig
554
+ handlerOptions
518
555
  )
519
556
  }
520
557
 
@@ -538,6 +575,7 @@ export class AptosResourcesProcessor {
538
575
  if (!data.rawResources || !data.version) {
539
576
  throw new ServerError(Status.INVALID_ARGUMENT, 'resource is null')
540
577
  }
578
+ const aptResource = new AptResource(data)
541
579
  const ctx = new AptosResourcesContext(
542
580
  processor.config.network,
543
581
  processor.config.address,
@@ -546,10 +584,11 @@ export class AptosResourcesProcessor {
546
584
  processor.config.baseLabels
547
585
  )
548
586
 
549
- let resources = (await decodeResourceChange(
550
- data.rawResources.map((r) => JSON.parse(r)),
551
- ctx.coder
552
- )) as NestedDecodedStruct<MoveResource, WriteSetChangeWriteResource, T>[]
587
+ let resources = (await aptResource.decodeResources<T>(ctx.coder)) as NestedDecodedStruct<
588
+ MoveResource,
589
+ WriteSetChangeWriteResource,
590
+ T
591
+ >[]
553
592
 
554
593
  if (hasAny) {
555
594
  resources = resources.filter((r) => {
@@ -581,6 +620,7 @@ function configure(options: AptosBindOptions): IndexConfigure {
581
620
 
582
621
  return {
583
622
  startVersion: startVersion,
623
+ endVersion: options.endVersion ? BigInt(options.endVersion) : undefined,
584
624
  address: options.address === ALL_ADDRESS ? ALL_ADDRESS : accountTypeString(options.address), // aptos don't use address string in api, so only use type string
585
625
  network: options.network || AptosNetwork.MAIN_NET,
586
626
  baseLabels: options.baseLabels