@sentio/sdk 1.8.0 → 1.8.2
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/base-processor.d.ts +10 -3
- package/lib/base-processor.js +31 -1
- package/lib/base-processor.js.map +1 -1
- package/lib/context.d.ts +15 -11
- package/lib/context.js +21 -13
- package/lib/context.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +56 -21
- package/lib/gen/processor/protos/processor.js +269 -51
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/meter.d.ts +4 -4
- package/lib/meter.js +11 -0
- package/lib/meter.js.map +1 -1
- package/lib/service.d.ts +4 -2
- package/lib/service.js +39 -4
- package/lib/service.js.map +1 -1
- package/lib/solana-processor.d.ts +2 -2
- package/lib/solana-processor.js +1 -0
- package/lib/solana-processor.js.map +1 -1
- package/lib/test/erc20.test.js +9 -11
- package/lib/test/erc20.test.js.map +1 -1
- package/lib/test/metric-utils.d.ts +3 -3
- package/lib/test/metric-utils.js.map +1 -1
- package/lib/trace.d.ts +35 -0
- package/lib/trace.js +22 -0
- package/lib/trace.js.map +1 -0
- package/package.json +1 -1
- package/src/base-processor.ts +40 -3
- package/src/context.ts +23 -14
- package/src/gen/processor/protos/processor.ts +330 -70
- package/src/meter.ts +19 -8
- package/src/service.ts +59 -15
- package/src/solana-processor.ts +3 -2
- package/src/test/erc20.test.ts +9 -11
- package/src/test/metric-utils.ts +3 -3
- package/src/trace.ts +64 -0
package/src/base-processor.ts
CHANGED
|
@@ -5,21 +5,29 @@ import { BaseContract, EventFilter } from '@ethersproject/contracts'
|
|
|
5
5
|
import Long from 'long'
|
|
6
6
|
|
|
7
7
|
import { BoundContractView, Context, ContractView } from './context'
|
|
8
|
-
import {
|
|
8
|
+
import { ProcessResult } from './gen/processor/protos/processor'
|
|
9
9
|
import { BindInternalOptions, BindOptions } from './bind-options'
|
|
10
10
|
import { PromiseOrVoid } from './promise-or-void'
|
|
11
|
+
import { Trace } from './trace'
|
|
12
|
+
import { utils } from 'ethers'
|
|
11
13
|
|
|
12
14
|
export class EventsHandler {
|
|
13
15
|
filters: EventFilter[]
|
|
14
|
-
handler: (event: Log) => Promise<
|
|
16
|
+
handler: (event: Log) => Promise<ProcessResult>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class TraceHandler {
|
|
20
|
+
signature: string
|
|
21
|
+
handler: (trace: Trace) => Promise<ProcessResult>
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
export abstract class BaseProcessor<
|
|
18
25
|
TContract extends BaseContract,
|
|
19
26
|
TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>
|
|
20
27
|
> {
|
|
21
|
-
blockHandlers: ((block: Block) => Promise<
|
|
28
|
+
blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []
|
|
22
29
|
eventHandlers: EventsHandler[] = []
|
|
30
|
+
traceHandlers: TraceHandler[] = []
|
|
23
31
|
|
|
24
32
|
name: string
|
|
25
33
|
config: BindInternalOptions
|
|
@@ -88,11 +96,13 @@ export abstract class BaseProcessor<
|
|
|
88
96
|
return {
|
|
89
97
|
gauges: ctx.gauges,
|
|
90
98
|
counters: ctx.counters,
|
|
99
|
+
logs: [],
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
return {
|
|
94
103
|
gauges: [],
|
|
95
104
|
counters: [],
|
|
105
|
+
logs: [],
|
|
96
106
|
}
|
|
97
107
|
},
|
|
98
108
|
})
|
|
@@ -109,6 +119,7 @@ export abstract class BaseProcessor<
|
|
|
109
119
|
return {
|
|
110
120
|
gauges: ctx.gauges,
|
|
111
121
|
counters: ctx.counters,
|
|
122
|
+
logs: [],
|
|
112
123
|
}
|
|
113
124
|
})
|
|
114
125
|
return this
|
|
@@ -125,4 +136,30 @@ export abstract class BaseProcessor<
|
|
|
125
136
|
return handler(log, ctx)
|
|
126
137
|
}, _filters)
|
|
127
138
|
}
|
|
139
|
+
|
|
140
|
+
public onTrace(
|
|
141
|
+
signature: string,
|
|
142
|
+
handler: (trace: Trace, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid
|
|
143
|
+
) {
|
|
144
|
+
const chainId = this.getChainId()
|
|
145
|
+
const contractView = this.CreateBoundContractView()
|
|
146
|
+
|
|
147
|
+
this.traceHandlers.push({
|
|
148
|
+
signature,
|
|
149
|
+
handler: async function (trace: Trace) {
|
|
150
|
+
const contractInterface = contractView.rawContract.interface
|
|
151
|
+
const fragment = contractInterface.getFunction(signature)
|
|
152
|
+
trace.args = contractInterface._abiCoder.decode(fragment.inputs, utils.hexDataSlice(trace.action.input, 4))
|
|
153
|
+
|
|
154
|
+
const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, undefined, trace)
|
|
155
|
+
await handler(trace, ctx)
|
|
156
|
+
return {
|
|
157
|
+
gauges: ctx.gauges,
|
|
158
|
+
counters: ctx.counters,
|
|
159
|
+
logs: [],
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
return this
|
|
164
|
+
}
|
|
128
165
|
}
|
package/src/context.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import { CounterResult, GaugeResult } from './gen/processor/protos/processor'
|
|
1
|
+
import { CounterResult, GaugeResult, LogResult } from './gen/processor/protos/processor'
|
|
2
2
|
import { BaseContract, EventFilter } from 'ethers'
|
|
3
3
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
4
4
|
import { Meter } from './meter'
|
|
5
5
|
import Long from 'long'
|
|
6
|
+
import { Trace } from './trace'
|
|
6
7
|
|
|
7
|
-
export class
|
|
8
|
+
export class BaseContext {
|
|
9
|
+
gauges: GaugeResult[] = []
|
|
10
|
+
counters: CounterResult[] = []
|
|
11
|
+
logs: LogResult[] = []
|
|
12
|
+
meter: Meter
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
this.meter = new Meter(this)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class EthContext extends BaseContext {
|
|
8
20
|
chainId: number
|
|
9
21
|
log?: Log
|
|
10
22
|
block?: Block
|
|
23
|
+
trace?: Trace
|
|
11
24
|
blockNumber: Long
|
|
12
|
-
gauges: GaugeResult[] = []
|
|
13
|
-
counters: CounterResult[] = []
|
|
14
|
-
meter: Meter
|
|
15
25
|
|
|
16
|
-
constructor(chainId: number, block?: Block, log?: Log) {
|
|
26
|
+
constructor(chainId: number, block?: Block, log?: Log, trace?: Trace) {
|
|
27
|
+
super()
|
|
17
28
|
this.chainId = chainId
|
|
18
29
|
this.log = log
|
|
19
30
|
this.block = block
|
|
@@ -22,7 +33,6 @@ export class EthContext {
|
|
|
22
33
|
} else if (block) {
|
|
23
34
|
this.blockNumber = Long.fromNumber(block.number)
|
|
24
35
|
}
|
|
25
|
-
this.meter = new Meter(this)
|
|
26
36
|
}
|
|
27
37
|
}
|
|
28
38
|
|
|
@@ -31,11 +41,13 @@ export class Context<
|
|
|
31
41
|
TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>
|
|
32
42
|
> extends EthContext {
|
|
33
43
|
contract: TContractBoundView
|
|
44
|
+
address: string
|
|
34
45
|
|
|
35
|
-
constructor(view: TContractBoundView, chainId: number, block?: Block, log?: Log) {
|
|
36
|
-
super(chainId, block, log)
|
|
46
|
+
constructor(view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace) {
|
|
47
|
+
super(chainId, block, log, trace)
|
|
37
48
|
view.context = this
|
|
38
49
|
this.contract = view
|
|
50
|
+
this.address = view.rawContract.address
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
53
|
|
|
@@ -79,14 +91,11 @@ export class BoundContractView<TContract extends BaseContract, TContractView ext
|
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
|
|
82
|
-
export class SolanaContext {
|
|
83
|
-
gauges: GaugeResult[] = []
|
|
84
|
-
counters: CounterResult[] = []
|
|
85
|
-
meter: Meter
|
|
86
|
-
|
|
94
|
+
export class SolanaContext extends BaseContext {
|
|
87
95
|
address: string
|
|
88
96
|
|
|
89
97
|
constructor(address: string) {
|
|
98
|
+
super()
|
|
90
99
|
this.meter = new Meter(this)
|
|
91
100
|
this.address = address
|
|
92
101
|
}
|