@sentio/sdk 1.20.2 → 1.21.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.
- package/lib/aptos/aptos-processor.d.ts +16 -15
- package/lib/aptos/aptos-processor.js +65 -13
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/bind-options.d.ts +0 -6
- package/lib/aptos/bind-options.js +1 -8
- package/lib/aptos/bind-options.js.map +1 -1
- package/lib/aptos/context.d.ts +5 -4
- package/lib/aptos/context.js +9 -6
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +3 -2
- package/lib/aptos/index.js +1 -2
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/runtime.d.ts +2 -0
- package/lib/aptos/runtime.js +16 -0
- package/lib/aptos/runtime.js.map +1 -0
- package/lib/aptos/types.d.ts +28 -0
- package/lib/aptos/types.js +159 -0
- package/lib/aptos/types.js.map +1 -0
- package/lib/aptos/utils.d.ts +6 -0
- package/lib/aptos/utils.js +19 -0
- package/lib/aptos/utils.js.map +1 -0
- package/lib/aptos-codegen/codegen.d.ts +5 -2
- package/lib/aptos-codegen/codegen.js +195 -17
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/aptos-codegen/typegen.d.ts +18 -0
- package/lib/aptos-codegen/typegen.js +196 -0
- package/lib/aptos-codegen/typegen.js.map +1 -0
- package/lib/binds.d.ts +2 -3
- package/lib/binds.js +6 -33
- package/lib/binds.js.map +1 -1
- package/lib/builtin/aptos/0x1.d.ts +1624 -0
- package/lib/builtin/aptos/0x1.js +2570 -0
- package/lib/builtin/aptos/0x1.js.map +1 -0
- package/lib/builtin/aptos/0x3.d.ts +414 -0
- package/lib/builtin/aptos/0x3.js +474 -0
- package/lib/builtin/aptos/0x3.js.map +1 -0
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +2 -2
- package/lib/builtin/internal/eacaggregatorproxy_processor.js +12 -11
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.d.ts +2 -2
- package/lib/builtin/internal/erc20_processor.js +12 -11
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.d.ts +2 -2
- package/lib/builtin/internal/erc20bytes_processor.js +12 -11
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +2 -2
- package/lib/builtin/internal/weth9_processor.js +12 -11
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/builtin/solana/types.d.ts +5 -5
- package/lib/builtin/solana/wormhole-processor.d.ts +6 -6
- package/lib/builtin/solana/wormhole-processor.js +15 -12
- package/lib/builtin/solana/wormhole-processor.js.map +1 -1
- package/lib/cli/build.js +17 -16
- package/lib/cli/build.js.map +1 -1
- package/lib/core/base-processor-template.d.ts +7 -7
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +5 -6
- package/lib/core/base-processor.js +6 -4
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/big-decimal.d.ts +1 -0
- package/lib/core/big-decimal.js +6 -0
- package/lib/core/big-decimal.js.map +1 -0
- package/lib/core/bind-options.d.ts +0 -2
- package/lib/core/bind-options.js +4 -4
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +14 -11
- package/lib/core/context.js +28 -19
- package/lib/core/context.js.map +1 -1
- package/lib/core/generic-processor.js +5 -5
- package/lib/core/generic-processor.js.map +1 -1
- package/lib/core/index.d.ts +5 -5
- package/lib/core/index.js +6 -6
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +2 -3
- package/lib/core/logger.js +6 -6
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +7 -4
- package/lib/core/metadata.js +13 -10
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +4 -7
- package/lib/core/meter.js +12 -13
- package/lib/core/meter.js.map +1 -1
- package/lib/core/solana-processor.d.ts +7 -4
- package/lib/core/solana-processor.js +14 -20
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.d.ts +5 -4
- package/lib/core/sui-processor.js +10 -17
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/error.d.ts +2 -2
- package/lib/error.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +24 -12
- package/lib/gen/processor/protos/processor.js +147 -58
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -4
- package/lib/index.js.map +1 -1
- package/lib/processor-state.d.ts +1 -1
- package/lib/processor-state.js.map +1 -1
- package/lib/service.js +15 -13
- package/lib/service.js.map +1 -1
- package/lib/target-ethers-sentio/codegen.js +14 -15
- package/lib/target-ethers-sentio/codegen.js.map +1 -1
- package/lib/test-abi-code-gen.js.map +1 -1
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/tests/aptos.test.js +95 -2
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/erc20.js +1 -1
- package/lib/tests/erc20.js.map +1 -1
- package/lib/tests/erc20.test.js +3 -4
- package/lib/tests/erc20.test.js.map +1 -1
- package/lib/tests/solana.test.js +5 -1
- package/lib/tests/solana.test.js.map +1 -1
- package/lib/tests/souffl3.js +17 -4
- package/lib/tests/souffl3.js.map +1 -1
- package/lib/tests/sui.test.js +1 -4
- package/lib/tests/sui.test.js.map +1 -1
- package/lib/tests/types/aptos/souffle.d.ts +311 -22
- package/lib/tests/types/aptos/souffle.js +172 -20
- package/lib/tests/types/aptos/souffle.js.map +1 -1
- package/lib/tests/types/solana/basic_1_processor.d.ts +2 -2
- package/lib/tests/types/solana/basic_1_processor.js +4 -4
- package/lib/tests/types/solana/basic_1_processor.js.map +1 -1
- package/lib/tests/wormhole-token-bridge.js +2 -1
- package/lib/tests/wormhole-token-bridge.js.map +1 -1
- package/lib/utils/chain.d.ts +1 -0
- package/lib/utils/chain.js +15 -1
- package/lib/utils/chain.js.map +1 -1
- package/lib/utils/conversion.d.ts +1 -1
- package/lib/utils/conversion.js.map +1 -1
- package/package.json +3 -2
- package/src/abis/aptos/0x1.json +9205 -0
- package/src/abis/aptos/0x3.json +1515 -0
- package/src/aptos/aptos-processor.ts +89 -25
- package/src/aptos/bind-options.ts +0 -7
- package/src/aptos/context.ts +11 -8
- package/src/aptos/index.ts +3 -2
- package/src/aptos/runtime.ts +13 -0
- package/src/aptos/types.ts +203 -0
- package/src/aptos/utils.ts +18 -0
- package/src/aptos-codegen/codegen.ts +222 -18
- package/src/aptos-codegen/typegen.test.ts +29 -0
- package/src/aptos-codegen/typegen.ts +216 -0
- package/src/binds.ts +5 -39
- package/src/builtin/aptos/0x1.ts +3917 -0
- package/src/builtin/aptos/0x3.ts +824 -0
- package/src/builtin/internal/eacaggregatorproxy_processor.ts +14 -31
- package/src/builtin/internal/erc20_processor.ts +14 -25
- package/src/builtin/internal/erc20bytes_processor.ts +14 -25
- package/src/builtin/internal/weth9_processor.ts +14 -25
- package/src/builtin/solana/wormhole-processor.ts +21 -18
- package/src/cli/build.ts +19 -17
- package/src/core/base-processor-template.ts +7 -7
- package/src/core/base-processor.ts +30 -9
- package/src/core/big-decimal.ts +1 -0
- package/src/core/bind-options.ts +3 -2
- package/src/core/context.ts +40 -24
- package/src/core/generic-processor.ts +6 -7
- package/src/core/index.ts +5 -5
- package/src/core/logger.ts +7 -7
- package/src/core/metadata.ts +14 -12
- package/src/core/meter.ts +12 -14
- package/src/core/solana-processor.ts +24 -21
- package/src/core/sui-processor.ts +10 -21
- package/src/error.ts +2 -2
- package/src/gen/processor/protos/processor.ts +177 -69
- package/src/index.ts +1 -2
- package/src/processor-state.ts +1 -1
- package/src/service.ts +23 -16
- package/src/target-ethers-sentio/codegen.ts +14 -15
- package/src/test-abi-code-gen.ts +1 -0
- package/src/testing/metric-utils.ts +2 -2
- package/src/tests/aptos.test.ts +102 -3
- package/src/tests/erc20.test.ts +3 -4
- package/src/tests/erc20.ts +1 -1
- package/src/tests/solana.test.ts +5 -1
- package/src/tests/souffl3.ts +21 -6
- package/src/tests/sui.test.ts +1 -4
- package/src/tests/types/aptos/souffle.ts +470 -56
- package/src/tests/types/solana/basic_1_processor.ts +6 -6
- package/src/tests/wormhole-token-bridge.ts +2 -1
- package/src/types/global.d.ts +1 -1
- package/src/utils/chain.ts +14 -0
- package/src/utils/conversion.ts +1 -1
- package/lib/contract-namer.d.ts +0 -6
- package/lib/contract-namer.js +0 -20
- package/lib/contract-namer.js.map +0 -1
- package/src/aptos-codegen/codgen.test.ts +0 -11
- package/src/contract-namer.ts +0 -17
package/src/core/context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CounterResult, GaugeResult, LogResult,
|
|
1
|
+
import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData } from '../gen'
|
|
2
2
|
import { BaseContract, EventFilter } from 'ethers'
|
|
3
3
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
4
4
|
import { Meter, normalizeLabels } from './meter'
|
|
@@ -20,18 +20,19 @@ export abstract class BaseContext {
|
|
|
20
20
|
this.logger = new Logger(this)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
abstract getMetaData(descriptor:
|
|
23
|
+
abstract getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export abstract class EthContext extends BaseContext {
|
|
27
27
|
chainId: number
|
|
28
|
+
address: string
|
|
28
29
|
log?: Log
|
|
29
30
|
block?: Block
|
|
30
31
|
trace?: Trace
|
|
31
32
|
blockNumber: Long
|
|
32
33
|
transactionHash?: string
|
|
33
34
|
|
|
34
|
-
protected constructor(chainId: number, block?: Block, log?: Log, trace?: Trace) {
|
|
35
|
+
protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {
|
|
35
36
|
super()
|
|
36
37
|
this.chainId = chainId
|
|
37
38
|
this.log = log
|
|
@@ -49,54 +50,64 @@ export abstract class EthContext extends BaseContext {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
export class
|
|
53
|
+
export class ContractContext<
|
|
53
54
|
TContract extends BaseContract,
|
|
54
55
|
TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>
|
|
55
56
|
> extends EthContext {
|
|
56
57
|
contract: TContractBoundView
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
constructor(
|
|
60
|
-
|
|
58
|
+
contractName: string
|
|
59
|
+
|
|
60
|
+
constructor(
|
|
61
|
+
contractName: string,
|
|
62
|
+
view: TContractBoundView,
|
|
63
|
+
chainId: number,
|
|
64
|
+
block?: Block,
|
|
65
|
+
log?: Log,
|
|
66
|
+
trace?: Trace
|
|
67
|
+
) {
|
|
68
|
+
super(chainId, view.rawContract.address, block, log, trace)
|
|
61
69
|
view.context = this
|
|
70
|
+
this.contractName = contractName
|
|
62
71
|
this.contract = view
|
|
63
|
-
this.address = view.rawContract.address
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
getMetaData(descriptor:
|
|
74
|
+
getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {
|
|
67
75
|
if (this.log) {
|
|
68
76
|
return {
|
|
69
|
-
|
|
77
|
+
address: this.contract.rawContract.address,
|
|
78
|
+
contractName: this.contractName,
|
|
70
79
|
blockNumber: this.blockNumber,
|
|
71
80
|
transactionIndex: this.log.transactionIndex,
|
|
72
81
|
transactionHash: this.transactionHash || '',
|
|
73
82
|
logIndex: this.log.logIndex,
|
|
74
83
|
chainId: this.chainId.toString(),
|
|
75
|
-
|
|
84
|
+
dataDescriptor: descriptor,
|
|
76
85
|
labels: normalizeLabels(labels),
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
88
|
if (this.block) {
|
|
80
89
|
return {
|
|
81
|
-
|
|
90
|
+
address: this.contract.rawContract.address,
|
|
91
|
+
contractName: this.contractName,
|
|
82
92
|
blockNumber: this.blockNumber,
|
|
83
93
|
transactionIndex: -1,
|
|
84
94
|
transactionHash: '',
|
|
85
95
|
logIndex: -1,
|
|
86
96
|
chainId: this.chainId.toString(),
|
|
87
|
-
|
|
97
|
+
dataDescriptor: descriptor,
|
|
88
98
|
labels: normalizeLabels(labels),
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
101
|
if (this.trace) {
|
|
92
102
|
return {
|
|
93
|
-
|
|
103
|
+
address: this.contract.rawContract.address,
|
|
104
|
+
contractName: this.contractName,
|
|
94
105
|
blockNumber: this.blockNumber,
|
|
95
106
|
transactionIndex: this.trace.transactionPosition,
|
|
96
107
|
transactionHash: this.transactionHash || '',
|
|
97
108
|
logIndex: -1,
|
|
98
109
|
chainId: this.chainId.toString(),
|
|
99
|
-
|
|
110
|
+
dataDescriptor: descriptor,
|
|
100
111
|
labels: normalizeLabels(labels),
|
|
101
112
|
}
|
|
102
113
|
}
|
|
@@ -125,7 +136,7 @@ export class ContractView<TContract extends BaseContract> {
|
|
|
125
136
|
export class BoundContractView<TContract extends BaseContract, TContractView extends ContractView<TContract>> {
|
|
126
137
|
protected view: TContractView
|
|
127
138
|
// context will be set right after context creation (in context's constructor)
|
|
128
|
-
context:
|
|
139
|
+
context: ContractContext<TContract, BoundContractView<TContract, TContractView>>
|
|
129
140
|
|
|
130
141
|
constructor(view: TContractView) {
|
|
131
142
|
this.view = view
|
|
@@ -146,23 +157,26 @@ export class BoundContractView<TContract extends BaseContract, TContractView ext
|
|
|
146
157
|
|
|
147
158
|
export class SolanaContext extends BaseContext {
|
|
148
159
|
address: string
|
|
160
|
+
programName: string
|
|
149
161
|
blockNumber: Long
|
|
150
162
|
|
|
151
|
-
constructor(address: string, slot: Long) {
|
|
163
|
+
constructor(programName: string, address: string, slot: Long) {
|
|
152
164
|
super()
|
|
165
|
+
this.programName = programName
|
|
153
166
|
this.address = address
|
|
154
167
|
this.blockNumber = slot
|
|
155
168
|
}
|
|
156
169
|
|
|
157
|
-
getMetaData(descriptor:
|
|
170
|
+
getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {
|
|
158
171
|
return {
|
|
159
|
-
|
|
172
|
+
address: this.address,
|
|
173
|
+
contractName: this.programName,
|
|
160
174
|
blockNumber: this.blockNumber,
|
|
161
175
|
transactionIndex: 0,
|
|
162
176
|
transactionHash: '', // TODO add
|
|
163
177
|
logIndex: 0,
|
|
164
178
|
chainId: SOL_MAINMET_ID, // TODO set in context
|
|
165
|
-
|
|
179
|
+
dataDescriptor: descriptor,
|
|
166
180
|
labels: normalizeLabels(labels),
|
|
167
181
|
}
|
|
168
182
|
}
|
|
@@ -170,6 +184,7 @@ export class SolanaContext extends BaseContext {
|
|
|
170
184
|
|
|
171
185
|
export class SuiContext extends BaseContext {
|
|
172
186
|
address: string
|
|
187
|
+
moduleName: string
|
|
173
188
|
blockNumber: Long
|
|
174
189
|
|
|
175
190
|
constructor(address: string, slot: Long) {
|
|
@@ -178,15 +193,16 @@ export class SuiContext extends BaseContext {
|
|
|
178
193
|
this.blockNumber = slot
|
|
179
194
|
}
|
|
180
195
|
|
|
181
|
-
getMetaData(descriptor:
|
|
196
|
+
getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {
|
|
182
197
|
return {
|
|
183
|
-
|
|
198
|
+
address: this.address,
|
|
199
|
+
contractName: this.moduleName,
|
|
184
200
|
blockNumber: this.blockNumber,
|
|
185
201
|
transactionIndex: 0,
|
|
186
202
|
transactionHash: '', // TODO
|
|
187
203
|
logIndex: 0,
|
|
188
204
|
chainId: SUI_DEVNET_ID, // TODO set in context
|
|
189
|
-
|
|
205
|
+
dataDescriptor: descriptor,
|
|
190
206
|
labels: normalizeLabels(labels),
|
|
191
207
|
}
|
|
192
208
|
}
|
|
@@ -3,7 +3,7 @@ import { BoundContractView, ContractView } from './context'
|
|
|
3
3
|
import { BindOptions } from './bind-options'
|
|
4
4
|
import { BaseProcessor } from './base-processor'
|
|
5
5
|
import { getProvider } from '../provider'
|
|
6
|
-
import { addProcessor
|
|
6
|
+
import { addProcessor } from '../binds'
|
|
7
7
|
|
|
8
8
|
export class GenericProcessor extends BaseProcessor<
|
|
9
9
|
BaseContract,
|
|
@@ -21,15 +21,14 @@ export class GenericProcessor extends BaseProcessor<
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public static bind(eventABI: string[] | string, options: BindOptions): GenericProcessor {
|
|
24
|
-
const AbiName = 'Generic'
|
|
25
24
|
if (!Array.isArray(eventABI)) {
|
|
26
25
|
eventABI = [eventABI]
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const processor = new GenericProcessor(eventABI,
|
|
32
|
-
addProcessor(
|
|
27
|
+
if (!options.name) {
|
|
28
|
+
options.name = 'Generic'
|
|
29
|
+
}
|
|
30
|
+
const processor = new GenericProcessor(eventABI, options)
|
|
31
|
+
addProcessor(options, processor)
|
|
33
32
|
return processor
|
|
34
33
|
}
|
|
35
34
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { CounterBinding, Meter, GaugeBinding, Counter, Gauge,
|
|
1
|
+
export { BigDecimal } from './big-decimal'
|
|
2
|
+
export { ContractContext, ContractView, BoundContractView, SolanaContext } from './context'
|
|
3
|
+
export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter'
|
|
4
4
|
export { type Numberish, toBigInteger, toMetricValue } from './numberish'
|
|
5
5
|
|
|
6
|
-
export { BindOptions, SolanaBindOptions
|
|
6
|
+
export { BindOptions, SolanaBindOptions } from './bind-options'
|
|
7
7
|
|
|
8
8
|
export { BaseProcessor } from './base-processor'
|
|
9
9
|
export { GenericProcessor } from './generic-processor'
|
|
10
10
|
export { BaseProcessorTemplate } from './base-processor-template'
|
|
11
11
|
export { SolanaBaseProcessor } from './solana-processor'
|
|
12
|
-
export { SuiBaseProcessor } from './sui-processor'
|
|
12
|
+
export { SuiBaseProcessor, SuiBindOptions } from './sui-processor'
|
|
13
13
|
// export * from '../aptos'
|
|
14
14
|
|
|
15
15
|
export type { TypedCallTrace, Trace } from './trace'
|
package/src/core/logger.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { BaseContext } from './context'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { DataDescriptor, LogLevel } from '../gen'
|
|
3
|
+
import { DescriptorWithUsage, Labels } from './metadata'
|
|
4
4
|
|
|
5
5
|
export type Attributes = Record<string, any>
|
|
6
6
|
|
|
7
|
-
export class Logger {
|
|
7
|
+
export class Logger extends DescriptorWithUsage {
|
|
8
8
|
private readonly ctx: BaseContext
|
|
9
|
-
private readonly name: string
|
|
10
9
|
|
|
11
10
|
constructor(ctx: BaseContext, name = '') {
|
|
11
|
+
super(DataDescriptor.fromPartial({ name }))
|
|
12
12
|
this.ctx = ctx
|
|
13
|
-
this.name = name
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
withName(name: string) {
|
|
@@ -22,9 +21,10 @@ export class Logger {
|
|
|
22
21
|
message = message.toString()
|
|
23
22
|
}
|
|
24
23
|
|
|
24
|
+
this.usage++
|
|
25
25
|
this.ctx.logs.push({
|
|
26
|
-
name: this.name,
|
|
27
|
-
metadata: GetRecordMetaData(this.ctx,
|
|
26
|
+
// name: this.name,
|
|
27
|
+
metadata: this.ctx.getMetaData(this.getShortDescriptor(), {}), // GetRecordMetaData(this.ctx, this, {}),
|
|
28
28
|
level,
|
|
29
29
|
message,
|
|
30
30
|
attributes: JSON.stringify(attributes),
|
package/src/core/metadata.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Metric, normalizeName } from './meter'
|
|
1
|
+
import { DataDescriptor } from '../gen'
|
|
2
|
+
import { normalizeName } from './meter'
|
|
4
3
|
|
|
5
4
|
export type Labels = { [key: string]: string }
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export class DescriptorWithUsage {
|
|
7
|
+
descriptor: DataDescriptor
|
|
8
|
+
usage = 0
|
|
9
|
+
constructor(descriptor: DataDescriptor) {
|
|
10
|
+
this.descriptor = descriptor
|
|
11
|
+
this.descriptor.name = normalizeName(descriptor.name)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getShortDescriptor(): DataDescriptor {
|
|
15
|
+
if (this.usage > 0) {
|
|
12
16
|
// Other setting don't need to be write multiple times
|
|
13
|
-
|
|
17
|
+
return DataDescriptor.fromPartial({ name: this.descriptor.name })
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
return this.descriptor
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
return ctx.getMetaData(descriptor, labels)
|
|
20
22
|
}
|
package/src/core/meter.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MetricDescriptor } from '../gen'
|
|
2
1
|
import { BaseContext } from './context'
|
|
3
2
|
import { toMetricValue, Numberish } from './numberish'
|
|
4
|
-
import {
|
|
3
|
+
import { DescriptorWithUsage, Labels } from './metadata'
|
|
4
|
+
import { DataDescriptor } from '../gen'
|
|
5
5
|
|
|
6
6
|
export function normalizeName(name: string): string {
|
|
7
7
|
const regex = new RegExp('![_.a-zA-Z0-9]')
|
|
@@ -27,29 +27,27 @@ export function normalizeLabels(labels: Labels): Labels {
|
|
|
27
27
|
return normLabels
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export class
|
|
30
|
+
export class MetricDescriptorOptions {
|
|
31
31
|
unit?: string
|
|
32
32
|
description?: string
|
|
33
33
|
sparse?: boolean
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export class Metric {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
constructor(name: string, option?: MetricDescriptorOption) {
|
|
41
|
-
this.descriptor.name = name
|
|
36
|
+
export class Metric extends DescriptorWithUsage {
|
|
37
|
+
constructor(name: string, option?: MetricDescriptorOptions) {
|
|
38
|
+
const descriptor = DataDescriptor.fromPartial({ name })
|
|
42
39
|
if (option) {
|
|
43
40
|
if (option.unit) {
|
|
44
|
-
|
|
41
|
+
descriptor.unit = option.unit
|
|
45
42
|
}
|
|
46
43
|
if (option.description) {
|
|
47
|
-
|
|
44
|
+
descriptor.description = option.description
|
|
48
45
|
}
|
|
49
46
|
if (option.sparse) {
|
|
50
|
-
|
|
47
|
+
descriptor.sparse = option.sparse
|
|
51
48
|
}
|
|
52
49
|
}
|
|
50
|
+
super(descriptor)
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
|
|
@@ -64,7 +62,7 @@ export class Counter extends Metric {
|
|
|
64
62
|
|
|
65
63
|
private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
|
|
66
64
|
ctx.counters.push({
|
|
67
|
-
metadata:
|
|
65
|
+
metadata: ctx.getMetaData(this.getShortDescriptor(), labels),
|
|
68
66
|
metricValue: toMetricValue(value),
|
|
69
67
|
add: add,
|
|
70
68
|
runtimeInfo: undefined,
|
|
@@ -94,7 +92,7 @@ export class CounterBinding {
|
|
|
94
92
|
export class Gauge extends Metric {
|
|
95
93
|
record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
|
96
94
|
ctx.gauges.push({
|
|
97
|
-
metadata:
|
|
95
|
+
metadata: ctx.getMetaData(this.getShortDescriptor(), labels),
|
|
98
96
|
metricValue: toMetricValue(value),
|
|
99
97
|
runtimeInfo: undefined,
|
|
100
98
|
})
|
|
@@ -9,8 +9,10 @@ type IndexConfigure = {
|
|
|
9
9
|
endSlot?: Long
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void
|
|
13
|
+
|
|
12
14
|
export class SolanaBaseProcessor {
|
|
13
|
-
public
|
|
15
|
+
public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()
|
|
14
16
|
address: string
|
|
15
17
|
endpoint: string
|
|
16
18
|
contractName: string
|
|
@@ -44,39 +46,40 @@ export class SolanaBaseProcessor {
|
|
|
44
46
|
return this
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
public onInstruction(instructionName: string, handler:
|
|
49
|
+
public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {
|
|
48
50
|
if (!this.isBind()) {
|
|
49
51
|
throw new Error("Processor doesn't bind to an address")
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
this.
|
|
54
|
+
this.instructionHandlerMap.set(instructionName, handler)
|
|
53
55
|
|
|
54
56
|
return this
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
public
|
|
58
|
-
const ctx = new SolanaContext(this.address, slot)
|
|
59
|
-
let parsedInstruction: Instruction | null = null
|
|
60
|
-
|
|
59
|
+
public getParsedInstruction(ins: string | { type: string; info: any }): Instruction | null {
|
|
61
60
|
if (ins) {
|
|
62
61
|
if ((ins as { type: string; info: any }).info) {
|
|
63
|
-
|
|
64
|
-
return null
|
|
65
|
-
}
|
|
66
|
-
parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })
|
|
67
|
-
} else {
|
|
68
|
-
if (this.decodeInstruction == null) {
|
|
69
|
-
return null
|
|
70
|
-
}
|
|
71
|
-
parsedInstruction = this.decodeInstruction(ins as string)
|
|
62
|
+
return this.fromParsedInstruction ? this.fromParsedInstruction(ins as { type: string; info: any }) : null
|
|
72
63
|
}
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
if (handler) {
|
|
76
|
-
handler(parsedInstruction, ctx)
|
|
77
|
-
}
|
|
64
|
+
if (this.decodeInstruction != null) {
|
|
65
|
+
return this.decodeInstruction(ins as string)
|
|
78
66
|
}
|
|
79
67
|
}
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {
|
|
72
|
+
return this.instructionHandlerMap.get(parsedInstruction.name)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public handleInstruction(
|
|
76
|
+
parsedInstruction: Instruction,
|
|
77
|
+
accounts: string[],
|
|
78
|
+
handler: SolanaInstructionHandler,
|
|
79
|
+
slot: Long
|
|
80
|
+
): ProcessResult {
|
|
81
|
+
const ctx = new SolanaContext(this.contractName, this.address, slot)
|
|
82
|
+
handler(parsedInstruction, ctx, accounts)
|
|
80
83
|
return {
|
|
81
84
|
gauges: ctx.gauges,
|
|
82
85
|
counters: ctx.counters,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SuiBindOptions } from './bind-options'
|
|
2
1
|
import { SuiContext } from './context'
|
|
3
2
|
import { ProcessResult } from '../gen'
|
|
4
3
|
import Long from 'long'
|
|
@@ -8,35 +7,29 @@ type IndexConfigure = {
|
|
|
8
7
|
endSeqNumber?: Long
|
|
9
8
|
}
|
|
10
9
|
|
|
10
|
+
export class SuiBindOptions {
|
|
11
|
+
address: string
|
|
12
|
+
// network?: Networkish = 1
|
|
13
|
+
// name?: string
|
|
14
|
+
startBlock?: Long | number
|
|
15
|
+
// endBlock?: Long | number
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
export class SuiBaseProcessor {
|
|
12
19
|
public transactionHanlder: (transaction: any, ctx: SuiContext) => void
|
|
13
20
|
address: string
|
|
14
21
|
config: IndexConfigure = { startSeqNumber: new Long(0) }
|
|
15
22
|
|
|
16
|
-
constructor(options: SuiBindOptions) {
|
|
17
|
-
if (options) {
|
|
18
|
-
this.bind(options)
|
|
19
|
-
}
|
|
20
|
-
global.PROCESSOR_STATE.suiProcessors.push(this)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
bind(options: SuiBindOptions) {
|
|
23
|
+
constructor(name: string, options: SuiBindOptions) {
|
|
24
24
|
this.address = options.address
|
|
25
25
|
if (options.startBlock) {
|
|
26
26
|
this.startSlot(options.startBlock)
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
this.endBlock(options.endBlock)
|
|
30
|
-
}
|
|
28
|
+
global.PROCESSOR_STATE.suiProcessors.push(this)
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {
|
|
34
|
-
if (!this.isBind()) {
|
|
35
|
-
throw new Error("Processor doesn't bind to an address")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
32
|
this.transactionHanlder = handler
|
|
39
|
-
|
|
40
33
|
return this
|
|
41
34
|
}
|
|
42
35
|
|
|
@@ -53,10 +46,6 @@ export class SuiBaseProcessor {
|
|
|
53
46
|
}
|
|
54
47
|
}
|
|
55
48
|
|
|
56
|
-
public isBind() {
|
|
57
|
-
return this.address !== null
|
|
58
|
-
}
|
|
59
|
-
|
|
60
49
|
public startSlot(startSlot: Long | number) {
|
|
61
50
|
if (typeof startSlot === 'number') {
|
|
62
51
|
startSlot = Long.fromNumber(startSlot)
|
package/src/error.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Transform error in more readable format
|
|
2
|
-
import {
|
|
2
|
+
import { ContractContext } from './core/context'
|
|
3
3
|
import { errors } from 'ethers'
|
|
4
4
|
|
|
5
5
|
export class EthersError extends Error {
|
|
@@ -15,7 +15,7 @@ export class EthersError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function transformEtherError(e: Error, ctx:
|
|
18
|
+
export function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined): Error {
|
|
19
19
|
let msg = ''
|
|
20
20
|
// @ts-ignore expected error fields
|
|
21
21
|
if (e.code === errors.CALL_EXCEPTION) {
|