@sentio/sdk 1.19.3 → 1.19.5
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 +40 -0
- package/lib/aptos/aptos-processor.js +126 -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/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/generic-processor.test.js +1 -1
- package/lib/core/generic-processor.test.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 +6 -3
- package/lib/core/logger.js +15 -9
- 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/gen/processor/protos/processor.d.ts +165 -163
- package/lib/gen/processor/protos/processor.js +455 -482
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +15 -2
- package/lib/index.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 +13 -7
- package/lib/service.js +133 -44
- 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 +16 -15
- package/lib/testing/test-processor-server.js +19 -14
- 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/erc20.test.js +1 -1
- package/lib/tests/erc20.test.js.map +1 -1
- package/lib/tests/logger.test.js +1 -1
- package/lib/tests/logger.test.js.map +1 -1
- package/lib/tests/souffl3.js +16 -4
- 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/lib/utils/erc20.test.js +0 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/package.json +3 -5
- package/src/aptos/aptos-processor.ts +156 -0
- package/src/aptos/bind-options.ts +15 -0
- package/src/aptos/context.ts +35 -0
- package/src/aptos/index.ts +8 -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/generic-processor.test.ts +1 -1
- package/src/core/index.ts +2 -2
- package/src/core/logger.ts +13 -5
- 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/gen/processor/protos/processor.ts +606 -650
- package/src/index.ts +4 -1
- package/src/processor-state.ts +3 -1
- package/src/service.ts +153 -61
- package/src/testing/metric-utils.ts +2 -2
- package/src/testing/test-processor-server.ts +31 -33
- package/src/testing/test-provider.ts +1 -1
- package/src/tests/aptos.test.ts +47 -11
- package/src/tests/erc20.test.ts +1 -1
- package/src/tests/logger.test.ts +1 -1
- package/src/tests/souffl3.ts +30 -12
- package/src/utils/chain.ts +2 -0
- package/src/utils/erc20.test.ts +1 -4
- package/lib/core/aptos-processor.d.ts +0 -22
- package/lib/core/aptos-processor.js +0 -67
- package/lib/core/aptos-processor.js.map +0 -1
- package/src/core/aptos-processor.ts +0 -77
package/src/tests/aptos.test.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { expect } from 'chai'
|
|
2
|
-
import Long from 'long'
|
|
3
2
|
import { TextEncoder } from 'util'
|
|
4
|
-
import {
|
|
5
|
-
import { chain } from '../utils'
|
|
3
|
+
import { HandlerType, ProcessBindingsRequest } from '..'
|
|
6
4
|
|
|
7
5
|
import { TestProcessorServer } from '../testing'
|
|
8
6
|
|
|
@@ -21,20 +19,57 @@ describe('Test Aptos Example', () => {
|
|
|
21
19
|
})
|
|
22
20
|
|
|
23
21
|
test('Check souffl3 transaction dispatch', async () => {
|
|
24
|
-
const request:
|
|
25
|
-
|
|
26
|
-
transactions: [
|
|
22
|
+
const request: ProcessBindingsRequest = {
|
|
23
|
+
bindings: [
|
|
27
24
|
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
data: {
|
|
26
|
+
raw: new TextEncoder().encode(JSON.stringify(testData)),
|
|
27
|
+
},
|
|
28
|
+
handlerId: 0,
|
|
29
|
+
handlerType: HandlerType.APT_CALL,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
}
|
|
33
|
+
const res = await service.processBindings(request)
|
|
34
|
+
expect(res.result?.counters).length(1)
|
|
35
|
+
expect(res.result?.gauges).length(0)
|
|
36
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('Check souffl3 function call dispatch', async () => {
|
|
40
|
+
const request: ProcessBindingsRequest = {
|
|
41
|
+
bindings: [
|
|
42
|
+
{
|
|
43
|
+
data: {
|
|
44
|
+
raw: new TextEncoder().encode(JSON.stringify(testData)),
|
|
45
|
+
},
|
|
46
|
+
handlerId: 1,
|
|
47
|
+
handlerType: HandlerType.APT_CALL,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
}
|
|
51
|
+
const res = await service.processBindings(request)
|
|
52
|
+
expect(res.result?.counters).length(1)
|
|
53
|
+
expect(res.result?.gauges).length(0)
|
|
54
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('Check souffl3 event dispatch', async () => {
|
|
58
|
+
const request: ProcessBindingsRequest = {
|
|
59
|
+
bindings: [
|
|
60
|
+
{
|
|
61
|
+
data: {
|
|
62
|
+
raw: new TextEncoder().encode(JSON.stringify(testData.events[1])),
|
|
63
|
+
},
|
|
64
|
+
handlerId: 0,
|
|
65
|
+
handlerType: HandlerType.APT_EVENT,
|
|
31
66
|
},
|
|
32
67
|
],
|
|
33
68
|
}
|
|
34
|
-
const res = await service.
|
|
69
|
+
const res = await service.processBindings(request)
|
|
35
70
|
expect(res.result?.counters).length(1)
|
|
36
71
|
expect(res.result?.gauges).length(0)
|
|
37
|
-
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(
|
|
72
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
|
|
38
73
|
})
|
|
39
74
|
})
|
|
40
75
|
|
|
@@ -84,6 +119,7 @@ const testData = {
|
|
|
84
119
|
},
|
|
85
120
|
},
|
|
86
121
|
{
|
|
122
|
+
version: '18483034',
|
|
87
123
|
guid: {
|
|
88
124
|
creation_number: '2',
|
|
89
125
|
account_address: '0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
|
package/src/tests/erc20.test.ts
CHANGED
|
@@ -57,7 +57,7 @@ describe('Test Basic Examples', () => {
|
|
|
57
57
|
expect(firstCounterValue(res.result, 'c1')).equals(1n)
|
|
58
58
|
|
|
59
59
|
expect(counters?.[0].metadata?.chainId).equals('1')
|
|
60
|
-
expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.
|
|
60
|
+
expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.ETH_LOG)
|
|
61
61
|
expect(res.configUpdated).equals(true)
|
|
62
62
|
|
|
63
63
|
const logData2 = Object.assign({}, logData)
|
package/src/tests/logger.test.ts
CHANGED
|
@@ -41,6 +41,6 @@ describe('Test Error Capture', () => {
|
|
|
41
41
|
)
|
|
42
42
|
const log = res.result?.logs?.[0]
|
|
43
43
|
expect(log?.message).eq('transferred 0')
|
|
44
|
-
expect(log?.
|
|
44
|
+
expect(JSON.parse(log?.attributes || '')['from'].toLowerCase()).eq('0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91')
|
|
45
45
|
})
|
|
46
46
|
})
|
package/src/tests/souffl3.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { aptos } from '@sentio/sdk'
|
|
2
2
|
|
|
3
|
-
class Souffl3 extends AptosBaseProcessor {
|
|
4
|
-
static bind(options: AptosBindOptions): Souffl3 {
|
|
3
|
+
class Souffl3 extends aptos.AptosBaseProcessor {
|
|
4
|
+
static bind(options: aptos.AptosBindOptions): Souffl3 {
|
|
5
5
|
if (options && !options.name) {
|
|
6
6
|
options.name = 'souffl3'
|
|
7
7
|
}
|
|
@@ -10,14 +10,32 @@ class Souffl3 extends AptosBaseProcessor {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
Souffl3.bind({
|
|
13
|
-
|
|
14
|
-
address: '
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
startVersion: 6604913,
|
|
14
|
+
address: '0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
|
|
15
|
+
})
|
|
16
|
+
.onTransaction((txn, ctx) => {
|
|
17
|
+
if (txn.events) {
|
|
18
|
+
for (const event of txn.events) {
|
|
19
|
+
if (event && event.type === '0x3::token::DepositEvent') {
|
|
20
|
+
ctx.meter.Counter('deposit_token_count').add(Number(event.data.amount))
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
+
})
|
|
25
|
+
.onFunctionCall(
|
|
26
|
+
(call, ctx) => {
|
|
27
|
+
ctx.meter.Counter('call_num').add(1)
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
function: 'SouffleChefCampaign::pull_token_v2',
|
|
31
|
+
typeArguments: undefined,
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
.onEvent(
|
|
35
|
+
(event, ctx) => {
|
|
36
|
+
ctx.meter.Counter('evt_num').add(1)
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: '0x1::coin::DepositEvent',
|
|
40
|
+
}
|
|
41
|
+
)
|
package/src/utils/chain.ts
CHANGED
|
@@ -91,7 +91,9 @@ export const SUI_DEVNET_ID = 'sui_devnet'
|
|
|
91
91
|
CHAIN_MAP[SUI_DEVNET_ID] = 'sui-dev'
|
|
92
92
|
|
|
93
93
|
export const APTOS_TESTNET_ID = 'aptos_testnet'
|
|
94
|
+
export const APTOS_MAINNET_ID = 'aptos_mainnet'
|
|
94
95
|
CHAIN_MAP[APTOS_TESTNET_ID] = 'aptos-test'
|
|
96
|
+
CHAIN_MAP[APTOS_MAINNET_ID] = 'aptos-mainnet'
|
|
95
97
|
|
|
96
98
|
export function getChainName(chainId: string | number): string {
|
|
97
99
|
if (typeof chainId === 'number') {
|
package/src/utils/erc20.test.ts
CHANGED
|
@@ -1,22 +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 declare class AptosBaseProcessor {
|
|
10
|
-
transactionHanlder: (transaction: any, ctx: AptosContext) => void;
|
|
11
|
-
address: string;
|
|
12
|
-
name: string;
|
|
13
|
-
config: IndexConfigure;
|
|
14
|
-
constructor(options: AptosBindOptions);
|
|
15
|
-
bind(options: AptosBindOptions): void;
|
|
16
|
-
onTransaction(handler: (transaction: any, ctx: AptosContext) => void): this;
|
|
17
|
-
handleTransaction(txn: any, slot: Long): ProcessResult | null;
|
|
18
|
-
isBind(): boolean;
|
|
19
|
-
startSlot(startSlot: Long | number): this;
|
|
20
|
-
endBlock(endBlock: Long | number): this;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,67 +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 = void 0;
|
|
7
|
-
const context_1 = require("./context");
|
|
8
|
-
const long_1 = __importDefault(require("long"));
|
|
9
|
-
class AptosBaseProcessor {
|
|
10
|
-
transactionHanlder;
|
|
11
|
-
address;
|
|
12
|
-
name;
|
|
13
|
-
config = { startSeqNumber: new long_1.default(0) };
|
|
14
|
-
constructor(options) {
|
|
15
|
-
if (options) {
|
|
16
|
-
this.bind(options);
|
|
17
|
-
}
|
|
18
|
-
global.PROCESSOR_STATE.aptosProcessors.push(this);
|
|
19
|
-
}
|
|
20
|
-
bind(options) {
|
|
21
|
-
this.address = options.address;
|
|
22
|
-
this.name = options.name || this.address;
|
|
23
|
-
if (options.startBlock) {
|
|
24
|
-
this.startSlot(options.startBlock);
|
|
25
|
-
}
|
|
26
|
-
if (options.endBlock) {
|
|
27
|
-
this.endBlock(options.endBlock);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
onTransaction(handler) {
|
|
31
|
-
if (!this.isBind()) {
|
|
32
|
-
throw new Error("Processor doesn't bind to an address");
|
|
33
|
-
}
|
|
34
|
-
this.transactionHanlder = handler;
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
handleTransaction(txn, slot) {
|
|
38
|
-
const ctx = new context_1.AptosContext(this.address, slot);
|
|
39
|
-
if (txn) {
|
|
40
|
-
this.transactionHanlder(txn, ctx);
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
gauges: ctx.gauges,
|
|
44
|
-
counters: ctx.counters,
|
|
45
|
-
logs: ctx.logs,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
isBind() {
|
|
49
|
-
return this.address !== null;
|
|
50
|
-
}
|
|
51
|
-
startSlot(startSlot) {
|
|
52
|
-
if (typeof startSlot === 'number') {
|
|
53
|
-
startSlot = long_1.default.fromNumber(startSlot);
|
|
54
|
-
}
|
|
55
|
-
this.config.startSeqNumber = startSlot;
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
endBlock(endBlock) {
|
|
59
|
-
if (typeof endBlock === 'number') {
|
|
60
|
-
endBlock = long_1.default.fromNumber(endBlock);
|
|
61
|
-
}
|
|
62
|
-
this.config.endSeqNumber = endBlock;
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.AptosBaseProcessor = AptosBaseProcessor;
|
|
67
|
-
//# 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;AAOvB,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;IAExD,YAAY,OAAyB;QACnC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,IAAI,CAAC,OAAyB;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAA;QACxC,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;SAChC;IACH,CAAC;IAEM,aAAa,CAAC,OAAsD;QACzE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;SACxD;QAED,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QAEjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,iBAAiB,CAAC,GAAQ,EAAE,IAAU;QAC3C,MAAM,GAAG,GAAG,IAAI,sBAAY,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAEhD,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,QAAQ,EAAE,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;AAlED,gDAkEC","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 class AptosBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: AptosContext) => void\n address: string\n name: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\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 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,77 +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 class AptosBaseProcessor {
|
|
12
|
-
public transactionHanlder: (transaction: any, ctx: AptosContext) => void
|
|
13
|
-
address: string
|
|
14
|
-
name: string
|
|
15
|
-
config: IndexConfigure = { startSeqNumber: new Long(0) }
|
|
16
|
-
|
|
17
|
-
constructor(options: AptosBindOptions) {
|
|
18
|
-
if (options) {
|
|
19
|
-
this.bind(options)
|
|
20
|
-
}
|
|
21
|
-
global.PROCESSOR_STATE.aptosProcessors.push(this)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
bind(options: AptosBindOptions) {
|
|
25
|
-
this.address = options.address
|
|
26
|
-
this.name = options.name || this.address
|
|
27
|
-
if (options.startBlock) {
|
|
28
|
-
this.startSlot(options.startBlock)
|
|
29
|
-
}
|
|
30
|
-
if (options.endBlock) {
|
|
31
|
-
this.endBlock(options.endBlock)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public onTransaction(handler: (transaction: any, ctx: AptosContext) => void) {
|
|
36
|
-
if (!this.isBind()) {
|
|
37
|
-
throw new Error("Processor doesn't bind to an address")
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.transactionHanlder = handler
|
|
41
|
-
|
|
42
|
-
return this
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public handleTransaction(txn: any, slot: Long): ProcessResult | null {
|
|
46
|
-
const ctx = new AptosContext(this.address, slot)
|
|
47
|
-
|
|
48
|
-
if (txn) {
|
|
49
|
-
this.transactionHanlder(txn, ctx)
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
gauges: ctx.gauges,
|
|
53
|
-
counters: ctx.counters,
|
|
54
|
-
logs: ctx.logs,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public isBind() {
|
|
59
|
-
return this.address !== null
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public startSlot(startSlot: Long | number) {
|
|
63
|
-
if (typeof startSlot === 'number') {
|
|
64
|
-
startSlot = Long.fromNumber(startSlot)
|
|
65
|
-
}
|
|
66
|
-
this.config.startSeqNumber = startSlot
|
|
67
|
-
return this
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public endBlock(endBlock: Long | number) {
|
|
71
|
-
if (typeof endBlock === 'number') {
|
|
72
|
-
endBlock = Long.fromNumber(endBlock)
|
|
73
|
-
}
|
|
74
|
-
this.config.endSeqNumber = endBlock
|
|
75
|
-
return this
|
|
76
|
-
}
|
|
77
|
-
}
|