@sentio/sdk 2.59.0-rc.4 → 2.59.0-rc.40
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/api.d.ts +1 -0
- package/lib/aptos/api.d.ts.map +1 -1
- package/lib/aptos/api.js +13 -1
- package/lib/aptos/api.js.map +1 -1
- package/lib/aptos/aptos-plugin.d.ts +8 -4
- package/lib/aptos/aptos-plugin.d.ts.map +1 -1
- package/lib/aptos/aptos-plugin.js +51 -8
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +21 -19
- package/lib/aptos/aptos-processor.d.ts.map +1 -1
- package/lib/aptos/aptos-processor.js +102 -50
- 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 +31 -4
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/data.d.ts +45 -0
- package/lib/aptos/data.d.ts.map +1 -0
- package/lib/aptos/data.js +99 -0
- package/lib/aptos/data.js.map +1 -0
- 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/aptos/move-coder.d.ts +8 -2
- package/lib/aptos/move-coder.d.ts.map +1 -1
- package/lib/aptos/move-coder.js +84 -1
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/aptos/network.d.ts +1 -0
- package/lib/aptos/network.d.ts.map +1 -1
- package/lib/aptos/network.js +1 -0
- package/lib/aptos/network.js.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/base-context.d.ts +4 -2
- package/lib/core/base-context.d.ts.map +1 -1
- package/lib/core/base-context.js +10 -5
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/event-logger.d.ts +5 -0
- package/lib/core/event-logger.d.ts.map +1 -1
- package/lib/core/event-logger.js +36 -1
- package/lib/core/event-logger.js.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 +3 -1
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/meter.d.ts +45 -2
- package/lib/core/meter.d.ts.map +1 -1
- package/lib/core/meter.js +124 -2
- package/lib/core/meter.js.map +1 -1
- package/lib/core/numberish.d.ts +2 -1
- package/lib/core/numberish.d.ts.map +1 -1
- package/lib/core/numberish.js +35 -1
- package/lib/core/numberish.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 +23 -17
- package/lib/eth/base-processor.d.ts.map +1 -1
- package/lib/eth/base-processor.js +173 -34
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/bind-options.d.ts +6 -0
- package/lib/eth/bind-options.d.ts.map +1 -1
- package/lib/eth/bind-options.js +2 -0
- package/lib/eth/bind-options.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 +5 -1
- package/lib/eth/eth-plugin.d.ts.map +1 -1
- package/lib/eth/eth-plugin.js +53 -5
- 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 +91 -28
- 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 +5 -0
- package/lib/move/filter.d.ts.map +1 -1
- package/lib/move/filter.js +5 -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 +32 -14
- package/lib/stark/starknet-processor.js.map +1 -1
- package/lib/store/codegen.d.ts.map +1 -1
- package/lib/store/codegen.js +36 -2
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/schema.d.ts.map +1 -1
- package/lib/store/schema.js +3 -1
- package/lib/store/schema.js.map +1 -1
- package/lib/store/store.d.ts +4 -3
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +41 -1
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +20 -1
- package/lib/store/types.d.ts.map +1 -1
- package/lib/store/types.js +22 -0
- package/lib/store/types.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-object-processor-template.js +1 -1
- package/lib/sui/sui-object-processor-template.js.map +1 -1
- package/lib/sui/sui-object-processor.d.ts +2 -0
- package/lib/sui/sui-object-processor.d.ts.map +1 -1
- package/lib/sui/sui-object-processor.js +4 -0
- package/lib/sui/sui-object-processor.js.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 +68 -24
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +6 -4
- package/lib/sui/sui-processor.d.ts.map +1 -1
- package/lib/sui/sui-processor.js +48 -11
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/testing/eth-facet.d.ts +2 -1
- package/lib/testing/eth-facet.d.ts.map +1 -1
- package/lib/testing/eth-facet.js.map +1 -1
- package/lib/utils/block.d.ts +2 -0
- package/lib/utils/block.d.ts.map +1 -1
- package/lib/utils/block.js +13 -0
- package/lib/utils/block.js.map +1 -1
- package/package.json +7 -6
- package/src/aptos/api.ts +13 -1
- package/src/aptos/aptos-plugin.ts +62 -13
- package/src/aptos/aptos-processor.ts +114 -74
- package/src/aptos/aptos-resource-processor-template.ts +9 -8
- package/src/aptos/builtin/0x1.ts +1566 -664
- package/src/aptos/builtin/0x3.ts +303 -130
- package/src/aptos/builtin/0x4.ts +124 -56
- package/src/aptos/codegen/codegen.ts +40 -5
- package/src/aptos/data.ts +123 -0
- package/src/aptos/index.ts +2 -0
- package/src/aptos/models.ts +2 -0
- package/src/aptos/move-coder.ts +96 -3
- package/src/aptos/network.ts +1 -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/base-context.ts +10 -5
- package/src/core/event-logger.ts +45 -1
- package/src/core/handler-options.ts +40 -0
- package/src/core/index.ts +17 -1
- package/src/core/meter.ts +159 -4
- package/src/core/numberish.ts +34 -1
- 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 +163 -41
- package/src/eth/bind-options.ts +7 -0
- 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 +76 -10
- 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 +90 -22
- package/src/fuel/types.ts +3 -0
- package/src/move/filter.ts +5 -0
- package/src/move/shared-network-codegen.ts +5 -4
- package/src/solana/solana-processor.ts +28 -6
- package/src/stark/starknet-processor.ts +31 -13
- package/src/store/codegen.ts +50 -2
- package/src/store/schema.ts +3 -1
- package/src/store/store.ts +57 -4
- package/src/store/types.ts +30 -1
- 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-object-processor-template.ts +1 -1
- package/src/sui/sui-object-processor.ts +6 -0
- package/src/sui/sui-plugin.ts +77 -26
- package/src/sui/sui-processor.ts +50 -11
- package/src/testing/eth-facet.ts +2 -1
- package/src/utils/block.ts +15 -0
package/src/core/meter.ts
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
import { BaseContext } from './base-context.js'
|
2
|
-
import { Numberish, toMetricValue } from './numberish.js'
|
2
|
+
import { Numberish, toMetricValue, toTimeSeriesData } from './numberish.js'
|
3
3
|
import { NamedResultDescriptor } from './metadata.js'
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
AggregationConfig,
|
6
|
+
AggregationType,
|
7
|
+
MetricConfig,
|
8
|
+
MetricType,
|
9
|
+
TimeseriesResult_TimeseriesType
|
10
|
+
} from '@sentio/protos'
|
5
11
|
import { MapStateStorage, processMetrics } from '@sentio/runtime'
|
6
12
|
|
7
13
|
export type Labels = { [key: string]: string }
|
@@ -30,6 +36,7 @@ export class CounterOptions {
|
|
30
36
|
|
31
37
|
export class Metric extends NamedResultDescriptor {
|
32
38
|
config: MetricConfig
|
39
|
+
|
33
40
|
constructor(type: MetricType, name: string, option?: MetricConfig) {
|
34
41
|
super(name)
|
35
42
|
this.config = MetricConfig.fromPartial({ ...option, name: this.name, type })
|
@@ -67,6 +74,28 @@ export class MetricState extends MapStateStorage<Metric> {
|
|
67
74
|
}
|
68
75
|
}
|
69
76
|
|
77
|
+
export class MetricStateNew extends MapStateStorage<Metric> {
|
78
|
+
static INSTANCE = new MetricStateNew()
|
79
|
+
|
80
|
+
getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {
|
81
|
+
const metricMap = this.getOrRegister()
|
82
|
+
let metric = metricMap.get(name)
|
83
|
+
if (metric && metric.config.type !== type) {
|
84
|
+
throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.config.type}`)
|
85
|
+
}
|
86
|
+
|
87
|
+
if (!metric) {
|
88
|
+
if (type === MetricType.COUNTER) {
|
89
|
+
metric = CounterNew._create(name, option)
|
90
|
+
} else {
|
91
|
+
metric = GaugeNew._create(name, option)
|
92
|
+
}
|
93
|
+
}
|
94
|
+
metricMap.set(name, metric)
|
95
|
+
return metric
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
70
99
|
export class Counter extends Metric {
|
71
100
|
static register(name: string, option?: CounterOptions): Counter {
|
72
101
|
return MetricState.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as Counter
|
@@ -79,7 +108,7 @@ export class Counter extends Metric {
|
|
79
108
|
return new Counter(name, option)
|
80
109
|
}
|
81
110
|
|
82
|
-
|
111
|
+
protected constructor(name: string, option?: CounterOptions) {
|
83
112
|
super(
|
84
113
|
MetricType.COUNTER,
|
85
114
|
name,
|
@@ -145,7 +174,7 @@ export class Gauge extends Metric {
|
|
145
174
|
return new Gauge(name, option)
|
146
175
|
}
|
147
176
|
|
148
|
-
|
177
|
+
protected constructor(name: string, option?: MetricOptions) {
|
149
178
|
super(MetricType.GAUGE, name, MetricConfig.fromPartial({ ...option }))
|
150
179
|
}
|
151
180
|
|
@@ -192,3 +221,129 @@ export class Meter {
|
|
192
221
|
return new GaugeBinding(name, this.ctx)
|
193
222
|
}
|
194
223
|
}
|
224
|
+
|
225
|
+
export class MeterNew {
|
226
|
+
private readonly ctx: BaseContext
|
227
|
+
|
228
|
+
constructor(ctx: BaseContext) {
|
229
|
+
this.ctx = ctx
|
230
|
+
}
|
231
|
+
|
232
|
+
Counter(name: string) {
|
233
|
+
return new CounterNewBinding(name, this.ctx)
|
234
|
+
}
|
235
|
+
|
236
|
+
Gauge(name: string) {
|
237
|
+
return new GaugeNewBinding(name, this.ctx)
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
export class CounterNew extends Counter {
|
242
|
+
static register(name: string, option?: CounterOptions): CounterNew {
|
243
|
+
return MetricStateNew.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as CounterNew
|
244
|
+
}
|
245
|
+
|
246
|
+
/**
|
247
|
+
* internal use only, to create a metric use {@link register} instead
|
248
|
+
*/
|
249
|
+
static _create(name: string, option?: CounterOptions): CounterNew {
|
250
|
+
return new CounterNew(name, option)
|
251
|
+
}
|
252
|
+
|
253
|
+
private constructor(name: string, option?: CounterOptions) {
|
254
|
+
super(
|
255
|
+
name,
|
256
|
+
MetricConfig.fromPartial({
|
257
|
+
...option,
|
258
|
+
aggregationConfig: {
|
259
|
+
intervalInMinutes: option?.resolutionConfig ? [option?.resolutionConfig?.intervalInMinutes] : []
|
260
|
+
}
|
261
|
+
})
|
262
|
+
)
|
263
|
+
}
|
264
|
+
|
265
|
+
add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
266
|
+
this.recordNew(ctx, value, labels, true)
|
267
|
+
}
|
268
|
+
|
269
|
+
sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
270
|
+
this.recordNew(ctx, value, labels, false)
|
271
|
+
}
|
272
|
+
|
273
|
+
private recordNew(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
|
274
|
+
processMetrics.process_metricrecord_count.add(1)
|
275
|
+
ctx.update({
|
276
|
+
timeseriesResult: [
|
277
|
+
{
|
278
|
+
metadata: ctx.getMetaData(this.name, labels),
|
279
|
+
type: TimeseriesResult_TimeseriesType.COUNTER,
|
280
|
+
data: toTimeSeriesData(value, labels, !add),
|
281
|
+
runtimeInfo: undefined
|
282
|
+
}
|
283
|
+
]
|
284
|
+
})
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
export class GaugeNewBinding {
|
289
|
+
private readonly gauge: GaugeNew
|
290
|
+
private readonly ctx: BaseContext
|
291
|
+
|
292
|
+
constructor(name: string, ctx: BaseContext) {
|
293
|
+
this.gauge = GaugeNew._create(name)
|
294
|
+
this.ctx = ctx
|
295
|
+
}
|
296
|
+
|
297
|
+
record(value: Numberish, labels: Labels = {}) {
|
298
|
+
this.gauge.record(this.ctx, value, labels)
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
export class CounterNewBinding {
|
303
|
+
private readonly counter: CounterNew
|
304
|
+
private readonly ctx: BaseContext
|
305
|
+
|
306
|
+
constructor(name: string, ctx: BaseContext) {
|
307
|
+
this.counter = CounterNew._create(name)
|
308
|
+
this.ctx = ctx
|
309
|
+
}
|
310
|
+
|
311
|
+
add(value: Numberish, labels: Labels = {}) {
|
312
|
+
this.counter.add(this.ctx, value, labels)
|
313
|
+
}
|
314
|
+
|
315
|
+
sub(value: Numberish, labels: Labels = {}) {
|
316
|
+
this.counter.sub(this.ctx, value, labels)
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
export class GaugeNew extends Gauge {
|
321
|
+
static register(name: string, option?: MetricOptions): Gauge {
|
322
|
+
return MetricStateNew.INSTANCE.getOrRegisterMetric(MetricType.GAUGE, name, option) as Gauge
|
323
|
+
}
|
324
|
+
|
325
|
+
/**
|
326
|
+
* internal use only, to create a metric use {@link register} instead
|
327
|
+
*/
|
328
|
+
static _create(name: string, option?: MetricOptions): GaugeNew {
|
329
|
+
return new GaugeNew(name, option)
|
330
|
+
}
|
331
|
+
|
332
|
+
private constructor(name: string, option?: MetricOptions) {
|
333
|
+
super(name, MetricConfig.fromPartial({ ...option }))
|
334
|
+
}
|
335
|
+
|
336
|
+
record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
337
|
+
processMetrics.process_metricrecord_count.add(1)
|
338
|
+
ctx.update({
|
339
|
+
timeseriesResult: [
|
340
|
+
{
|
341
|
+
metadata: ctx.getMetaData(this.name, labels),
|
342
|
+
type: TimeseriesResult_TimeseriesType.GAUGE,
|
343
|
+
data: toTimeSeriesData(value, labels, false),
|
344
|
+
runtimeInfo: undefined
|
345
|
+
}
|
346
|
+
]
|
347
|
+
})
|
348
|
+
}
|
349
|
+
}
|
package/src/core/numberish.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BigDecimalRichValue, BigInteger, MetricValue } from '@sentio/protos'
|
1
|
+
import { BigDecimalRichValue, BigInteger, MetricValue, RichStruct, RichValue_NullValue } from '@sentio/protos'
|
2
2
|
import { BigDecimal } from './big-decimal.js'
|
3
3
|
|
4
4
|
export type Numberish = number | bigint | BigDecimal | string
|
@@ -120,3 +120,36 @@ export function toBigDecimal(value: BigDecimal): BigDecimalRichValue {
|
|
120
120
|
exp: exp
|
121
121
|
}
|
122
122
|
}
|
123
|
+
|
124
|
+
export function toTimeSeriesData(value: Numberish, labels: Record<string, string>, neg: boolean) {
|
125
|
+
const mv = toMetricValue(value)
|
126
|
+
const data: RichStruct = {
|
127
|
+
fields: {
|
128
|
+
value: {}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
for (const key in labels) {
|
133
|
+
if (labels[key] == null) {
|
134
|
+
data.fields[key] = { nullValue: RichValue_NullValue.NULL_VALUE }
|
135
|
+
} else {
|
136
|
+
data.fields[key] = { stringValue: labels[key] }
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
if (mv.bigInteger != null) {
|
141
|
+
mv.bigInteger.negative = neg ? !mv.bigInteger.negative : mv.bigInteger.negative
|
142
|
+
data.fields.value.bigintValue = mv.bigInteger
|
143
|
+
} else if (mv.bigDecimal != null) {
|
144
|
+
let v = new BigDecimal(mv.bigDecimal)
|
145
|
+
if (neg) {
|
146
|
+
v = v.negated()
|
147
|
+
}
|
148
|
+
data.fields.value.bigdecimalValue = toBigDecimal(v)
|
149
|
+
} else if (mv.doubleValue != null) {
|
150
|
+
data.fields.value.floatValue = neg ? -mv.doubleValue : mv.doubleValue
|
151
|
+
} else {
|
152
|
+
data.fields.value.nullValue = RichValue_NullValue.NULL_VALUE
|
153
|
+
}
|
154
|
+
return data
|
155
|
+
}
|
@@ -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)
|