@sentio/sdk 2.60.2-rc.2 → 2.60.3-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 (69) hide show
  1. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  2. package/lib/aptos/aptos-plugin.js +3 -3
  3. package/lib/aptos/aptos-plugin.js.map +1 -1
  4. package/lib/btc/btc-plugin.d.ts.map +1 -1
  5. package/lib/btc/btc-plugin.js +2 -2
  6. package/lib/btc/btc-plugin.js.map +1 -1
  7. package/lib/core/handler-register.d.ts +1 -2
  8. package/lib/core/handler-register.d.ts.map +1 -1
  9. package/lib/core/handler-register.js +8 -47
  10. package/lib/core/handler-register.js.map +1 -1
  11. package/lib/cosmos/cosmos-plugin.d.ts.map +1 -1
  12. package/lib/cosmos/cosmos-plugin.js +1 -1
  13. package/lib/cosmos/cosmos-plugin.js.map +1 -1
  14. package/lib/eth/eth-plugin.js +4 -4
  15. package/lib/eth/eth-plugin.js.map +1 -1
  16. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  17. package/lib/fuel/fuel-plugin.js +3 -3
  18. package/lib/fuel/fuel-plugin.js.map +1 -1
  19. package/lib/stark/starknet-plugin.d.ts.map +1 -1
  20. package/lib/stark/starknet-plugin.js +1 -1
  21. package/lib/stark/starknet-plugin.js.map +1 -1
  22. package/lib/sui/sui-plugin.d.ts.map +1 -1
  23. package/lib/sui/sui-plugin.js +4 -4
  24. package/lib/sui/sui-plugin.js.map +1 -1
  25. package/lib/testing/aptos-facet.d.ts.map +1 -1
  26. package/lib/testing/aptos-facet.js +4 -2
  27. package/lib/testing/aptos-facet.js.map +1 -1
  28. package/lib/testing/btc-facet.d.ts.map +1 -1
  29. package/lib/testing/btc-facet.js +2 -1
  30. package/lib/testing/btc-facet.js.map +1 -1
  31. package/lib/testing/cosmos-facet.d.ts.map +1 -1
  32. package/lib/testing/cosmos-facet.js +2 -1
  33. package/lib/testing/cosmos-facet.js.map +1 -1
  34. package/lib/testing/eth-facet.d.ts.map +1 -1
  35. package/lib/testing/eth-facet.js +10 -5
  36. package/lib/testing/eth-facet.js.map +1 -1
  37. package/lib/testing/fuel-facet.d.ts.map +1 -1
  38. package/lib/testing/fuel-facet.js +6 -3
  39. package/lib/testing/fuel-facet.js.map +1 -1
  40. package/lib/testing/iota-facet.d.ts.map +1 -1
  41. package/lib/testing/iota-facet.js +6 -3
  42. package/lib/testing/iota-facet.js.map +1 -1
  43. package/lib/testing/solana-facet.d.ts.map +1 -1
  44. package/lib/testing/solana-facet.js +4 -2
  45. package/lib/testing/solana-facet.js.map +1 -1
  46. package/lib/testing/starknet-facet.d.ts.map +1 -1
  47. package/lib/testing/starknet-facet.js +2 -1
  48. package/lib/testing/starknet-facet.js.map +1 -1
  49. package/lib/testing/sui-facet.d.ts.map +1 -1
  50. package/lib/testing/sui-facet.js +6 -3
  51. package/lib/testing/sui-facet.js.map +1 -1
  52. package/package.json +3 -3
  53. package/src/aptos/aptos-plugin.ts +12 -3
  54. package/src/btc/btc-plugin.ts +8 -2
  55. package/src/core/handler-register.ts +9 -54
  56. package/src/cosmos/cosmos-plugin.ts +4 -1
  57. package/src/eth/eth-plugin.ts +4 -4
  58. package/src/fuel/fuel-plugin.ts +12 -3
  59. package/src/stark/starknet-plugin.ts +4 -1
  60. package/src/sui/sui-plugin.ts +16 -4
  61. package/src/testing/aptos-facet.ts +4 -2
  62. package/src/testing/btc-facet.ts +2 -1
  63. package/src/testing/cosmos-facet.ts +2 -1
  64. package/src/testing/eth-facet.ts +10 -5
  65. package/src/testing/fuel-facet.ts +6 -3
  66. package/src/testing/iota-facet.ts +6 -3
  67. package/src/testing/solana-facet.ts +4 -2
  68. package/src/testing/starknet-facet.ts +2 -1
  69. package/src/testing/sui-facet.ts +6 -3
@@ -10,49 +10,16 @@ interface HandlerEntry {
10
10
  chainId: ChainId | string
11
11
  }
12
12
 
13
- const chainToNumber: Map<string, number> = new Map()
14
- const numberToChain: Map<number, string> = new Map()
15
-
16
- const generateHash = (s: string) => {
17
- let hash = 0
18
- for (const char of s) {
19
- hash = (hash << 5) - hash + char.charCodeAt(0)
20
- hash |= 0 // Constrain to 32bit integer
21
- }
22
- return Math.abs(hash)
23
- }
24
-
25
- for (const chainId of Object.values(ChainId)) {
26
- let num = parseInt(chainId)
27
- if (isNaN(num)) {
28
- // If the chainId is not a number, generate a hash
29
- num = generateHash(chainId)
30
- }
31
-
32
- if (numberToChain.has(num)) {
33
- // If the number is already used for another chain, throw an error, this should not happen
34
- throw new Error(`Chain ID ${chainId}'s number ${num} conflicts with existing chain ID ${numberToChain.get(num)}`)
35
- }
36
- chainToNumber.set(chainId, num)
37
- numberToChain.set(num, chainId)
38
- }
39
-
40
- const MAX_HANDLER_PER_CHAIN = 1000000 // Maximum handlers per chain
41
-
42
13
  export class HandlerRegister {
43
- private handlerByChain: Map<number, HandlerEntry[]> = new Map()
44
- private handlers: Map<number, HandlerEntry> = new Map()
14
+ private handlerByChain: Map<ChainId | string, HandlerEntry[]> = new Map()
45
15
 
46
16
  /**
47
17
  * Register a handler function with chain ID and handle type
48
18
  * @returns handler ID
49
19
  */
50
20
  register(handler: HandlerFunction, chainId: ChainId | string): number {
51
- const chainNum = chainToNumber.get(chainId) || 0
52
- const entries = this.handlerByChain.get(chainNum) || []
53
-
54
- const len = entries.length
55
- const id = chainNum * MAX_HANDLER_PER_CHAIN + len + 1
21
+ const entries = this.handlerByChain.get(chainId) || []
22
+ const id = entries.length
56
23
 
57
24
  const entry: HandlerEntry = {
58
25
  id,
@@ -60,38 +27,26 @@ export class HandlerRegister {
60
27
  chainId
61
28
  }
62
29
  entries.push(entry)
63
- this.handlerByChain.set(chainNum, entries)
64
- this.handlers.set(id, entry)
65
-
30
+ this.handlerByChain.set(chainId, entries)
66
31
  return id
67
32
  }
68
33
 
69
34
  /**
70
35
  * Get handler function by ID
71
36
  */
72
- getHandlerById(id: number): HandlerFunction {
73
- const entry = this.handlers.get(id)
74
- if (!entry) {
37
+ getHandlerById(chainId: ChainId | string, id: number): HandlerFunction {
38
+ const entries = this.handlerByChain.get(chainId)
39
+ if (!entries || id < 0 || id >= entries.length) {
75
40
  throw new ServerError(Status.INTERNAL, `Handler with ID ${id} not found.`)
76
41
  }
77
- return entry.handler
42
+ return entries[id].handler
78
43
  }
79
44
 
80
45
  clear(chainId?: ChainId): void {
81
46
  if (chainId) {
82
- const chainNum = chainToNumber.get(chainId)
83
- if (chainNum !== undefined) {
84
- const chainHandlers = this.handlerByChain.get(chainNum)
85
- if (chainHandlers) {
86
- for (const entry of chainHandlers) {
87
- this.handlers.delete(entry.id)
88
- }
89
- }
90
- this.handlerByChain.delete(chainNum)
91
- }
47
+ this.handlerByChain.delete(chainId)
92
48
  } else {
93
49
  this.handlerByChain.clear()
94
- this.handlers.clear()
95
50
  }
96
51
  }
97
52
  }
@@ -86,7 +86,10 @@ export class CosmosPlugin extends Plugin {
86
86
 
87
87
  for (const handlerId of binding.handlerIds) {
88
88
  const promise = this.handlerRegister
89
- .getHandlerById(handlerId)(call)
89
+ .getHandlerById(
90
+ binding.chainId,
91
+ handlerId
92
+ )(call)
90
93
  .catch((e) => {
91
94
  throw new ServerError(
92
95
  Status.INTERNAL,
@@ -417,7 +417,7 @@ export class EthPlugin extends Plugin {
417
417
 
418
418
  const promises: Promise<ProcessResult>[] = []
419
419
  for (const handlerId of request.handlerIds) {
420
- const handler = this.handlerRegister.getHandlerById(handlerId)
420
+ const handler = this.handlerRegister.getHandlerById(request.chainId, handlerId)
421
421
  const promise = handler(ethLog, preparedData).catch((e: any) => {
422
422
  console.error('error processing log: ', e)
423
423
  throw new ServerError(
@@ -443,7 +443,7 @@ export class EthPlugin extends Plugin {
443
443
 
444
444
  for (const handlerId of binding.handlerIds) {
445
445
  const promise = this.handlerRegister
446
- .getHandlerById(handlerId)(ethTrace, preparedData)
446
+ .getHandlerById(binding.chainId, handlerId)(ethTrace, preparedData)
447
447
  .catch((e: any) => {
448
448
  console.error('error processing trace: ', e)
449
449
  throw new ServerError(
@@ -468,7 +468,7 @@ export class EthPlugin extends Plugin {
468
468
  const promises: Promise<ProcessResult>[] = []
469
469
  for (const handlerId of binding.handlerIds) {
470
470
  const promise = this.handlerRegister
471
- .getHandlerById(handlerId)(ethBlock, preparedData)
471
+ .getHandlerById(binding.chainId, handlerId)(ethBlock, preparedData)
472
472
  .catch((e: any) => {
473
473
  console.error('error processing block: ', e)
474
474
  throw new ServerError(
@@ -494,7 +494,7 @@ export class EthPlugin extends Plugin {
494
494
 
495
495
  for (const handlerId of binding.handlerIds) {
496
496
  const promise = this.handlerRegister
497
- .getHandlerById(handlerId)(ethTransaction, preparedData)
497
+ .getHandlerById(binding.chainId, handlerId)(ethTransaction, preparedData)
498
498
  .catch((e: any) => {
499
499
  throw new ServerError(
500
500
  Status.INTERNAL,
@@ -206,7 +206,10 @@ export class FuelPlugin extends Plugin {
206
206
 
207
207
  for (const handlerId of binding.handlerIds) {
208
208
  const promise = this.handlerRegister
209
- .getHandlerById(handlerId)(receipt)
209
+ .getHandlerById(
210
+ binding.chainId,
211
+ handlerId
212
+ )(receipt)
210
213
  .catch((e: any) => {
211
214
  throw new ServerError(
212
215
  Status.INTERNAL,
@@ -231,7 +234,10 @@ export class FuelPlugin extends Plugin {
231
234
 
232
235
  for (const handlerId of binding.handlerIds) {
233
236
  const promise = this.handlerRegister
234
- .getHandlerById(handlerId)(fuelTransaction)
237
+ .getHandlerById(
238
+ binding.chainId,
239
+ handlerId
240
+ )(fuelTransaction)
235
241
  .catch((e: any) => {
236
242
  throw new ServerError(
237
243
  Status.INTERNAL,
@@ -255,7 +261,10 @@ export class FuelPlugin extends Plugin {
255
261
  const promises: Promise<ProcessResult>[] = []
256
262
  for (const handlerId of binding.handlerIds) {
257
263
  const promise = this.handlerRegister
258
- .getHandlerById(handlerId)(ethBlock)
264
+ .getHandlerById(
265
+ binding.chainId,
266
+ handlerId
267
+ )(ethBlock)
259
268
  .catch((e: any) => {
260
269
  console.error('error processing block: ', e)
261
270
  throw new ServerError(
@@ -94,7 +94,10 @@ export class StarknetPlugin extends Plugin {
94
94
 
95
95
  for (const handlerId of binding.handlerIds) {
96
96
  const promise = this.handlerRegister
97
- .getHandlerById(handlerId)(binding.data?.starknetEvents)
97
+ .getHandlerById(
98
+ binding.chainId,
99
+ handlerId
100
+ )(binding.data?.starknetEvents)
98
101
  .catch((e: any) => {
99
102
  throw new ServerError(
100
103
  Status.INTERNAL,
@@ -114,7 +114,10 @@ export class SuiPlugin extends Plugin {
114
114
  for (const handlerId of binding.handlerIds) {
115
115
  promises.push(
116
116
  this.handlerRegister
117
- .getHandlerById(handlerId)(event)
117
+ .getHandlerById(
118
+ binding.chainId,
119
+ handlerId
120
+ )(event)
118
121
  .catch((e: any) => {
119
122
  throw new ServerError(
120
123
  Status.INTERNAL,
@@ -135,7 +138,10 @@ export class SuiPlugin extends Plugin {
135
138
  const promises: Promise<ProcessResult>[] = []
136
139
  for (const handlerId of binding.handlerIds) {
137
140
  const promise = this.handlerRegister
138
- .getHandlerById(handlerId)(call)
141
+ .getHandlerById(
142
+ binding.chainId,
143
+ handlerId
144
+ )(call)
139
145
  .catch((e: any) => {
140
146
  throw new ServerError(
141
147
  Status.INTERNAL,
@@ -157,7 +163,10 @@ export class SuiPlugin extends Plugin {
157
163
  for (const handlerId of binding.handlerIds) {
158
164
  promises.push(
159
165
  this.handlerRegister
160
- .getHandlerById(handlerId)(object)
166
+ .getHandlerById(
167
+ binding.chainId,
168
+ handlerId
169
+ )(object)
161
170
  .catch((e: any) => {
162
171
  throw new ServerError(
163
172
  Status.INTERNAL,
@@ -179,7 +188,10 @@ export class SuiPlugin extends Plugin {
179
188
  for (const handlerId of binding.handlerIds) {
180
189
  promises.push(
181
190
  this.handlerRegister
182
- .getHandlerById(handlerId)(objectChange)
191
+ .getHandlerById(
192
+ binding.chainId,
193
+ handlerId
194
+ )(objectChange)
183
195
  .catch((e: any) => {
184
196
  throw new ServerError(
185
197
  Status.INTERNAL,
@@ -47,7 +47,8 @@ export class AptosFacet {
47
47
  }
48
48
  },
49
49
  handlerIds: [callConfig.handlerId],
50
- handlerType: HandlerType.APT_CALL
50
+ handlerType: HandlerType.APT_CALL,
51
+ chainId: network
51
52
  }
52
53
  }
53
54
  }
@@ -89,7 +90,8 @@ export class AptosFacet {
89
90
  }
90
91
  },
91
92
  handlerIds: [eventConfig.handlerId],
92
- handlerType: HandlerType.APT_EVENT
93
+ handlerType: HandlerType.APT_EVENT,
94
+ chainId: network
93
95
  }
94
96
  }
95
97
  }
@@ -35,7 +35,8 @@ export class BTCFacet {
35
35
  btcTransaction: data
36
36
  },
37
37
  handlerIds: [txConfig.handlerId],
38
- handlerType: HandlerType.BTC_TRANSACTION
38
+ handlerType: HandlerType.BTC_TRANSACTION,
39
+ chainId: network
39
40
  } as DataBinding
40
41
  res.push(binding)
41
42
  }
@@ -36,7 +36,8 @@ export class CosmosFacet {
36
36
  }
37
37
  },
38
38
  handlerIds: [logConfig.handlerId],
39
- handlerType: HandlerType.COSMOS_CALL
39
+ handlerType: HandlerType.COSMOS_CALL,
40
+ chainId: network
40
41
  }
41
42
 
42
43
  const logFilters = logConfig.logFilters
@@ -56,7 +56,8 @@ export class EthFacet {
56
56
  }
57
57
  },
58
58
  handlerIds: [config.handlerId],
59
- handlerType: HandlerType.ETH_TRACE
59
+ handlerType: HandlerType.ETH_TRACE,
60
+ chainId: network
60
61
  }
61
62
  }
62
63
  }
@@ -120,7 +121,8 @@ export class EthFacet {
120
121
  ethLog: { log, timestamp: new Date(), rawLog: JSON.stringify(log) }
121
122
  },
122
123
  handlerIds: [config.handlerId],
123
- handlerType: HandlerType.ETH_LOG
124
+ handlerType: HandlerType.ETH_LOG,
125
+ chainId: network
124
126
  }
125
127
  }
126
128
  }
@@ -193,7 +195,8 @@ export class EthFacet {
193
195
  ethLog: { log, timestamp: new Date(), rawLog: JSON.stringify(log) }
194
196
  },
195
197
  handlerIds: [config.handlerId],
196
- handlerType: HandlerType.ETH_LOG
198
+ handlerType: HandlerType.ETH_LOG,
199
+ chainId: network
197
200
  }
198
201
  }
199
202
  }
@@ -232,7 +235,8 @@ export class EthFacet {
232
235
  ethBlock: { block }
233
236
  },
234
237
  handlerType: HandlerType.ETH_BLOCK,
235
- handlerIds: []
238
+ handlerIds: [],
239
+ chainId: network
236
240
  }
237
241
  for (const contract of this.server.contractConfigs) {
238
242
  if (contract.contract?.chainId !== network) {
@@ -283,7 +287,8 @@ export class EthFacet {
283
287
  ethTransaction: { transaction, timestamp: new Date(), rawTransaction: JSON.stringify(transaction) }
284
288
  },
285
289
  handlerType: HandlerType.ETH_TRANSACTION,
286
- handlerIds: []
290
+ handlerIds: [],
291
+ chainId: network
287
292
  }
288
293
  for (const contract of this.server.contractConfigs) {
289
294
  if (contract.contract?.chainId !== network) {
@@ -55,7 +55,8 @@ export class FuelFacet {
55
55
  }
56
56
  },
57
57
  handlerIds: [callConfig.handlerId],
58
- handlerType: HandlerType.FUEL_TRANSACTION
58
+ handlerType: HandlerType.FUEL_TRANSACTION,
59
+ chainId: network
59
60
  }
60
61
 
61
62
  res.push(binding)
@@ -70,7 +71,8 @@ export class FuelFacet {
70
71
  }
71
72
  },
72
73
  handlerIds: [assetConfig.handlerId],
73
- handlerType: HandlerType.FUEL_TRANSACTION
74
+ handlerType: HandlerType.FUEL_TRANSACTION,
75
+ chainId: network
74
76
  }
75
77
 
76
78
  res.push(binding)
@@ -98,7 +100,8 @@ export class FuelFacet {
98
100
  }
99
101
  },
100
102
  handlerIds: [logConfig.handlerId],
101
- handlerType: HandlerType.FUEL_RECEIPT
103
+ handlerType: HandlerType.FUEL_RECEIPT,
104
+ chainId: network
102
105
  }
103
106
  res.push(binding)
104
107
  }
@@ -56,7 +56,8 @@ export class IotaFacet {
56
56
  }
57
57
  },
58
58
  handlerIds: [callConfig.handlerId],
59
- handlerType: HandlerType.SUI_CALL
59
+ handlerType: HandlerType.SUI_CALL,
60
+ chainId: network
60
61
  }
61
62
  }
62
63
  }
@@ -99,7 +100,8 @@ export class IotaFacet {
99
100
  timestamp: transaction.timestampMs ? new Date(transaction.timestampMs) : new Date(),
100
101
  slot: BigInt(transaction.checkpoint || 0)
101
102
  }
102
- }
103
+ },
104
+ chainId: network
103
105
  }
104
106
  return this.server.processBinding(binding)
105
107
  }
@@ -131,7 +133,8 @@ export class IotaFacet {
131
133
  }
132
134
  },
133
135
  handlerIds: [eventConfig.handlerId],
134
- handlerType: HandlerType.SUI_EVENT
136
+ handlerType: HandlerType.SUI_EVENT,
137
+ chainId: network
135
138
  }
136
139
  }
137
140
  }
@@ -1,5 +1,6 @@
1
1
  import { TestProcessorServer } from './test-processor-server.js'
2
2
  import { Data_SolInstruction, HandlerType, ProcessBindingResponse } from '@sentio/protos'
3
+ import { ChainId } from '@sentio/chain'
3
4
 
4
5
  export class SolanaFacet {
5
6
  server: TestProcessorServer
@@ -14,12 +15,13 @@ export class SolanaFacet {
14
15
  return {
15
16
  data: {
16
17
  raw: new Uint8Array(),
17
- solInstruction: instruction,
18
+ solInstruction: instruction
18
19
  },
19
20
  handlerIds: [],
20
21
  handlerType: HandlerType.SOL_INSTRUCTION,
22
+ chainId: ChainId.SOLANA_MAINNET
21
23
  }
22
- }),
24
+ })
23
25
  })
24
26
  }
25
27
  }
@@ -38,7 +38,8 @@ export class StarknetFacet {
38
38
  }
39
39
  },
40
40
  handlerIds: [logConfig.handlerId],
41
- handlerType: HandlerType.STARKNET_EVENT
41
+ handlerType: HandlerType.STARKNET_EVENT,
42
+ chainId: config.contract.chainId
42
43
  }
43
44
 
44
45
  const logFilters = logConfig.filters
@@ -56,7 +56,8 @@ export class SuiFacet {
56
56
  }
57
57
  },
58
58
  handlerIds: [callConfig.handlerId],
59
- handlerType: HandlerType.SUI_CALL
59
+ handlerType: HandlerType.SUI_CALL,
60
+ chainId: network
60
61
  }
61
62
  }
62
63
  }
@@ -99,7 +100,8 @@ export class SuiFacet {
99
100
  timestamp: transaction.timestampMs ? new Date(transaction.timestampMs) : new Date(),
100
101
  slot: BigInt(transaction.checkpoint || 0)
101
102
  }
102
- }
103
+ },
104
+ chainId: network
103
105
  }
104
106
  return this.server.processBinding(binding)
105
107
  }
@@ -131,7 +133,8 @@ export class SuiFacet {
131
133
  }
132
134
  },
133
135
  handlerIds: [eventConfig.handlerId],
134
- handlerType: HandlerType.SUI_EVENT
136
+ handlerType: HandlerType.SUI_EVENT,
137
+ chainId: network
135
138
  }
136
139
  }
137
140
  }