@sentio/sdk 2.59.0-rc.9 → 2.59.1-rc.1

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 (253) 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 +40 -3
  8. package/lib/aptos/aptos-plugin.js.map +1 -1
  9. package/lib/aptos/aptos-processor.d.ts +20 -19
  10. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  11. package/lib/aptos/aptos-processor.js +101 -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 +333 -332
  18. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  19. package/lib/aptos/builtin/0x1.js +664 -664
  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 +130 -130
  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 +56 -56
  28. package/lib/aptos/builtin/0x4.js.map +1 -1
  29. package/lib/aptos/codegen/codegen.js +27 -0
  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/btc/btc-plugin.d.ts +4 -1
  45. package/lib/btc/btc-plugin.d.ts.map +1 -1
  46. package/lib/btc/btc-plugin.js +27 -0
  47. package/lib/btc/btc-plugin.js.map +1 -1
  48. package/lib/btc/btc-processor.d.ts +6 -5
  49. package/lib/btc/btc-processor.d.ts.map +1 -1
  50. package/lib/btc/btc-processor.js +35 -9
  51. package/lib/btc/btc-processor.js.map +1 -1
  52. package/lib/btc/types.d.ts +2 -1
  53. package/lib/btc/types.d.ts.map +1 -1
  54. package/lib/core/base-context.d.ts +4 -2
  55. package/lib/core/base-context.d.ts.map +1 -1
  56. package/lib/core/base-context.js +10 -5
  57. package/lib/core/base-context.js.map +1 -1
  58. package/lib/core/event-logger.d.ts +5 -0
  59. package/lib/core/event-logger.d.ts.map +1 -1
  60. package/lib/core/event-logger.js +36 -1
  61. package/lib/core/event-logger.js.map +1 -1
  62. package/lib/core/handler-options.d.ts +25 -0
  63. package/lib/core/handler-options.d.ts.map +1 -0
  64. package/lib/core/handler-options.js +21 -0
  65. package/lib/core/handler-options.js.map +1 -0
  66. package/lib/core/index.d.ts +3 -1
  67. package/lib/core/index.d.ts.map +1 -1
  68. package/lib/core/index.js +3 -1
  69. package/lib/core/index.js.map +1 -1
  70. package/lib/core/meter.d.ts +45 -2
  71. package/lib/core/meter.d.ts.map +1 -1
  72. package/lib/core/meter.js +124 -2
  73. package/lib/core/meter.js.map +1 -1
  74. package/lib/core/numberish.d.ts +2 -1
  75. package/lib/core/numberish.d.ts.map +1 -1
  76. package/lib/core/numberish.js +35 -1
  77. package/lib/core/numberish.js.map +1 -1
  78. package/lib/core/partition-handler-manager.d.ts +44 -0
  79. package/lib/core/partition-handler-manager.d.ts.map +1 -0
  80. package/lib/core/partition-handler-manager.js +76 -0
  81. package/lib/core/partition-handler-manager.js.map +1 -0
  82. package/lib/cosmos/cosmos-processor.d.ts +3 -2
  83. package/lib/cosmos/cosmos-processor.d.ts.map +1 -1
  84. package/lib/cosmos/cosmos-processor.js +11 -1
  85. package/lib/cosmos/cosmos-processor.js.map +1 -1
  86. package/lib/cosmos/types.d.ts +1 -0
  87. package/lib/cosmos/types.d.ts.map +1 -1
  88. package/lib/eth/base-processor.d.ts +18 -13
  89. package/lib/eth/base-processor.d.ts.map +1 -1
  90. package/lib/eth/base-processor.js +151 -26
  91. package/lib/eth/base-processor.js.map +1 -1
  92. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +32 -31
  93. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
  94. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +62 -62
  95. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  96. package/lib/eth/builtin/internal/erc1155-processor.d.ts +17 -16
  97. package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
  98. package/lib/eth/builtin/internal/erc1155-processor.js +32 -32
  99. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  100. package/lib/eth/builtin/internal/erc20-processor.d.ts +25 -24
  101. package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
  102. package/lib/eth/builtin/internal/erc20-processor.js +48 -48
  103. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  104. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +14 -13
  105. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
  106. package/lib/eth/builtin/internal/erc20bytes-processor.js +26 -26
  107. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  108. package/lib/eth/builtin/internal/erc721-processor.d.ts +21 -20
  109. package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
  110. package/lib/eth/builtin/internal/erc721-processor.js +40 -40
  111. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  112. package/lib/eth/builtin/internal/weth9-processor.d.ts +20 -19
  113. package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
  114. package/lib/eth/builtin/internal/weth9-processor.js +38 -38
  115. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  116. package/lib/eth/codegen/event-handler.js +2 -2
  117. package/lib/eth/codegen/event-handler.js.map +1 -1
  118. package/lib/eth/codegen/file.d.ts.map +1 -1
  119. package/lib/eth/codegen/file.js +1 -0
  120. package/lib/eth/codegen/file.js.map +1 -1
  121. package/lib/eth/codegen/functions-handler.js +2 -2
  122. package/lib/eth/codegen/functions-handler.js.map +1 -1
  123. package/lib/eth/eth-plugin.d.ts +4 -1
  124. package/lib/eth/eth-plugin.d.ts.map +1 -1
  125. package/lib/eth/eth-plugin.js +42 -1
  126. package/lib/eth/eth-plugin.js.map +1 -1
  127. package/lib/eth/eth.d.ts +2 -7
  128. package/lib/eth/eth.d.ts.map +1 -1
  129. package/lib/eth/eth.js +8 -1
  130. package/lib/eth/eth.js.map +1 -1
  131. package/lib/fuel/codegen/codegen.js +5 -5
  132. package/lib/fuel/codegen/codegen.js.map +1 -1
  133. package/lib/fuel/fuel-plugin.d.ts +4 -1
  134. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  135. package/lib/fuel/fuel-plugin.js +41 -0
  136. package/lib/fuel/fuel-plugin.js.map +1 -1
  137. package/lib/fuel/fuel-processor-template.d.ts +7 -4
  138. package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
  139. package/lib/fuel/fuel-processor-template.js +11 -9
  140. package/lib/fuel/fuel-processor-template.js.map +1 -1
  141. package/lib/fuel/fuel-processor.d.ts +7 -7
  142. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  143. package/lib/fuel/fuel-processor.js +91 -28
  144. package/lib/fuel/fuel-processor.js.map +1 -1
  145. package/lib/fuel/types.d.ts +3 -0
  146. package/lib/fuel/types.d.ts.map +1 -1
  147. package/lib/move/filter.d.ts +5 -0
  148. package/lib/move/filter.d.ts.map +1 -1
  149. package/lib/move/filter.js +5 -0
  150. package/lib/move/filter.js.map +1 -1
  151. package/lib/move/shared-network-codegen.d.ts.map +1 -1
  152. package/lib/move/shared-network-codegen.js +5 -4
  153. package/lib/move/shared-network-codegen.js.map +1 -1
  154. package/lib/solana/solana-processor.d.ts +10 -4
  155. package/lib/solana/solana-processor.d.ts.map +1 -1
  156. package/lib/solana/solana-processor.js +13 -4
  157. package/lib/solana/solana-processor.js.map +1 -1
  158. package/lib/stark/starknet-processor.d.ts +3 -1
  159. package/lib/stark/starknet-processor.d.ts.map +1 -1
  160. package/lib/stark/starknet-processor.js +32 -14
  161. package/lib/stark/starknet-processor.js.map +1 -1
  162. package/lib/store/codegen.d.ts.map +1 -1
  163. package/lib/store/codegen.js +36 -2
  164. package/lib/store/codegen.js.map +1 -1
  165. package/lib/store/schema.d.ts.map +1 -1
  166. package/lib/store/schema.js +3 -1
  167. package/lib/store/schema.js.map +1 -1
  168. package/lib/store/store.d.ts +4 -3
  169. package/lib/store/store.d.ts.map +1 -1
  170. package/lib/store/store.js +41 -1
  171. package/lib/store/store.js.map +1 -1
  172. package/lib/store/types.d.ts +20 -1
  173. package/lib/store/types.d.ts.map +1 -1
  174. package/lib/store/types.js +22 -0
  175. package/lib/store/types.js.map +1 -1
  176. package/lib/sui/builtin/0x1.d.ts +7 -6
  177. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  178. package/lib/sui/builtin/0x1.js +12 -12
  179. package/lib/sui/builtin/0x1.js.map +1 -1
  180. package/lib/sui/builtin/0x2.d.ts +61 -60
  181. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  182. package/lib/sui/builtin/0x2.js +120 -120
  183. package/lib/sui/builtin/0x2.js.map +1 -1
  184. package/lib/sui/builtin/0x3.d.ts +49 -48
  185. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  186. package/lib/sui/builtin/0x3.js +96 -96
  187. package/lib/sui/builtin/0x3.js.map +1 -1
  188. package/lib/sui/models.d.ts +1 -0
  189. package/lib/sui/models.d.ts.map +1 -1
  190. package/lib/sui/sui-plugin.d.ts +6 -3
  191. package/lib/sui/sui-plugin.d.ts.map +1 -1
  192. package/lib/sui/sui-plugin.js +59 -20
  193. package/lib/sui/sui-plugin.js.map +1 -1
  194. package/lib/sui/sui-processor.d.ts +5 -4
  195. package/lib/sui/sui-processor.d.ts.map +1 -1
  196. package/lib/sui/sui-processor.js +47 -11
  197. package/lib/sui/sui-processor.js.map +1 -1
  198. package/package.json +4 -4
  199. package/src/aptos/api.ts +13 -1
  200. package/src/aptos/aptos-plugin.ts +51 -8
  201. package/src/aptos/aptos-processor.ts +112 -74
  202. package/src/aptos/aptos-resource-processor-template.ts +9 -8
  203. package/src/aptos/builtin/0x1.ts +1565 -664
  204. package/src/aptos/builtin/0x3.ts +302 -130
  205. package/src/aptos/builtin/0x4.ts +123 -56
  206. package/src/aptos/codegen/codegen.ts +34 -1
  207. package/src/aptos/data.ts +123 -0
  208. package/src/aptos/index.ts +2 -0
  209. package/src/aptos/models.ts +2 -0
  210. package/src/aptos/move-coder.ts +96 -3
  211. package/src/btc/btc-plugin.ts +38 -0
  212. package/src/btc/btc-processor.ts +35 -10
  213. package/src/btc/types.ts +2 -1
  214. package/src/core/base-context.ts +10 -5
  215. package/src/core/event-logger.ts +45 -1
  216. package/src/core/handler-options.ts +40 -0
  217. package/src/core/index.ts +17 -1
  218. package/src/core/meter.ts +159 -4
  219. package/src/core/numberish.ts +34 -1
  220. package/src/core/partition-handler-manager.ts +94 -0
  221. package/src/cosmos/cosmos-processor.ts +12 -1
  222. package/src/cosmos/types.ts +1 -0
  223. package/src/eth/base-processor.ts +139 -28
  224. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +118 -62
  225. package/src/eth/builtin/internal/erc1155-processor.ts +76 -32
  226. package/src/eth/builtin/internal/erc20-processor.ts +79 -48
  227. package/src/eth/builtin/internal/erc20bytes-processor.ts +47 -26
  228. package/src/eth/builtin/internal/erc721-processor.ts +77 -40
  229. package/src/eth/builtin/internal/weth9-processor.ts +79 -38
  230. package/src/eth/codegen/event-handler.ts +2 -2
  231. package/src/eth/codegen/file.ts +1 -0
  232. package/src/eth/codegen/functions-handler.ts +2 -2
  233. package/src/eth/eth-plugin.ts +55 -3
  234. package/src/eth/eth.ts +12 -1
  235. package/src/fuel/codegen/codegen.ts +5 -5
  236. package/src/fuel/fuel-plugin.ts +56 -0
  237. package/src/fuel/fuel-processor-template.ts +17 -10
  238. package/src/fuel/fuel-processor.ts +90 -22
  239. package/src/fuel/types.ts +3 -0
  240. package/src/move/filter.ts +5 -0
  241. package/src/move/shared-network-codegen.ts +5 -4
  242. package/src/solana/solana-processor.ts +28 -6
  243. package/src/stark/starknet-processor.ts +31 -13
  244. package/src/store/codegen.ts +50 -2
  245. package/src/store/schema.ts +3 -1
  246. package/src/store/store.ts +57 -4
  247. package/src/store/types.ts +30 -1
  248. package/src/sui/builtin/0x1.ts +22 -12
  249. package/src/sui/builtin/0x2.ts +220 -120
  250. package/src/sui/builtin/0x3.ts +241 -96
  251. package/src/sui/models.ts +2 -0
  252. package/src/sui/sui-plugin.ts +68 -22
  253. package/src/sui/sui-processor.ts +48 -11
@@ -0,0 +1,123 @@
1
+ import { Data_AptEvent, Data_AptCall, Data_AptResource } from '@sentio/protos'
2
+ import { UserTransactionResponse, MoveResource } from '@aptos-labs/ts-sdk'
3
+ import { MoveCoder, decodeResourceChange, ResourceChange } from '@typemove/aptos'
4
+
5
+ type Data_AptEvent_Ext = Data_AptEvent & {
6
+ _tx?: UserTransactionResponse
7
+ _event?: any
8
+ _decodedEvent?: any
9
+ }
10
+
11
+ type Data_AptCall_Ext = Data_AptCall & {
12
+ _tx?: UserTransactionResponse
13
+ _decodedCall?: any
14
+ }
15
+
16
+ type Data_AptResource_Ext = Data_AptResource & {
17
+ _resources?: MoveResource[]
18
+ _decodedResources?: ResourceChange<any>[]
19
+ }
20
+
21
+ export class AptEvent implements Data_AptEvent {
22
+ constructor(readonly data: Data_AptEvent_Ext) {}
23
+
24
+ get rawEvent(): string {
25
+ return this.data.rawEvent
26
+ }
27
+ get eventIndex(): number {
28
+ return this.data.eventIndex
29
+ }
30
+ get rawTransaction(): string {
31
+ return this.data.rawTransaction
32
+ }
33
+
34
+ get transaction() {
35
+ if (!this.data._tx) {
36
+ this.data._tx = JSON.parse(this.data.rawTransaction) as UserTransactionResponse
37
+ if (this.data._tx.events == null) {
38
+ this.data._tx.events = []
39
+ }
40
+ }
41
+ return this.data._tx
42
+ }
43
+
44
+ get event() {
45
+ if (!this.data._event) {
46
+ this.data._event = JSON.parse(this.data.rawEvent)
47
+ }
48
+ return this.data._event
49
+ }
50
+
51
+ async decodeEvent(coder: MoveCoder) {
52
+ if (!this.data._decodedEvent) {
53
+ this.data._decodedEvent = await coder.decodeEvent<any>(this.event)
54
+ return this.data._decodedEvent
55
+ }
56
+ return this.data._decodedEvent
57
+ }
58
+ }
59
+
60
+ export class AptCall implements Data_AptCall {
61
+ constructor(readonly data: Data_AptCall_Ext) {}
62
+
63
+ get rawTransaction(): string {
64
+ return this.data.rawTransaction
65
+ }
66
+
67
+ get transaction() {
68
+ if (!this.data._tx) {
69
+ this.data._tx = JSON.parse(this.data.rawTransaction) as UserTransactionResponse
70
+ if (this.data._tx.events == null) {
71
+ this.data._tx.events = []
72
+ }
73
+ }
74
+ return this.data._tx
75
+ }
76
+
77
+ async decodeCall(coder: MoveCoder) {
78
+ if (!this.data._decodedCall) {
79
+ const tx = this.transaction
80
+ let payload = tx.payload
81
+ if (payload.type === 'multisig_payload') {
82
+ payload = (payload as any).transaction_payload ?? payload
83
+ }
84
+ this.data._decodedCall = await coder.decodeFunctionPayload(payload as any)
85
+ return this.data._decodedCall
86
+ }
87
+ return this.data._decodedCall
88
+ }
89
+ }
90
+
91
+ export class AptResource implements Data_AptResource {
92
+ constructor(readonly data: Data_AptResource_Ext) {}
93
+
94
+ get version(): bigint {
95
+ return this.data.version
96
+ }
97
+
98
+ get timestampMicros(): bigint {
99
+ return this.data.timestampMicros
100
+ }
101
+
102
+ get rawResources(): string[] {
103
+ return this.data.rawResources
104
+ }
105
+
106
+ get resources(): MoveResource[] {
107
+ if (!this.data._resources) {
108
+ this.data._resources = this.data.rawResources.map((r) => JSON.parse(r) as MoveResource)
109
+ }
110
+ return this.data._resources
111
+ }
112
+
113
+ get timestamp(): Date {
114
+ return new Date(Number(this.data.timestampMicros) / 1000)
115
+ }
116
+
117
+ async decodeResources<T>(coder: MoveCoder): Promise<ResourceChange<T>[]> {
118
+ if (!this.data._decodedResources) {
119
+ this.data._decodedResources = await decodeResourceChange<T>(this.resources, coder)
120
+ }
121
+ return this.data._decodedResources as ResourceChange<T>[]
122
+ }
123
+ }
@@ -20,4 +20,6 @@ export { MoveCoder } from '@typemove/aptos'
20
20
 
21
21
  export { BUILTIN_TYPES } from '@typemove/move'
22
22
 
23
+ export { type HandlerOptions, type PartitionHandler } from './models.js'
24
+
23
25
  // export * from './utils.js'
@@ -27,3 +27,5 @@ export type TypedFunctionPayload<T extends Array<any>> = EntryFunctionPayloadRes
27
27
  */
28
28
  arguments_decoded: T
29
29
  }
30
+
31
+ export type { PartitionHandler, HandlerOptions } from '../core/index.js'
@@ -1,6 +1,7 @@
1
1
  import { AptosNetwork, getClient } from './network.js'
2
- import { MoveCoder } from '@typemove/aptos'
3
- import { Aptos } from '@aptos-labs/ts-sdk'
2
+ import { MoveCoder, TypedFunctionPayload } from '@typemove/aptos'
3
+ import { Aptos, EntryFunctionPayloadResponse } from '@aptos-labs/ts-sdk'
4
+ import { TypeDescriptor, VECTOR_STR } from '@typemove/move'
4
5
 
5
6
  const CODERS = new Map<AptosNetwork, MoveCoder>()
6
7
  const URL_CODERS = new Map<string, MoveCoder>()
@@ -9,7 +10,8 @@ export function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET):
9
10
  let coder = CODERS.get(network)
10
11
  if (!coder) {
11
12
  const client = getClient(network)
12
- coder = new MoveCoder(getClient(network), network == AptosNetwork.INITIA_ECHELON)
13
+
14
+ coder = network == AptosNetwork.INITIA_ECHELON ? new InitiaMoveCoder(client) : new MoveCoder(client)
13
15
  CODERS.set(network, coder)
14
16
  URL_CODERS.set(client.config.fullnode || '', coder)
15
17
  }
@@ -29,3 +31,94 @@ export function defaultMoveCoderForClient(client: Aptos): MoveCoder {
29
31
  }
30
32
  return coder
31
33
  }
34
+
35
+ export class InitiaMoveCoder extends MoveCoder {
36
+ constructor(client: Aptos) {
37
+ super(client, true)
38
+ }
39
+
40
+ async decodeFunctionPayload<T extends Array<any>>(
41
+ payload: EntryFunctionPayloadResponse
42
+ ): Promise<TypedFunctionPayload<T>> {
43
+ const func = await this.getMoveFunction(payload.function)
44
+ const paramsTypes = this.adapter.getMeaningfulFunctionParams(func.params)
45
+ const argumentsDecoded = []
46
+
47
+ for (let i = 0; i < paramsTypes.length; i++) {
48
+ const arg = payload.arguments[i]
49
+ const paramType = paramsTypes[i]
50
+ if (arg == null) {
51
+ argumentsDecoded.push(null)
52
+ } else {
53
+ argumentsDecoded.push(await this.decodeBase64(Buffer.from(arg, 'base64'), paramType))
54
+ }
55
+ }
56
+
57
+ return {
58
+ ...payload,
59
+ arguments_decoded: argumentsDecoded
60
+ } as TypedFunctionPayload<T>
61
+ }
62
+
63
+ protected async decodeBase64(b: Buffer, type: TypeDescriptor): Promise<any> {
64
+ switch (type.qname.toLowerCase()) {
65
+ case 'signer': // TODO check this, aptos only
66
+ case 'address':
67
+ case '0x1::string::String':
68
+ return b.toString()
69
+ case 'bool':
70
+ return b.readUInt8() !== 0 // Convert first byte to boolean
71
+ case 'u8':
72
+ return b.readUInt8()
73
+ case 'u16':
74
+ return b.readUInt16LE()
75
+ case 'u32':
76
+ return b.readUInt32LE()
77
+ case 'u64':
78
+ return b.readBigUInt64LE()
79
+ case 'u128':
80
+ case 'u256':
81
+ const hex = b.toString('hex')
82
+ const reversedHex = hex.match(/.{2}/g)?.reverse().join('') || ''
83
+ return BigInt('0x' + reversedHex)
84
+ case '0x1::object::object':
85
+ return b.toString('hex')
86
+ case VECTOR_STR:
87
+ // vector<u8> as hex string
88
+ if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {
89
+ return b.toString('hex')
90
+ }
91
+
92
+ console.warn(`can't decode vector type: ${type.qname}, data: ${b.toString('base64')}`)
93
+ return b.toString('base64')
94
+ default:
95
+ // try enum type first
96
+ const enumType = await this.maybeGetMoveEnum(type.qname)
97
+ if (enumType) {
98
+ return b.toString('utf-8')
99
+ }
100
+
101
+ // Process complex type
102
+ /*const struct = await this.getMoveStruct(type.qname)
103
+
104
+ const typeCtx = new Map<string, TypeDescriptor>()
105
+ for (const [idx, typeArg] of type.typeArgs.entries()) {
106
+ typeCtx.set('T' + idx, typeArg)
107
+ }
108
+
109
+ const typedData: any = {}
110
+
111
+ for (const field of struct.fields) {
112
+ let filedType = field.type
113
+ filedType = filedType.applyTypeArgs(typeCtx)
114
+ const fieldValue = this.adapter.getData(data)[field.name]
115
+ const value = await this.decode(fieldValue, filedType)
116
+ typedData[field.name] = value
117
+ }*/
118
+
119
+ // todo: how to decode complex type?
120
+ console.warn(`can't decode type:${type.qname}, data: ${b.toString('base64')}`)
121
+ return b.toString('hex')
122
+ }
123
+ }
124
+ }
@@ -7,10 +7,12 @@ import {
7
7
  HandlerType,
8
8
  ProcessConfigResponse,
9
9
  ProcessResult,
10
+ ProcessStreamResponse_Partitions,
10
11
  StartRequest
11
12
  } from '@sentio/protos'
12
13
 
13
14
  import { ServerError, Status } from 'nice-grpc'
15
+ import { PartitionHandlerManager } from '../core/index.js'
14
16
  import { TemplateInstanceState } from '../core/template.js'
15
17
  import { BTCProcessorState } from './btc-processor.js'
16
18
  import { filters2Proto, TransactionFilter } from './filter.js'
@@ -27,6 +29,8 @@ export class BTCPlugin extends Plugin {
27
29
  blockHandlers: []
28
30
  }
29
31
 
32
+ partitionManager = new PartitionHandlerManager()
33
+
30
34
  async configure(config: ProcessConfigResponse) {
31
35
  const handlers: Handlers = {
32
36
  txHandlers: [],
@@ -47,6 +51,11 @@ export class BTCPlugin extends Plugin {
47
51
  })
48
52
  for (const callHandler of processor.callHandlers) {
49
53
  const handlerId = handlers.txHandlers.push(callHandler.handler) - 1
54
+ this.partitionManager.registerPartitionHandler(
55
+ HandlerType.BTC_TRANSACTION,
56
+ handlerId,
57
+ callHandler.partitionHandler
58
+ )
50
59
  const handlerName = callHandler.handlerName
51
60
 
52
61
  if (callHandler.filter) {
@@ -70,6 +79,7 @@ export class BTCPlugin extends Plugin {
70
79
 
71
80
  for (const blockHandler of processor.blockHandlers) {
72
81
  const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
82
+ this.partitionManager.registerPartitionHandler(HandlerType.BTC_BLOCK, handlerId, blockHandler.partitionHandler)
73
83
  contractConfig.intervalConfigs.push({
74
84
  slot: 0,
75
85
  slotInterval: blockHandler.blockInterval,
@@ -107,6 +117,34 @@ export class BTCPlugin extends Plugin {
107
117
  }
108
118
  }
109
119
 
120
+ async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {
121
+ let data: any
122
+ switch (request.handlerType) {
123
+ case HandlerType.BTC_TRANSACTION:
124
+ if (!request.data?.btcTransaction) {
125
+ throw new ServerError(Status.INVALID_ARGUMENT, "btcTransaction can't be empty")
126
+ }
127
+ data = request.data.btcTransaction
128
+ break
129
+ case HandlerType.BTC_BLOCK:
130
+ if (!request.data?.btcBlock) {
131
+ throw new ServerError(Status.INVALID_ARGUMENT, "btcBlock can't be empty")
132
+ }
133
+ data = request.data.btcBlock
134
+ break
135
+ default:
136
+ throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
137
+ }
138
+ const partitions = await this.partitionManager.processPartitionForHandlerType(
139
+ request.handlerType,
140
+ request.handlerIds,
141
+ data
142
+ )
143
+ return {
144
+ partitions
145
+ }
146
+ }
147
+
110
148
  async start(request: StartRequest) {}
111
149
 
112
150
  stateDiff(config: ProcessConfigResponse): boolean {
@@ -2,7 +2,7 @@ import { ListStateStorage } from '@sentio/runtime'
2
2
  import { BlockHandler, BTCBlock, BTCBlockContext, BTCContext, BTCOnIntervalFetchConfig, Transaction } from './types.js'
3
3
  import { Data_BTCBlock, Data_BTCTransaction, HandleInterval, ProcessResult } from '@sentio/protos'
4
4
  import { TransactionFilters } from './filter.js'
5
- import { PromiseOrVoid } from '../core/index.js'
5
+ import { HandlerOptions, PromiseOrVoid } from '../core/index.js'
6
6
  import { ServerError, Status } from 'nice-grpc'
7
7
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
8
8
 
@@ -26,7 +26,8 @@ export class BTCProcessor {
26
26
 
27
27
  public onTransaction(
28
28
  handler: (transaction: Transaction, ctx: BTCContext) => void | Promise<void>,
29
- filter?: TransactionFilters
29
+ filter?: TransactionFilters,
30
+ handlerOptions?: HandlerOptions<object, Transaction>
30
31
  ) {
31
32
  const callHandler = {
32
33
  handlerName: getHandlerName(),
@@ -42,7 +43,16 @@ export class BTCProcessor {
42
43
  await handler(tx, ctx)
43
44
  return ctx.stopAndGetResult()
44
45
  },
45
- filter
46
+ filter,
47
+ partitionHandler: async (call: Data_BTCTransaction): Promise<string | undefined> => {
48
+ const p = handlerOptions?.partitionKey
49
+ if (!p) return undefined
50
+ if (typeof p === 'function') {
51
+ const tx = call.transaction as Transaction
52
+ return p(tx)
53
+ }
54
+ return p
55
+ }
46
56
  }
47
57
  this.callHandlers.push(callHandler)
48
58
  return this
@@ -52,7 +62,7 @@ export class BTCProcessor {
52
62
  handler: (block: BTCBlock, ctx: BTCBlockContext) => PromiseOrVoid,
53
63
  timeInterval: HandleInterval | undefined,
54
64
  blockInterval: HandleInterval | undefined,
55
- fetchConfig?: BTCOnIntervalFetchConfig
65
+ handlerOptions?: HandlerOptions<BTCOnIntervalFetchConfig, BTCBlock>
56
66
  ): this {
57
67
  if (timeInterval) {
58
68
  if (timeInterval.backfillInterval < timeInterval.recentInterval) {
@@ -75,7 +85,7 @@ export class BTCProcessor {
75
85
  const block = {
76
86
  ...header
77
87
  } as BTCBlock
78
- if (fetchConfig?.getTransactions) {
88
+ if (handlerOptions?.getTransactions) {
79
89
  block.tx = header.rawtx?.map((tx: any) => tx as Transaction)
80
90
  }
81
91
 
@@ -88,7 +98,21 @@ export class BTCProcessor {
88
98
  await handler(block, ctx)
89
99
  return ctx.stopAndGetResult()
90
100
  },
91
- fetchConfig
101
+ fetchConfig: handlerOptions,
102
+ partitionHandler: async (data: Data_BTCBlock): Promise<string | undefined> => {
103
+ const p = handlerOptions?.partitionKey
104
+ if (!p) return undefined
105
+ if (typeof p === 'function') {
106
+ const header = data.block
107
+ if (!header) return undefined
108
+ const block = { ...header } as BTCBlock
109
+ if (handlerOptions?.getTransactions) {
110
+ block.tx = header.rawtx?.map((tx: any) => tx as Transaction)
111
+ }
112
+ return p(block)
113
+ }
114
+ return p
115
+ }
92
116
  })
93
117
  return this
94
118
  }
@@ -97,7 +121,7 @@ export class BTCProcessor {
97
121
  handler: (block: BTCBlock, ctx: BTCBlockContext) => PromiseOrVoid,
98
122
  blockInterval = 250,
99
123
  backfillBlockInterval = 1000,
100
- fetchConfig?: BTCOnIntervalFetchConfig
124
+ handlerOptions?: HandlerOptions<BTCOnIntervalFetchConfig, BTCBlock>
101
125
  ): this {
102
126
  return this.onInterval(
103
127
  handler,
@@ -106,7 +130,7 @@ export class BTCProcessor {
106
130
  recentInterval: blockInterval,
107
131
  backfillInterval: backfillBlockInterval
108
132
  },
109
- fetchConfig
133
+ handlerOptions
110
134
  )
111
135
  }
112
136
 
@@ -114,13 +138,13 @@ export class BTCProcessor {
114
138
  handler: (block: BTCBlock, ctx: BTCBlockContext) => PromiseOrVoid,
115
139
  timeIntervalInMinutes = 60,
116
140
  backfillTimeIntervalInMinutes = 240,
117
- fetchConfig?: BTCOnIntervalFetchConfig
141
+ handlerOptions?: HandlerOptions<BTCOnIntervalFetchConfig, BTCBlock>
118
142
  ): this {
119
143
  return this.onInterval(
120
144
  handler,
121
145
  { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
122
146
  undefined,
123
- fetchConfig
147
+ handlerOptions
124
148
  )
125
149
  }
126
150
  }
@@ -137,4 +161,5 @@ export type CallHandler<T> = {
137
161
  handlerName: string
138
162
  handler: (call: T) => Promise<ProcessResult>
139
163
  filter?: TransactionFilters
164
+ partitionHandler?: (call: T) => Promise<string | undefined>
140
165
  }
package/src/btc/types.ts CHANGED
@@ -126,8 +126,9 @@ export type BlockHandler = {
126
126
  handler: (block: Data_BTCBlock) => Promise<ProcessResult>
127
127
  handlerName: string
128
128
  fetchConfig?: BTCOnIntervalFetchConfig
129
+ partitionHandler?: (block: Data_BTCBlock) => Promise<string | undefined>
129
130
  }
130
131
 
131
132
  export type BTCOnIntervalFetchConfig = {
132
- getTransactions: boolean
133
+ getTransactions?: boolean
133
134
  }
@@ -1,15 +1,17 @@
1
1
  import { ProcessResult, RecordMetaData } from '@sentio/protos'
2
- import { EventLoggerBinding } from './event-logger.js'
3
- import { Meter, Labels } from './meter.js'
2
+ import { EventLoggerBinding, EventLoggerBindingNew } from './event-logger.js'
3
+ import { Meter, Labels, MeterNew } from './meter.js'
4
4
  import { ChainId } from '@sentio/chain'
5
- import { mergeProcessResults, PluginManager } from '@sentio/runtime'
5
+ import { mergeProcessResultsInPlace, PluginManager } from '@sentio/runtime'
6
6
  import { Required } from 'utility-types'
7
7
  import { ServerError, Status } from 'nice-grpc'
8
8
  import { Store } from '../store/store.js'
9
9
 
10
10
  export abstract class BaseContext {
11
11
  meter: Meter
12
+ meterNew: MeterNew
12
13
  eventLogger: EventLoggerBinding
14
+ eventLoggerNew: EventLoggerBindingNew
13
15
  private _store: Store
14
16
  baseLabels: Labels
15
17
  private active: boolean
@@ -21,12 +23,13 @@ export abstract class BaseContext {
21
23
  gauges: [],
22
24
  states: {
23
25
  configUpdated: false
24
- }
26
+ },
27
+ timeseriesResult: []
25
28
  }
26
29
 
27
30
  public update(res: Partial<ProcessResult>) {
28
31
  if (this.active) {
29
- this._res = mergeProcessResults([this._res, ProcessResult.fromPartial(res)])
32
+ mergeProcessResultsInPlace(this._res, [ProcessResult.fromPartial(res)])
30
33
  } else {
31
34
  throw new ServerError(Status.INTERNAL, 'context not active, possible async function invoke without await')
32
35
  }
@@ -34,7 +37,9 @@ export abstract class BaseContext {
34
37
 
35
38
  protected constructor(baseLabels: Labels | undefined) {
36
39
  this.meter = new Meter(this)
40
+ this.meterNew = new MeterNew(this)
37
41
  this.eventLogger = new EventLoggerBinding(this)
42
+ this.eventLoggerNew = new EventLoggerBindingNew(this)
38
43
  this.baseLabels = baseLabels || {}
39
44
  this.active = true
40
45
  this.initStore()
@@ -6,7 +6,10 @@ import {
6
6
  EventLogConfig_Field,
7
7
  EventLogConfig_StructFieldType,
8
8
  EventTrackingResult,
9
- LogLevel
9
+ LogLevel,
10
+ RichStruct,
11
+ TimeseriesResult,
12
+ TimeseriesResult_TimeseriesType
10
13
  } from '@sentio/protos'
11
14
  import { normalizeAttribute, normalizeLabels, normalizeToRichStruct } from './normalization.js'
12
15
  import { MapStateStorage, processMetrics } from '@sentio/runtime'
@@ -141,3 +144,44 @@ function checkEventName(eventName: string) {
141
144
  throw new Error(`Event name ${eventName} is already used in the database schema`)
142
145
  }
143
146
  }
147
+
148
+ function emitNew<T>(ctx: BaseContext, eventName: string, event: Event<T>) {
149
+ const { distinctId, severity, message, ...payload } = event
150
+
151
+ const data: RichStruct = {
152
+ fields: {
153
+ severity: {
154
+ stringValue: (severity || LogLevel.INFO).toString()
155
+ },
156
+ message: {
157
+ stringValue: message || ''
158
+ },
159
+ distinctEntityId: {
160
+ stringValue: distinctId || ''
161
+ },
162
+ ...normalizeToRichStruct(ctx.baseLabels, payload).fields
163
+ }
164
+ }
165
+ const res: TimeseriesResult = {
166
+ metadata: ctx.getMetaData(eventName, {}),
167
+ type: TimeseriesResult_TimeseriesType.EVENT,
168
+ data,
169
+ runtimeInfo: undefined
170
+ }
171
+
172
+ processMetrics.process_eventemit_count.add(1)
173
+ ctx.update({ timeseriesResult: [res] })
174
+ }
175
+
176
+ export class EventLoggerBindingNew {
177
+ private readonly ctx: BaseContext
178
+
179
+ constructor(ctx: BaseContext) {
180
+ this.ctx = ctx
181
+ }
182
+
183
+ emit<T>(eventName: string, event: Event<T>) {
184
+ checkEventName(eventName)
185
+ emitNew(this.ctx, eventName, event)
186
+ }
187
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Function type that extracts a partition key from data.
3
+ * @template D The data type to process
4
+ */
5
+ export type PartitionHandler<D> = (data: D) => string | Promise<string>
6
+
7
+ /**
8
+ * Handler options that extend fetch configuration with optional partitioning support.
9
+ * @template F The fetch configuration type (e.g., EthFetchConfig, MoveFetchConfig)
10
+ * @template D The data type that will be processed (e.g., Event, Transaction, Block)
11
+ */
12
+ export type HandlerOptions<F, D> = Partial<F> & {
13
+ /**
14
+ * Optional partition key for data partitioning.
15
+ * Can be a static string or a function that computes the key from the data.
16
+ */
17
+ partitionKey?: string | PartitionHandler<D>
18
+ }
19
+
20
+ /**
21
+ * Merge two handler options, with the second options taking precedence over the first.
22
+ * @param options1 First handler options
23
+ * @param options2 Second handler options (takes precedence)
24
+ * @returns Merged handler options
25
+ */
26
+ export function mergeHandlerOptions<F, D>(
27
+ options1?: HandlerOptions<F, D>,
28
+ options2?: HandlerOptions<F, D>
29
+ ): HandlerOptions<F, D> | undefined {
30
+ if (!options1 && !options2) return undefined
31
+ if (!options1) return options2
32
+ if (!options2) return options1
33
+
34
+ return {
35
+ ...options1,
36
+ ...options2,
37
+ // For partitionKey, the second option takes precedence
38
+ partitionKey: options2.partitionKey ?? options1.partitionKey
39
+ }
40
+ }
package/src/core/index.ts CHANGED
@@ -3,7 +3,18 @@ export type { PromiseOrValue, PromiseOrVoid } from './promises.js'
3
3
  export type { PartiallyOptional } from './partial-optional.js'
4
4
  export { BaseContext } from './base-context.js'
5
5
  export { normalizeLabels } from './normalization.js'
6
- export { CounterBinding, Meter, type Labels, GaugeBinding, Counter, Gauge, MetricOptions } from './meter.js'
6
+ export {
7
+ CounterBinding,
8
+ Meter,
9
+ type Labels,
10
+ GaugeBinding,
11
+ Counter,
12
+ Gauge,
13
+ MetricOptions,
14
+ CounterNew,
15
+ GaugeNew,
16
+ MeterNew
17
+ } from './meter.js'
7
18
  export { Exporter } from './exporter.js'
8
19
  export * from './event-logger.js'
9
20
  export { type Numberish, toBigInteger, toMetricValue } from './numberish.js'
@@ -11,3 +22,8 @@ export { type Numberish, toBigInteger, toMetricValue } from './numberish.js'
11
22
  export { CorePlugin } from './core-plugin.js'
12
23
  export { DatabaseSchema } from './database-schema.js'
13
24
  export * from './constants.js'
25
+ export { type HandlerOptions, type PartitionHandler, mergeHandlerOptions } from './handler-options.js'
26
+ export {
27
+ PartitionHandlerManager,
28
+ type PartitionHandler as PartitionHandlerFunction
29
+ } from './partition-handler-manager.js'