@sentio/sdk 2.62.0-rc.8 → 2.62.0
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/context.d.ts.map +1 -1
- package/lib/aptos/context.js +17 -4
- package/lib/aptos/context.js.map +1 -1
- package/lib/core/base-context.test.d.ts +2 -0
- package/lib/core/base-context.test.d.ts.map +1 -0
- package/lib/core/base-context.test.js.map +1 -0
- package/lib/core/normalization.js +1 -1
- package/lib/core/normalization.js.map +1 -1
- package/lib/fuel/asset-processor.d.ts.map +1 -1
- package/lib/fuel/asset-processor.js +10 -7
- package/lib/fuel/asset-processor.js.map +1 -1
- package/lib/store/convert.test.js.map +1 -1
- package/lib/store/decorators.d.ts.map +1 -1
- package/lib/testing/test-processor-server.d.ts +0 -4
- package/lib/testing/test-processor-server.d.ts.map +1 -1
- package/lib/testing/test-processor-server.js +0 -6
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +10 -15
- package/src/aptos/context.ts +28 -4
- package/src/core/normalization.ts +1 -1
- package/src/fuel/asset-processor.ts +10 -7
- package/src/testing/test-processor-server.ts +0 -6
- package/lib/btc/btc-plugin.d.ts +0 -19
- package/lib/btc/btc-plugin.d.ts.map +0 -1
- package/lib/btc/btc-plugin.js +0 -161
- package/lib/btc/btc-plugin.js.map +0 -1
- package/lib/btc/btc-processor.d.ts +0 -34
- package/lib/btc/btc-processor.d.ts.map +0 -1
- package/lib/btc/btc-processor.js +0 -101
- package/lib/btc/btc-processor.js.map +0 -1
- package/lib/btc/filter.d.ts +0 -44
- package/lib/btc/filter.d.ts.map +0 -1
- package/lib/btc/filter.js +0 -127
- package/lib/btc/filter.js.map +0 -1
- package/lib/btc/filter.test.d.ts +0 -2
- package/lib/btc/filter.test.d.ts.map +0 -1
- package/lib/btc/filter.test.js.map +0 -1
- package/lib/btc/index.d.ts +0 -5
- package/lib/btc/index.d.ts.map +0 -1
- package/lib/btc/index.js +0 -5
- package/lib/btc/index.js.map +0 -1
- package/lib/btc/types.d.ts +0 -89
- package/lib/btc/types.d.ts.map +0 -1
- package/lib/btc/types.js +0 -60
- package/lib/btc/types.js.map +0 -1
- package/lib/stark/codegen/codegen.d.ts +0 -2
- package/lib/stark/codegen/codegen.d.ts.map +0 -1
- package/lib/stark/codegen/codegen.js +0 -110
- package/lib/stark/codegen/codegen.js.map +0 -1
- package/lib/stark/codegen/index.d.ts +0 -2
- package/lib/stark/codegen/index.d.ts.map +0 -1
- package/lib/stark/codegen/index.js +0 -2
- package/lib/stark/codegen/index.js.map +0 -1
- package/lib/stark/codegen/run.d.ts +0 -2
- package/lib/stark/codegen/run.d.ts.map +0 -1
- package/lib/stark/codegen/run.js +0 -11
- package/lib/stark/codegen/run.js.map +0 -1
- package/lib/stark/codegen/utils.d.ts +0 -2
- package/lib/stark/codegen/utils.d.ts.map +0 -1
- package/lib/stark/codegen/utils.js +0 -4
- package/lib/stark/codegen/utils.js.map +0 -1
- package/lib/stark/context.d.ts +0 -28
- package/lib/stark/context.d.ts.map +0 -1
- package/lib/stark/context.js +0 -59
- package/lib/stark/context.js.map +0 -1
- package/lib/stark/contract.d.ts +0 -12
- package/lib/stark/contract.d.ts.map +0 -1
- package/lib/stark/contract.js +0 -43
- package/lib/stark/contract.js.map +0 -1
- package/lib/stark/event.d.ts +0 -7
- package/lib/stark/event.d.ts.map +0 -1
- package/lib/stark/event.js +0 -11
- package/lib/stark/event.js.map +0 -1
- package/lib/stark/index.d.ts +0 -7
- package/lib/stark/index.d.ts.map +0 -1
- package/lib/stark/index.js +0 -7
- package/lib/stark/index.js.map +0 -1
- package/lib/stark/starknet-plugin.d.ts +0 -15
- package/lib/stark/starknet-plugin.d.ts.map +0 -1
- package/lib/stark/starknet-plugin.js +0 -87
- package/lib/stark/starknet-plugin.js.map +0 -1
- package/lib/stark/starknet-processor.d.ts +0 -35
- package/lib/stark/starknet-processor.d.ts.map +0 -1
- package/lib/stark/starknet-processor.js +0 -133
- package/lib/stark/starknet-processor.js.map +0 -1
- package/lib/stark/types.d.ts +0 -11
- package/lib/stark/types.d.ts.map +0 -1
- package/lib/stark/types.js +0 -2
- package/lib/stark/types.js.map +0 -1
- package/lib/testing/btc-facet.d.ts +0 -10
- package/lib/testing/btc-facet.d.ts.map +0 -1
- package/lib/testing/btc-facet.js +0 -39
- package/lib/testing/btc-facet.js.map +0 -1
- package/lib/testing/starknet-facet.d.ts +0 -9
- package/lib/testing/starknet-facet.d.ts.map +0 -1
- package/lib/testing/starknet-facet.js +0 -53
- package/lib/testing/starknet-facet.js.map +0 -1
- package/src/btc/btc-plugin.ts +0 -209
- package/src/btc/btc-processor.ts +0 -165
- package/src/btc/filter.ts +0 -206
- package/src/btc/index.ts +0 -4
- package/src/btc/types.ts +0 -134
- package/src/stark/codegen/codegen.ts +0 -125
- package/src/stark/codegen/index.ts +0 -1
- package/src/stark/codegen/run.ts +0 -10
- package/src/stark/codegen/utils.ts +0 -3
- package/src/stark/context.ts +0 -78
- package/src/stark/contract.ts +0 -55
- package/src/stark/event.ts +0 -7
- package/src/stark/index.ts +0 -9
- package/src/stark/starknet-plugin.ts +0 -116
- package/src/stark/starknet-processor.ts +0 -164
- package/src/stark/types.ts +0 -11
- package/src/testing/btc-facet.ts +0 -46
- package/src/testing/starknet-facet.ts +0 -62
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { ProcessResult } from '@sentio/protos';
|
|
2
|
-
import { StarknetChainId } from '@sentio/chain';
|
|
3
|
-
import { CallData, events, RpcProvider } from 'starknet';
|
|
4
|
-
import { StarknetContext } from './context.js';
|
|
5
|
-
import { StarknetEvent } from './event.js';
|
|
6
|
-
import { ListStateStorage, mergeProcessResults } from '@sentio/runtime';
|
|
7
|
-
import { getHandlerName, proxyProcessor } from '../utils/metrics.js';
|
|
8
|
-
export class StarknetProcessor {
|
|
9
|
-
config;
|
|
10
|
-
callHandlers = [];
|
|
11
|
-
provider;
|
|
12
|
-
static bind(config) {
|
|
13
|
-
const processor = new StarknetProcessor(config);
|
|
14
|
-
StarknetProcessorState.INSTANCE.addValue(processor);
|
|
15
|
-
return processor;
|
|
16
|
-
}
|
|
17
|
-
classHash;
|
|
18
|
-
constructor(config) {
|
|
19
|
-
this.config = config;
|
|
20
|
-
return proxyProcessor(this);
|
|
21
|
-
}
|
|
22
|
-
async configure() {
|
|
23
|
-
this.provider = new RpcProvider({
|
|
24
|
-
nodeUrl: getRpcEndpoint(this.config.chainId)
|
|
25
|
-
});
|
|
26
|
-
const classHash = await this.provider.getClassHashAt(this.config.address);
|
|
27
|
-
if (!classHash) {
|
|
28
|
-
throw new Error("can't find the class hash defined at " + this.config.address);
|
|
29
|
-
}
|
|
30
|
-
this.classHash = classHash;
|
|
31
|
-
if (!this.config.abi) {
|
|
32
|
-
const clazz = await this.provider.getClass(classHash, 'latest');
|
|
33
|
-
this.config.abi = clazz.abi;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
onEvent(event, handler, handlerOptions) {
|
|
37
|
-
const eventFilter = Array.isArray(event) ? event : [event];
|
|
38
|
-
if (!this.config.abi) {
|
|
39
|
-
throw new Error('abi not found');
|
|
40
|
-
}
|
|
41
|
-
const abi = this.config.abi;
|
|
42
|
-
const callHandler = {
|
|
43
|
-
handlerName: getHandlerName(),
|
|
44
|
-
handler: async (call) => {
|
|
45
|
-
try {
|
|
46
|
-
const eventData = [call.result];
|
|
47
|
-
const abiEvents = events.getAbiEvents(abi);
|
|
48
|
-
const abiStructs = CallData.getAbiStruct(abi);
|
|
49
|
-
const abiEnums = CallData.getAbiEnum(abi);
|
|
50
|
-
const parsedEvents = events.parseEvents(eventData, abiEvents, abiStructs, abiEnums);
|
|
51
|
-
const results = [];
|
|
52
|
-
const { block_hash, block_number, transaction_hash, from_address } = call.result;
|
|
53
|
-
for (let i = 0; i < parsedEvents.length; i++) {
|
|
54
|
-
const ctx = new StarknetContext(this.config, this.provider, block_number, block_hash, transaction_hash, i, this.classHash);
|
|
55
|
-
const e = new StarknetEvent(from_address, transaction_hash, parsedEvents[i]);
|
|
56
|
-
try {
|
|
57
|
-
await handler(e, ctx);
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
console.error(e);
|
|
61
|
-
}
|
|
62
|
-
results.push(ctx.stopAndGetResult());
|
|
63
|
-
}
|
|
64
|
-
return mergeProcessResults(results);
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
console.error(e);
|
|
68
|
-
return ProcessResult.fromPartial({});
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
eventFilter,
|
|
72
|
-
partitionHandler: async (call) => {
|
|
73
|
-
const p = handlerOptions?.partitionKey;
|
|
74
|
-
if (!p)
|
|
75
|
-
return undefined;
|
|
76
|
-
if (typeof p === 'function') {
|
|
77
|
-
try {
|
|
78
|
-
const eventData = [call.result];
|
|
79
|
-
const abiEvents = events.getAbiEvents(abi);
|
|
80
|
-
const abiStructs = CallData.getAbiStruct(abi);
|
|
81
|
-
const abiEnums = CallData.getAbiEnum(abi);
|
|
82
|
-
const parsedEvents = events.parseEvents(eventData, abiEvents, abiStructs, abiEnums);
|
|
83
|
-
if (parsedEvents.length > 0) {
|
|
84
|
-
const { from_address, transaction_hash } = call.result;
|
|
85
|
-
const e = new StarknetEvent(from_address, transaction_hash, parsedEvents[0]);
|
|
86
|
-
return p(e);
|
|
87
|
-
}
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
console.error(e);
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return p;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
this.callHandlers.push(callHandler);
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function getRpcEndpoint(chainId) {
|
|
103
|
-
switch (chainId) {
|
|
104
|
-
case StarknetChainId.STARKNET_MAINNET:
|
|
105
|
-
return 'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_8/8sD5yitBslIYCPFzSq_Q1ObJHqPlZxFw';
|
|
106
|
-
default:
|
|
107
|
-
return 'https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_8/8sD5yitBslIYCPFzSq_Q1ObJHqPlZxFw';
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
export class StarknetProcessorState extends ListStateStorage {
|
|
111
|
-
static INSTANCE = new StarknetProcessorState();
|
|
112
|
-
}
|
|
113
|
-
export class AbstractStarknetProcessor {
|
|
114
|
-
abi;
|
|
115
|
-
config;
|
|
116
|
-
processor;
|
|
117
|
-
constructor(abi, config) {
|
|
118
|
-
this.abi = abi;
|
|
119
|
-
this.config = config;
|
|
120
|
-
this.processor = new StarknetProcessor(config);
|
|
121
|
-
StarknetProcessorState.INSTANCE.addValue(this.processor);
|
|
122
|
-
return proxyProcessor(this);
|
|
123
|
-
}
|
|
124
|
-
onEvent(eventName, structName, handler) {
|
|
125
|
-
this.processor.onEvent(eventName, async (events, ctx) => {
|
|
126
|
-
const eventData = events.data[structName];
|
|
127
|
-
const e = new StarknetEvent(events.caller, events.transactionHash, eventData);
|
|
128
|
-
await handler(e, ctx);
|
|
129
|
-
});
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=starknet-processor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"starknet-processor.js","sourceRoot":"","sources":["../../src/stark/starknet-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAe,WAAW,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAA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AAiB,EACjB,UAAkB,EAClB,OAA4E;QAE5E,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;YACtD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAM,CAAA;YAC9C,MAAM,CAAC,GAAG,IAAI,aAAa,CAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,EAAE,SAAS,CAAC,CAAA;YAChF,MAAM,OAAO,CAAC,CAAC,EAAE,GAAyB,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
package/lib/stark/types.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { StarknetChainId } from '@sentio/chain';
|
|
2
|
-
import { Abi } from 'starknet';
|
|
3
|
-
export type StarknetProcessorConfig = {
|
|
4
|
-
address: string;
|
|
5
|
-
name?: string;
|
|
6
|
-
chainId: StarknetChainId | string;
|
|
7
|
-
startBlock?: bigint;
|
|
8
|
-
endBlock?: bigint;
|
|
9
|
-
abi?: Abi;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=types.d.ts.map
|
package/lib/stark/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/stark/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,eAAe,GAAG,MAAM,CAAA;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,GAAG,CAAA;CACV,CAAA"}
|
package/lib/stark/types.js
DELETED
package/lib/stark/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/stark/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TestProcessorServer } from './test-processor-server.js';
|
|
2
|
-
import { BTCChainId } from '@sentio/chain';
|
|
3
|
-
import '../btc/btc-plugin.js';
|
|
4
|
-
export declare class BTCFacet {
|
|
5
|
-
server: TestProcessorServer;
|
|
6
|
-
constructor(server: TestProcessorServer);
|
|
7
|
-
testOnTransactions(events: any, network?: BTCChainId): Promise<import("@sentio/protos").ProcessBindingResponse>;
|
|
8
|
-
private buildBinding;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=btc-facet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"btc-facet.d.ts","sourceRoot":"","sources":["../../src/testing/btc-facet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,sBAAsB,CAAA;AAE7B,qBAAa,QAAQ;IACnB,MAAM,EAAE,mBAAmB,CAAA;gBAEf,MAAM,EAAE,mBAAmB;IAIvC,kBAAkB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,GAAE,UAAmC;IAW5E,OAAO,CAAC,YAAY;CAsBrB"}
|
package/lib/testing/btc-facet.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { HandlerType } from '@sentio/protos';
|
|
2
|
-
import { BTCChainId } from '@sentio/chain';
|
|
3
|
-
import '../btc/btc-plugin.js';
|
|
4
|
-
export class BTCFacet {
|
|
5
|
-
server;
|
|
6
|
-
constructor(server) {
|
|
7
|
-
this.server = server;
|
|
8
|
-
}
|
|
9
|
-
testOnTransactions(events, network = BTCChainId.BTC_TESTNET) {
|
|
10
|
-
const bindings = this.buildBinding(events, network);
|
|
11
|
-
if (!bindings) {
|
|
12
|
-
throw Error('Invalid test : ' + JSON.stringify(events));
|
|
13
|
-
}
|
|
14
|
-
return this.server.processBindings({
|
|
15
|
-
bindings
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
buildBinding(data, network) {
|
|
19
|
-
const res = [];
|
|
20
|
-
for (const config of this.server.contractConfigs) {
|
|
21
|
-
if (config.contract?.chainId !== network) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
for (const txConfig of config.btcTransactionConfigs) {
|
|
25
|
-
const binding = {
|
|
26
|
-
data: {
|
|
27
|
-
btcTransaction: data
|
|
28
|
-
},
|
|
29
|
-
handlerIds: [txConfig.handlerId],
|
|
30
|
-
handlerType: HandlerType.BTC_TRANSACTION,
|
|
31
|
-
chainId: network
|
|
32
|
-
};
|
|
33
|
-
res.push(binding);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return res;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=btc-facet.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"btc-facet.js","sourceRoot":"","sources":["../../src/testing/btc-facet.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,sBAAsB,CAAA;AAE7B,MAAM,OAAO,QAAQ;IACnB,MAAM,CAAqB;IAE3B,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,kBAAkB,CAAC,MAAW,EAAE,UAAsB,UAAU,CAAC,WAAW;QAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;QACzD,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YACjC,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAEO,YAAY,CAAC,IAAS,EAAE,OAAmB;QACjD,MAAM,GAAG,GAAkB,EAAE,CAAA;QAE7B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;YACjD,IAAI,MAAM,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,EAAE,CAAC;gBACzC,SAAQ;YACV,CAAC;YAED,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;gBACpD,MAAM,OAAO,GAAG;oBACd,IAAI,EAAE;wBACJ,cAAc,EAAE,IAAI;qBACrB;oBACD,UAAU,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;oBAChC,WAAW,EAAE,WAAW,CAAC,eAAe;oBACxC,OAAO,EAAE,OAAO;iBACF,CAAA;gBAChB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TestProcessorServer } from './test-processor-server.js';
|
|
2
|
-
import { StarknetChainId } from '@sentio/chain';
|
|
3
|
-
export declare class StarknetFacet {
|
|
4
|
-
server: TestProcessorServer;
|
|
5
|
-
constructor(server: TestProcessorServer);
|
|
6
|
-
testOnEvents(events: any, network?: StarknetChainId): Promise<import("@sentio/protos").ProcessBindingResponse>;
|
|
7
|
-
private buildBinding;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=starknet-facet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"starknet-facet.d.ts","sourceRoot":"","sources":["../../src/testing/starknet-facet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,qBAAa,aAAa;IACxB,MAAM,EAAE,mBAAmB,CAAA;gBAEf,MAAM,EAAE,mBAAmB;IAIvC,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,GAAE,eAAkD;IAWrF,OAAO,CAAC,YAAY;CAuCrB"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { HandlerType } from '@sentio/protos';
|
|
2
|
-
import { StarknetChainId } from '@sentio/chain';
|
|
3
|
-
export class StarknetFacet {
|
|
4
|
-
server;
|
|
5
|
-
constructor(server) {
|
|
6
|
-
this.server = server;
|
|
7
|
-
}
|
|
8
|
-
testOnEvents(events, network = StarknetChainId.STARKNET_SEPOLIA) {
|
|
9
|
-
const bindings = this.buildBinding(events, network);
|
|
10
|
-
if (!bindings) {
|
|
11
|
-
throw Error('Invalid test : ' + JSON.stringify(events));
|
|
12
|
-
}
|
|
13
|
-
return this.server.processBindings({
|
|
14
|
-
bindings
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
buildBinding(events, network) {
|
|
18
|
-
const res = [];
|
|
19
|
-
const data = Array.isArray(events) ? events : [events];
|
|
20
|
-
for (const event of data) {
|
|
21
|
-
for (const config of this.server.contractConfigs) {
|
|
22
|
-
if (config.contract?.chainId !== network) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
for (const logConfig of config.starknetEventConfigs) {
|
|
26
|
-
const binding = {
|
|
27
|
-
data: {
|
|
28
|
-
starknetEvents: {
|
|
29
|
-
result: event,
|
|
30
|
-
timestamp: new Date()
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
handlerIds: [logConfig.handlerId],
|
|
34
|
-
handlerType: HandlerType.STARKNET_EVENT,
|
|
35
|
-
chainId: config.contract.chainId
|
|
36
|
-
};
|
|
37
|
-
const logFilters = logConfig.filters;
|
|
38
|
-
const keys = event.keys;
|
|
39
|
-
for (const key of keys) {
|
|
40
|
-
for (const logFilter of logFilters) {
|
|
41
|
-
if (logFilter.keys.includes(key)) {
|
|
42
|
-
res.push(binding);
|
|
43
|
-
return res;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return res;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=starknet-facet.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"starknet-facet.js","sourceRoot":"","sources":["../../src/testing/starknet-facet.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,MAAM,OAAO,aAAa;IACxB,MAAM,CAAqB;IAE3B,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,YAAY,CAAC,MAAW,EAAE,UAA2B,eAAe,CAAC,gBAAgB;QACnF,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;QACzD,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YACjC,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAEO,YAAY,CAAC,MAAW,EAAE,OAAwB;QACxD,MAAM,GAAG,GAAkB,EAAE,CAAA;QAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QACtD,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;YACzB,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;gBACjD,IAAI,MAAM,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,EAAE,CAAC;oBACzC,SAAQ;gBACV,CAAC;gBAED,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,oBAAoB,EAAE,CAAC;oBACpD,MAAM,OAAO,GAAG;wBACd,IAAI,EAAE;4BACJ,cAAc,EAAE;gCACd,MAAM,EAAE,KAAK;gCACb,SAAS,EAAE,IAAI,IAAI,EAAE;6BACtB;yBACF;wBACD,UAAU,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC;wBACjC,WAAW,EAAE,WAAW,CAAC,cAAc;wBACvC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO;qBACjC,CAAA;oBAED,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAA;oBACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAgB,CAAA;oBAEnC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;wBACvB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;4BACnC,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gCACjC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gCACjB,OAAO,GAAG,CAAA;4BACZ,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
|
package/src/btc/btc-plugin.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
|
|
2
|
-
import {
|
|
3
|
-
ContractConfig,
|
|
4
|
-
DataBinding,
|
|
5
|
-
HandlerType,
|
|
6
|
-
InitResponse,
|
|
7
|
-
ProcessConfigResponse,
|
|
8
|
-
ProcessResult,
|
|
9
|
-
ProcessStreamResponse_Partitions,
|
|
10
|
-
StartRequest
|
|
11
|
-
} from '@sentio/protos'
|
|
12
|
-
|
|
13
|
-
import { ServerError, Status } from 'nice-grpc'
|
|
14
|
-
import { PartitionHandlerManager } from '../core/index.js'
|
|
15
|
-
import { HandlerRegister } from '../core/handler-register.js'
|
|
16
|
-
import { TemplateInstanceState } from '../core/template.js'
|
|
17
|
-
import { BTCProcessorState } from './btc-processor.js'
|
|
18
|
-
import { filters2Proto, TransactionFilter } from './filter.js'
|
|
19
|
-
|
|
20
|
-
export class BTCPlugin extends Plugin {
|
|
21
|
-
name: string = 'BTCPlugin'
|
|
22
|
-
handlerRegister = new HandlerRegister()
|
|
23
|
-
partitionManager = new PartitionHandlerManager()
|
|
24
|
-
|
|
25
|
-
async init(config: InitResponse) {
|
|
26
|
-
for (const aptosProcessor of BTCProcessorState.INSTANCE.getValues()) {
|
|
27
|
-
const chainId = aptosProcessor.config.chainId
|
|
28
|
-
config.chainIds.push(chainId)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async configure(config: ProcessConfigResponse, forChainId?: string) {
|
|
33
|
-
this.handlerRegister.clear(forChainId as any)
|
|
34
|
-
|
|
35
|
-
for (const processor of BTCProcessorState.INSTANCE.getValues()) {
|
|
36
|
-
const chainId = processor.config.chainId
|
|
37
|
-
if (forChainId !== undefined && forChainId !== chainId.toString()) {
|
|
38
|
-
continue
|
|
39
|
-
}
|
|
40
|
-
const contractConfig = ContractConfig.fromPartial({
|
|
41
|
-
processorType: USER_PROCESSOR,
|
|
42
|
-
contract: {
|
|
43
|
-
name: processor.config.name,
|
|
44
|
-
chainId: processor.config.chainId.toString(),
|
|
45
|
-
address: processor.config.address || '*',
|
|
46
|
-
abi: ''
|
|
47
|
-
},
|
|
48
|
-
startBlock: processor.config.startBlock,
|
|
49
|
-
endBlock: processor.config.endBlock
|
|
50
|
-
})
|
|
51
|
-
for (const callHandler of processor.callHandlers) {
|
|
52
|
-
const handlerId = this.handlerRegister.register(callHandler.handler, chainId)
|
|
53
|
-
this.partitionManager.registerPartitionHandler(
|
|
54
|
-
HandlerType.BTC_TRANSACTION,
|
|
55
|
-
handlerId,
|
|
56
|
-
callHandler.partitionHandler
|
|
57
|
-
)
|
|
58
|
-
const handlerName = callHandler.handlerName
|
|
59
|
-
|
|
60
|
-
if (callHandler.filter) {
|
|
61
|
-
contractConfig.btcTransactionConfigs.push({
|
|
62
|
-
filters: filters2Proto(callHandler.filter),
|
|
63
|
-
handlerId,
|
|
64
|
-
handlerName
|
|
65
|
-
})
|
|
66
|
-
} else if (contractConfig.contract?.address != '*') {
|
|
67
|
-
contractConfig.btcTransactionConfigs.push({
|
|
68
|
-
filters: filters2Proto({
|
|
69
|
-
outputFilter: {
|
|
70
|
-
script_address: processor.config.address
|
|
71
|
-
}
|
|
72
|
-
} as TransactionFilter),
|
|
73
|
-
handlerId,
|
|
74
|
-
handlerName
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
for (const blockHandler of processor.blockHandlers) {
|
|
80
|
-
const handlerId = this.handlerRegister.register(blockHandler.handler, chainId)
|
|
81
|
-
this.partitionManager.registerPartitionHandler(HandlerType.BTC_BLOCK, handlerId, blockHandler.partitionHandler)
|
|
82
|
-
contractConfig.intervalConfigs.push({
|
|
83
|
-
slot: 0,
|
|
84
|
-
slotInterval: blockHandler.blockInterval,
|
|
85
|
-
minutes: 0,
|
|
86
|
-
minutesInterval: blockHandler.timeIntervalInMinutes,
|
|
87
|
-
handlerId,
|
|
88
|
-
handlerName: blockHandler.handlerName,
|
|
89
|
-
fetchConfig: {
|
|
90
|
-
transaction: blockHandler.fetchConfig?.getTransactions ?? false,
|
|
91
|
-
trace: false,
|
|
92
|
-
block: true,
|
|
93
|
-
transactionReceipt: false,
|
|
94
|
-
transactionReceiptLogs: false
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Finish up a contract
|
|
100
|
-
config.contractConfigs.push(contractConfig)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
supportedHandlers = [HandlerType.BTC_TRANSACTION, HandlerType.BTC_BLOCK]
|
|
105
|
-
|
|
106
|
-
processBinding(request: DataBinding): Promise<ProcessResult> {
|
|
107
|
-
switch (request.handlerType) {
|
|
108
|
-
case HandlerType.BTC_TRANSACTION:
|
|
109
|
-
return this.processTransaction(request)
|
|
110
|
-
case HandlerType.BTC_BLOCK:
|
|
111
|
-
return this.processBlock(request)
|
|
112
|
-
default:
|
|
113
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {
|
|
118
|
-
let data: any
|
|
119
|
-
switch (request.handlerType) {
|
|
120
|
-
case HandlerType.BTC_TRANSACTION:
|
|
121
|
-
if (!request.data?.btcTransaction) {
|
|
122
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "btcTransaction can't be empty")
|
|
123
|
-
}
|
|
124
|
-
data = request.data.btcTransaction
|
|
125
|
-
break
|
|
126
|
-
case HandlerType.BTC_BLOCK:
|
|
127
|
-
if (!request.data?.btcBlock) {
|
|
128
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "btcBlock can't be empty")
|
|
129
|
-
}
|
|
130
|
-
data = request.data.btcBlock
|
|
131
|
-
break
|
|
132
|
-
default:
|
|
133
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
134
|
-
}
|
|
135
|
-
const partitions = await this.partitionManager.processPartitionForHandlerType(
|
|
136
|
-
request.handlerType,
|
|
137
|
-
request.handlerIds,
|
|
138
|
-
data
|
|
139
|
-
)
|
|
140
|
-
return {
|
|
141
|
-
partitions
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async start(request: StartRequest) {}
|
|
146
|
-
|
|
147
|
-
stateDiff(config: ProcessConfigResponse): boolean {
|
|
148
|
-
return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async processTransaction(binding: DataBinding): Promise<ProcessResult> {
|
|
152
|
-
if (!binding.data?.btcTransaction) {
|
|
153
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "BTCEvents can't be null")
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const promises: Promise<ProcessResult>[] = []
|
|
157
|
-
|
|
158
|
-
const result = binding.data?.btcTransaction
|
|
159
|
-
|
|
160
|
-
for (const handlerId of binding.handlerIds) {
|
|
161
|
-
const promise = this.handlerRegister
|
|
162
|
-
.getHandlerById(
|
|
163
|
-
binding.chainId,
|
|
164
|
-
handlerId
|
|
165
|
-
)(binding.data?.btcTransaction)
|
|
166
|
-
.catch((e: any) => {
|
|
167
|
-
throw new ServerError(
|
|
168
|
-
Status.INTERNAL,
|
|
169
|
-
'error processing transaction: ' + JSON.stringify(result) + '\n' + errorString(e)
|
|
170
|
-
)
|
|
171
|
-
})
|
|
172
|
-
if (GLOBAL_CONFIG.execution.sequential) {
|
|
173
|
-
await promise
|
|
174
|
-
}
|
|
175
|
-
promises.push(promise)
|
|
176
|
-
}
|
|
177
|
-
return mergeProcessResults(await Promise.all(promises))
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
private async processBlock(request: DataBinding) {
|
|
181
|
-
if (!request.data?.btcBlock) {
|
|
182
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const block = request.data.btcBlock
|
|
186
|
-
|
|
187
|
-
const promises: Promise<ProcessResult>[] = []
|
|
188
|
-
for (const handlerId of request.handlerIds) {
|
|
189
|
-
const promise = this.handlerRegister
|
|
190
|
-
.getHandlerById(
|
|
191
|
-
request.chainId,
|
|
192
|
-
handlerId
|
|
193
|
-
)(block)
|
|
194
|
-
.catch((e: any) => {
|
|
195
|
-
throw new ServerError(
|
|
196
|
-
Status.INTERNAL,
|
|
197
|
-
'error processing block: ' + JSON.stringify(block) + '\n' + errorString(e)
|
|
198
|
-
)
|
|
199
|
-
})
|
|
200
|
-
if (GLOBAL_CONFIG.execution.sequential) {
|
|
201
|
-
await promise
|
|
202
|
-
}
|
|
203
|
-
promises.push(promise)
|
|
204
|
-
}
|
|
205
|
-
return mergeProcessResults(await Promise.all(promises))
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
PluginManager.INSTANCE.register(new BTCPlugin())
|
package/src/btc/btc-processor.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { ListStateStorage } from '@sentio/runtime'
|
|
2
|
-
import { BlockHandler, BTCBlock, BTCBlockContext, BTCContext, BTCOnIntervalFetchConfig, Transaction } from './types.js'
|
|
3
|
-
import { Data_BTCBlock, Data_BTCTransaction, HandleInterval, ProcessResult } from '@sentio/protos'
|
|
4
|
-
import { TransactionFilters } from './filter.js'
|
|
5
|
-
import { HandlerOptions, PromiseOrVoid } from '../core/index.js'
|
|
6
|
-
import { ServerError, Status } from 'nice-grpc'
|
|
7
|
-
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
|
8
|
-
|
|
9
|
-
export class BTCProcessorState extends ListStateStorage<BTCProcessor> {
|
|
10
|
-
static INSTANCE = new BTCProcessorState()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class BTCProcessor {
|
|
14
|
-
callHandlers: CallHandler<Data_BTCTransaction>[] = []
|
|
15
|
-
blockHandlers: BlockHandler[] = []
|
|
16
|
-
|
|
17
|
-
constructor(readonly config: BTCProcessorConfig) {
|
|
18
|
-
return proxyProcessor(this)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static bind(config: BTCProcessorConfig): BTCProcessor {
|
|
22
|
-
const processor = new BTCProcessor(config)
|
|
23
|
-
BTCProcessorState.INSTANCE.addValue(processor)
|
|
24
|
-
return processor
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public onTransaction(
|
|
28
|
-
handler: (transaction: Transaction, ctx: BTCContext) => void | Promise<void>,
|
|
29
|
-
filter?: TransactionFilters,
|
|
30
|
-
handlerOptions?: HandlerOptions<object, Transaction>
|
|
31
|
-
) {
|
|
32
|
-
const callHandler = {
|
|
33
|
-
handlerName: getHandlerName(),
|
|
34
|
-
handler: async (call: Data_BTCTransaction) => {
|
|
35
|
-
const tx = call.transaction as Transaction
|
|
36
|
-
|
|
37
|
-
const ctx = new BTCContext(
|
|
38
|
-
this.config.chainId,
|
|
39
|
-
this.config.name ?? this.config.address ?? '',
|
|
40
|
-
tx,
|
|
41
|
-
this.config.address ?? tx.vout?.[0]?.scriptPubKey?.address
|
|
42
|
-
)
|
|
43
|
-
await handler(tx, ctx)
|
|
44
|
-
return ctx.stopAndGetResult()
|
|
45
|
-
},
|
|
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
|
-
}
|
|
56
|
-
}
|
|
57
|
-
this.callHandlers.push(callHandler)
|
|
58
|
-
return this
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public onInterval(
|
|
62
|
-
handler: (block: BTCBlock, ctx: BTCBlockContext) => PromiseOrVoid,
|
|
63
|
-
timeInterval: HandleInterval | undefined,
|
|
64
|
-
blockInterval: HandleInterval | undefined,
|
|
65
|
-
handlerOptions?: HandlerOptions<BTCOnIntervalFetchConfig, BTCBlock>
|
|
66
|
-
): this {
|
|
67
|
-
if (timeInterval) {
|
|
68
|
-
if (timeInterval.backfillInterval < timeInterval.recentInterval) {
|
|
69
|
-
timeInterval.backfillInterval = timeInterval.recentInterval
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const processor = this
|
|
74
|
-
|
|
75
|
-
this.blockHandlers.push({
|
|
76
|
-
blockInterval,
|
|
77
|
-
timeIntervalInMinutes: timeInterval,
|
|
78
|
-
handlerName: getHandlerName(),
|
|
79
|
-
handler: async function (data: Data_BTCBlock) {
|
|
80
|
-
const header = data.block
|
|
81
|
-
if (!header) {
|
|
82
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const block = {
|
|
86
|
-
...header
|
|
87
|
-
} as BTCBlock
|
|
88
|
-
if (handlerOptions?.getTransactions) {
|
|
89
|
-
block.tx = header.rawtx?.map((tx: any) => tx as Transaction)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const ctx = new BTCBlockContext(
|
|
93
|
-
processor.config.chainId,
|
|
94
|
-
processor.config.name ?? processor.config.address ?? '',
|
|
95
|
-
block,
|
|
96
|
-
processor.config.address
|
|
97
|
-
)
|
|
98
|
-
await handler(block, ctx)
|
|
99
|
-
return ctx.stopAndGetResult()
|
|
100
|
-
},
|
|
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
|
-
}
|
|
116
|
-
})
|
|
117
|
-
return this
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public onBlockInterval(
|
|
121
|
-
handler: (block: BTCBlock, ctx: BTCBlockContext) => PromiseOrVoid,
|
|
122
|
-
blockInterval = 250,
|
|
123
|
-
backfillBlockInterval = 1000,
|
|
124
|
-
handlerOptions?: HandlerOptions<BTCOnIntervalFetchConfig, BTCBlock>
|
|
125
|
-
): this {
|
|
126
|
-
return this.onInterval(
|
|
127
|
-
handler,
|
|
128
|
-
undefined,
|
|
129
|
-
{
|
|
130
|
-
recentInterval: blockInterval,
|
|
131
|
-
backfillInterval: backfillBlockInterval
|
|
132
|
-
},
|
|
133
|
-
handlerOptions
|
|
134
|
-
)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public onTimeInterval(
|
|
138
|
-
handler: (block: BTCBlock, ctx: BTCBlockContext) => PromiseOrVoid,
|
|
139
|
-
timeIntervalInMinutes = 60,
|
|
140
|
-
backfillTimeIntervalInMinutes = 240,
|
|
141
|
-
handlerOptions?: HandlerOptions<BTCOnIntervalFetchConfig, BTCBlock>
|
|
142
|
-
): this {
|
|
143
|
-
return this.onInterval(
|
|
144
|
-
handler,
|
|
145
|
-
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
|
|
146
|
-
undefined,
|
|
147
|
-
handlerOptions
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
interface BTCProcessorConfig {
|
|
153
|
-
chainId: string
|
|
154
|
-
name?: string
|
|
155
|
-
address?: string
|
|
156
|
-
startBlock?: bigint
|
|
157
|
-
endBlock?: bigint
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export type CallHandler<T> = {
|
|
161
|
-
handlerName: string
|
|
162
|
-
handler: (call: T) => Promise<ProcessResult>
|
|
163
|
-
filter?: TransactionFilters
|
|
164
|
-
partitionHandler?: (call: T) => Promise<string | undefined>
|
|
165
|
-
}
|