@subql/node-stellar 3.9.2-0 → 3.10.1-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/CHANGELOG.md +11 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +2 -2
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/stellar-block-dispatcher.d.ts +2 -1
- package/dist/indexer/blockDispatcher/stellar-block-dispatcher.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +2 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary/index.d.ts +1 -0
- package/dist/indexer/dictionary/index.js +20 -0
- package/dist/indexer/dictionary/index.js.map +1 -0
- package/dist/indexer/dictionary/stellarDictionary.service.d.ts +13 -0
- package/dist/indexer/dictionary/stellarDictionary.service.js +69 -0
- package/dist/indexer/dictionary/stellarDictionary.service.js.map +1 -0
- package/dist/indexer/dictionary/v1/index.d.ts +1 -0
- package/dist/indexer/dictionary/v1/index.js +20 -0
- package/dist/indexer/dictionary/v1/index.js.map +1 -0
- package/dist/indexer/dictionary/v1/stellarDictionaryV1.d.ts +16 -0
- package/dist/indexer/dictionary/v1/stellarDictionaryV1.js +210 -0
- package/dist/indexer/dictionary/v1/stellarDictionaryV1.js.map +1 -0
- package/dist/indexer/{fetch.service.spec.js → dictionary/v1/stellarDictionaryV1.spec.js} +51 -6
- package/dist/indexer/dictionary/v1/stellarDictionaryV1.spec.js.map +1 -0
- package/dist/indexer/dynamic-ds.service.js +3 -2
- package/dist/indexer/dynamic-ds.service.js.map +1 -1
- package/dist/indexer/fetch.module.js +3 -10
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.d.ts +4 -14
- package/dist/indexer/fetch.service.js +5 -192
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/indexer.manager.d.ts +2 -2
- package/dist/indexer/indexer.manager.js +1 -1
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.d.ts +0 -2
- package/dist/indexer/unfinalizedBlocks.service.js +4 -20
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker.service.d.ts +3 -3
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.d.ts +2 -2
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +2 -2
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -1
- package/dist/stellar/api.connection.d.ts +4 -4
- package/dist/stellar/api.connection.js.map +1 -1
- package/dist/stellar/api.service.stellar.d.ts +2 -2
- package/dist/stellar/api.service.stellar.js +0 -1
- package/dist/stellar/api.service.stellar.js.map +1 -1
- package/dist/stellar/api.service.stellar.spec.js +2 -3
- package/dist/stellar/api.service.stellar.spec.js.map +1 -1
- package/dist/stellar/api.stellar.d.ts +3 -2
- package/dist/stellar/api.stellar.js +2 -1
- package/dist/stellar/api.stellar.js.map +1 -1
- package/dist/stellar/api.stellar.spec.js +2 -2
- package/dist/stellar/api.stellar.spec.js.map +1 -1
- package/dist/stellar/utils.stellar.d.ts +4 -1
- package/dist/stellar/utils.stellar.js +16 -1
- package/dist/stellar/utils.stellar.js.map +1 -1
- package/package.json +6 -6
- package/dist/indexer/dictionary.service.d.ts +0 -8
- package/dist/indexer/dictionary.service.js +0 -46
- package/dist/indexer/dictionary.service.js.map +0 -1
- package/dist/indexer/fetch.service.spec.js.map +0 -1
- /package/dist/indexer/{fetch.service.spec.d.ts → dictionary/v1/stellarDictionaryV1.spec.d.ts} +0 -0
|
@@ -11,43 +11,27 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.UnfinalizedBlocksService =
|
|
14
|
+
exports.UnfinalizedBlocksService = void 0;
|
|
15
15
|
const common_1 = require("@nestjs/common");
|
|
16
16
|
const node_core_1 = require("@subql/node-core");
|
|
17
|
+
const utils_stellar_1 = require("../stellar/utils.stellar");
|
|
17
18
|
const logger = (0, node_core_1.getLogger)('unfinalized');
|
|
18
|
-
function blockToHeader(blockHeight) {
|
|
19
|
-
return {
|
|
20
|
-
blockHeight: blockHeight,
|
|
21
|
-
blockHash: blockHeight.toString(),
|
|
22
|
-
parentHash: (blockHeight - 1).toString(),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
exports.blockToHeader = blockToHeader;
|
|
26
19
|
let UnfinalizedBlocksService = class UnfinalizedBlocksService extends node_core_1.BaseUnfinalizedBlocksService {
|
|
27
20
|
constructor(apiService, nodeConfig, storeCache) {
|
|
28
21
|
super(nodeConfig, storeCache);
|
|
29
22
|
this.apiService = apiService;
|
|
30
23
|
}
|
|
31
|
-
blockToHeader(block) {
|
|
32
|
-
return blockToHeader(block.block.sequence);
|
|
33
|
-
}
|
|
34
24
|
async getFinalizedHead() {
|
|
35
25
|
const finalizedHeight = await this.apiService.api.getFinalizedBlockHeight();
|
|
36
|
-
return blockToHeader(finalizedHeight);
|
|
26
|
+
return (0, utils_stellar_1.blockToHeader)(finalizedHeight);
|
|
37
27
|
}
|
|
38
28
|
async getHeaderForHash(hash) {
|
|
39
29
|
return this.getHeaderForHeight(parseInt(hash, 10));
|
|
40
30
|
}
|
|
41
31
|
async getHeaderForHeight(height) {
|
|
42
|
-
return Promise.resolve(blockToHeader(height));
|
|
32
|
+
return Promise.resolve((0, utils_stellar_1.blockToHeader)(height));
|
|
43
33
|
}
|
|
44
34
|
};
|
|
45
|
-
__decorate([
|
|
46
|
-
(0, node_core_1.mainThreadOnly)(),
|
|
47
|
-
__metadata("design:type", Function),
|
|
48
|
-
__metadata("design:paramtypes", [Object]),
|
|
49
|
-
__metadata("design:returntype", Object)
|
|
50
|
-
], UnfinalizedBlocksService.prototype, "blockToHeader", null);
|
|
51
35
|
__decorate([
|
|
52
36
|
(0, node_core_1.mainThreadOnly)(),
|
|
53
37
|
__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../src/indexer/unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;AAEnC,2CAA4C;AAC5C,gDAQ0B;
|
|
1
|
+
{"version":3,"file":"unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../src/indexer/unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;AAEnC,2CAA4C;AAC5C,gDAQ0B;AAE1B,4DAAyD;AAEzD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAGjC,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,wCAA0C;IACtF,YACmB,UAAsB,EACvC,UAAsB,EACtB,UAA6B;QAE7B,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAJb,eAAU,GAAV,UAAU,CAAY;IAKzC,CAAC;IAGe,AAAN,KAAK,CAAC,gBAAgB;QAC9B,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC;QAC5E,OAAO,IAAA,6BAAa,EAAC,eAAe,CAAC,CAAC;IACxC,CAAC;IAGe,AAAN,KAAK,CAAC,gBAAgB,CAAC,IAAY;QAC3C,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAGe,AAAN,KAAK,CAAC,kBAAkB,CAAC,MAAc;QAC/C,OAAO,OAAO,CAAC,OAAO,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;CACF,CAAA;AAdiB;IADf,IAAA,0BAAc,GAAE;;;;gEAIhB;AAGe;IADf,IAAA,0BAAc,GAAE;;;;gEAGhB;AAGe;IADf,IAAA,0BAAc,GAAE;;;;kEAGhB;AAvBU,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAGoB,sBAAU;QAC3B,sBAAU;QACV,6BAAiB;GAJpB,wBAAwB,CAwBpC;AAxBY,4DAAwB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Injectable } from '@nestjs/common';\nimport {\n ApiService,\n BaseUnfinalizedBlocksService,\n Header,\n NodeConfig,\n StoreCacheService,\n getLogger,\n mainThreadOnly,\n} from '@subql/node-core';\nimport { BlockWrapper } from '@subql/types-stellar';\nimport { blockToHeader } from '../stellar/utils.stellar';\n\nconst logger = getLogger('unfinalized');\n\n@Injectable()\nexport class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<BlockWrapper> {\n constructor(\n private readonly apiService: ApiService,\n nodeConfig: NodeConfig,\n storeCache: StoreCacheService,\n ) {\n super(nodeConfig, storeCache);\n }\n\n @mainThreadOnly()\n protected async getFinalizedHead(): Promise<Header> {\n const finalizedHeight = await this.apiService.api.getFinalizedBlockHeight();\n return blockToHeader(finalizedHeight);\n }\n\n @mainThreadOnly()\n protected async getHeaderForHash(hash: string): Promise<Header> {\n return this.getHeaderForHeight(parseInt(hash, 10));\n }\n\n @mainThreadOnly()\n protected async getHeaderForHeight(height: number): Promise<Header> {\n return Promise.resolve(blockToHeader(height));\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SubqlStellarDataSource } from '@subql/common-stellar';
|
|
2
|
-
import { NodeConfig, IProjectService, ProcessBlockResponse, ApiService, BaseWorkerService, IProjectUpgradeService } from '@subql/node-core';
|
|
2
|
+
import { NodeConfig, IProjectService, ProcessBlockResponse, ApiService, BaseWorkerService, IProjectUpgradeService, IBlock } from '@subql/node-core';
|
|
3
3
|
import { BlockWrapper } from '@subql/types-stellar';
|
|
4
4
|
import { StellarProjectDs } from '../../configure/SubqueryProject';
|
|
5
5
|
import { IndexerManager } from '../indexer.manager';
|
|
@@ -16,9 +16,9 @@ export declare class WorkerService extends BaseWorkerService<BlockWrapper, Fetch
|
|
|
16
16
|
private apiService;
|
|
17
17
|
private indexerManager;
|
|
18
18
|
constructor(apiService: ApiService, indexerManager: IndexerManager, projectService: IProjectService<StellarProjectDs>, projectUpgradeService: IProjectUpgradeService, nodeConfig: NodeConfig);
|
|
19
|
-
protected fetchChainBlock(heights: number, extra: {}): Promise<BlockWrapper
|
|
19
|
+
protected fetchChainBlock(heights: number, extra: {}): Promise<IBlock<BlockWrapper>>;
|
|
20
20
|
protected toBlockResponse(block: BlockWrapper): {
|
|
21
21
|
parentHash: string;
|
|
22
22
|
};
|
|
23
|
-
protected processFetchedBlock(block: BlockWrapper
|
|
23
|
+
protected processFetchedBlock(block: IBlock<BlockWrapper>, dataSources: SubqlStellarDataSource[]): Promise<ProcessBlockResponse>;
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,6DAA+C;AAC/C,2CAAoD;AAEpD,
|
|
1
|
+
{"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,6DAA+C;AAC/C,2CAAoD;AAEpD,gDAS0B;AAG1B,wDAAoD;AAWpD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,mBAAmB,8BAAQ,EAAE,CAAC,CAAC;AAGjD,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,6BAKlC;IACC,YACU,UAAsB,EACtB,cAA8B,EAEtC,cAAiD,EAEjD,qBAA6C,EAC7C,UAAsB;QAEtB,KAAK,CAAC,cAAc,EAAE,qBAAqB,EAAE,UAAU,CAAC,CAAC;QARjD,eAAU,GAAV,UAAU,CAAY;QACtB,mBAAc,GAAd,cAAc,CAAgB;IAQxC,CAAC;IACS,KAAK,CAAC,eAAe,CAC7B,OAAe,EACf,KAAS;QAET,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAmB;QAC3C,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,mBAAmB,CACjC,KAA2B,EAC3B,WAAqC;QAErC,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;CACF,CAAA;AArCY,aAAa;IADzB,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCAJb,sBAAU;QACN,gCAAc,kBAK1B,sBAAU;GAbb,aAAa,CAqCzB;AArCY,sCAAa","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { threadId } from 'node:worker_threads';\nimport { Inject, Injectable } from '@nestjs/common';\nimport { SubqlStellarDataSource } from '@subql/common-stellar';\nimport {\n NodeConfig,\n getLogger,\n IProjectService,\n ProcessBlockResponse,\n ApiService,\n BaseWorkerService,\n IProjectUpgradeService,\n IBlock,\n} from '@subql/node-core';\nimport { BlockWrapper } from '@subql/types-stellar';\nimport { StellarProjectDs } from '../../configure/SubqueryProject';\nimport { IndexerManager } from '../indexer.manager';\n\nexport type FetchBlockResponse = { parentHash: string } | undefined;\n\nexport type WorkerStatusResponse = {\n threadId: number;\n isIndexing: boolean;\n fetchedBlocks: number;\n toFetchBlocks: number;\n};\n\nconst logger = getLogger(`Worker Service #${threadId}`);\n\n@Injectable()\nexport class WorkerService extends BaseWorkerService<\n BlockWrapper,\n FetchBlockResponse,\n SubqlStellarDataSource,\n {}\n> {\n constructor(\n private apiService: ApiService,\n private indexerManager: IndexerManager,\n @Inject('IProjectService')\n projectService: IProjectService<StellarProjectDs>,\n @Inject('IProjectUpgradeService')\n projectUpgradeService: IProjectUpgradeService,\n nodeConfig: NodeConfig,\n ) {\n super(projectService, projectUpgradeService, nodeConfig);\n }\n protected async fetchChainBlock(\n heights: number,\n extra: {},\n ): Promise<IBlock<BlockWrapper>> {\n const [block] = await this.apiService.fetchBlocks([heights]);\n return block;\n }\n\n protected toBlockResponse(block: BlockWrapper): { parentHash: string } {\n return {\n parentHash: block.block.prev_hash,\n };\n }\n\n protected async processFetchedBlock(\n block: IBlock<BlockWrapper>,\n dataSources: SubqlStellarDataSource[],\n ): Promise<ProcessBlockResponse> {\n return this.indexerManager.indexBlock(block, dataSources);\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Header, HostUnfinalizedBlocks, IUnfinalizedBlocksService } from '@subql/node-core';
|
|
1
|
+
import { Header, HostUnfinalizedBlocks, IUnfinalizedBlocksService, IBlock } from '@subql/node-core';
|
|
2
2
|
import { BlockWrapper } from '@subql/types-stellar';
|
|
3
3
|
export declare class WorkerUnfinalizedBlocksService implements IUnfinalizedBlocksService<BlockWrapper> {
|
|
4
4
|
private host;
|
|
5
5
|
constructor(host: HostUnfinalizedBlocks);
|
|
6
6
|
processUnfinalizedBlockHeader(header: Header): Promise<number | null>;
|
|
7
|
-
processUnfinalizedBlocks({ block, }: BlockWrapper): Promise<number | null>;
|
|
7
|
+
processUnfinalizedBlocks({ block, }: IBlock<BlockWrapper>): Promise<number | null>;
|
|
8
8
|
init(reindex: (targetHeight: number) => Promise<void>): Promise<number>;
|
|
9
9
|
resetUnfinalizedBlocks(): void;
|
|
10
10
|
resetLastFinalizedVerifiedHeight(): void;
|
|
@@ -13,7 +13,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.WorkerUnfinalizedBlocksService = void 0;
|
|
15
15
|
const common_1 = require("@nestjs/common");
|
|
16
|
-
const
|
|
16
|
+
const utils_stellar_1 = require("../../stellar/utils.stellar");
|
|
17
17
|
let WorkerUnfinalizedBlocksService = class WorkerUnfinalizedBlocksService {
|
|
18
18
|
constructor(host) {
|
|
19
19
|
this.host = host;
|
|
@@ -22,7 +22,7 @@ let WorkerUnfinalizedBlocksService = class WorkerUnfinalizedBlocksService {
|
|
|
22
22
|
return this.host.unfinalizedBlocksProcess(header);
|
|
23
23
|
}
|
|
24
24
|
async processUnfinalizedBlocks({ block, }) {
|
|
25
|
-
return this.host.unfinalizedBlocksProcess((0,
|
|
25
|
+
return this.host.unfinalizedBlocksProcess((0, utils_stellar_1.blockToHeader)(block.block.sequence));
|
|
26
26
|
}
|
|
27
27
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
28
28
|
init(reindex) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;AAEnC,2CAA4C;
|
|
1
|
+
{"version":3,"file":"worker.unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;AAEnC,2CAA4C;AAQ5C,+DAA4D;AAGrD,IAAM,8BAA8B,GAApC,MAAM,8BAA8B;IAGzC,YAAoB,IAA2B;QAA3B,SAAI,GAAJ,IAAI,CAAuB;IAAG,CAAC;IAEnD,KAAK,CAAC,6BAA6B,CAAC,MAAc;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,wBAAwB,CAAC,EAC7B,KAAK,GACgB;QACrB,OAAO,IAAI,CAAC,IAAI,CAAC,wBAAwB,CACvC,IAAA,6BAAa,EAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CACpC,CAAC;IACJ,CAAC;IAED,qEAAqE;IACrE,IAAI,CAAC,OAAgD;QACnD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,sBAAsB;QACpB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,gCAAgC;QAC9B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,qEAAqE;IACrE,4BAA4B;QAC1B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;CACF,CAAA;AA/BY,8BAA8B;IAD1C,IAAA,mBAAU,GAAE;;GACA,8BAA8B,CA+B1C;AA/BY,wEAA8B","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Injectable } from '@nestjs/common';\nimport {\n Header,\n HostUnfinalizedBlocks,\n IUnfinalizedBlocksService,\n IBlock,\n} from '@subql/node-core';\nimport { BlockWrapper } from '@subql/types-stellar';\nimport { blockToHeader } from '../../stellar/utils.stellar';\n\n@Injectable()\nexport class WorkerUnfinalizedBlocksService\n implements IUnfinalizedBlocksService<BlockWrapper>\n{\n constructor(private host: HostUnfinalizedBlocks) {}\n\n async processUnfinalizedBlockHeader(header: Header): Promise<number | null> {\n return this.host.unfinalizedBlocksProcess(header);\n }\n\n async processUnfinalizedBlocks({\n block,\n }: IBlock<BlockWrapper>): Promise<number | null> {\n return this.host.unfinalizedBlocksProcess(\n blockToHeader(block.block.sequence),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n init(reindex: (targetHeight: number) => Promise<void>): Promise<number> {\n throw new Error('This method should not be called from a worker');\n }\n resetUnfinalizedBlocks(): void {\n throw new Error('This method should not be called from a worker');\n }\n resetLastFinalizedVerifiedHeight(): void {\n throw new Error('This method should not be called from a worker');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getMetadataUnfinalizedBlocks(): Promise<Header[]> {\n throw new Error('This method should not be called from a worker');\n }\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
2
|
-
import { ApiConnectionError, IApiConnectionSpecific, NetworkMetadataPayload } from '@subql/node-core';
|
|
2
|
+
import { ApiConnectionError, IApiConnectionSpecific, NetworkMetadataPayload, IBlock } from '@subql/node-core';
|
|
3
3
|
import { StellarBlockWrapper } from '@subql/types-stellar';
|
|
4
4
|
import { StellarApi } from './api.stellar';
|
|
5
5
|
import SafeStellarProvider from './safe-api';
|
|
6
6
|
import { SorobanServer } from './soroban.server';
|
|
7
|
-
type FetchFunc = (api: StellarApi, batch: number[]) => Promise<StellarBlockWrapper[]>;
|
|
8
|
-
export declare class StellarApiConnection implements IApiConnectionSpecific<StellarApi, SafeStellarProvider, StellarBlockWrapper[]> {
|
|
7
|
+
type FetchFunc = (api: StellarApi, batch: number[]) => Promise<IBlock<StellarBlockWrapper>[]>;
|
|
8
|
+
export declare class StellarApiConnection implements IApiConnectionSpecific<StellarApi, SafeStellarProvider, IBlock<StellarBlockWrapper>[]> {
|
|
9
9
|
unsafeApi: StellarApi;
|
|
10
10
|
private fetchBlocksBatches;
|
|
11
11
|
readonly networkMeta: NetworkMetadataPayload;
|
|
@@ -14,7 +14,7 @@ export declare class StellarApiConnection implements IApiConnectionSpecific<Stel
|
|
|
14
14
|
safeApi(height: number): SafeStellarProvider;
|
|
15
15
|
apiConnect(): Promise<void>;
|
|
16
16
|
apiDisconnect(): Promise<void>;
|
|
17
|
-
fetchBlocks(heights: number[]): Promise<StellarBlockWrapper[]>;
|
|
17
|
+
fetchBlocks(heights: number[]): Promise<IBlock<StellarBlockWrapper>[]>;
|
|
18
18
|
handleError: typeof StellarApiConnection.handleError;
|
|
19
19
|
static handleError(e: Error): ApiConnectionError;
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/stellar/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,
|
|
1
|
+
{"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/stellar/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,gDAU0B;AAE1B,+CAA2C;AAC3C,0DAA6C;AAQ7C,MAAa,oBAAoB;IAU/B,YACS,SAAqB,EACpB,kBAA6B;QAD9B,cAAS,GAAT,SAAS,CAAY;QACpB,uBAAkB,GAAlB,kBAAkB,CAAW;QAwCvC,gBAAW,GAAG,oBAAoB,CAAC,WAAW,CAAC;QAtC7C,IAAI,CAAC,WAAW,GAAG;YACjB,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE;YAC7B,QAAQ,EAAE,SAAS,CAAC,WAAW,EAAE;YACjC,WAAW,EAAE,SAAS,CAAC,cAAc,EAAE;SACxC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,QAAgB,EAChB,iBAA4B,EAC5B,YAA2B,EAC3B,OAAuB;QAEvB,MAAM,GAAG,GAAG,IAAI,wBAAU,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QAE5D,MAAM,GAAG,CAAC,IAAI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B,CACtC,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;SACH;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA5ED,oDA4EC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n IApiConnectionSpecific,\n NetworkMetadataPayload,\n TimeoutError,\n RateLimitError,\n DisconnectionError,\n LargeResponseError,\n IBlock,\n} from '@subql/node-core';\nimport { StellarBlockWrapper } from '@subql/types-stellar';\nimport { StellarApi } from './api.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\n\ntype FetchFunc = (\n api: StellarApi,\n batch: number[],\n) => Promise<IBlock<StellarBlockWrapper>[]>;\n\nexport class StellarApiConnection\n implements\n IApiConnectionSpecific<\n StellarApi,\n SafeStellarProvider,\n IBlock<StellarBlockWrapper>[]\n >\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n constructor(\n public unsafeApi: StellarApi,\n private fetchBlocksBatches: FetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.getChainId(),\n specName: unsafeApi.getSpecName(),\n genesisHash: unsafeApi.getGenesisHash(),\n };\n }\n\n static async create(\n endpoint: string,\n fetchBlockBatches: FetchFunc,\n eventEmitter: EventEmitter2,\n soroban?: SorobanServer,\n ): Promise<StellarApiConnection> {\n const api = new StellarApi(endpoint, eventEmitter, soroban);\n\n await api.init();\n\n return new StellarApiConnection(api, fetchBlockBatches);\n }\n\n safeApi(height: number): SafeStellarProvider {\n //safe api not implemented\n return new SafeStellarProvider(null, height);\n }\n\n async apiConnect(): Promise<void> {\n await this.unsafeApi.connect();\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async fetchBlocks(heights: number[]): Promise<IBlock<StellarBlockWrapper>[]> {\n const blocks = await this.fetchBlocksBatches(this.unsafeApi, heights);\n return blocks;\n }\n\n handleError = StellarApiConnection.handleError;\n\n static handleError(e: Error): ApiConnectionError {\n let formatted_error: ApiConnectionError;\n if (e.message.includes(`Timeout`)) {\n formatted_error = new TimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = new DisconnectionError(e);\n } else if (\n e.message.includes(`Rate Limit Exceeded`) ||\n e.message.includes('Too Many Requests')\n ) {\n formatted_error = new RateLimitError(e);\n } else if (e.message.includes(`limit must not exceed`)) {\n formatted_error = new LargeResponseError(e);\n } else {\n formatted_error = new ApiConnectionError(\n e.name,\n e.message,\n ApiErrorType.Default,\n );\n }\n return formatted_error;\n }\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
2
|
-
import { ApiService, ConnectionPoolService, ProjectUpgradeService } from '@subql/node-core';
|
|
2
|
+
import { ApiService, ConnectionPoolService, ProjectUpgradeService, IBlock } from '@subql/node-core';
|
|
3
3
|
import { StellarBlockWrapper } from '@subql/types-stellar';
|
|
4
4
|
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
5
5
|
import { StellarApiConnection } from './api.connection';
|
|
6
6
|
import { StellarApi } from './api.stellar';
|
|
7
7
|
import SafeStellarProvider from './safe-api';
|
|
8
|
-
export declare class StellarApiService extends ApiService<StellarApi, SafeStellarProvider, StellarBlockWrapper[]> {
|
|
8
|
+
export declare class StellarApiService extends ApiService<StellarApi, SafeStellarProvider, IBlock<StellarBlockWrapper>[]> {
|
|
9
9
|
private project;
|
|
10
10
|
private projectUpgradeService;
|
|
11
11
|
constructor(project: SubqueryProject, projectUpgradeService: ProjectUpgradeService, connectionPoolService: ConnectionPoolService<StellarApiConnection>, eventEmitter: EventEmitter2);
|
|
@@ -22,7 +22,6 @@ const SubqueryProject_1 = require("../configure/SubqueryProject");
|
|
|
22
22
|
const api_connection_1 = require("./api.connection");
|
|
23
23
|
const soroban_server_1 = require("./soroban.server");
|
|
24
24
|
const logger = (0, node_core_1.getLogger)('api');
|
|
25
|
-
const MAX_RECONNECT_ATTEMPTS = 5;
|
|
26
25
|
let StellarApiService = class StellarApiService extends node_core_1.ApiService {
|
|
27
26
|
constructor(project, projectUpgradeService, connectionPoolService, eventEmitter) {
|
|
28
27
|
super(connectionPoolService, eventEmitter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AAKtD,
|
|
1
|
+
{"version":3,"file":"api.service.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AAKtD,gDAM0B;AAE1B,kEAIsC;AACtC,qDAAwD;AAGxD,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,sBAItC;IACC,YACsC,OAAwB,EAEpD,qBAA4C,EACpD,qBAAkE,EAClE,YAA2B;QAE3B,KAAK,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;QANP,YAAO,GAAP,OAAO,CAAiB;QAEpD,0BAAqB,GAArB,qBAAqB,CAAuB;IAKtD,CAAC;IAED,KAAK,CAAC,IAAI;;QACR,IAAI,OAAoC,CAAC;QACzC,IAAI;YACF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;SAChC;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,C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AAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCADY,iCAAe;QAE7B,iCAAqB;QAC7B,iCAAqB;QAC9B,6BAAa;GAVlB,iBAAiB,CAuH7B;AAvHY,8CAAiB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n StellarProjectNetwork,\n StellarProjectNetworkConfig,\n} from '@subql/common-stellar';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n ProjectUpgradeService,\n IBlock,\n} from '@subql/node-core';\nimport { StellarBlockWrapper } from '@subql/types-stellar';\nimport {\n StellarProjectDs,\n SubqueryProject,\n dsHasSorobanEventHandler,\n} from '../configure/SubqueryProject';\nimport { StellarApiConnection } from './api.connection';\nimport { StellarApi } from './api.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class StellarApiService extends ApiService<\n StellarApi,\n SafeStellarProvider,\n IBlock<StellarBlockWrapper>[]\n> {\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n @Inject('IProjectUpgradeService')\n private projectUpgradeService: ProjectUpgradeService,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n ) {\n super(connectionPoolService, eventEmitter);\n }\n\n async init(): Promise<StellarApiService> {\n let network: StellarProjectNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const sorobanEndpoint: string | undefined =\n network.sorobanEndpoint ??\n (\n this.projectUpgradeService.getProject(Number.MAX_SAFE_INTEGER)\n .network as StellarProjectNetwork\n ).soroban;\n\n if (!network.sorobanEndpoint && sorobanEndpoint) {\n //update sorobanEndpoint from parent project\n this.project.network.sorobanEndpoint = sorobanEndpoint;\n }\n\n if (\n dsHasSorobanEventHandler([\n ...this.project.dataSources,\n ...(this.project.templates as StellarProjectDs[]),\n ]) &&\n !sorobanEndpoint\n ) {\n throw new Error(\n `Soroban network endpoint must be provided for network. chainId=\"${this.project.network.chainId}\"`,\n );\n }\n\n const sorobanClient = sorobanEndpoint\n ? new SorobanServer(sorobanEndpoint)\n : undefined;\n\n await this.createConnections(\n network,\n (endpoint) =>\n StellarApiConnection.create(\n endpoint,\n this.fetchBlockBatches,\n this.eventEmitter,\n sorobanClient,\n ),\n //eslint-disable-next-line @typescript-eslint/require-await\n async (connection: StellarApiConnection) => {\n const api = connection.unsafeApi;\n return api.getChainId();\n },\n );\n\n return this;\n }\n\n get api(): StellarApi {\n return this.unsafeApi;\n }\n\n safeApi(height: number): SafeStellarProvider {\n const maxRetries = 5;\n\n const handler: ProxyHandler<SafeStellarProvider> = {\n get: (target, prop, receiver) => {\n const originalMethod = target[prop as keyof SafeStellarProvider];\n if (typeof originalMethod === 'function') {\n return async (...args: any[]) => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error) {\n logger.warn(\n `Request failed with api at height ${height} (retry ${retries}): ${error.message}`,\n );\n throwingError = error;\n currentApi = this.unsafeApi.getSafeApi(height);\n retries++;\n }\n }\n\n logger.error(\n `Maximum retries (${maxRetries}) exceeded for api at height ${height}`,\n );\n throw throwingError;\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n };\n\n return new Proxy(this.unsafeApi.getSafeApi(height), handler);\n }\n\n private async fetchBlockBatches(\n api: StellarApi,\n batch: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n return api.fetchBlocks(batch);\n }\n}\n"]}
|
|
@@ -11,7 +11,6 @@ const lodash_1 = require("lodash");
|
|
|
11
11
|
const stellar_sdk_1 = require("stellar-sdk");
|
|
12
12
|
const api_service_stellar_1 = require("./api.service.stellar");
|
|
13
13
|
const api_stellar_1 = require("./api.stellar");
|
|
14
|
-
const block_stellar_1 = require("./block.stellar");
|
|
15
14
|
const HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';
|
|
16
15
|
const SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';
|
|
17
16
|
function testSubqueryProject(endpoint, sorobanEndpoint) {
|
|
@@ -69,7 +68,7 @@ describe('StellarApiService', () => {
|
|
|
69
68
|
const latestHeight = await apiService.api.getFinalizedBlockHeight();
|
|
70
69
|
const blocks = await apiService.fetchBlocks((0, lodash_1.range)(latestHeight - 1, latestHeight));
|
|
71
70
|
expect(blocks).toBeDefined();
|
|
72
|
-
expect(blocks).toEqual(
|
|
71
|
+
expect(blocks[0].block.block.sequence).toEqual(latestHeight - 1);
|
|
73
72
|
});
|
|
74
73
|
it('should throw error when chainId does not match', async () => {
|
|
75
74
|
const faultyProject = Object.assign(Object.assign({}, testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT)), { network: Object.assign(Object.assign({}, testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT).network), { chainId: 'Incorrect ChainId' }) });
|
|
@@ -110,7 +109,7 @@ describe.skip('testnet StellarApiService', () => {
|
|
|
110
109
|
const blocks = await apiService.fetchBlocks([228236]);
|
|
111
110
|
expect(blocks).toBeDefined();
|
|
112
111
|
const block228236 = blocks[0];
|
|
113
|
-
const transferEvent = block228236.events.find((e) => e.id === '0000980266155778048-0000000001');
|
|
112
|
+
const transferEvent = block228236.block.events.find((e) => e.id === '0000980266155778048-0000000001');
|
|
114
113
|
const [sys, from, to] = transferEvent.topic;
|
|
115
114
|
const decodedFrom = (0, stellar_sdk_1.scValToNative)(from).toString();
|
|
116
115
|
const decodedTo = (0, stellar_sdk_1.scValToNative)(to).toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAA4E;AAC5E,gDAAmE;AACnE,qCAAwC;AACxC,mCAAqC;AACrC,6CAA4C;AAE5C,+DAA0D;AAC1D,+CAA2C;
|
|
1
|
+
{"version":3,"file":"api.service.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAA4E;AAC5E,gDAAmE;AACnE,qCAAwC;AACxC,mCAAqC;AACrC,6CAA4C;AAE5C,+DAA0D;AAC1D,+CAA2C;AAG3C,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,eAAuB;IAEvB,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,QAAQ,CAAC;YACpB,eAAe;YACf,OAAO,EAAE,wCAAwC;SAClD;QACD,WAAW,EAAE,EAAE;QACf,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI,uBAAa,CAAC,EAAE,CAAC;QAC7B,SAAS,EAAE,EAAE;KACgB,CAAC;AAClC,CAAC;AAED,MAAM,iBAAiB,GAAG,KAAK,EAC7B,WAAmB,aAAa,EAChC,UAAkB,gBAAgB,EAClC,OAAyB,EACuB,EAAE;IAClD,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;QAC5C,SAAS,EAAE;YACT,iCAAqB;YACrB,iCAA0B;YAC1B;gBACE,OAAO,EAAE,wBAAwB;gBACjC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gB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C,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { INestApplication } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { Test } from '@nestjs/testing';\nimport { ConnectionPoolService, delay, NodeConfig } from '@subql/node-core';\nimport { ConnectionPoolStateManager } from '@subql/node-core/dist';\nimport { GraphQLSchema } from 'graphql';\nimport { range, some } from 'lodash';\nimport { scValToNative } from 'stellar-sdk';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApiService } from './api.service.stellar';\nimport { StellarApi } from './api.stellar';\nimport { StellarBlockWrapped } from './block.stellar';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\nfunction testSubqueryProject(\n endpoint: string,\n sorobanEndpoint: string,\n): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Future Network ; October 2022',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n}\n\nconst prepareApiService = async (\n endpoint: string = HTTP_ENDPOINT,\n soroban: string = SOROBAN_ENDPOINT,\n project?: SubqueryProject,\n): Promise<[StellarApiService, INestApplication]> => {\n const module = await Test.createTestingModule({\n providers: [\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: 'IProjectUpgradeService',\n useFactory: () => ({}),\n },\n {\n provide: NodeConfig,\n useFactory: () => ({}),\n },\n {\n provide: 'ISubqueryProject',\n useFactory: () => project ?? testSubqueryProject(endpoint, soroban),\n },\n StellarApiService,\n ],\n imports: [EventEmitterModule.forRoot()],\n }).compile();\n\n const app = module.createNestApplication();\n await app.init();\n const apiService = app.get(StellarApiService);\n await apiService.init();\n return [apiService, app];\n};\n\njest.setTimeout(90000);\ndescribe('StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService();\n });\n\n it('should instantiate api', () => {\n expect(apiService.api).toBeInstanceOf(StellarApi);\n });\n\n it('should fetch blocks', async () => {\n const latestHeight = await apiService.api.getFinalizedBlockHeight();\n const blocks = await apiService.fetchBlocks(\n range(latestHeight - 1, latestHeight),\n );\n expect(blocks).toBeDefined();\n expect(blocks[0].block.block.sequence).toEqual(latestHeight - 1);\n });\n\n it('should throw error when chainId does not match', async () => {\n const faultyProject = {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT),\n network: {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT).network,\n chainId: 'Incorrect ChainId',\n },\n };\n\n await expect(\n prepareApiService(\n HTTP_ENDPOINT,\n SOROBAN_ENDPOINT,\n faultyProject as unknown as SubqueryProject,\n ),\n ).rejects.toThrow();\n });\n\n it('fails after maximum retries', async () => {\n const api = apiService.unsafeApi;\n\n // Mock the fetchBlocks method to always throw an error\n (api as any).fetchBlocks = jest\n .fn()\n .mockRejectedValue(new Error('Network error'));\n\n await expect(\n (api as any).fetchBlocks(range(50000, 50100)),\n ).rejects.toThrow();\n });\n});\n\n// Skip test as rpc is pruned and block can be missing,\n// To test this, find any block with transfer event first\ndescribe.skip('testnet StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n function testSubqueryProject2(\n endpoint: string,\n sorobanEndpoint: string,\n ): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Network ; September 2015',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n }\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n testSubqueryProject2(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n ),\n );\n });\n\n it('should fetch blocks, and decode address', async () => {\n const blocks = await apiService.fetchBlocks([228236]);\n expect(blocks).toBeDefined();\n\n const block228236 = blocks[0];\n const transferEvent = block228236.block.events.find(\n (e) => e.id === '0000980266155778048-0000000001',\n );\n\n const [sys, from, to] = transferEvent.topic;\n const decodedFrom = scValToNative(from).toString();\n const decodedTo = scValToNative(to).toString();\n\n console.log(scValToNative(sys));\n console.log(decodedFrom);\n console.log(decodedTo);\n });\n});\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
2
|
+
import { IBlock } from '@subql/node-core';
|
|
2
3
|
import { ApiWrapper, SorobanEvent, StellarBlockWrapper } from '@subql/types-stellar';
|
|
3
4
|
import { Server, ServerApi } from 'stellar-sdk/lib/horizon';
|
|
4
5
|
import SafeStellarProvider from './safe-api';
|
|
5
6
|
import { SorobanServer } from './soroban.server';
|
|
6
|
-
export declare class StellarApi implements ApiWrapper
|
|
7
|
+
export declare class StellarApi implements ApiWrapper {
|
|
7
8
|
private endpoint;
|
|
8
9
|
private eventEmitter;
|
|
9
10
|
private sorobanClient?;
|
|
@@ -30,7 +31,7 @@ export declare class StellarApi implements ApiWrapper<StellarBlockWrapper> {
|
|
|
30
31
|
private wrapOperationsForTx;
|
|
31
32
|
private wrapTransactionsForLedger;
|
|
32
33
|
private fetchAndWrapLedger;
|
|
33
|
-
fetchBlocks(bufferBlocks: number[]): Promise<StellarBlockWrapper[]>;
|
|
34
|
+
fetchBlocks(bufferBlocks: number[]): Promise<IBlock<StellarBlockWrapper>[]>;
|
|
34
35
|
get api(): Server;
|
|
35
36
|
getSafeApi(blockHeight: number): SafeStellarProvider;
|
|
36
37
|
connect(): Promise<void>;
|
|
@@ -11,6 +11,7 @@ const lodash_1 = require("lodash");
|
|
|
11
11
|
const block_stellar_1 = require("../stellar/block.stellar");
|
|
12
12
|
const safe_api_1 = __importDefault(require("./safe-api"));
|
|
13
13
|
const stellar_server_1 = require("./stellar.server");
|
|
14
|
+
const utils_stellar_1 = require("./utils.stellar");
|
|
14
15
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
15
16
|
const { version: packageVersion } = require('../../package.json');
|
|
16
17
|
const logger = (0, node_core_1.getLogger)('api.Stellar');
|
|
@@ -217,7 +218,7 @@ class StellarApi {
|
|
|
217
218
|
});
|
|
218
219
|
});
|
|
219
220
|
const wrappedLedgerInstance = new block_stellar_1.StellarBlockWrapped(wrappedLedger, wrappedLedger.transactions, wrappedLedger.operations, wrappedLedger.effects, wrappedLedger.events);
|
|
220
|
-
return wrappedLedgerInstance;
|
|
221
|
+
return (0, utils_stellar_1.formatBlockUtil)(wrappedLedgerInstance);
|
|
221
222
|
}
|
|
222
223
|
async fetchBlocks(bufferBlocks) {
|
|
223
224
|
const ledgers = await Promise.all(bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,gDAA6C;AAU7C,mCAAmC;AAEnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AAEjD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQrB,YACU,QAAgB,EAChB,YAA2B,EAC3B,aAA6B;QAF7B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAe;QAC3B,kBAAa,GAAb,aAAa,CAAgB;QAErC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,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M,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,WAAW,CAAC,CAAQ,EAAE,MAAc;QAClC,IAAI,CAAC,CAAC,OAAO,KAAK,+BAA+B,EAAE;YACjD,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;SAC/E;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA5XD,gCA4XC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { Server, ServerApi } from 'stellar-sdk/lib/horizon';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper<StellarBlockWrapper> {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n private genesisHash: string;\n private name: string;\n\n constructor(\n private endpoint: string,\n private eventEmitter: EventEmitter2,\n private sorobanClient?: SorobanServer,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Server.Options = {\n allowHttp: protocolStr === 'http',\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n async getFinalizedBlock(): Promise<ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): string {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<ServerApi.TransactionRecord[]> {\n const txs: ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<ServerApi.OperationRecord[]> {\n const operations: ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<ServerApi.EffectRecord[]> {\n const effects: ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getTransactionApplicationOrder(eventId: string) {\n // Right shift the ID by 12 bits to exclude the Operation Index\n const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);\n\n // Create a mask for 20 bits to ignore the Ledger Sequence Number\n const mask = BigInt((1 << 20) - 1);\n\n // Apply bitwise AND operation with the mask to get the Transaction Application Order\n const transactionApplicationOrder = shiftedId & mask;\n return Number(transactionApplicationOrder);\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n applicationOrder: number,\n sequence: number,\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const events = eventsForSequence.filter(\n (event) =>\n this.getTransactionApplicationOrder(event.id) === applicationOrder,\n );\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: ServerApi.TransactionRecord[],\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx, index) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<StellarBlockWrapper> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e) {\n if (e.message === 'start is after newest ledger') {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.\n To resolve this issue, please check you endpoint node start height`);\n }\n\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return wrappedLedgerInstance;\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<StellarBlockWrapper[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(null, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,gDAAqD;AAUrD,mCAAmC;AAEnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAkD;AAElD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQrB,YACU,QAAgB,EAChB,YAA2B,EAC3B,aAA6B;QAF7B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAe;QAC3B,kBAAa,GAAb,aAAa,CAAgB;QAErC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEpE,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAE9C,MAAM,CAAC,IAAI,CAAC,aAAa,QAAQ,aAAa,WAAW,EAAE,CAAC,CAAC;QAC7D,IAAI,WAAW,KAAK,OAAO,IAAI,WAAW,KAAK,MAAM,EAAE;YACrD,MAAM,OAAO,GAAmB;gBAC9B,SAA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C;IACX,CAAC;CACF;AA9XD,gCA8XC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { Server, ServerApi } from 'stellar-sdk/lib/horizon';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\nimport { formatBlockUtil } from './utils.stellar';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n private genesisHash: string;\n private name: string;\n\n constructor(\n private endpoint: string,\n private eventEmitter: EventEmitter2,\n private sorobanClient?: SorobanServer,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Server.Options = {\n allowHttp: protocolStr === 'http',\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n async getFinalizedBlock(): Promise<ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): string {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<ServerApi.TransactionRecord[]> {\n const txs: ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<ServerApi.OperationRecord[]> {\n const operations: ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<ServerApi.EffectRecord[]> {\n const effects: ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getTransactionApplicationOrder(eventId: string) {\n // Right shift the ID by 12 bits to exclude the Operation Index\n const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);\n\n // Create a mask for 20 bits to ignore the Ledger Sequence Number\n const mask = BigInt((1 << 20) - 1);\n\n // Apply bitwise AND operation with the mask to get the Transaction Application Order\n const transactionApplicationOrder = shiftedId & mask;\n return Number(transactionApplicationOrder);\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n applicationOrder: number,\n sequence: number,\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const events = eventsForSequence.filter(\n (event) =>\n this.getTransactionApplicationOrder(event.id) === applicationOrder,\n );\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: ServerApi.TransactionRecord[],\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx, index) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<IBlock<StellarBlockWrapper>> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e) {\n if (e.message === 'start is after newest ledger') {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.\n To resolve this issue, please check you endpoint node start height`);\n }\n\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return formatBlockUtil(wrappedLedgerInstance);\n }\n\n async fetchBlocks(\n bufferBlocks: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(null, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
|
|
@@ -35,7 +35,7 @@ describe('StellarApi', () => {
|
|
|
35
35
|
it('should fetch block', async () => {
|
|
36
36
|
const latestHeight = await stellarApi.getFinalizedBlockHeight();
|
|
37
37
|
const block = (await stellarApi.fetchBlocks([latestHeight]))[0];
|
|
38
|
-
expect(block.
|
|
38
|
+
expect(block.getHeader().blockHeight).toEqual(latestHeight);
|
|
39
39
|
});
|
|
40
40
|
it('should throw on calling connect', async () => {
|
|
41
41
|
await expect(stellarApi.connect()).rejects.toThrow('Not implemented');
|
|
@@ -73,7 +73,7 @@ describe('StellarApi', () => {
|
|
|
73
73
|
stellarApi.fetchOperationsForLedger = jest.fn((seq) => [
|
|
74
74
|
{ type: { toString: () => 'invoke_host_function' } },
|
|
75
75
|
]);
|
|
76
|
-
await expect(stellarApi.fetchAndWrapLedger(100)).rejects.toThrow(/
|
|
76
|
+
await expect(stellarApi.fetchAndWrapLedger(100)).rejects.toThrow(/Not Found/);
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
79
|
//# 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;;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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,IAAI,CAAC,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC;YACtE,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,sBAAsB,EAAE,EAAE;SACrD,CAAC,CAAC;QACH,MAAM,MAAM,CAAE,UAAkB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACvE,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 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.getHeader().blockHeight).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 it('handleError - soroban node been reset', async () => {\n const error = new Error('start is after newest ledger');\n stellarApi.getAndWrapEvents = jest.fn(() => {\n throw new Error('start is after newest ledger');\n });\n (stellarApi as any).fetchOperationsForLedger = jest.fn((seq: number) => [\n { type: { toString: () => 'invoke_host_function' } },\n ]);\n await expect((stellarApi as any).fetchAndWrapLedger(100)).rejects.toThrow(\n /Not Found/,\n );\n });\n});\n"]}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Header, IBlock } from '@subql/node-core';
|
|
2
|
+
import { ApiWrapper, StellarBlockWrapper } from '@subql/types-stellar';
|
|
3
|
+
export declare function blockToHeader(blockHeight: number): Header;
|
|
4
|
+
export declare function formatBlockUtil<B extends StellarBlockWrapper = StellarBlockWrapper>(block: B): IBlock<B>;
|
|
2
5
|
export declare function calcInterval(api: ApiWrapper): number;
|
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.calcInterval = void 0;
|
|
5
|
+
exports.calcInterval = exports.formatBlockUtil = exports.blockToHeader = void 0;
|
|
6
|
+
function blockToHeader(blockHeight) {
|
|
7
|
+
return {
|
|
8
|
+
blockHeight: blockHeight,
|
|
9
|
+
blockHash: blockHeight.toString(),
|
|
10
|
+
parentHash: (blockHeight - 1).toString(),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.blockToHeader = blockToHeader;
|
|
14
|
+
function formatBlockUtil(block) {
|
|
15
|
+
return {
|
|
16
|
+
block,
|
|
17
|
+
getHeader: () => blockToHeader(block.block.sequence),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.formatBlockUtil = formatBlockUtil;
|
|
6
21
|
function calcInterval(api) {
|
|
7
22
|
return 6000;
|
|
8
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;
|
|
1
|
+
{"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AASnC,SAAgB,aAAa,CAAC,WAAmB;IAC/C,OAAO;QACL,WAAW,EAAE,WAAW;QACxB,SAAS,EAAE,WAAW,CAAC,QAAQ,EAAE;QACjC,UAAU,EAAE,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;KACzC,CAAC;AACJ,CAAC;AAND,sCAMC;AAED,SAAgB,eAAe,CAE7B,KAAQ;IACR,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;KACrD,CAAC;AACJ,CAAC;AAPD,0CAOC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,oCAEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Header, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n StellarBlock,\n StellarBlockWrapper,\n} from '@subql/types-stellar';\n\nexport function blockToHeader(blockHeight: number): Header {\n return {\n blockHeight: blockHeight,\n blockHash: blockHeight.toString(),\n parentHash: (blockHeight - 1).toString(),\n };\n}\n\nexport function formatBlockUtil<\n B extends StellarBlockWrapper = StellarBlockWrapper,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => blockToHeader(block.block.sequence),\n };\n}\n\nexport function calcInterval(api: ApiWrapper): number {\n return 6000;\n}\n"]}
|