@sentio/sdk 1.19.4 → 1.19.6
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 +41 -0
- package/lib/aptos/aptos-processor.js +129 -0
- package/lib/aptos/aptos-processor.js.map +1 -0
- package/lib/aptos/bind-options.d.ts +11 -0
- package/lib/aptos/bind-options.js +17 -0
- package/lib/aptos/bind-options.js.map +1 -0
- package/lib/aptos/context.d.ts +12 -0
- package/lib/aptos/context.js +33 -0
- package/lib/aptos/context.js.map +1 -0
- package/lib/aptos/index.d.ts +5 -0
- package/lib/aptos/index.js +11 -0
- package/lib/aptos/index.js.map +1 -0
- package/lib/cli/webpack.config.js +1 -0
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +1 -1
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/bind-options.d.ts +0 -2
- package/lib/core/bind-options.js +1 -4
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +10 -10
- package/lib/core/context.js +65 -11
- package/lib/core/context.js.map +1 -1
- package/lib/core/index.d.ts +1 -2
- package/lib/core/index.js +1 -4
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/logger.js +5 -5
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +1 -1
- package/lib/core/metadata.js +3 -79
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +1 -1
- package/lib/core/meter.js +2 -2
- package/lib/core/meter.js.map +1 -1
- package/lib/core/numberish.d.ts +1 -1
- package/lib/core/numberish.js +7 -7
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/numberish.test.js.map +1 -1
- package/lib/core/solana-processor.d.ts +1 -1
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/gen/index.d.ts +1 -0
- package/lib/gen/index.js +18 -0
- package/lib/gen/index.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +15 -2
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +2 -2
- package/lib/processor-runner.js.map +1 -1
- package/lib/processor-state.d.ts +2 -1
- package/lib/processor-state.js.map +1 -1
- package/lib/service.d.ts +2 -2
- package/lib/service.js +41 -36
- package/lib/service.js.map +1 -1
- package/lib/testing/metric-utils.d.ts +1 -1
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +2 -1
- package/lib/testing/test-processor-server.js +11 -11
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +2 -2
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/tests/aptos.test.js +44 -12
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/souffl3.js +19 -12
- package/lib/tests/souffl3.js.map +1 -1
- package/lib/utils/chain.d.ts +1 -0
- package/lib/utils/chain.js +3 -1
- package/lib/utils/chain.js.map +1 -1
- package/package.json +5 -7
- package/src/aptos/aptos-processor.ts +171 -0
- package/src/aptos/bind-options.ts +15 -0
- package/src/aptos/context.ts +35 -0
- package/src/aptos/index.ts +5 -0
- package/src/cli/webpack.config.js +1 -0
- package/src/core/base-processor-template.ts +1 -1
- package/src/core/base-processor.ts +1 -1
- package/src/core/bind-options.ts +0 -1
- package/src/core/context.ts +74 -15
- package/src/core/index.ts +2 -2
- package/src/core/logger.ts +1 -1
- package/src/core/metadata.ts +4 -76
- package/src/core/meter.ts +1 -1
- package/src/core/numberish.test.ts +1 -1
- package/src/core/numberish.ts +1 -1
- package/src/core/solana-processor.ts +1 -1
- package/src/core/sui-processor.ts +1 -1
- package/src/gen/index.ts +1 -0
- package/src/index.ts +4 -1
- package/src/processor-runner.ts +1 -1
- package/src/processor-state.ts +3 -1
- package/src/service.ts +29 -29
- package/src/testing/metric-utils.ts +2 -2
- package/src/testing/test-processor-server.ts +5 -2
- package/src/testing/test-provider.ts +1 -1
- package/src/tests/aptos.test.ts +47 -11
- package/src/tests/souffl3.ts +31 -19
- package/src/utils/chain.ts +2 -0
- package/lib/core/aptos-processor.d.ts +0 -41
- package/lib/core/aptos-processor.js +0 -125
- package/lib/core/aptos-processor.js.map +0 -1
- package/src/core/aptos-processor.ts +0 -147
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { AptosBindOptions } from './bind-options';
|
|
2
|
-
import { AptosContext } from './context';
|
|
3
|
-
import { ProcessResult } from '..';
|
|
4
|
-
import Long from 'long';
|
|
5
|
-
declare type IndexConfigure = {
|
|
6
|
-
startSeqNumber: Long;
|
|
7
|
-
endSeqNumber?: Long;
|
|
8
|
-
};
|
|
9
|
-
export interface AptosEventFilter {
|
|
10
|
-
type: string;
|
|
11
|
-
}
|
|
12
|
-
export interface AptosCallFilter {
|
|
13
|
-
function: string;
|
|
14
|
-
typeArguments: string[] | undefined;
|
|
15
|
-
}
|
|
16
|
-
export declare class AptosEventHandler {
|
|
17
|
-
filters: AptosEventFilter[];
|
|
18
|
-
handler: (event: any) => Promise<ProcessResult>;
|
|
19
|
-
}
|
|
20
|
-
export declare class AptosCallHandler {
|
|
21
|
-
filters: AptosCallFilter[];
|
|
22
|
-
handler: (func: any) => Promise<ProcessResult>;
|
|
23
|
-
}
|
|
24
|
-
export declare class AptosBaseProcessor {
|
|
25
|
-
transactionHanlder: (transaction: any, ctx: AptosContext) => void;
|
|
26
|
-
address: string;
|
|
27
|
-
name: string;
|
|
28
|
-
config: IndexConfigure;
|
|
29
|
-
eventHandlers: AptosEventHandler[];
|
|
30
|
-
callHandlers: AptosCallHandler[];
|
|
31
|
-
constructor(options: AptosBindOptions);
|
|
32
|
-
bind(options: AptosBindOptions): void;
|
|
33
|
-
onTransaction(handler: (transaction: any, ctx: AptosContext) => void): this;
|
|
34
|
-
onEvent(handler: (event: any, ctx: AptosContext) => void, filter: AptosEventFilter | AptosEventFilter[]): void;
|
|
35
|
-
onCall(handler: (func: any, ctx: AptosContext) => void, filter: AptosCallFilter | AptosCallFilter[]): void;
|
|
36
|
-
handleTransaction(txn: any, slot: Long): ProcessResult | null;
|
|
37
|
-
isBind(): boolean;
|
|
38
|
-
startSlot(startSlot: Long | number): this;
|
|
39
|
-
endBlock(endBlock: Long | number): this;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AptosBaseProcessor = exports.AptosCallHandler = exports.AptosEventHandler = void 0;
|
|
7
|
-
const context_1 = require("./context");
|
|
8
|
-
const long_1 = __importDefault(require("long"));
|
|
9
|
-
class AptosEventHandler {
|
|
10
|
-
filters;
|
|
11
|
-
handler;
|
|
12
|
-
}
|
|
13
|
-
exports.AptosEventHandler = AptosEventHandler;
|
|
14
|
-
class AptosCallHandler {
|
|
15
|
-
filters;
|
|
16
|
-
handler;
|
|
17
|
-
}
|
|
18
|
-
exports.AptosCallHandler = AptosCallHandler;
|
|
19
|
-
class AptosBaseProcessor {
|
|
20
|
-
transactionHanlder;
|
|
21
|
-
address;
|
|
22
|
-
name;
|
|
23
|
-
config = { startSeqNumber: new long_1.default(0) };
|
|
24
|
-
eventHandlers = [];
|
|
25
|
-
callHandlers = [];
|
|
26
|
-
constructor(options) {
|
|
27
|
-
if (options) {
|
|
28
|
-
this.bind(options);
|
|
29
|
-
}
|
|
30
|
-
global.PROCESSOR_STATE.aptosProcessors.push(this);
|
|
31
|
-
}
|
|
32
|
-
bind(options) {
|
|
33
|
-
this.address = options.address;
|
|
34
|
-
this.name = options.name || this.address;
|
|
35
|
-
if (options.startBlock) {
|
|
36
|
-
this.startSlot(options.startBlock);
|
|
37
|
-
}
|
|
38
|
-
if (options.endBlock) {
|
|
39
|
-
this.endBlock(options.endBlock);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
onTransaction(handler) {
|
|
43
|
-
if (!this.isBind()) {
|
|
44
|
-
throw new Error("Processor doesn't bind to an address");
|
|
45
|
-
}
|
|
46
|
-
this.transactionHanlder = handler;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
onEvent(handler, filter) {
|
|
50
|
-
let _filters = [];
|
|
51
|
-
if (Array.isArray(filter)) {
|
|
52
|
-
_filters = filter;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
_filters.push(filter);
|
|
56
|
-
}
|
|
57
|
-
this.eventHandlers.push({
|
|
58
|
-
handler: async function (event) {
|
|
59
|
-
const ctx = new context_1.AptosContext(this.address, event.slot);
|
|
60
|
-
if (event) {
|
|
61
|
-
handler(event, ctx);
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
gauges: ctx.gauges,
|
|
65
|
-
counters: ctx.counters,
|
|
66
|
-
logs: ctx.logs,
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
filters: _filters,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
onCall(handler, filter) {
|
|
73
|
-
let _filters = [];
|
|
74
|
-
if (Array.isArray(filter)) {
|
|
75
|
-
_filters = filter;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
_filters.push(filter);
|
|
79
|
-
}
|
|
80
|
-
this.callHandlers.push({
|
|
81
|
-
handler: async function (call) {
|
|
82
|
-
const ctx = new context_1.AptosContext(this.address, call.slot);
|
|
83
|
-
if (call) {
|
|
84
|
-
handler(call, ctx);
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
gauges: ctx.gauges,
|
|
88
|
-
counters: ctx.counters,
|
|
89
|
-
logs: ctx.logs,
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
filters: _filters,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
handleTransaction(txn, slot) {
|
|
96
|
-
const ctx = new context_1.AptosContext(this.address, slot);
|
|
97
|
-
if (txn) {
|
|
98
|
-
this.transactionHanlder(txn, ctx);
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
gauges: ctx.gauges,
|
|
102
|
-
counters: ctx.counters,
|
|
103
|
-
logs: ctx.logs,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
isBind() {
|
|
107
|
-
return this.address !== null;
|
|
108
|
-
}
|
|
109
|
-
startSlot(startSlot) {
|
|
110
|
-
if (typeof startSlot === 'number') {
|
|
111
|
-
startSlot = long_1.default.fromNumber(startSlot);
|
|
112
|
-
}
|
|
113
|
-
this.config.startSeqNumber = startSlot;
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
endBlock(endBlock) {
|
|
117
|
-
if (typeof endBlock === 'number') {
|
|
118
|
-
endBlock = long_1.default.fromNumber(endBlock);
|
|
119
|
-
}
|
|
120
|
-
this.config.endSeqNumber = endBlock;
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.AptosBaseProcessor = AptosBaseProcessor;
|
|
125
|
-
//# sourceMappingURL=aptos-processor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/core/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAwC;AAExC,gDAAuB;AAevB,MAAa,iBAAiB;IAC5B,OAAO,CAAoB;IAC3B,OAAO,CAAwC;CAChD;AAHD,8CAGC;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAmB;IAC1B,OAAO,CAAuC;CAC/C;AAHD,4CAGC;AAED,MAAa,kBAAkB;IACtB,kBAAkB,CAA+C;IACxE,OAAO,CAAQ;IACf,IAAI,CAAQ;IACZ,MAAM,GAAmB,EAAE,cAAc,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACxD,aAAa,GAAwB,EAAE,C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GAAG,CAAC,QAAQ;YACtB,IAAI,EAAE,GAAG,CAAC,IAAI;SACf,CAAA;IACH,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAA;IAC9B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,SAAS,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAtHD,gDAsHC","sourcesContent":["import { AptosBindOptions } from './bind-options'\nimport { AptosContext } from './context'\nimport { ProcessResult } from '..'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport interface AptosEventFilter {\n type: string\n}\nexport interface AptosCallFilter {\n function: string\n typeArguments: string[] | undefined\n}\n\nexport class AptosEventHandler {\n filters: AptosEventFilter[]\n handler: (event: any) => Promise<ProcessResult>\n}\n\nexport class AptosCallHandler {\n filters: AptosCallFilter[]\n handler: (func: any) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: AptosContext) => void\n address: string\n name: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n eventHandlers: AptosEventHandler[] = []\n callHandlers: AptosCallHandler[] = []\n\n constructor(options: AptosBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n bind(options: AptosBindOptions) {\n this.address = options.address\n this.name = options.name || this.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n }\n\n public onTransaction(handler: (transaction: any, ctx: AptosContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.transactionHanlder = handler\n\n return this\n }\n\n public onEvent(handler: (event: any, ctx: AptosContext) => void, filter: AptosEventFilter | AptosEventFilter[]) {\n let _filters: AptosEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n this.eventHandlers.push({\n handler: async function (event) {\n const ctx = new AptosContext(this.address, event.slot)\n if (event) {\n handler(event, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n }\n\n public onCall(handler: (func: any, ctx: AptosContext) => void, filter: AptosCallFilter | AptosCallFilter[]) {\n let _filters: AptosCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n this.callHandlers.push({\n handler: async function (call) {\n const ctx = new AptosContext(this.address, call.slot)\n if (call) {\n handler(call, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new AptosContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { AptosBindOptions } from './bind-options'
|
|
2
|
-
import { AptosContext } from './context'
|
|
3
|
-
import { ProcessResult } from '..'
|
|
4
|
-
import Long from 'long'
|
|
5
|
-
|
|
6
|
-
type IndexConfigure = {
|
|
7
|
-
startSeqNumber: Long
|
|
8
|
-
endSeqNumber?: Long
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface AptosEventFilter {
|
|
12
|
-
type: string
|
|
13
|
-
}
|
|
14
|
-
export interface AptosCallFilter {
|
|
15
|
-
function: string
|
|
16
|
-
typeArguments: string[] | undefined
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class AptosEventHandler {
|
|
20
|
-
filters: AptosEventFilter[]
|
|
21
|
-
handler: (event: any) => Promise<ProcessResult>
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class AptosCallHandler {
|
|
25
|
-
filters: AptosCallFilter[]
|
|
26
|
-
handler: (func: any) => Promise<ProcessResult>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class AptosBaseProcessor {
|
|
30
|
-
public transactionHanlder: (transaction: any, ctx: AptosContext) => void
|
|
31
|
-
address: string
|
|
32
|
-
name: string
|
|
33
|
-
config: IndexConfigure = { startSeqNumber: new Long(0) }
|
|
34
|
-
eventHandlers: AptosEventHandler[] = []
|
|
35
|
-
callHandlers: AptosCallHandler[] = []
|
|
36
|
-
|
|
37
|
-
constructor(options: AptosBindOptions) {
|
|
38
|
-
if (options) {
|
|
39
|
-
this.bind(options)
|
|
40
|
-
}
|
|
41
|
-
global.PROCESSOR_STATE.aptosProcessors.push(this)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
bind(options: AptosBindOptions) {
|
|
45
|
-
this.address = options.address
|
|
46
|
-
this.name = options.name || this.address
|
|
47
|
-
if (options.startBlock) {
|
|
48
|
-
this.startSlot(options.startBlock)
|
|
49
|
-
}
|
|
50
|
-
if (options.endBlock) {
|
|
51
|
-
this.endBlock(options.endBlock)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public onTransaction(handler: (transaction: any, ctx: AptosContext) => void) {
|
|
56
|
-
if (!this.isBind()) {
|
|
57
|
-
throw new Error("Processor doesn't bind to an address")
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.transactionHanlder = handler
|
|
61
|
-
|
|
62
|
-
return this
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public onEvent(handler: (event: any, ctx: AptosContext) => void, filter: AptosEventFilter | AptosEventFilter[]) {
|
|
66
|
-
let _filters: AptosEventFilter[] = []
|
|
67
|
-
|
|
68
|
-
if (Array.isArray(filter)) {
|
|
69
|
-
_filters = filter
|
|
70
|
-
} else {
|
|
71
|
-
_filters.push(filter)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.eventHandlers.push({
|
|
75
|
-
handler: async function (event) {
|
|
76
|
-
const ctx = new AptosContext(this.address, event.slot)
|
|
77
|
-
if (event) {
|
|
78
|
-
handler(event, ctx)
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
gauges: ctx.gauges,
|
|
82
|
-
counters: ctx.counters,
|
|
83
|
-
logs: ctx.logs,
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
filters: _filters,
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public onCall(handler: (func: any, ctx: AptosContext) => void, filter: AptosCallFilter | AptosCallFilter[]) {
|
|
91
|
-
let _filters: AptosCallFilter[] = []
|
|
92
|
-
|
|
93
|
-
if (Array.isArray(filter)) {
|
|
94
|
-
_filters = filter
|
|
95
|
-
} else {
|
|
96
|
-
_filters.push(filter)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this.callHandlers.push({
|
|
100
|
-
handler: async function (call) {
|
|
101
|
-
const ctx = new AptosContext(this.address, call.slot)
|
|
102
|
-
if (call) {
|
|
103
|
-
handler(call, ctx)
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
gauges: ctx.gauges,
|
|
107
|
-
counters: ctx.counters,
|
|
108
|
-
logs: ctx.logs,
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
filters: _filters,
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public handleTransaction(txn: any, slot: Long): ProcessResult | null {
|
|
116
|
-
const ctx = new AptosContext(this.address, slot)
|
|
117
|
-
|
|
118
|
-
if (txn) {
|
|
119
|
-
this.transactionHanlder(txn, ctx)
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
gauges: ctx.gauges,
|
|
123
|
-
counters: ctx.counters,
|
|
124
|
-
logs: ctx.logs,
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public isBind() {
|
|
129
|
-
return this.address !== null
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public startSlot(startSlot: Long | number) {
|
|
133
|
-
if (typeof startSlot === 'number') {
|
|
134
|
-
startSlot = Long.fromNumber(startSlot)
|
|
135
|
-
}
|
|
136
|
-
this.config.startSeqNumber = startSlot
|
|
137
|
-
return this
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public endBlock(endBlock: Long | number) {
|
|
141
|
-
if (typeof endBlock === 'number') {
|
|
142
|
-
endBlock = Long.fromNumber(endBlock)
|
|
143
|
-
}
|
|
144
|
-
this.config.endSeqNumber = endBlock
|
|
145
|
-
return this
|
|
146
|
-
}
|
|
147
|
-
}
|