@sentio/sdk 2.44.0-rc.1 → 2.44.0-rc.10
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/btc/btc-plugin.d.ts +3 -1
- package/lib/btc/btc-plugin.d.ts.map +1 -1
- package/lib/btc/btc-plugin.js +41 -3
- package/lib/btc/btc-plugin.js.map +1 -1
- package/lib/btc/btc-processor.d.ts +7 -2
- package/lib/btc/btc-processor.d.ts.map +1 -1
- package/lib/btc/btc-processor.js +40 -1
- package/lib/btc/btc-processor.js.map +1 -1
- package/lib/btc/types.d.ts +29 -10
- package/lib/btc/types.d.ts.map +1 -1
- package/lib/btc/types.js +29 -0
- package/lib/btc/types.js.map +1 -1
- package/lib/fuel/asset-processor.d.ts.map +1 -1
- package/lib/fuel/asset-processor.js +7 -1
- package/lib/fuel/asset-processor.js.map +1 -1
- package/lib/fuel/base-processor.d.ts.map +1 -1
- package/lib/fuel/base-processor.js +2 -3
- package/lib/fuel/base-processor.js.map +1 -1
- package/lib/fuel/codegen/codegen.js +50 -9
- package/lib/fuel/codegen/codegen.js.map +1 -1
- package/lib/fuel/context.d.ts +6 -6
- package/lib/fuel/context.d.ts.map +1 -1
- package/lib/fuel/context.js.map +1 -1
- package/lib/fuel/fuel-processor-template.d.ts +42 -0
- package/lib/fuel/fuel-processor-template.d.ts.map +1 -0
- package/lib/fuel/fuel-processor-template.js +109 -0
- package/lib/fuel/fuel-processor-template.js.map +1 -0
- package/lib/fuel/fuel-processor.d.ts +5 -2
- package/lib/fuel/fuel-processor.d.ts.map +1 -1
- package/lib/fuel/fuel-processor.js +26 -1
- package/lib/fuel/fuel-processor.js.map +1 -1
- package/lib/fuel/global-processor.d.ts.map +1 -1
- package/lib/fuel/global-processor.js +7 -1
- package/lib/fuel/global-processor.js.map +1 -1
- package/lib/fuel/index.d.ts +1 -0
- package/lib/fuel/index.d.ts.map +1 -1
- package/lib/fuel/index.js +1 -0
- package/lib/fuel/index.js.map +1 -1
- package/lib/fuel/types.d.ts +2 -2
- package/lib/fuel/types.d.ts.map +1 -1
- package/lib/fuel/types.js +2 -2
- package/lib/fuel/types.js.map +1 -1
- package/package.json +3 -3
- package/src/btc/btc-plugin.ts +50 -3
- package/src/btc/btc-processor.ts +79 -2
- package/src/btc/types.ts +51 -10
- package/src/fuel/asset-processor.ts +8 -1
- package/src/fuel/base-processor.ts +3 -3
- package/src/fuel/codegen/codegen.ts +55 -11
- package/src/fuel/context.ts +4 -4
- package/src/fuel/fuel-processor-template.ts +161 -0
- package/src/fuel/fuel-processor.ts +32 -3
- package/src/fuel/global-processor.ts +8 -2
- package/src/fuel/index.ts +1 -0
- package/src/fuel/types.ts +2 -2
package/src/btc/types.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
|
2
|
-
import { RecordMetaData } from '@sentio/protos'
|
2
|
+
import { Data_BTCBlock, HandleInterval, ProcessResult, RecordMetaData } from '@sentio/protos'
|
3
3
|
import { ChainId } from '@sentio/chain'
|
4
4
|
|
5
5
|
export type Transaction = {
|
@@ -44,21 +44,22 @@ export type Vout = {
|
|
44
44
|
}
|
45
45
|
}
|
46
46
|
|
47
|
-
export type
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
export type BTCBlock = {
|
48
|
+
hash: string
|
49
|
+
confirmations: number
|
50
|
+
strippedsize: number
|
51
51
|
size: number
|
52
|
-
stripped_size: number
|
53
52
|
weight: number
|
53
|
+
height: number
|
54
54
|
version: number
|
55
|
-
|
55
|
+
merkleroot: string
|
56
|
+
tx?: Transaction[]
|
57
|
+
time: number
|
56
58
|
nonce: number
|
57
59
|
bits: string
|
58
60
|
difficulty: number
|
59
|
-
|
60
|
-
|
61
|
-
transaction_count: number
|
61
|
+
previousblockhash: string
|
62
|
+
nextblockhash: string
|
62
63
|
}
|
63
64
|
|
64
65
|
export class BTCContext extends BaseContext {
|
@@ -89,3 +90,43 @@ export class BTCContext extends BaseContext {
|
|
89
90
|
return this.chainId as ChainId
|
90
91
|
}
|
91
92
|
}
|
93
|
+
|
94
|
+
export class BTCBlockContext extends BaseContext {
|
95
|
+
constructor(
|
96
|
+
readonly chainId: string,
|
97
|
+
readonly name: string,
|
98
|
+
readonly block: BTCBlock,
|
99
|
+
readonly address?: string
|
100
|
+
) {
|
101
|
+
super({})
|
102
|
+
}
|
103
|
+
|
104
|
+
protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
105
|
+
return {
|
106
|
+
address: this.address ?? '',
|
107
|
+
contractName: this.name,
|
108
|
+
blockNumber: BigInt(this.block.height ?? 0),
|
109
|
+
transactionIndex: 0,
|
110
|
+
transactionHash: '',
|
111
|
+
chainId: this.getChainId(),
|
112
|
+
name: name,
|
113
|
+
logIndex: 0,
|
114
|
+
labels: normalizeLabels(labels)
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
getChainId(): ChainId {
|
119
|
+
return this.chainId as ChainId
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
export type BlockHandler = {
|
124
|
+
blockInterval?: HandleInterval
|
125
|
+
timeIntervalInMinutes?: HandleInterval
|
126
|
+
handler: (block: Data_BTCBlock) => Promise<ProcessResult>
|
127
|
+
fetchConfig?: BTCOnIntervalFetchConfig
|
128
|
+
}
|
129
|
+
|
130
|
+
export type BTCOnIntervalFetchConfig = {
|
131
|
+
getTransactions: boolean
|
132
|
+
}
|
@@ -4,6 +4,7 @@ import { FuelNetwork, getRpcEndpoint } from './network.js'
|
|
4
4
|
import { FuelContext } from './context.js'
|
5
5
|
import { decodeFuelTransaction } from './transaction.js'
|
6
6
|
import { Provider, InputType, OutputType } from 'fuels'
|
7
|
+
import { getOptionsSignature } from './fuel-processor.js'
|
7
8
|
|
8
9
|
export class FuelAssetProcessor implements FuelBaseProcessor<FuelAssetProcessorConfig> {
|
9
10
|
callHandlers: CallHandler<Data_FuelCall>[] = []
|
@@ -12,7 +13,13 @@ export class FuelAssetProcessor implements FuelBaseProcessor<FuelAssetProcessorC
|
|
12
13
|
|
13
14
|
static bind(config: FuelAssetProcessorConfig): FuelAssetProcessor {
|
14
15
|
const processor = new FuelAssetProcessor(config)
|
15
|
-
|
16
|
+
const sig =
|
17
|
+
'assets_' +
|
18
|
+
getOptionsSignature({
|
19
|
+
...config,
|
20
|
+
address: '*'
|
21
|
+
})
|
22
|
+
FuelProcessorState.INSTANCE.getOrSetValue(sig, processor)
|
16
23
|
return processor
|
17
24
|
}
|
18
25
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { FuelProcessor, FuelProcessorConfig } from './fuel-processor.js'
|
1
|
+
import { addFuelProcessor, FuelProcessor, FuelProcessorConfig } from './fuel-processor.js'
|
2
2
|
import { Contract, JsonAbi } from 'fuels'
|
3
3
|
// import { FuelCall } from './context.js'
|
4
4
|
import { FuelChainId } from '@sentio/chain'
|
5
|
-
import { FuelLog
|
5
|
+
import { FuelLog } from './types.js'
|
6
6
|
|
7
7
|
export abstract class FuelAbstractProcessor<TContract extends Contract> extends FuelProcessor<TContract> {
|
8
8
|
protected constructor(abi: JsonAbi, config?: Omit<FuelProcessorConfig, 'abi'>) {
|
@@ -16,7 +16,7 @@ export abstract class FuelAbstractProcessor<TContract extends Contract> extends
|
|
16
16
|
...config,
|
17
17
|
abi
|
18
18
|
})
|
19
|
-
|
19
|
+
addFuelProcessor(config, this)
|
20
20
|
}
|
21
21
|
}
|
22
22
|
|
@@ -115,7 +115,7 @@ async function codegenInternal(abisDir: string, outDir: string): Promise<number>
|
|
115
115
|
/* tslint:disable */
|
116
116
|
/* eslint-disable */
|
117
117
|
|
118
|
-
import { FuelAbstractProcessor, FuelContractContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall, FuelLog} from '@sentio/sdk/fuel'
|
118
|
+
import { FuelAbstractProcessor, FuelContractContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall, FuelLog, addFuelProcessor, getFuelProcessor, FuelBaseProcessorTemplate } from '@sentio/sdk/fuel'
|
119
119
|
import {${abi.commonTypesInUse.join(',')}} from './common.js'
|
120
120
|
import {${importedTypes.join(',')}, ${abi.capitalizedName}} from './${abi.capitalizedName}.js'
|
121
121
|
|
@@ -144,12 +144,23 @@ ${
|
|
144
144
|
}
|
145
145
|
}
|
146
146
|
|
147
|
+
type LogIdFilter<T> = T | T[]
|
148
|
+
${getLogConstants(logByTypes)}
|
149
|
+
|
147
150
|
export class ${name}Processor extends FuelAbstractProcessor<${name}> {
|
148
|
-
static bind(
|
149
|
-
|
150
|
-
name
|
151
|
-
|
152
|
-
}
|
151
|
+
static bind(options: Omit<FuelProcessorConfig, 'abi'>) {
|
152
|
+
if (!options.name) {
|
153
|
+
options.name = "${name}"
|
154
|
+
}
|
155
|
+
let processor = getFuelProcessor(options) as ${name}Processor
|
156
|
+
if (!processor) {
|
157
|
+
processor = new ${name}Processor(${abi.capitalizedName}.abi, {
|
158
|
+
name: '${name}',
|
159
|
+
...options,
|
160
|
+
})
|
161
|
+
addFuelProcessor(options, processor)
|
162
|
+
}
|
163
|
+
return processor
|
153
164
|
}
|
154
165
|
|
155
166
|
${
|
@@ -158,11 +169,22 @@ ${
|
|
158
169
|
abi.functions.map((f) => genOnCallFunction(name, f)).join('\n') */
|
159
170
|
}
|
160
171
|
|
161
|
-
${Object.entries(logByTypes)
|
162
|
-
|
163
|
-
|
172
|
+
${Object.entries(logByTypes)
|
173
|
+
.map((e) => genOnLogFunction(name, e))
|
174
|
+
.join('\n')}
|
175
|
+
|
176
|
+
}
|
177
|
+
|
178
|
+
export class ${name}ProcessorTemplate extends FuelBaseProcessorTemplate<${name}> {
|
179
|
+
bindInternal(options: Omit<FuelProcessorConfig, 'abi'>) {
|
180
|
+
return ${name}Processor.bind(options)
|
181
|
+
}
|
164
182
|
|
183
|
+
${Object.entries(logByTypes)
|
184
|
+
.map((e) => genOnLogFunction(name, e))
|
185
|
+
.join('\n')}
|
165
186
|
}
|
187
|
+
|
166
188
|
`
|
167
189
|
writeFileSync(filePath, content)
|
168
190
|
count++
|
@@ -215,11 +237,33 @@ function collectImportedTypes(types: any[]): string[] {
|
|
215
237
|
return Array.from(ret)
|
216
238
|
}
|
217
239
|
|
240
|
+
function getLogConstants(logByTypes: Record<string, string[]>) {
|
241
|
+
return Object.entries(logByTypes)
|
242
|
+
.map(([t, ids]) => {
|
243
|
+
const name = getTypeName(t)
|
244
|
+
if (ids.length == 1) {
|
245
|
+
return `const Log${name}Id = "${ids[0]}"`
|
246
|
+
}
|
247
|
+
return ids.map((id, idx) => `const Log${name}Id${idx} = "${id}"`).join('\n')
|
248
|
+
})
|
249
|
+
.join('\n')
|
250
|
+
}
|
251
|
+
|
218
252
|
function genOnLogFunction(contractName: string, [type, ids]: [string, string[]]) {
|
219
253
|
const name = getTypeName(type)
|
254
|
+
|
255
|
+
if (ids.length == 1) {
|
256
|
+
return `
|
257
|
+
onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContractContext<${contractName}>) => void | Promise<void>) {
|
258
|
+
return super.onLog<${type}>([Log${name}Id], (log, ctx) => handler(log, ctx))
|
259
|
+
}`
|
260
|
+
}
|
261
|
+
const logIdFilterValues = ids.map((_, idx) => `Log${name}Id${idx}`)
|
262
|
+
|
220
263
|
return `
|
221
|
-
onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContractContext<${contractName}>) => void | Promise<void>,
|
222
|
-
|
264
|
+
onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContractContext<${contractName}>) => void | Promise<void>,
|
265
|
+
logIdFilter?: LogIdFilter<${logIdFilterValues.map((d) => `typeof ${d}`).join(' | ')}> ) {
|
266
|
+
return super.onLog<${type}>(logIdFilter ?? [${logIdFilterValues.join(', ')}], (log, ctx) => handler(log, ctx))
|
223
267
|
}`
|
224
268
|
}
|
225
269
|
|
package/src/fuel/context.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
|
2
|
-
import {
|
2
|
+
import { FuelChainId } from '@sentio/chain'
|
3
3
|
import { RecordMetaData } from '@sentio/protos'
|
4
4
|
import type { CallResult, Contract } from 'fuels'
|
5
5
|
import { InvocationScopeLike } from 'fuels'
|
@@ -20,7 +20,7 @@ export class FuelCall {
|
|
20
20
|
export class FuelContext extends BaseContext {
|
21
21
|
private logIndex: number = -1
|
22
22
|
constructor(
|
23
|
-
readonly chainId:
|
23
|
+
readonly chainId: FuelChainId,
|
24
24
|
readonly contractAddress: string,
|
25
25
|
readonly contractName: string,
|
26
26
|
readonly timestamp: Date,
|
@@ -30,7 +30,7 @@ export class FuelContext extends BaseContext {
|
|
30
30
|
super({})
|
31
31
|
}
|
32
32
|
|
33
|
-
getChainId():
|
33
|
+
getChainId(): FuelChainId {
|
34
34
|
return this.chainId
|
35
35
|
}
|
36
36
|
|
@@ -55,7 +55,7 @@ export class FuelContext extends BaseContext {
|
|
55
55
|
|
56
56
|
export class FuelContractContext<TContract extends Contract> extends FuelContext {
|
57
57
|
constructor(
|
58
|
-
readonly chainId:
|
58
|
+
readonly chainId: FuelChainId,
|
59
59
|
readonly contract: TContract,
|
60
60
|
readonly contractAddress: string,
|
61
61
|
readonly contractName: string,
|
@@ -0,0 +1,161 @@
|
|
1
|
+
import { FuelContext, FuelContractContext } from './context.js'
|
2
|
+
import { HandleInterval, TemplateInstance } from '@sentio/protos'
|
3
|
+
import { PromiseOrVoid } from '../core/promises.js'
|
4
|
+
import { ListStateStorage } from '@sentio/runtime'
|
5
|
+
import { TemplateInstanceState } from '../core/template.js'
|
6
|
+
import { Contract } from 'fuels'
|
7
|
+
import { FuelBlock, FuelLog, FuelTransaction } from './types.js'
|
8
|
+
import { DEFAULT_FUEL_FETCH_CONFIG, FuelFetchConfig } from './transaction.js'
|
9
|
+
import { FuelProcessor, FuelProcessorConfig, getOptionsSignature } from './fuel-processor.js'
|
10
|
+
|
11
|
+
export class FuelProcessorTemplateProcessorState extends ListStateStorage<FuelBaseProcessorTemplate<Contract>> {
|
12
|
+
static INSTANCE = new FuelProcessorTemplateProcessorState()
|
13
|
+
}
|
14
|
+
|
15
|
+
export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
|
16
|
+
id: number
|
17
|
+
binds = new Set<string>()
|
18
|
+
blockHandlers: {
|
19
|
+
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
20
|
+
blockInterval?: HandleInterval
|
21
|
+
timeIntervalInMinutes?: HandleInterval
|
22
|
+
// fetchConfig?: FuelFetchConfig
|
23
|
+
}[] = []
|
24
|
+
|
25
|
+
logHandlers: {
|
26
|
+
logIdFilter: string | string[]
|
27
|
+
handler: (logs: FuelLog<any>, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
28
|
+
// fetchConfig?: FuelFetchConfig
|
29
|
+
}[] = []
|
30
|
+
|
31
|
+
transactionHandlers: {
|
32
|
+
handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
33
|
+
fetchConfig: FuelFetchConfig
|
34
|
+
}[] = []
|
35
|
+
|
36
|
+
constructor() {
|
37
|
+
this.id = FuelProcessorTemplateProcessorState.INSTANCE.getValues().length
|
38
|
+
FuelProcessorTemplateProcessorState.INSTANCE.addValue(this)
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Bind template using {@param options}, using {@param ctx}'s network value if not provided in the option
|
43
|
+
* @param options
|
44
|
+
* @param ctx
|
45
|
+
*/
|
46
|
+
public bind(options: Omit<Omit<FuelProcessorConfig, 'chainId'>, 'abi'>, ctx: FuelContext): void {
|
47
|
+
const sig = getOptionsSignature({
|
48
|
+
address: options.address,
|
49
|
+
chainId: ctx.chainId
|
50
|
+
})
|
51
|
+
if (this.binds.has(sig)) {
|
52
|
+
console.log(`Same address can be bind to one template only once, ignore duplicate bind: ${sig}`)
|
53
|
+
return
|
54
|
+
}
|
55
|
+
this.binds.add(sig)
|
56
|
+
|
57
|
+
const processor = this.bindInternal({ ...options, chainId: ctx.chainId })
|
58
|
+
|
59
|
+
for (const eh of this.logHandlers) {
|
60
|
+
processor.onLog(eh.logIdFilter, eh.handler)
|
61
|
+
}
|
62
|
+
for (const bh of this.blockHandlers) {
|
63
|
+
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)
|
64
|
+
}
|
65
|
+
for (const th of this.transactionHandlers) {
|
66
|
+
processor.onTransaction(th.handler)
|
67
|
+
}
|
68
|
+
|
69
|
+
const instance: TemplateInstance = {
|
70
|
+
templateId: this.id,
|
71
|
+
contract: {
|
72
|
+
address: options.address,
|
73
|
+
name: options.name || '',
|
74
|
+
chainId: ctx.chainId,
|
75
|
+
abi: ''
|
76
|
+
},
|
77
|
+
startBlock: BigInt(options.startBlock || 0),
|
78
|
+
endBlock: BigInt(options.endBlock || 0),
|
79
|
+
baseLabels: {}
|
80
|
+
// baseLabels: options.baseLabels
|
81
|
+
}
|
82
|
+
TemplateInstanceState.INSTANCE.addValue(instance)
|
83
|
+
ctx.update({
|
84
|
+
states: {
|
85
|
+
configUpdated: true
|
86
|
+
}
|
87
|
+
})
|
88
|
+
}
|
89
|
+
|
90
|
+
protected onLog<T>(
|
91
|
+
logIdFilter: string | string[],
|
92
|
+
handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
93
|
+
// fetchConfig?: Partial<FuelFetchConfig>
|
94
|
+
) {
|
95
|
+
this.logHandlers.push({
|
96
|
+
logIdFilter,
|
97
|
+
handler
|
98
|
+
// fetchConfig: { ...fetchConfig}
|
99
|
+
})
|
100
|
+
return this
|
101
|
+
}
|
102
|
+
|
103
|
+
public onBlockInterval(
|
104
|
+
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
105
|
+
blockInterval = 1000,
|
106
|
+
backfillBlockInterval = 4000
|
107
|
+
// fetchConfig?: Partial<FuelFetchConfig>
|
108
|
+
) {
|
109
|
+
return this.onInterval(
|
110
|
+
handler,
|
111
|
+
undefined,
|
112
|
+
{
|
113
|
+
recentInterval: blockInterval,
|
114
|
+
backfillInterval: backfillBlockInterval
|
115
|
+
}
|
116
|
+
// fetchConfig
|
117
|
+
)
|
118
|
+
}
|
119
|
+
|
120
|
+
public onTimeInterval(
|
121
|
+
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
122
|
+
timeIntervalInMinutes = 60,
|
123
|
+
backfillBlockInterval = 240
|
124
|
+
// fetchConfig?: Partial<FuelFetchConfig>
|
125
|
+
) {
|
126
|
+
return this.onInterval(
|
127
|
+
handler,
|
128
|
+
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },
|
129
|
+
undefined
|
130
|
+
// fetchConfig
|
131
|
+
)
|
132
|
+
}
|
133
|
+
|
134
|
+
public onInterval(
|
135
|
+
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
136
|
+
timeInterval: HandleInterval | undefined,
|
137
|
+
blockInterval: HandleInterval | undefined
|
138
|
+
// fetchConfig?: FuelFetchConfig
|
139
|
+
) {
|
140
|
+
this.blockHandlers.push({
|
141
|
+
handler,
|
142
|
+
timeIntervalInMinutes: timeInterval,
|
143
|
+
blockInterval
|
144
|
+
// fetchConfig: { ...fetchConfig }
|
145
|
+
})
|
146
|
+
return this
|
147
|
+
}
|
148
|
+
|
149
|
+
protected onTransaction(
|
150
|
+
handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
151
|
+
config: FuelFetchConfig = DEFAULT_FUEL_FETCH_CONFIG
|
152
|
+
) {
|
153
|
+
this.transactionHandlers.push({
|
154
|
+
handler,
|
155
|
+
fetchConfig: config
|
156
|
+
})
|
157
|
+
return this
|
158
|
+
}
|
159
|
+
|
160
|
+
protected abstract bindInternal(options: Omit<FuelProcessorConfig, 'abi'>): FuelProcessor<TContract>
|
161
|
+
}
|
@@ -25,7 +25,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
25
25
|
|
26
26
|
static bind(config: FuelProcessorConfig): FuelProcessor<any> {
|
27
27
|
const processor = new FuelProcessor(config)
|
28
|
-
|
28
|
+
addFuelProcessor(config, processor)
|
29
29
|
return processor
|
30
30
|
}
|
31
31
|
|
@@ -49,7 +49,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
49
49
|
}
|
50
50
|
|
51
51
|
public onTransaction(
|
52
|
-
handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) =>
|
52
|
+
handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
53
53
|
config: FuelFetchConfig = DEFAULT_FUEL_FETCH_CONFIG
|
54
54
|
) {
|
55
55
|
const callHandler = {
|
@@ -161,7 +161,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
161
161
|
|
162
162
|
public onLog<T>(
|
163
163
|
logIdFilter: string | string[],
|
164
|
-
handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) =>
|
164
|
+
handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
165
165
|
) {
|
166
166
|
const logIds = new Set(Array.isArray(logIdFilter) ? logIdFilter : [logIdFilter])
|
167
167
|
|
@@ -308,3 +308,32 @@ export type FuelProcessorConfig = {
|
|
308
308
|
endBlock?: bigint
|
309
309
|
abi: JsonAbi
|
310
310
|
}
|
311
|
+
|
312
|
+
export function getOptionsSignature(opts: Omit<FuelProcessorConfig, 'abi'>): string {
|
313
|
+
const sig = [opts.address]
|
314
|
+
if (opts.chainId) {
|
315
|
+
sig.push(opts.chainId)
|
316
|
+
}
|
317
|
+
if (opts.name) {
|
318
|
+
sig.push(opts.name)
|
319
|
+
}
|
320
|
+
if (opts.startBlock) {
|
321
|
+
sig.push(opts.startBlock.toString())
|
322
|
+
}
|
323
|
+
if (opts.endBlock) {
|
324
|
+
sig.push(opts.endBlock.toString())
|
325
|
+
}
|
326
|
+
return sig.join('_')
|
327
|
+
}
|
328
|
+
|
329
|
+
// Dedup processor that bind multiple times
|
330
|
+
export function getFuelProcessor(opts: Omit<FuelProcessorConfig, 'abi'>) {
|
331
|
+
const sig = getOptionsSignature(opts)
|
332
|
+
return FuelProcessorState.INSTANCE.getValue(sig)
|
333
|
+
}
|
334
|
+
|
335
|
+
export function addFuelProcessor(opts: Omit<FuelProcessorConfig, 'abi'>, processor: FuelBaseProcessor<any>) {
|
336
|
+
const sig = getOptionsSignature(opts)
|
337
|
+
|
338
|
+
FuelProcessorState.INSTANCE.getOrSetValue(sig, processor)
|
339
|
+
}
|
@@ -4,7 +4,7 @@ import { Provider } from 'fuels'
|
|
4
4
|
import { getRpcEndpoint } from './network.js'
|
5
5
|
import { decodeFuelTransaction, DEFAULT_FUEL_FETCH_CONFIG, FuelFetchConfig } from './transaction.js'
|
6
6
|
import { FuelContext } from './context.js'
|
7
|
-
import { FuelProcessorConfig } from './fuel-processor.js'
|
7
|
+
import { FuelProcessorConfig, getOptionsSignature } from './fuel-processor.js'
|
8
8
|
import { mergeProcessResults } from '@sentio/runtime'
|
9
9
|
|
10
10
|
type GlobalFuelProcessorConfig = Omit<FuelProcessorConfig, 'address' | 'abi'>
|
@@ -17,7 +17,13 @@ export class FuelGlobalProcessor implements FuelBaseProcessor<GlobalFuelProcesso
|
|
17
17
|
|
18
18
|
static bind(config: GlobalFuelProcessorConfig): FuelGlobalProcessor {
|
19
19
|
const processor = new FuelGlobalProcessor(config)
|
20
|
-
|
20
|
+
const sig =
|
21
|
+
'global_' +
|
22
|
+
getOptionsSignature({
|
23
|
+
...config,
|
24
|
+
address: '*'
|
25
|
+
})
|
26
|
+
FuelProcessorState.INSTANCE.getOrSetValue(sig, processor)
|
21
27
|
return processor
|
22
28
|
}
|
23
29
|
|
package/src/fuel/index.ts
CHANGED
package/src/fuel/types.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { MapStateStorage } from '@sentio/runtime'
|
2
2
|
import {
|
3
3
|
Data_FuelBlock,
|
4
4
|
Data_FuelCall,
|
@@ -17,7 +17,7 @@ export interface FuelBaseProcessor<T> {
|
|
17
17
|
blockHandlers: BlockHandler[]
|
18
18
|
}
|
19
19
|
|
20
|
-
export class FuelProcessorState extends
|
20
|
+
export class FuelProcessorState extends MapStateStorage<FuelBaseProcessor<any>> {
|
21
21
|
static INSTANCE = new FuelProcessorState()
|
22
22
|
}
|
23
23
|
|