@subql/node-stellar 2.9.3-2 → 2.9.3-3
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/dist/.tsbuildinfo +1 -1
- package/dist/configure/SubqueryProject.d.ts +1 -0
- package/dist/configure/SubqueryProject.js +18 -2
- package/dist/configure/SubqueryProject.js.map +1 -1
- package/dist/configure/configure.module.d.ts +4 -1
- package/dist/configure/configure.module.js +1 -0
- package/dist/configure/configure.module.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.js +97 -0
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/fetch.service.spec.js +121 -47
- package/dist/indexer/fetch.service.spec.js.map +1 -1
- package/dist/indexer/indexer.manager.d.ts +24 -5
- package/dist/indexer/indexer.manager.js +62 -4
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.js +1 -1
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +1 -1
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -1
- package/dist/meta/meta.module.js.map +1 -1
- package/dist/meta/meta.service.d.ts +4 -0
- package/dist/meta/meta.service.js +6 -1
- package/dist/meta/meta.service.js.map +1 -1
- package/dist/stellar/api.connection.d.ts +2 -1
- package/dist/stellar/api.connection.js +4 -3
- package/dist/stellar/api.connection.js.map +1 -1
- package/dist/stellar/api.connection.spec.js +32 -36
- package/dist/stellar/api.connection.spec.js.map +1 -1
- package/dist/stellar/api.service.stellar.js +5 -1
- package/dist/stellar/api.service.stellar.js.map +1 -1
- package/dist/stellar/api.service.stellar.spec.d.ts +2 -2
- package/dist/stellar/api.service.stellar.spec.js +20 -22
- package/dist/stellar/api.service.stellar.spec.js.map +1 -1
- package/dist/stellar/api.stellar.d.ts +18 -8
- package/dist/stellar/api.stellar.js +160 -28
- package/dist/stellar/api.stellar.js.map +1 -1
- package/dist/stellar/api.stellar.spec.js +26 -38
- package/dist/stellar/api.stellar.spec.js.map +1 -1
- package/dist/stellar/block.stellar.d.ts +15 -5
- package/dist/stellar/block.stellar.js +50 -2
- package/dist/stellar/block.stellar.js.map +1 -1
- package/dist/stellar/block.stellar.spec.js +150 -46
- package/dist/stellar/block.stellar.spec.js.map +1 -1
- package/dist/stellar/safe-api.d.ts +2 -2
- package/dist/stellar/safe-api.js +3 -3
- package/dist/stellar/safe-api.js.map +1 -1
- package/dist/stellar/soroban.server.d.ts +8 -0
- package/dist/stellar/soroban.server.js +72 -0
- package/dist/stellar/soroban.server.js.map +1 -0
- package/dist/stellar/{stellar.server.spec.js → soroban.server.spec.js} +4 -4
- package/dist/stellar/{stellar.server.spec.js.map → soroban.server.spec.js.map} +1 -1
- package/dist/stellar/stellar.server.d.ts +6 -6
- package/dist/stellar/stellar.server.js +9 -61
- package/dist/stellar/stellar.server.js.map +1 -1
- package/dist/utils/project.d.ts +0 -2
- package/dist/utils/project.js +1 -12
- package/dist/utils/project.js.map +1 -1
- package/dist/yargs.d.ts +6 -1
- package/dist/yargs.js +5 -0
- package/dist/yargs.js.map +1 -1
- package/package.json +5 -4
- /package/dist/stellar/{stellar.server.spec.d.ts → soroban.server.spec.d.ts} +0 -0
|
@@ -1,81 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const eventemitter2_1 =
|
|
5
|
+
const eventemitter2_1 = require("eventemitter2");
|
|
9
6
|
const api_stellar_1 = require("./api.stellar");
|
|
10
|
-
const
|
|
11
|
-
const HTTP_ENDPOINT = 'https://
|
|
7
|
+
const soroban_server_1 = require("./soroban.server");
|
|
8
|
+
const HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';
|
|
9
|
+
const SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';
|
|
12
10
|
jest.setTimeout(60000);
|
|
13
11
|
const prepareStellarApi = async function () {
|
|
14
|
-
const
|
|
12
|
+
const soroban = new soroban_server_1.SorobanServer(SOROBAN_ENDPOINT);
|
|
13
|
+
const api = new api_stellar_1.StellarApi(HTTP_ENDPOINT, new eventemitter2_1.EventEmitter2(), soroban);
|
|
15
14
|
await api.init();
|
|
16
15
|
return api;
|
|
17
16
|
};
|
|
18
|
-
describe('StellarApi',
|
|
17
|
+
describe('StellarApi', () => {
|
|
19
18
|
let stellarApi;
|
|
20
|
-
beforeEach(async
|
|
19
|
+
beforeEach(async () => {
|
|
21
20
|
stellarApi = await prepareStellarApi();
|
|
22
21
|
});
|
|
23
|
-
it('should initialize chainId',
|
|
22
|
+
it('should initialize chainId', () => {
|
|
24
23
|
expect(stellarApi.getChainId()).toEqual('Test SDF Future Network ; October 2022');
|
|
25
24
|
});
|
|
26
|
-
it('should get finalized block height', async
|
|
27
|
-
|
|
25
|
+
it('should get finalized block height', async () => {
|
|
26
|
+
const height = await stellarApi.getFinalizedBlockHeight();
|
|
27
|
+
expect(height).not.toBeNaN();
|
|
28
|
+
expect(height).toBeGreaterThan(0);
|
|
28
29
|
});
|
|
29
|
-
it('should get best block height', async
|
|
30
|
-
|
|
30
|
+
it('should get best block height', async () => {
|
|
31
|
+
const height = await stellarApi.getBestBlockHeight();
|
|
32
|
+
expect(height).not.toBeNaN();
|
|
33
|
+
expect(height).toBeGreaterThan(0);
|
|
31
34
|
});
|
|
32
|
-
it('should fetch block', async
|
|
35
|
+
it('should fetch block', async () => {
|
|
33
36
|
const latestHeight = await stellarApi.getFinalizedBlockHeight();
|
|
34
37
|
const block = (await stellarApi.fetchBlocks([latestHeight]))[0];
|
|
35
|
-
expect(block.block.
|
|
36
|
-
});
|
|
37
|
-
it('throws error if getEvents throws error', async function () {
|
|
38
|
-
jest
|
|
39
|
-
.spyOn(stellarApi, 'getEvents')
|
|
40
|
-
.mockImplementation(() => Promise.reject(new Error('Test error')));
|
|
41
|
-
await expect(stellarApi.fetchBlock(1)).rejects.toThrow('Test error');
|
|
38
|
+
expect(block.block.sequence).toEqual(latestHeight);
|
|
42
39
|
});
|
|
43
|
-
it('should
|
|
44
|
-
const height = 1;
|
|
45
|
-
const safeApi = stellarApi.getSafeApi(height);
|
|
46
|
-
expect(safeApi).toBeInstanceOf(safe_api_1.default);
|
|
47
|
-
});
|
|
48
|
-
it('should throw on calling connect', async function () {
|
|
40
|
+
it('should throw on calling connect', async () => {
|
|
49
41
|
await expect(stellarApi.connect()).rejects.toThrow('Not implemented');
|
|
50
42
|
});
|
|
51
|
-
it('should throw on calling disconnect', async
|
|
43
|
+
it('should throw on calling disconnect', async () => {
|
|
52
44
|
await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');
|
|
53
45
|
});
|
|
54
|
-
it('handleError - pruned node errors',
|
|
46
|
+
it('handleError - pruned node errors', () => {
|
|
55
47
|
const error = new Error('start is before oldest ledger');
|
|
56
48
|
const handled = stellarApi.handleError(error, 1000);
|
|
57
49
|
expect(handled.message).toContain('The requested ledger number 1000 is not available on the current blockchain node');
|
|
58
50
|
});
|
|
59
|
-
it('handleError - non pruned node errors should return the same error',
|
|
51
|
+
it('handleError - non pruned node errors should return the same error', () => {
|
|
60
52
|
const error = new Error('Generic error');
|
|
61
53
|
const handled = stellarApi.handleError(error, 1000);
|
|
62
54
|
expect(handled).toBe(error);
|
|
63
55
|
});
|
|
64
|
-
it('should get runtime chain',
|
|
56
|
+
it('should get runtime chain', () => {
|
|
65
57
|
const runtimeChain = stellarApi.getRuntimeChain();
|
|
66
58
|
expect(runtimeChain).toEqual(stellarApi.name);
|
|
67
59
|
});
|
|
68
|
-
it('should return chainId for genesis hash',
|
|
60
|
+
it('should return chainId for genesis hash', () => {
|
|
69
61
|
const genesisHash = stellarApi.getGenesisHash();
|
|
70
62
|
expect(genesisHash).toEqual(stellarApi.getChainId());
|
|
71
63
|
});
|
|
72
|
-
it('should get spec name',
|
|
64
|
+
it('should get spec name', () => {
|
|
73
65
|
const specName = stellarApi.getSpecName();
|
|
74
66
|
expect(specName).toEqual('Stellar');
|
|
75
67
|
});
|
|
76
|
-
it('should get client for api', function () {
|
|
77
|
-
const apiClient = stellarApi.api;
|
|
78
|
-
expect(apiClient).toEqual(stellarApi.client);
|
|
79
|
-
});
|
|
80
68
|
});
|
|
81
69
|
//# sourceMappingURL=api.stellar.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC
|
|
1
|
+
{"version":3,"file":"api.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,iDAA8C;AAC9C,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEvB,MAAM,iBAAiB,GAAG,KAAK;IAC7B,MAAM,OAAO,GAAG,IAAI,8BAAa,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAI,wBAAU,CAAC,aAAa,EAAE,IAAI,6BAAa,EAAE,EAAE,OAAO,CAAC,CAAC;IACxE,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,QAAQ,CAAC,YAAY,EAAE,GAAG,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CAAC,UAAU,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from 'eventemitter2';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\njest.setTimeout(60000);\n\nconst prepareStellarApi = async function () {\n const soroban = new SorobanServer(SOROBAN_ENDPOINT);\n const api = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), soroban);\n await api.init();\n return api;\n};\n\ndescribe('StellarApi', () => {\n let stellarApi: StellarApi;\n\n beforeEach(async () => {\n stellarApi = await prepareStellarApi();\n });\n\n it('should initialize chainId', () => {\n expect(stellarApi.getChainId()).toEqual(\n 'Test SDF Future Network ; October 2022',\n );\n });\n\n it('should get finalized block height', async () => {\n const height = await stellarApi.getFinalizedBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should get best block height', async () => {\n const height = await stellarApi.getBestBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should fetch block', async () => {\n const latestHeight = await stellarApi.getFinalizedBlockHeight();\n const block = (await stellarApi.fetchBlocks([latestHeight]))[0];\n expect(block.block.sequence).toEqual(latestHeight);\n });\n\n it('should throw on calling connect', async () => {\n await expect(stellarApi.connect()).rejects.toThrow('Not implemented');\n });\n\n it('should throw on calling disconnect', async () => {\n await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');\n });\n\n it('handleError - pruned node errors', () => {\n const error = new Error('start is before oldest ledger');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled.message).toContain(\n 'The requested ledger number 1000 is not available on the current blockchain node',\n );\n });\n\n it('handleError - non pruned node errors should return the same error', () => {\n const error = new Error('Generic error');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled).toBe(error);\n });\n\n it('should get runtime chain', () => {\n const runtimeChain = stellarApi.getRuntimeChain();\n expect(runtimeChain).toEqual((stellarApi as any).name);\n });\n\n it('should return chainId for genesis hash', () => {\n const genesisHash = stellarApi.getGenesisHash();\n expect(genesisHash).toEqual(stellarApi.getChainId());\n });\n\n it('should get spec name', () => {\n const specName = stellarApi.getSpecName();\n expect(specName).toEqual('Stellar');\n });\n});\n"]}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import { StellarBlock, StellarBlockWrapper,
|
|
1
|
+
import { StellarBlock, StellarBlockFilter, StellarBlockWrapper, StellarEffect, StellarEffectFilter, SorobanEvent, SorobanEventFilter, StellarOperation, StellarOperationFilter, StellarTransaction, StellarTransactionFilter } from '@subql/types-stellar';
|
|
2
2
|
import { xdr } from 'soroban-client';
|
|
3
3
|
export declare class StellarBlockWrapped implements StellarBlockWrapper {
|
|
4
|
-
private _events;
|
|
5
4
|
private _block;
|
|
6
|
-
|
|
5
|
+
private _transactions;
|
|
6
|
+
private _operations;
|
|
7
|
+
private _effects;
|
|
8
|
+
private _events;
|
|
9
|
+
constructor(_block: StellarBlock, _transactions: StellarTransaction[], _operations: StellarOperation[], _effects: StellarEffect[], _events: SorobanEvent[]);
|
|
7
10
|
get block(): StellarBlock;
|
|
8
|
-
get
|
|
9
|
-
|
|
11
|
+
get transactions(): StellarTransaction[];
|
|
12
|
+
get operations(): StellarOperation[];
|
|
13
|
+
get effects(): StellarEffect[];
|
|
14
|
+
get events(): SorobanEvent[];
|
|
15
|
+
static filterBlocksProcessor(block: StellarBlock, filter: StellarBlockFilter, address?: string): boolean;
|
|
16
|
+
static filterTransactionProcessor(tx: StellarTransaction, filter: StellarTransactionFilter, address?: string): boolean;
|
|
17
|
+
static filterOperationProcessor(op: StellarOperation, filter: StellarOperationFilter, address?: string): boolean;
|
|
18
|
+
static filterEffectProcessor(effect: StellarEffect, filter: StellarEffectFilter, address?: string): boolean;
|
|
19
|
+
static filterEventProcessor(event: SorobanEvent, filter: SorobanEventFilter, address?: string): boolean;
|
|
10
20
|
static decodeScVals(scVal: xdr.ScVal): any;
|
|
11
21
|
}
|
|
@@ -6,16 +6,64 @@ exports.StellarBlockWrapped = void 0;
|
|
|
6
6
|
const soroban_client_1 = require("soroban-client");
|
|
7
7
|
const string_1 = require("../utils/string");
|
|
8
8
|
class StellarBlockWrapped {
|
|
9
|
-
constructor(
|
|
10
|
-
this._events = _events;
|
|
9
|
+
constructor(_block, _transactions, _operations, _effects, _events) {
|
|
11
10
|
this._block = _block;
|
|
11
|
+
this._transactions = _transactions;
|
|
12
|
+
this._operations = _operations;
|
|
13
|
+
this._effects = _effects;
|
|
14
|
+
this._events = _events;
|
|
12
15
|
}
|
|
13
16
|
get block() {
|
|
14
17
|
return this._block;
|
|
15
18
|
}
|
|
19
|
+
get transactions() {
|
|
20
|
+
return this._transactions;
|
|
21
|
+
}
|
|
22
|
+
get operations() {
|
|
23
|
+
return this._operations;
|
|
24
|
+
}
|
|
25
|
+
get effects() {
|
|
26
|
+
return this._effects;
|
|
27
|
+
}
|
|
16
28
|
get events() {
|
|
17
29
|
return this._events;
|
|
18
30
|
}
|
|
31
|
+
static filterBlocksProcessor(block, filter, address) {
|
|
32
|
+
if ((filter === null || filter === void 0 ? void 0 : filter.modulo) && block.sequence % filter.modulo !== 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
static filterTransactionProcessor(tx, filter, address) {
|
|
38
|
+
if (!filter)
|
|
39
|
+
return true;
|
|
40
|
+
if (filter.account && filter.account !== tx.source_account) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
static filterOperationProcessor(op, filter, address) {
|
|
46
|
+
if (!filter)
|
|
47
|
+
return true;
|
|
48
|
+
if (filter.sourceAccount && filter.sourceAccount !== op.source_account) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (filter.type && filter.type !== op.type) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
static filterEffectProcessor(effect, filter, address) {
|
|
57
|
+
if (!filter)
|
|
58
|
+
return true;
|
|
59
|
+
if (filter.account && filter.account !== effect.account) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (filter.type && filter.type !== effect.type) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
19
67
|
static filterEventProcessor(event, filter, address) {
|
|
20
68
|
if (address && !(0, string_1.stringNormalizedEq)(address, event.contractId)) {
|
|
21
69
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.stellar.js","sourceRoot":"","sources":["../../src/stellar/block.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;
|
|
1
|
+
{"version":3,"file":"block.stellar.js","sourceRoot":"","sources":["../../src/stellar/block.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAenC,mDAA6D;AAC7D,4CAAqD;AAErD,MAAa,mBAAmB;IAC9B,YACU,MAAoB,EACpB,aAAmC,EACnC,WAA+B,EAC/B,QAAyB,EACzB,OAAuB;QAJvB,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAAsB;QACnC,gBAAW,GAAX,WAAW,CAAoB;QAC/B,aAAQ,GAAR,QAAQ,CAAiB;QACzB,YAAO,GAAP,OAAO,CAAgB;IAC9B,CAAC;IAEJ,I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,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/B,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;aAC3D;YACD,KAAK,oBAAG,CAAC,SAAS,CAAC,MAAM,EAAE;gBACzB,OAAO,MAAM,CAAC,WAAW,CACvB,KAAK,CAAC,GAAG,EAAG,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;oBACzB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;oBAC9B,OAAO,CAAC,GAAG,EAAE,mBAAmB,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;gBAC9D,CAAC,CAAC,CACH,CAAC;YACJ;gBACE,OAAO,IAAA,8BAAa,EAAC,KAAK,CAAC,CAAC;SAC/B;IACH,CAAC;CACF;AA9JD,kDA8JC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n StellarBlock,\n StellarBlockFilter,\n StellarBlockWrapper,\n StellarEffect,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n StellarOperation,\n StellarOperationFilter,\n StellarTransaction,\n StellarTransactionFilter,\n} from '@subql/types-stellar';\nimport { Address, scValToNative, xdr } from 'soroban-client';\nimport { stringNormalizedEq } from '../utils/string';\n\nexport class StellarBlockWrapped implements StellarBlockWrapper {\n constructor(\n private _block: StellarBlock,\n private _transactions: StellarTransaction[],\n private _operations: StellarOperation[],\n private _effects: StellarEffect[],\n private _events: SorobanEvent[],\n ) {}\n\n get block(): StellarBlock {\n return this._block;\n }\n\n get transactions(): StellarTransaction[] {\n return this._transactions;\n }\n\n get operations(): StellarOperation[] {\n return this._operations;\n }\n\n get effects(): StellarEffect[] {\n return this._effects;\n }\n\n get events(): SorobanEvent[] {\n return this._events;\n }\n\n static filterBlocksProcessor(\n block: StellarBlock,\n filter: StellarBlockFilter,\n address?: string,\n ): boolean {\n if (filter?.modulo && block.sequence % filter.modulo !== 0) {\n return false;\n }\n return true;\n }\n\n static filterTransactionProcessor(\n tx: StellarTransaction,\n filter: StellarTransactionFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== tx.source_account) {\n return false;\n }\n\n return true;\n }\n\n static filterOperationProcessor(\n op: StellarOperation,\n filter: StellarOperationFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.sourceAccount && filter.sourceAccount !== op.source_account) {\n return false;\n }\n if (filter.type && filter.type !== op.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEffectProcessor(\n effect: StellarEffect,\n filter: StellarEffectFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== effect.account) {\n return false;\n }\n if (filter.type && filter.type !== effect.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEventProcessor(\n event: SorobanEvent,\n filter: SorobanEventFilter,\n address?: string,\n ): boolean {\n if (address && !stringNormalizedEq(address, event.contractId)) {\n return false;\n }\n\n if (!filter) return true;\n\n if (filter.contractId && filter.contractId !== event.contractId) {\n return false;\n }\n\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n\n if (!event.topic[i]) {\n return false;\n }\n\n if (topic !== event.topic[i]) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n static decodeScVals(scVal: xdr.ScVal): any {\n switch (scVal.switch()) {\n case xdr.ScValType.scvBool():\n return scVal.b();\n case xdr.ScValType.scvSymbol():\n return scVal.sym().toString();\n case xdr.ScValType.scvU64():\n return scVal.u64().low;\n case xdr.ScValType.scvAddress(): {\n try {\n return Address.account(\n scVal.address().accountId().value(),\n ).toString();\n } catch (error) {\n return Address.contract(scVal.address().contractId()).toString();\n }\n }\n case xdr.ScValType.scvString(): {\n return Buffer.from(scVal.str().toString(), 'base64').toString();\n }\n case xdr.ScValType.scvBytes():\n return scVal.bytes();\n case xdr.ScValType.scvI128(): {\n const low = scVal.i128().lo();\n const high = scVal.i128().hi();\n return BigInt(low.low) | (BigInt(low.high) << BigInt(32));\n }\n case xdr.ScValType.scvMap():\n return Object.fromEntries(\n scVal.map()!.map((entry) => {\n const key = entry.key().sym();\n return [key, StellarBlockWrapped.decodeScVals(entry.val())];\n }),\n );\n default:\n return scValToNative(scVal);\n }\n }\n}\n"]}
|
|
@@ -2,57 +2,161 @@
|
|
|
2
2
|
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const stellar_sdk_1 = require("stellar-sdk");
|
|
5
6
|
const block_stellar_1 = require("./block.stellar");
|
|
6
|
-
describe('StellarBlockWrapped',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
topic: ['topic1', 'topic2'],
|
|
15
|
-
value: null,
|
|
16
|
-
};
|
|
17
|
-
const mockBlock = {
|
|
18
|
-
ledger: 2000,
|
|
19
|
-
hash: '2000',
|
|
20
|
-
events: [mockEvent],
|
|
21
|
-
};
|
|
22
|
-
const mockEventFilterValid = {
|
|
23
|
-
topics: ['topic1', 'topic2'],
|
|
24
|
-
};
|
|
25
|
-
const mockEventFilterInvalid = {
|
|
26
|
-
topics: ['topics3'],
|
|
27
|
-
};
|
|
28
|
-
it('should pass filter - valid address and topics', function () {
|
|
29
|
-
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid, 'testaddress')).toEqual(true);
|
|
7
|
+
describe('StellarBlockWrapped', () => {
|
|
8
|
+
describe('filterBlocksProcessor', () => {
|
|
9
|
+
it('should filter by modulo', () => {
|
|
10
|
+
const block = { sequence: 5 };
|
|
11
|
+
const filter = { modulo: 2 };
|
|
12
|
+
const result = block_stellar_1.StellarBlockWrapped.filterBlocksProcessor(block, filter);
|
|
13
|
+
expect(result).toBe(false);
|
|
14
|
+
});
|
|
30
15
|
});
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
describe('filterTransactionProcessor', () => {
|
|
17
|
+
it('should filter by account', () => {
|
|
18
|
+
const transaction = {
|
|
19
|
+
source_account: 'account1',
|
|
20
|
+
};
|
|
21
|
+
const filter = { account: 'account2' };
|
|
22
|
+
const result = block_stellar_1.StellarBlockWrapped.filterTransactionProcessor(transaction, filter);
|
|
23
|
+
expect(result).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
it('should pass when account filter condition is fulfilled', () => {
|
|
26
|
+
const transaction = {
|
|
27
|
+
source_account: 'account1',
|
|
28
|
+
};
|
|
29
|
+
const filter = { account: 'account1' };
|
|
30
|
+
const result = block_stellar_1.StellarBlockWrapped.filterTransactionProcessor(transaction, filter);
|
|
31
|
+
expect(result).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
it('should pass when there is no account filter', () => {
|
|
34
|
+
const transaction = {
|
|
35
|
+
source_account: 'account1',
|
|
36
|
+
};
|
|
37
|
+
const filter = {};
|
|
38
|
+
const result = block_stellar_1.StellarBlockWrapped.filterTransactionProcessor(transaction, filter);
|
|
39
|
+
expect(result).toBe(true);
|
|
40
|
+
});
|
|
33
41
|
});
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
describe('filterOperationProcessor', () => {
|
|
43
|
+
it('should filter by source_account and type', () => {
|
|
44
|
+
const operation = {
|
|
45
|
+
source_account: 'account1',
|
|
46
|
+
type: 'type1',
|
|
47
|
+
};
|
|
48
|
+
const filter = {
|
|
49
|
+
sourceAccount: 'account2',
|
|
50
|
+
type: stellar_sdk_1.Horizon.OperationResponseType.createAccount,
|
|
51
|
+
};
|
|
52
|
+
const result = block_stellar_1.StellarBlockWrapped.filterOperationProcessor(operation, filter);
|
|
53
|
+
expect(result).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
it('should pass when source_account and type filter conditions are fulfilled', () => {
|
|
56
|
+
const operation = {
|
|
57
|
+
source_account: 'account1',
|
|
58
|
+
type: stellar_sdk_1.Horizon.OperationResponseType.createAccount,
|
|
59
|
+
};
|
|
60
|
+
const filter = {
|
|
61
|
+
sourceAccount: 'account1',
|
|
62
|
+
type: stellar_sdk_1.Horizon.OperationResponseType.createAccount,
|
|
63
|
+
};
|
|
64
|
+
const result = block_stellar_1.StellarBlockWrapped.filterOperationProcessor(operation, filter);
|
|
65
|
+
expect(result).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
it('should pass when there are no filter conditions', () => {
|
|
68
|
+
const operation = {
|
|
69
|
+
source_account: 'account1',
|
|
70
|
+
type: 'type1',
|
|
71
|
+
};
|
|
72
|
+
const filter = {};
|
|
73
|
+
const result = block_stellar_1.StellarBlockWrapped.filterOperationProcessor(operation, filter);
|
|
74
|
+
expect(result).toBe(true);
|
|
75
|
+
});
|
|
36
76
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
77
|
+
describe('filterEffectProcessor', () => {
|
|
78
|
+
it('should filter by account and type', () => {
|
|
79
|
+
const effect = {
|
|
80
|
+
account: 'account1',
|
|
81
|
+
type: 'type1',
|
|
82
|
+
};
|
|
83
|
+
const filter = {
|
|
84
|
+
account: 'account2',
|
|
85
|
+
type: 'type2',
|
|
86
|
+
};
|
|
87
|
+
const result = block_stellar_1.StellarBlockWrapped.filterEffectProcessor(effect, filter);
|
|
88
|
+
expect(result).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
it('should pass when account and type filter conditions are fulfilled', () => {
|
|
91
|
+
const effect = {
|
|
92
|
+
account: 'account1',
|
|
93
|
+
type: 'type1',
|
|
94
|
+
};
|
|
95
|
+
const filter = {
|
|
96
|
+
account: 'account1',
|
|
97
|
+
type: 'type1',
|
|
98
|
+
};
|
|
99
|
+
const result = block_stellar_1.StellarBlockWrapped.filterEffectProcessor(effect, filter);
|
|
100
|
+
expect(result).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
it('should pass when there are no filter conditions', () => {
|
|
103
|
+
const effect = {
|
|
104
|
+
account: 'account1',
|
|
105
|
+
type: 'type1',
|
|
106
|
+
};
|
|
107
|
+
const filter = {};
|
|
108
|
+
const result = block_stellar_1.StellarBlockWrapped.filterEffectProcessor(effect, filter);
|
|
109
|
+
expect(result).toBe(true);
|
|
110
|
+
});
|
|
40
111
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
112
|
+
describe('StellarBlockWrapped', function () {
|
|
113
|
+
const mockEvent = {
|
|
114
|
+
ledger: null,
|
|
115
|
+
transaction: null,
|
|
116
|
+
operation: null,
|
|
117
|
+
ledgerClosedAt: null,
|
|
118
|
+
contractId: 'testaddress',
|
|
119
|
+
id: null,
|
|
120
|
+
pagingToken: null,
|
|
121
|
+
inSuccessfulContractCall: null,
|
|
122
|
+
topic: ['topic1', 'topic2'],
|
|
123
|
+
value: null,
|
|
124
|
+
};
|
|
125
|
+
const mockEventFilterValid = {
|
|
126
|
+
topics: ['topic1', 'topic2'],
|
|
127
|
+
};
|
|
128
|
+
const mockEventFilterInvalid = {
|
|
129
|
+
topics: ['topics3'],
|
|
130
|
+
};
|
|
131
|
+
it('should pass filter - valid address and topics', function () {
|
|
132
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid, 'testaddress')).toEqual(true);
|
|
133
|
+
});
|
|
134
|
+
it('should pass filter - no address and valid topics', function () {
|
|
135
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid)).toEqual(true);
|
|
136
|
+
});
|
|
137
|
+
it('should fail filter - valid address and invalid topics', function () {
|
|
138
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterInvalid, 'testaddress')).toEqual(false);
|
|
139
|
+
});
|
|
140
|
+
it('should fail filter - event not found', function () {
|
|
141
|
+
mockEventFilterInvalid.topics = ['topic1', 'topic2', 'topic3'];
|
|
142
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterInvalid)).toEqual(false);
|
|
143
|
+
});
|
|
144
|
+
it('should pass filter - skip null topics', function () {
|
|
145
|
+
mockEventFilterValid.topics = [null, 'topic2'];
|
|
146
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid)).toEqual(true);
|
|
147
|
+
});
|
|
148
|
+
it('should pass filer - valid contractId', function () {
|
|
149
|
+
mockEventFilterValid.contractId = 'testaddress';
|
|
150
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid)).toEqual(true);
|
|
151
|
+
});
|
|
152
|
+
it('should fail filter - invalid contractId', function () {
|
|
153
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, {
|
|
154
|
+
contractId: 'invalidaddress',
|
|
155
|
+
})).toEqual(false);
|
|
156
|
+
});
|
|
157
|
+
it('should fail filter - invalid address', function () {
|
|
158
|
+
expect(block_stellar_1.StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid, 'invalidaddress')).toEqual(false);
|
|
159
|
+
});
|
|
56
160
|
});
|
|
57
161
|
});
|
|
58
162
|
//# sourceMappingURL=block.stellar.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/block.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAQnC,mDAAsD;AAEtD,QAAQ,CAAC,qBAAqB,EAAE;IAC9B,MAAM,SAAS,GAAiB;QAC9B,MA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B,CACvB,CACF,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE;QAC1C,oBAAoB,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC/C,MAAM,CACJ,mCAAmB,CAAC,oBAAoB,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAC1E,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE;QACzC,oBAAoB,CAAC,UAAU,GAAG,aAAa,CAAC;QAChD,MAAM,CACJ,mCAAmB,CAAC,oBAAoB,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAC1E,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE;QAC5C,MAAM,CACJ,mCAAmB,CAAC,oBAAoB,CAAC,SAAS,EAAE;YAClD,UAAU,EAAE,gBAAgB;SAC7B,CAAC,CACH,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE;QACzC,MAAM,CACJ,mCAAmB,CAAC,oBAAoB,CACtC,SAAS,EACT,oBAAoB,EACpB,gBAAgB,CACjB,CACF,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n StellarBlock,\n StellarEvent,\n StellarEventFilter,\n} from '@subql/types-stellar';\nimport { xdr } from 'soroban-client';\nimport { StellarBlockWrapped } from './block.stellar';\n\ndescribe('StellarBlockWrapped', function () {\n const mockEvent: StellarEvent = {\n ledger: '2000',\n ledgerClosedAt: null,\n contractId: 'testaddress',\n id: null,\n pagingToken: null,\n inSuccessfulContractCall: null,\n topic: ['topic1', 'topic2'],\n value: null,\n };\n const mockBlock: StellarBlock = {\n ledger: 2000,\n hash: '2000',\n events: [mockEvent],\n };\n\n const mockEventFilterValid: StellarEventFilter = {\n topics: ['topic1', 'topic2'],\n };\n\n const mockEventFilterInvalid: StellarEventFilter = {\n topics: ['topics3'],\n };\n\n it('should pass filter - valid address and topics', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterValid,\n 'testaddress',\n ),\n ).toEqual(true);\n });\n\n it('should pass filter - no address and valid topics', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid),\n ).toEqual(true);\n });\n\n it('should fail filter - valid address and invalid topics', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterInvalid,\n 'testaddress',\n ),\n ).toEqual(false);\n });\n\n it('should fail filter - event not found', function () {\n mockEventFilterInvalid.topics = ['topic1', 'topic2', 'topic3'];\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterInvalid,\n ),\n ).toEqual(false);\n });\n\n it('should pass filter - skip null topics', function () {\n mockEventFilterValid.topics = [null, 'topic2'];\n expect(\n StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid),\n ).toEqual(true);\n });\n\n it('should pass filer - valid contractId', function () {\n mockEventFilterValid.contractId = 'testaddress';\n expect(\n StellarBlockWrapped.filterEventProcessor(mockEvent, mockEventFilterValid),\n ).toEqual(true);\n });\n\n it('should fail filter - invalid contractId', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(mockEvent, {\n contractId: 'invalidaddress',\n }),\n ).toEqual(false);\n });\n\n it('should fail filter - invalid address', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterValid,\n 'invalidaddress',\n ),\n ).toEqual(false);\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"block.stellar.spec.js","sourceRoot":"","sources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AAS,EACT,oBAAoB,EACpB,gBAAgB,CACjB,CACF,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n StellarBlock,\n StellarBlockFilter,\n StellarEffect,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n StellarOperation,\n StellarOperationFilter,\n StellarTransaction,\n StellarTransactionFilter,\n} from '@subql/types-stellar';\nimport { Horizon, ServerApi } from 'stellar-sdk';\nimport { StellarBlockWrapped } from './block.stellar';\n\ndescribe('StellarBlockWrapped', () => {\n describe('filterBlocksProcessor', () => {\n it('should filter by modulo', () => {\n const block: StellarBlock = { sequence: 5 } as unknown as StellarBlock;\n const filter: StellarBlockFilter = { modulo: 2 };\n\n const result = StellarBlockWrapped.filterBlocksProcessor(block, filter);\n\n expect(result).toBe(false);\n });\n });\n\n describe('filterTransactionProcessor', () => {\n it('should filter by account', () => {\n const transaction: StellarTransaction = {\n source_account: 'account1',\n } as unknown as StellarTransaction;\n const filter: StellarTransactionFilter = { account: 'account2' };\n\n const result = StellarBlockWrapped.filterTransactionProcessor(\n transaction,\n filter,\n );\n\n expect(result).toBe(false);\n });\n\n it('should pass when account filter condition is fulfilled', () => {\n const transaction: StellarTransaction = {\n source_account: 'account1',\n } as unknown as StellarTransaction;\n const filter: StellarTransactionFilter = { account: 'account1' };\n\n const result = StellarBlockWrapped.filterTransactionProcessor(\n transaction,\n filter,\n );\n\n expect(result).toBe(true);\n });\n\n it('should pass when there is no account filter', () => {\n const transaction: StellarTransaction = {\n source_account: 'account1',\n } as unknown as StellarTransaction;\n const filter: StellarTransactionFilter = {};\n\n const result = StellarBlockWrapped.filterTransactionProcessor(\n transaction,\n filter,\n );\n\n expect(result).toBe(true);\n });\n });\n\n describe('filterOperationProcessor', () => {\n it('should filter by source_account and type', () => {\n const operation: StellarOperation = {\n source_account: 'account1',\n type: 'type1',\n } as unknown as StellarOperation;\n const filter: StellarOperationFilter = {\n sourceAccount: 'account2',\n type: Horizon.OperationResponseType.createAccount,\n };\n\n const result = StellarBlockWrapped.filterOperationProcessor(\n operation,\n filter,\n );\n\n expect(result).toBe(false);\n });\n\n it('should pass when source_account and type filter conditions are fulfilled', () => {\n const operation: StellarOperation = {\n source_account: 'account1',\n type: Horizon.OperationResponseType.createAccount,\n } as unknown as StellarOperation;\n const filter: StellarOperationFilter = {\n sourceAccount: 'account1',\n type: Horizon.OperationResponseType.createAccount,\n };\n\n const result = StellarBlockWrapped.filterOperationProcessor(\n operation,\n filter,\n );\n\n expect(result).toBe(true);\n });\n\n it('should pass when there are no filter conditions', () => {\n const operation: StellarOperation = {\n source_account: 'account1',\n type: 'type1',\n } as unknown as StellarOperation;\n const filter: StellarOperationFilter = {};\n\n const result = StellarBlockWrapped.filterOperationProcessor(\n operation,\n filter,\n );\n\n expect(result).toBe(true);\n });\n });\n\n describe('filterEffectProcessor', () => {\n it('should filter by account and type', () => {\n const effect: StellarEffect = {\n account: 'account1',\n type: 'type1',\n } as unknown as StellarEffect;\n const filter: StellarEffectFilter = {\n account: 'account2',\n type: 'type2',\n };\n\n const result = StellarBlockWrapped.filterEffectProcessor(effect, filter);\n\n expect(result).toBe(false);\n });\n\n it('should pass when account and type filter conditions are fulfilled', () => {\n const effect: StellarEffect = {\n account: 'account1',\n type: 'type1',\n } as unknown as StellarEffect;\n const filter: StellarEffectFilter = {\n account: 'account1',\n type: 'type1',\n };\n\n const result = StellarBlockWrapped.filterEffectProcessor(effect, filter);\n\n expect(result).toBe(true);\n });\n\n it('should pass when there are no filter conditions', () => {\n const effect: StellarEffect = {\n account: 'account1',\n type: 'type1',\n } as unknown as StellarEffect;\n const filter: StellarEffectFilter = {};\n\n const result = StellarBlockWrapped.filterEffectProcessor(effect, filter);\n\n expect(result).toBe(true);\n });\n });\n\n describe('StellarBlockWrapped', function () {\n const mockEvent: SorobanEvent = {\n ledger: null,\n transaction: null,\n operation: null,\n ledgerClosedAt: null,\n contractId: 'testaddress',\n id: null,\n pagingToken: null,\n inSuccessfulContractCall: null,\n topic: ['topic1', 'topic2'],\n value: null,\n };\n\n const mockEventFilterValid: SorobanEventFilter = {\n topics: ['topic1', 'topic2'],\n };\n\n const mockEventFilterInvalid: SorobanEventFilter = {\n topics: ['topics3'],\n };\n\n it('should pass filter - valid address and topics', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterValid,\n 'testaddress',\n ),\n ).toEqual(true);\n });\n\n it('should pass filter - no address and valid topics', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterValid,\n ),\n ).toEqual(true);\n });\n\n it('should fail filter - valid address and invalid topics', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterInvalid,\n 'testaddress',\n ),\n ).toEqual(false);\n });\n\n it('should fail filter - event not found', function () {\n mockEventFilterInvalid.topics = ['topic1', 'topic2', 'topic3'];\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterInvalid,\n ),\n ).toEqual(false);\n });\n\n it('should pass filter - skip null topics', function () {\n mockEventFilterValid.topics = [null, 'topic2'];\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterValid,\n ),\n ).toEqual(true);\n });\n\n it('should pass filer - valid contractId', function () {\n mockEventFilterValid.contractId = 'testaddress';\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterValid,\n ),\n ).toEqual(true);\n });\n\n it('should fail filter - invalid contractId', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(mockEvent, {\n contractId: 'invalidaddress',\n }),\n ).toEqual(false);\n });\n\n it('should fail filter - invalid address', function () {\n expect(\n StellarBlockWrapped.filterEventProcessor(\n mockEvent,\n mockEventFilterValid,\n 'invalidaddress',\n ),\n ).toEqual(false);\n });\n });\n});\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Account, Address, Contract, FeeBumpTransaction, Server, SorobanRpc, Transaction, xdr } from 'soroban-client';
|
|
2
2
|
import { Durability, GetEventsRequest } from 'soroban-client/lib/server';
|
|
3
|
-
import {
|
|
4
|
-
export default class SafeStellarProvider extends
|
|
3
|
+
import { SorobanServer } from './soroban.server';
|
|
4
|
+
export default class SafeStellarProvider extends SorobanServer {
|
|
5
5
|
private blockHeight;
|
|
6
6
|
private baseApi;
|
|
7
7
|
constructor(baseApi: Server, blockHeight: number);
|
package/dist/stellar/safe-api.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
const node_core_1 = require("@subql/node-core");
|
|
6
6
|
const server_1 = require("soroban-client/lib/server");
|
|
7
|
-
const
|
|
7
|
+
const soroban_server_1 = require("./soroban.server");
|
|
8
8
|
const logger = (0, node_core_1.getLogger)('safe.api.stellar');
|
|
9
|
-
class SafeStellarProvider extends
|
|
9
|
+
class SafeStellarProvider extends soroban_server_1.SorobanServer {
|
|
10
10
|
constructor(baseApi, blockHeight) {
|
|
11
|
-
super(baseApi.serverURL);
|
|
11
|
+
super(baseApi.serverURL.toString());
|
|
12
12
|
this.blockHeight = blockHeight;
|
|
13
13
|
this.baseApi = baseApi;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-api.js","sourceRoot":"","sources":["../../src/stellar/safe-api.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,gDAA6C;AAW7C,sDAAyE;AACzE,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,kBAAkB,CAAC,CAAC;AAE7C,MAAqB,mBAAoB,SAAQ,8BAAa;IAI5D,YAAY,OAAe,EAAE,WAAmB;QAC9C,KAAK,CAAC,OAAO,CAAC,SAAS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,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,mBAAmB,CACvB,WAA6C;QAE7C,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,kBAAkB,CACtB,WAA6C,EAC7C,iBAA0B;QAE1B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,eAAe,CACnB,WAA6C;QAE7C,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,cAAc,CAClB,OAA4C,EAC5C,YAAqB;QAErB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;CACF;AA3FD,sCA2FC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { getLogger } from '@subql/node-core';\nimport {\n Account,\n Address,\n Contract,\n FeeBumpTransaction,\n Server,\n SorobanRpc,\n Transaction,\n xdr,\n} from 'soroban-client';\nimport { Durability, GetEventsRequest } from 'soroban-client/lib/server';\nimport { SorobanServer } from './soroban.server';\n\nconst logger = getLogger('safe.api.stellar');\n\nexport default class SafeStellarProvider extends SorobanServer {\n private blockHeight: number;\n private baseApi: Server;\n\n constructor(baseApi: Server, blockHeight: number) {\n super(baseApi.serverURL.toString());\n this.blockHeight = blockHeight;\n this.baseApi = baseApi;\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getAccount(address: string): Promise<Account> {\n throw new Error('Method getAccount is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getHealth(): Promise<SorobanRpc.GetHealthResponse> {\n throw new Error('Method getHealth is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getContractData(\n contract: string | Address | Contract,\n key: xdr.ScVal,\n durability: Durability = Durability.Persistent,\n ): Promise<SorobanRpc.LedgerEntryResult> {\n throw new Error('Method getContractData is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getLedgerEntries(\n keys: xdr.LedgerKey[],\n ): Promise<SorobanRpc.GetLedgerEntriesResponse> {\n throw new Error('Method getLedgerEntries is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getTransaction(\n hash: string,\n ): Promise<SorobanRpc.GetTransactionResponse> {\n throw new Error('Method getTransaction is not implemented.');\n }\n\n async getEvents(\n request: GetEventsRequest,\n ): Promise<SorobanRpc.GetEventsResponse> {\n return this.baseApi.getEvents({\n startLedger: this.blockHeight,\n filters: [],\n });\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getNetwork(): Promise<SorobanRpc.GetNetworkResponse> {\n throw new Error('Method getNetwork is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getLatestLedger(): Promise<SorobanRpc.GetLatestLedgerResponse> {\n throw new Error('Method getLatestLedger is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async simulateTransaction(\n transaction: Transaction | FeeBumpTransaction,\n ): Promise<SorobanRpc.SimulateTransactionResponse> {\n throw new Error('Method simulateTransaction is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async prepareTransaction(\n transaction: Transaction | FeeBumpTransaction,\n networkPassphrase?: string,\n ): Promise<Transaction | FeeBumpTransaction> {\n throw new Error('Method prepareTransaction is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async sendTransaction(\n transaction: Transaction | FeeBumpTransaction,\n ): Promise<SorobanRpc.SendTransactionResponse> {\n throw new Error('Method sendTransaction is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async requestAirdrop(\n address: string | Pick<Account, 'accountId'>,\n friendbotUrl?: string,\n ): Promise<Account> {\n throw new Error('Method requestAirdrop is not implemented.');\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Server, SorobanRpc } from 'soroban-client';
|
|
2
|
+
import { GetEventsRequest } from 'soroban-client/lib/server';
|
|
3
|
+
export declare class SorobanServer extends Server {
|
|
4
|
+
private eventsCache;
|
|
5
|
+
private fetchEventsForSequence;
|
|
6
|
+
private updateEventCache;
|
|
7
|
+
getEvents(request: GetEventsRequest): Promise<SorobanRpc.GetEventsResponse>;
|
|
8
|
+
}
|