@sentio/sdk 2.59.0-rc.23 → 2.59.0-rc.25
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.
- package/lib/aptos/aptos-plugin.d.ts +6 -5
- package/lib/aptos/aptos-plugin.d.ts.map +1 -1
- package/lib/aptos/aptos-plugin.js +31 -33
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +19 -19
- package/lib/aptos/aptos-processor.d.ts.map +1 -1
- package/lib/aptos/aptos-processor.js +95 -44
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts +5 -4
- package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.js +8 -8
- package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +333 -332
- package/lib/aptos/builtin/0x1.d.ts.map +1 -1
- package/lib/aptos/builtin/0x1.js +664 -664
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +66 -65
- package/lib/aptos/builtin/0x3.d.ts.map +1 -1
- package/lib/aptos/builtin/0x3.js +130 -130
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/builtin/0x4.d.ts +29 -28
- package/lib/aptos/builtin/0x4.d.ts.map +1 -1
- package/lib/aptos/builtin/0x4.js +56 -56
- package/lib/aptos/builtin/0x4.js.map +1 -1
- package/lib/aptos/codegen/codegen.js +27 -0
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/data.d.ts +28 -3
- package/lib/aptos/data.d.ts.map +1 -1
- package/lib/aptos/data.js +61 -0
- package/lib/aptos/data.js.map +1 -1
- package/lib/aptos/index.d.ts +1 -0
- package/lib/aptos/index.d.ts.map +1 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +1 -0
- package/lib/aptos/models.d.ts.map +1 -1
- package/lib/btc/btc-plugin.d.ts +4 -1
- package/lib/btc/btc-plugin.d.ts.map +1 -1
- package/lib/btc/btc-plugin.js +27 -0
- package/lib/btc/btc-plugin.js.map +1 -1
- package/lib/btc/btc-processor.d.ts +6 -5
- package/lib/btc/btc-processor.d.ts.map +1 -1
- package/lib/btc/btc-processor.js +35 -9
- package/lib/btc/btc-processor.js.map +1 -1
- package/lib/btc/types.d.ts +2 -1
- package/lib/btc/types.d.ts.map +1 -1
- package/lib/core/handler-options.d.ts +25 -0
- package/lib/core/handler-options.d.ts.map +1 -0
- package/lib/core/handler-options.js +21 -0
- package/lib/core/handler-options.js.map +1 -0
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +2 -0
- package/lib/core/index.js.map +1 -1
- package/lib/core/partition-handler-manager.d.ts +44 -0
- package/lib/core/partition-handler-manager.d.ts.map +1 -0
- package/lib/core/partition-handler-manager.js +76 -0
- package/lib/core/partition-handler-manager.js.map +1 -0
- package/lib/cosmos/cosmos-processor.d.ts +3 -2
- package/lib/cosmos/cosmos-processor.d.ts.map +1 -1
- package/lib/cosmos/cosmos-processor.js +11 -1
- package/lib/cosmos/cosmos-processor.js.map +1 -1
- package/lib/cosmos/types.d.ts +1 -0
- package/lib/cosmos/types.d.ts.map +1 -1
- package/lib/eth/base-processor.d.ts +18 -17
- package/lib/eth/base-processor.d.ts.map +1 -1
- package/lib/eth/base-processor.js +147 -26
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +32 -31
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +62 -62
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts +17 -16
- package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.js +32 -32
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts +25 -24
- package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.js +48 -48
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +14 -13
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.js +26 -26
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts +21 -20
- package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.js +40 -40
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts +20 -19
- package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.js +38 -38
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/event-handler.js +2 -2
- package/lib/eth/codegen/event-handler.js.map +1 -1
- package/lib/eth/codegen/file.d.ts.map +1 -1
- package/lib/eth/codegen/file.js +1 -0
- package/lib/eth/codegen/file.js.map +1 -1
- package/lib/eth/codegen/functions-handler.js +2 -2
- package/lib/eth/codegen/functions-handler.js.map +1 -1
- package/lib/eth/eth-plugin.d.ts +4 -1
- package/lib/eth/eth-plugin.d.ts.map +1 -1
- package/lib/eth/eth-plugin.js +42 -1
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +2 -7
- package/lib/eth/eth.d.ts.map +1 -1
- package/lib/eth/eth.js +8 -1
- package/lib/eth/eth.js.map +1 -1
- package/lib/fuel/codegen/codegen.js +5 -5
- package/lib/fuel/codegen/codegen.js.map +1 -1
- package/lib/fuel/fuel-plugin.d.ts +4 -1
- package/lib/fuel/fuel-plugin.d.ts.map +1 -1
- package/lib/fuel/fuel-plugin.js +41 -0
- package/lib/fuel/fuel-plugin.js.map +1 -1
- package/lib/fuel/fuel-processor-template.d.ts +7 -4
- package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
- package/lib/fuel/fuel-processor-template.js +11 -9
- package/lib/fuel/fuel-processor-template.js.map +1 -1
- package/lib/fuel/fuel-processor.d.ts +7 -7
- package/lib/fuel/fuel-processor.d.ts.map +1 -1
- package/lib/fuel/fuel-processor.js +90 -19
- package/lib/fuel/fuel-processor.js.map +1 -1
- package/lib/fuel/types.d.ts +3 -0
- package/lib/fuel/types.d.ts.map +1 -1
- package/lib/move/filter.d.ts +4 -0
- package/lib/move/filter.d.ts.map +1 -1
- package/lib/move/filter.js +4 -0
- package/lib/move/filter.js.map +1 -1
- package/lib/move/shared-network-codegen.d.ts.map +1 -1
- package/lib/move/shared-network-codegen.js +5 -4
- package/lib/move/shared-network-codegen.js.map +1 -1
- package/lib/solana/solana-processor.d.ts +10 -4
- package/lib/solana/solana-processor.d.ts.map +1 -1
- package/lib/solana/solana-processor.js +13 -4
- package/lib/solana/solana-processor.js.map +1 -1
- package/lib/stark/starknet-processor.d.ts +3 -1
- package/lib/stark/starknet-processor.d.ts.map +1 -1
- package/lib/stark/starknet-processor.js +27 -2
- package/lib/stark/starknet-processor.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +7 -6
- package/lib/sui/builtin/0x1.d.ts.map +1 -1
- package/lib/sui/builtin/0x1.js +12 -12
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +61 -60
- package/lib/sui/builtin/0x2.d.ts.map +1 -1
- package/lib/sui/builtin/0x2.js +120 -120
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +49 -48
- package/lib/sui/builtin/0x3.d.ts.map +1 -1
- package/lib/sui/builtin/0x3.js +96 -96
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/models.d.ts +1 -0
- package/lib/sui/models.d.ts.map +1 -1
- package/lib/sui/sui-plugin.d.ts +6 -3
- package/lib/sui/sui-plugin.d.ts.map +1 -1
- package/lib/sui/sui-plugin.js +59 -20
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +5 -4
- package/lib/sui/sui-processor.d.ts.map +1 -1
- package/lib/sui/sui-processor.js +47 -11
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +3 -3
- package/src/aptos/aptos-plugin.ts +35 -39
- package/src/aptos/aptos-processor.ts +104 -60
- package/src/aptos/aptos-resource-processor-template.ts +9 -8
- package/src/aptos/builtin/0x1.ts +1565 -664
- package/src/aptos/builtin/0x3.ts +302 -130
- package/src/aptos/builtin/0x4.ts +123 -56
- package/src/aptos/codegen/codegen.ts +34 -1
- package/src/aptos/data.ts +78 -3
- package/src/aptos/index.ts +2 -0
- package/src/aptos/models.ts +2 -0
- package/src/btc/btc-plugin.ts +38 -0
- package/src/btc/btc-processor.ts +35 -10
- package/src/btc/types.ts +2 -1
- package/src/core/handler-options.ts +40 -0
- package/src/core/index.ts +5 -0
- package/src/core/partition-handler-manager.ts +94 -0
- package/src/cosmos/cosmos-processor.ts +12 -1
- package/src/cosmos/types.ts +1 -0
- package/src/eth/base-processor.ts +139 -33
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +118 -62
- package/src/eth/builtin/internal/erc1155-processor.ts +76 -32
- package/src/eth/builtin/internal/erc20-processor.ts +79 -48
- package/src/eth/builtin/internal/erc20bytes-processor.ts +47 -26
- package/src/eth/builtin/internal/erc721-processor.ts +77 -40
- package/src/eth/builtin/internal/weth9-processor.ts +79 -38
- package/src/eth/codegen/event-handler.ts +2 -2
- package/src/eth/codegen/file.ts +1 -0
- package/src/eth/codegen/functions-handler.ts +2 -2
- package/src/eth/eth-plugin.ts +55 -3
- package/src/eth/eth.ts +12 -1
- package/src/fuel/codegen/codegen.ts +5 -5
- package/src/fuel/fuel-plugin.ts +56 -0
- package/src/fuel/fuel-processor-template.ts +17 -10
- package/src/fuel/fuel-processor.ts +89 -13
- package/src/fuel/types.ts +3 -0
- package/src/move/filter.ts +4 -0
- package/src/move/shared-network-codegen.ts +5 -4
- package/src/solana/solana-processor.ts +28 -6
- package/src/stark/starknet-processor.ts +28 -2
- package/src/sui/builtin/0x1.ts +22 -12
- package/src/sui/builtin/0x2.ts +220 -120
- package/src/sui/builtin/0x3.ts +241 -96
- package/src/sui/models.ts +2 -0
- package/src/sui/sui-plugin.ts +68 -22
- package/src/sui/sui-processor.ts +48 -11
package/src/btc/btc-plugin.ts
CHANGED
@@ -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 {
|
package/src/btc/btc-processor.ts
CHANGED
@@ -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
|
-
|
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 (
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
133
|
+
getTransactions?: boolean
|
133
134
|
}
|
@@ -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
@@ -22,3 +22,8 @@ export { type Numberish, toBigInteger, toMetricValue } from './numberish.js'
|
|
22
22
|
export { CorePlugin } from './core-plugin.js'
|
23
23
|
export { DatabaseSchema } from './database-schema.js'
|
24
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'
|
@@ -0,0 +1,94 @@
|
|
1
|
+
import {
|
2
|
+
HandlerType,
|
3
|
+
ProcessStreamResponse_Partitions_Partition,
|
4
|
+
ProcessStreamResponse_Partitions_Partition_SysValue
|
5
|
+
} from '@sentio/protos'
|
6
|
+
import { ServerError, Status } from 'nice-grpc'
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Type for partition handler functions that can process any data type
|
10
|
+
*/
|
11
|
+
export type PartitionHandler = (request: any) => Promise<string | undefined>
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Generic manager for handling partition logic across all chain plugins.
|
15
|
+
* Provides a unified interface for registering, storing, and processing partition handlers.
|
16
|
+
* Chain-specific logic should remain in individual plugins.
|
17
|
+
*/
|
18
|
+
export class PartitionHandlerManager {
|
19
|
+
private partitionHandlers: Map<HandlerType, Record<number, PartitionHandler>> = new Map()
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Register a partition handler for a specific handler type and ID
|
23
|
+
* @param handlerType The type of handler (e.g., HandlerType.ETH_LOG, HandlerType.APT_EVENT)
|
24
|
+
* @param handlerId The unique ID for this handler instance
|
25
|
+
* @param partitionHandler The partition handler function (optional)
|
26
|
+
*/
|
27
|
+
registerPartitionHandler(handlerType: HandlerType, handlerId: number, partitionHandler?: PartitionHandler): void {
|
28
|
+
if (partitionHandler) {
|
29
|
+
const existingHandlers = this.partitionHandlers.get(handlerType) || {}
|
30
|
+
existingHandlers[handlerId] = partitionHandler
|
31
|
+
this.partitionHandlers.set(handlerType, existingHandlers)
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Process partition logic for a specific handler type
|
37
|
+
* @param handlerType The type of handler being processed
|
38
|
+
* @param handlerIds Array of handler IDs to process
|
39
|
+
* @param data The data to pass to partition handlers
|
40
|
+
* @returns Record mapping handler IDs to partition results
|
41
|
+
*/
|
42
|
+
async processPartitionForHandlerType(
|
43
|
+
handlerType: HandlerType,
|
44
|
+
handlerIds: number[],
|
45
|
+
data: any
|
46
|
+
): Promise<Record<number, ProcessStreamResponse_Partitions_Partition>> {
|
47
|
+
const result: Record<number, ProcessStreamResponse_Partitions_Partition> = {}
|
48
|
+
|
49
|
+
for (const handlerId of handlerIds) {
|
50
|
+
const partitionHandler = this.partitionHandlers.get(handlerType)?.[handlerId]
|
51
|
+
if (partitionHandler && data) {
|
52
|
+
try {
|
53
|
+
const partitionValue = await partitionHandler(data)
|
54
|
+
result[handlerId] = {
|
55
|
+
userValue: partitionValue
|
56
|
+
}
|
57
|
+
} catch (error) {
|
58
|
+
// If partition handler fails, fall back to unrecognized
|
59
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'compute partition key failed, error:' + error.message)
|
60
|
+
}
|
61
|
+
} else {
|
62
|
+
result[handlerId] = {
|
63
|
+
sysValue: ProcessStreamResponse_Partitions_Partition_SysValue.UNRECOGNIZED
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
return result
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Clear all partition handlers (useful for testing or reinitialization)
|
73
|
+
*/
|
74
|
+
clear(): void {
|
75
|
+
this.partitionHandlers.clear()
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Get all registered handler types
|
80
|
+
* @returns Array of handler types that have registered partition handlers
|
81
|
+
*/
|
82
|
+
getRegisteredHandlerTypes(): HandlerType[] {
|
83
|
+
return Array.from(this.partitionHandlers.keys())
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Get the number of registered handlers for a specific handler type
|
88
|
+
* @param handlerType The handler type to check
|
89
|
+
* @returns Number of registered handlers for this type
|
90
|
+
*/
|
91
|
+
getHandlerCount(handlerType: HandlerType): number {
|
92
|
+
return Object.keys(this.partitionHandlers.get(handlerType) || {}).length
|
93
|
+
}
|
94
|
+
}
|
@@ -3,6 +3,7 @@ import { Data_CosmosCall } from '@sentio/protos'
|
|
3
3
|
import { CosmosContext } from './context.js'
|
4
4
|
import { CosmosEvent, CosmosTransaction, CosmosTxLog } from './transaction.js'
|
5
5
|
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
6
|
+
import { HandlerOptions } from '../core/handler-options.js'
|
6
7
|
|
7
8
|
export class CosmosProcessor {
|
8
9
|
callHandlers: CallHandler<Data_CosmosCall>[] = []
|
@@ -19,7 +20,8 @@ export class CosmosProcessor {
|
|
19
20
|
|
20
21
|
public onLogEvent(
|
21
22
|
logFilters: string[] | string,
|
22
|
-
handler: (log: CosmosTxLog, event: CosmosEvent, context: CosmosContext) => void | Promise<void
|
23
|
+
handler: (log: CosmosTxLog, event: CosmosEvent, context: CosmosContext) => void | Promise<void>,
|
24
|
+
handlerOptions?: HandlerOptions<object, CosmosTransaction>
|
23
25
|
) {
|
24
26
|
const filter = Array.isArray(logFilters) ? logFilters : [logFilters]
|
25
27
|
const callHandler = {
|
@@ -39,6 +41,15 @@ export class CosmosProcessor {
|
|
39
41
|
},
|
40
42
|
logConfig: {
|
41
43
|
logFilters: filter
|
44
|
+
},
|
45
|
+
partitionHandler: async (call: Data_CosmosCall): Promise<string | undefined> => {
|
46
|
+
const p = handlerOptions?.partitionKey
|
47
|
+
if (!p) return undefined
|
48
|
+
if (typeof p === 'function') {
|
49
|
+
const transaction = call.transaction as CosmosTransaction
|
50
|
+
return p(transaction)
|
51
|
+
}
|
52
|
+
return p
|
42
53
|
}
|
43
54
|
}
|
44
55
|
this.callHandlers.push(callHandler)
|