@subql/node-stellar 2.12.1 → 3.0.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 +6 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/configure/SubqueryProject.d.ts +19 -19
- package/dist/configure/SubqueryProject.js +49 -88
- package/dist/configure/SubqueryProject.js.map +1 -1
- package/dist/configure/configure.module.d.ts +3 -6
- package/dist/configure/configure.module.js +22 -89
- package/dist/configure/configure.module.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +4 -4
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +6 -5
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +4 -4
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +9 -27
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary.service.d.ts +3 -3
- package/dist/indexer/dictionary.service.js +7 -2
- package/dist/indexer/dictionary.service.js.map +1 -1
- package/dist/indexer/ds-processor.service.d.ts +4 -4
- package/dist/indexer/ds-processor.service.js.map +1 -1
- package/dist/indexer/dynamic-ds.service.d.ts +3 -3
- package/dist/indexer/dynamic-ds.service.js +12 -2
- package/dist/indexer/dynamic-ds.service.js.map +1 -1
- package/dist/indexer/fetch.module.js +13 -10
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.d.ts +12 -8
- package/dist/indexer/fetch.service.js +25 -47
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/fetch.service.spec.js +4 -4
- package/dist/indexer/fetch.service.spec.js.map +1 -1
- package/dist/indexer/indexer.manager.d.ts +2 -2
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/project.service.d.ts +10 -6
- package/dist/indexer/project.service.js +19 -14
- package/dist/indexer/project.service.js.map +1 -1
- package/dist/indexer/sandbox.service.d.ts +1 -1
- package/dist/indexer/sandbox.service.js +1 -0
- package/dist/indexer/sandbox.service.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.js +24 -0
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker-fetch.module.d.ts +2 -0
- package/dist/indexer/{indexer.module.js → worker/worker-fetch.module.js} +23 -25
- package/dist/indexer/worker/worker-fetch.module.js.map +1 -0
- package/dist/indexer/worker/worker.d.ts +4 -28
- package/dist/indexer/worker/worker.js +8 -71
- package/dist/indexer/worker/worker.js.map +1 -1
- package/dist/indexer/worker/worker.module.js +2 -2
- package/dist/indexer/worker/worker.module.js.map +1 -1
- package/dist/indexer/worker/worker.service.d.ts +11 -13
- package/dist/indexer/worker/worker.service.js +14 -54
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.d.ts +1 -5
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +1 -4
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -1
- package/dist/init.js +2 -1
- package/dist/init.js.map +1 -1
- package/dist/main.js +4 -7
- package/dist/main.js.map +1 -1
- package/dist/stellar/api.connection.d.ts +1 -1
- package/dist/stellar/api.connection.js.map +1 -1
- package/dist/stellar/api.service.stellar.d.ts +4 -6
- package/dist/stellar/api.service.stellar.js +33 -68
- package/dist/stellar/api.service.stellar.js.map +1 -1
- package/dist/stellar/api.service.stellar.spec.d.ts +1 -5
- package/dist/stellar/api.service.stellar.spec.js +7 -6
- package/dist/stellar/api.service.stellar.spec.js.map +1 -1
- package/dist/stellar/api.stellar.js +1 -7
- package/dist/stellar/api.stellar.js.map +1 -1
- package/dist/stellar/soroban.server.spec.js +1 -1
- package/dist/stellar/soroban.server.spec.js.map +1 -1
- package/dist/subcommands/reindex.init.js +1 -2
- package/dist/subcommands/reindex.init.js.map +1 -1
- package/dist/subcommands/reindex.module.js +9 -6
- package/dist/subcommands/reindex.module.js.map +1 -1
- package/dist/subcommands/testing.init.js +2 -4
- package/dist/subcommands/testing.init.js.map +1 -1
- package/dist/subcommands/testing.module.js +9 -7
- package/dist/subcommands/testing.module.js.map +1 -1
- package/dist/subcommands/testing.service.d.ts +7 -4
- package/dist/subcommands/testing.service.js +2 -7
- package/dist/subcommands/testing.service.js.map +1 -1
- package/dist/utils/project.js.map +1 -1
- package/package.json +6 -6
- package/dist/indexer/indexer.module.d.ts +0 -2
- package/dist/indexer/indexer.module.js.map +0 -1
- package/dist/subcommands/mmrMigrate.init.d.ts +0 -2
- package/dist/subcommands/mmrMigrate.init.js +0 -28
- package/dist/subcommands/mmrMigrate.init.js.map +0 -1
- package/dist/subcommands/mmrMigrate.module.d.ts +0 -2
- package/dist/subcommands/mmrMigrate.module.js +0 -28
- package/dist/subcommands/mmrMigrate.module.js.map +0 -1
- package/dist/subcommands/mmrRegenerate.init.d.ts +0 -1
- package/dist/subcommands/mmrRegenerate.init.js +0 -28
- package/dist/subcommands/mmrRegenerate.init.js.map +0 -1
- package/dist/subcommands/mmrRegenerate.module.d.ts +0 -2
- package/dist/subcommands/mmrRegenerate.module.js +0 -30
- package/dist/subcommands/mmrRegenerate.module.js.map +0 -1
- package/dist/subcommands/reindex.service.d.ts +0 -11
- package/dist/subcommands/reindex.service.js +0 -46
- package/dist/subcommands/reindex.service.js.map +0 -1
|
@@ -13,13 +13,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
13
13
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
14
14
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
15
15
|
};
|
|
16
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
17
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
18
|
-
var m = o[Symbol.asyncIterator], i;
|
|
19
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
20
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
21
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
22
|
-
};
|
|
23
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
17
|
exports.StellarApiService = void 0;
|
|
25
18
|
const common_1 = require("@nestjs/common");
|
|
@@ -31,74 +24,44 @@ const soroban_server_1 = require("./soroban.server");
|
|
|
31
24
|
const logger = (0, node_core_1.getLogger)('api');
|
|
32
25
|
const MAX_RECONNECT_ATTEMPTS = 5;
|
|
33
26
|
let StellarApiService = class StellarApiService extends node_core_1.ApiService {
|
|
34
|
-
constructor(project, connectionPoolService, eventEmitter) {
|
|
35
|
-
super(connectionPoolService);
|
|
27
|
+
constructor(project, projectUpgradeService, connectionPoolService, eventEmitter) {
|
|
28
|
+
super(connectionPoolService, eventEmitter);
|
|
36
29
|
this.project = project;
|
|
37
|
-
this.
|
|
30
|
+
this.projectUpgradeService = projectUpgradeService;
|
|
38
31
|
}
|
|
39
32
|
async init() {
|
|
40
|
-
var _a
|
|
33
|
+
var _a;
|
|
34
|
+
let network;
|
|
41
35
|
try {
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
network = this.project.network;
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
logger.error(Object.keys(e));
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
const sorobanClient = network.soroban
|
|
51
|
-
? new soroban_server_1.SorobanServer(network.soroban)
|
|
52
|
-
: undefined;
|
|
53
|
-
const endpoints = Array.isArray(network.endpoint)
|
|
54
|
-
? network.endpoint
|
|
55
|
-
: [network.endpoint];
|
|
56
|
-
const endpointToApiIndex = {};
|
|
57
|
-
try {
|
|
58
|
-
for (var _d = true, _e = __asyncValues(endpoints.entries()), _f; _f = await _e.next(), _a = _f.done, !_a;) {
|
|
59
|
-
_c = _f.value;
|
|
60
|
-
_d = false;
|
|
61
|
-
try {
|
|
62
|
-
const [i, endpoint] = _c;
|
|
63
|
-
const connection = await api_connection_1.StellarApiConnection.create(endpoint, this.fetchBlockBatches, this.eventEmitter, sorobanClient);
|
|
64
|
-
const api = connection.unsafeApi;
|
|
65
|
-
this.eventEmitter.emit(node_core_1.IndexerEvent.ApiConnected, {
|
|
66
|
-
value: 1,
|
|
67
|
-
apiIndex: i,
|
|
68
|
-
endpoint: endpoint,
|
|
69
|
-
});
|
|
70
|
-
if (!this.networkMeta) {
|
|
71
|
-
this.networkMeta = connection.networkMeta;
|
|
72
|
-
}
|
|
73
|
-
if (network.chainId !== api.getChainId().toString()) {
|
|
74
|
-
throw this.metadataMismatchError('ChainId', network.chainId, api.getChainId().toString());
|
|
75
|
-
}
|
|
76
|
-
endpointToApiIndex[endpoint] = connection;
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
_d = true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
84
|
-
finally {
|
|
85
|
-
try {
|
|
86
|
-
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
|
|
87
|
-
}
|
|
88
|
-
finally { if (e_1) throw e_1.error; }
|
|
89
|
-
}
|
|
90
|
-
this.connectionPoolService.addBatchToConnections(endpointToApiIndex);
|
|
91
|
-
return this;
|
|
36
|
+
network = this.project.network;
|
|
92
37
|
}
|
|
93
38
|
catch (e) {
|
|
94
|
-
logger.error(e
|
|
95
|
-
|
|
39
|
+
logger.error(Object.keys(e));
|
|
40
|
+
process.exit(1);
|
|
96
41
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
42
|
+
const sorobanEndpoint = (_a = network.sorobanEndpoint) !== null && _a !== void 0 ? _a : this.projectUpgradeService.getProject(Number.MAX_SAFE_INTEGER)
|
|
43
|
+
.network.soroban;
|
|
44
|
+
if (!network.sorobanEndpoint && sorobanEndpoint) {
|
|
45
|
+
//update sorobanEndpoint from parent project
|
|
46
|
+
this.project.network.sorobanEndpoint = sorobanEndpoint;
|
|
47
|
+
}
|
|
48
|
+
if ((0, SubqueryProject_1.dsHasSorobanEventHandler)([
|
|
49
|
+
...this.project.dataSources,
|
|
50
|
+
...this.project.templates,
|
|
51
|
+
]) &&
|
|
52
|
+
!sorobanEndpoint) {
|
|
53
|
+
throw new Error(`Soroban network endpoint must be provided for network. chainId="${this.project.network.chainId}"`);
|
|
54
|
+
}
|
|
55
|
+
const sorobanClient = sorobanEndpoint
|
|
56
|
+
? new soroban_server_1.SorobanServer(sorobanEndpoint)
|
|
57
|
+
: undefined;
|
|
58
|
+
await this.createConnections(network, (endpoint) => api_connection_1.StellarApiConnection.create(endpoint, this.fetchBlockBatches, this.eventEmitter, sorobanClient),
|
|
59
|
+
//eslint-disable-next-line @typescript-eslint/require-await
|
|
60
|
+
async (connection) => {
|
|
61
|
+
const api = connection.unsafeApi;
|
|
62
|
+
return api.getChainId();
|
|
63
|
+
});
|
|
64
|
+
return this;
|
|
102
65
|
}
|
|
103
66
|
get api() {
|
|
104
67
|
return this.unsafeApi;
|
|
@@ -140,7 +103,9 @@ let StellarApiService = class StellarApiService extends node_core_1.ApiService {
|
|
|
140
103
|
StellarApiService = __decorate([
|
|
141
104
|
(0, common_1.Injectable)(),
|
|
142
105
|
__param(0, (0, common_1.Inject)('ISubqueryProject')),
|
|
106
|
+
__param(1, (0, common_1.Inject)('IProjectUpgradeService')),
|
|
143
107
|
__metadata("design:paramtypes", [SubqueryProject_1.SubqueryProject,
|
|
108
|
+
node_core_1.ProjectUpgradeSevice,
|
|
144
109
|
node_core_1.ConnectionPoolService,
|
|
145
110
|
event_emitter_1.EventEmitter2])
|
|
146
111
|
], StellarApiService);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC
|
|
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,gDAO0B;AAE1B,kEAIsC;AACtC,qDAAwD;AAGxD,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAEhC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAG1B,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,sBAItC;IACC,YACsC,OAAwB,EAEpD,qBAA2C,EACnD,qBAAkE,EAClE,YAA2B;QAE3B,KAAK,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;QANP,YAAO,GAAP,OAAO,CAAiB;QAEpD,0BAAqB,GAArB,qBAAqB,CAAsB;IAKrD,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,CAAC,CAAC,CAAC;SACjB;QAED,MAAM,eAAe,GACnB,MAAA,OAAO,CAAC,eAAe,mCAErB,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC;aAC3D,OACJ,CAAC,OAAO,CAAC;QAEZ,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,eAAe,EAAE;YAC/C,4CAA4C;YAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe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AC;wBAEzB,OAAO,OAAO,GAAG,UAAU,EAAE;4BAC3B,IAAI;gCACF,OAAO,MAAM,cAAc,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;6BACrD;4BAAC,OAAO,KAAK,EAAE;gCACd,MAAM,CAAC,IAAI,CACT,qCAAqC,MAAM,WAAW,OAAO,MAAM,KAAK,CAAC,OAAO,EAAE,CACnF,CAAC;gCACF,aAAa,GAAG,KAAK,CAAC;gCACtB,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gCAC/C,OAAO,EAAE,CAAC;6BACX;yBACF;wBAED,MAAM,CAAC,KAAK,CACV,oBAAoB,UAAU,gCAAgC,MAAM,EAAE,CACvE,CAAC;wBACF,MAAM,aAAa,CAAC;oBACtB,CAAC,CAAC;iBACH;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC;QAEF,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAC7B,GAAe,EACf,KAAe;QAEf,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AAvHY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCADY,iCAAe;QAE7B,gCAAoB;QAC5B,iCAAqB;QAC9B,6BAAa;GAVlB,iBAAiB,CAuH7B;AAvHY,8CAAiB","sourcesContent":["// Copyright 2020-2023 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 NetworkMetadataPayload,\n getLogger,\n IndexerEvent,\n ProjectUpgradeSevice,\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\nconst MAX_RECONNECT_ATTEMPTS = 5;\n\n@Injectable()\nexport class StellarApiService extends ApiService<\n StellarApi,\n SafeStellarProvider,\n StellarBlockWrapper[]\n> {\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n @Inject('IProjectUpgradeService')\n private projectUpgradeService: ProjectUpgradeSevice,\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<StellarBlockWrapper[]> {\n return api.fetchBlocks(batch);\n }\n}\n"]}
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
3
|
-
import { StellarApiService } from './api.service.stellar';
|
|
4
|
-
export declare function testSubqueryProject(endpoint: string, sorobanEndpoint: string): SubqueryProject;
|
|
5
|
-
export declare const prepareApiService: (endpoint?: string, soroban?: string, project?: SubqueryProject) => Promise<[StellarApiService, INestApplication]>;
|
|
1
|
+
export {};
|
|
@@ -2,7 +2,6 @@
|
|
|
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
|
-
exports.prepareApiService = exports.testSubqueryProject = void 0;
|
|
6
5
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
7
6
|
const testing_1 = require("@nestjs/testing");
|
|
8
7
|
const node_core_1 = require("@subql/node-core");
|
|
@@ -17,7 +16,7 @@ const SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';
|
|
|
17
16
|
function testSubqueryProject(endpoint, sorobanEndpoint) {
|
|
18
17
|
return {
|
|
19
18
|
network: {
|
|
20
|
-
endpoint,
|
|
19
|
+
endpoint: [endpoint],
|
|
21
20
|
sorobanEndpoint,
|
|
22
21
|
chainId: 'Test SDF Future Network ; October 2022',
|
|
23
22
|
},
|
|
@@ -28,12 +27,15 @@ function testSubqueryProject(endpoint, sorobanEndpoint) {
|
|
|
28
27
|
templates: [],
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
|
-
exports.testSubqueryProject = testSubqueryProject;
|
|
32
30
|
const prepareApiService = async (endpoint = HTTP_ENDPOINT, soroban = SOROBAN_ENDPOINT, project) => {
|
|
33
31
|
const module = await testing_1.Test.createTestingModule({
|
|
34
32
|
providers: [
|
|
35
33
|
node_core_1.ConnectionPoolService,
|
|
36
34
|
dist_1.ConnectionPoolStateManager,
|
|
35
|
+
{
|
|
36
|
+
provide: 'IProjectUpgradeService',
|
|
37
|
+
useFactory: () => ({}),
|
|
38
|
+
},
|
|
37
39
|
{
|
|
38
40
|
provide: node_core_1.NodeConfig,
|
|
39
41
|
useFactory: () => ({}),
|
|
@@ -52,13 +54,12 @@ const prepareApiService = async (endpoint = HTTP_ENDPOINT, soroban = SOROBAN_END
|
|
|
52
54
|
await apiService.init();
|
|
53
55
|
return [apiService, app];
|
|
54
56
|
};
|
|
55
|
-
exports.prepareApiService = prepareApiService;
|
|
56
57
|
jest.setTimeout(90000);
|
|
57
58
|
describe('StellarApiService', () => {
|
|
58
59
|
let apiService;
|
|
59
60
|
let app;
|
|
60
61
|
beforeEach(async () => {
|
|
61
|
-
[apiService, app] = await
|
|
62
|
+
[apiService, app] = await prepareApiService();
|
|
62
63
|
});
|
|
63
64
|
it('should instantiate api', () => {
|
|
64
65
|
expect(apiService.api).toBeInstanceOf(api_stellar_1.StellarApi);
|
|
@@ -71,7 +72,7 @@ describe('StellarApiService', () => {
|
|
|
71
72
|
});
|
|
72
73
|
it('should throw error when chainId does not match', async () => {
|
|
73
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' }) });
|
|
74
|
-
await expect(
|
|
75
|
+
await expect(prepareApiService(HTTP_ENDPOINT, SOROBAN_ENDPOINT, faultyProject)).rejects.toThrow();
|
|
75
76
|
});
|
|
76
77
|
it('fails after maximum retries', async () => {
|
|
77
78
|
const api = apiService.unsafeApi;
|
|
@@ -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
|
|
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;AAErC,+DAA0D;AAC1D,+CAA2C;AAC3C,mDAAsD;AAEtD,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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AAM,GAAG,GAAG,UAAU,CAAC,SAAS,CAAC;QAEjC,uDAAuD;QACtD,GAAW,CAAC,WAAW,GAAG,IAAI;aAC5B,EAAE,EAAE;aACJ,iBAAiB,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;QAEjD,MAAM,MAAM,CACT,GAAW,CAAC,WAAW,CAAC,IAAA,cAAK,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAC9C,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACtB,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 { 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 { 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).toEqual(\n expect.arrayContaining([expect.any(StellarBlockWrapped)]),\n );\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"]}
|
|
@@ -19,19 +19,13 @@ class StellarApi {
|
|
|
19
19
|
this.endpoint = endpoint;
|
|
20
20
|
this.eventEmitter = eventEmitter;
|
|
21
21
|
this.sorobanClient = sorobanClient;
|
|
22
|
-
const { hostname, protocol, searchParams } = new URL(endpoint);
|
|
22
|
+
const { hostname, protocol, searchParams } = new URL(this.endpoint);
|
|
23
23
|
const protocolStr = protocol.replace(':', '');
|
|
24
24
|
logger.info(`Api host: ${hostname}, method: ${protocolStr}`);
|
|
25
25
|
if (protocolStr === 'https' || protocolStr === 'http') {
|
|
26
26
|
const options = {
|
|
27
|
-
//headers: {
|
|
28
|
-
// 'User-Agent': `Subquery-Node ${packageVersion}`,
|
|
29
|
-
//},
|
|
30
27
|
allowHttp: protocolStr === 'http',
|
|
31
28
|
};
|
|
32
|
-
//searchParams.forEach((value, name, searchParams) => {
|
|
33
|
-
// (connection.headers as any)[name] = value;
|
|
34
|
-
//});
|
|
35
29
|
this.stellarClient = new stellar_server_1.StellarServer(endpoint, options);
|
|
36
30
|
}
|
|
37
31
|
else {
|
|
@@ -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,QAAQ,CAAC,CAAC;QAE/D,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE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,gCAkXC","sourcesContent":["// Copyright 2020-2023 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';\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(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 //headers: {\n // 'User-Agent': `Subquery-Node ${packageVersion}`,\n //},\n allowHttp: protocolStr === 'http',\n };\n //searchParams.forEach((value, name, searchParams) => {\n // (connection.headers as any)[name] = value;\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 effects.forEach((effect) => {\n effect.operation = cloneDeep(wrappedOp);\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 operations = this.wrapOperationsForTx(\n tx.id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = cloneDeep(wrappedTx);\n op.effects = op.effects.map((effect) => {\n effect.transaction = cloneDeep(wrappedTx);\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = cloneDeep(wrappedTx);\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 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 wrapperTxs.forEach((tx) => {\n tx.ledger = cloneDeep(wrappedLedger);\n tx.operations = tx.operations.map((op) => {\n op.ledger = cloneDeep(wrappedLedger);\n op.effects = op.effects.map((effect) => {\n effect.ledger = cloneDeep(wrappedLedger);\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = cloneDeep(wrappedLedger);\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,gDAA6C;A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,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU;QACd,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,MAAM,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;AA7WD,gCA6WC","sourcesContent":["// Copyright 2020-2023 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';\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 effects.forEach((effect) => {\n effect.operation = cloneDeep(wrappedOp);\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 operations = this.wrapOperationsForTx(\n tx.id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = cloneDeep(wrappedTx);\n op.effects = op.effects.map((effect) => {\n effect.transaction = cloneDeep(wrappedTx);\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = cloneDeep(wrappedTx);\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 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 wrapperTxs.forEach((tx) => {\n tx.ledger = cloneDeep(wrappedLedger);\n tx.operations = tx.operations.map((op) => {\n op.ledger = cloneDeep(wrappedLedger);\n op.effects = op.effects.map((effect) => {\n effect.ledger = cloneDeep(wrappedLedger);\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = cloneDeep(wrappedLedger);\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soroban.server.spec.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,sDAAqE;AACrE,qDAAiD;AAEjD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,MAAqB,CAAC;IAC1B,MAAM,GAAG,GAAG,qBAAqB,CAAC;IAClC,IAAI,GAAqB,CAAC;IAE1B,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,GAAG,IAAI,8BAAa,CAAC,GAAG,CAAC,CAAC;QAChC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,eAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;QACzC,GAAG,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QAEtC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC;YACtC,WAAW,EAAE,CAAC;SACK,CAAC,CAAC;QAEvB,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,CAAC,CAAC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C,CAAC;oBAC1D,EAAE,EAAE,GAAG,CAAC,EAAE;oBACV,MAAM,EAAE,GAAG;oBACX,WAAW,EAAE,GAAG,CAAC,EAAE;iBACpB,CAAC,CAAC;aACJ;SACF,CAAC,CAAC;QACH,MAAM,CAAE,MAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACvD,MAAM,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACvC,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 { GetEventsRequest, Server } from 'soroban-client/lib/server';\nimport { SorobanServer } from './soroban.server';\n\nconst DEFAULT_PAGE_SIZE = 100;\n\ndescribe('SorobanServer', () => {\n let server: SorobanServer;\n const url = 'https://example.com';\n let spy: jest.SpyInstance;\n\n beforeEach(() => {\n server = new SorobanServer(url);\n spy = jest.spyOn(Server.prototype, 'getEvents');\n });\n\n afterEach(() => {\n spy.mockRestore();\n });\n\n test('should handle no events', async () => {\n spy.mockResolvedValue({ events: [] });\n\n const response = await server.getEvents({\n startLedger: 1,\n } as GetEventsRequest);\n\n expect(response).toEqual({ events: [] });\n expect(spy).toHaveBeenCalledTimes(1);\n });\n\n test('should handle events from different ledgers', async () => {\n spy.mockResolvedValue({\n events: [\n { id: '1', ledger: '1', pagingToken: '1' },\n { id: '2', ledger: '2', pagingToken: '2' },\n ],\n });\n\n const response = await server.getEvents({\n startLedger: 1,\n } as GetEventsRequest);\n\n expect(response).toEqual({\n events: [{ id: '1', ledger: '1', pagingToken: '1' }],\n });\n expect(spy).toHaveBeenCalledTimes(1);\n });\n\n test('should handle response length less than DEFAULT_PAGE_SIZE', async () => {\n spy.mockResolvedValue({\n events: Array.from({ length: DEFAULT_PAGE_SIZE - 1 }, (_, i) => ({\n id: `${i}`,\n ledger: '1',\n pagingToken: `${i}`,\n })),\n });\n\n const response = await server.getEvents({\n startLedger: 1,\n } as GetEventsRequest);\n\n expect(response.events.length).toBe(DEFAULT_PAGE_SIZE - 1);\n expect(spy).toHaveBeenCalledTimes(1);\n });\n\n test('should handle no matching ledger', async () => {\n spy.mockResolvedValue({\n events: [\n { id: '1', ledger: '2', pagingToken: '1' },\n { id: '1', ledger: '3', pagingToken: '2' },\n ],\n });\n\n const response = await server.getEvents({\n startLedger: 1,\n } as GetEventsRequest);\n\n expect(response).toEqual({ events: [] });\n expect(spy).toHaveBeenCalledTimes(1);\n });\n\n test('should return cached events for given startLedger', async () => {\n (server as any).eventsCache[1] = {\n events: [{ ledger: '1', pagingToken: '1' }],\n };\n\n const response = await server.getEvents({\n startLedger: 1,\n } as GetEventsRequest);\n\n expect(response).toEqual({ events: [{ ledger: '1', pagingToken: '1' }] });\n expect(spy).toHaveBeenCalledTimes(0);\n });\n\n test('should handle startLedger events greater than DEFAULT_PAGE_SIZE', async () => {\n spy\n .mockResolvedValueOnce({\n events: Array.from({ length: DEFAULT_PAGE_SIZE }, (_, i) => ({\n id: `${i}`,\n ledger: '1',\n pagingToken: `${i}`,\n })),\n })\n .mockResolvedValueOnce({\n events: Array.from({ length: 5 }, (_, i) => ({\n id: `${i + DEFAULT_PAGE_SIZE}`,\n ledger: '1',\n pagingToken: `${i + DEFAULT_PAGE_SIZE}`,\n })),\n });\n\n const response = await server.getEvents({\n startLedger: 1,\n } as GetEventsRequest);\n\n expect(response.events.length).toBe(DEFAULT_PAGE_SIZE + 5);\n expect(spy).toHaveBeenCalledTimes(2);\n });\n\n test('should handle last block of otherEvents on next page', async () => {\n spy\n .mockResolvedValueOnce({\n events: [\n ...Array.from({ length: DEFAULT_PAGE_SIZE - 1 }, (_, i) => ({\n id: `${i}`,\n ledger: '1',\n pagingToken: `${i}`,\n })),\n { id: '2-1', ledger: '2', pagingToken: '1' },\n ],\n })\n .mockResolvedValueOnce({\n events: [{ id: '2-2', ledger: '2', pagingToken: '2' }],\n });\n\n const response = await server.getEvents({\n startLedger: 1,\n } as GetEventsRequest);\n\n expect(response).toEqual({\n events: [\n ...Array.from({ length: DEFAULT_PAGE_SIZE - 1 }, (_, i) => ({\n id: `${i}`,\n ledger: '1',\n pagingToken: `${i}`,\n })),\n ],\n });\n expect((server as any).eventsCache[2]).toBeUndefined();\n expect(spy).toHaveBeenCalledTimes(1);\n });\n});\n"]}
|
|
@@ -6,13 +6,12 @@ exports.reindexInit = void 0;
|
|
|
6
6
|
const core_1 = require("@nestjs/core");
|
|
7
7
|
const node_core_1 = require("@subql/node-core");
|
|
8
8
|
const reindex_module_1 = require("./reindex.module");
|
|
9
|
-
const reindex_service_1 = require("./reindex.service");
|
|
10
9
|
const logger = (0, node_core_1.getLogger)('CLI-Reindex');
|
|
11
10
|
async function reindexInit(targetHeight) {
|
|
12
11
|
try {
|
|
13
12
|
const app = await core_1.NestFactory.create(reindex_module_1.ReindexModule);
|
|
14
13
|
await app.init();
|
|
15
|
-
const reindexService = app.get(
|
|
14
|
+
const reindexService = app.get(node_core_1.ReindexService);
|
|
16
15
|
await reindexService.init();
|
|
17
16
|
const actualReindexHeight = await reindexService.getTargetHeightWithUnfinalizedBlocks(targetHeight);
|
|
18
17
|
if (actualReindexHeight !== targetHeight) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reindex.init.js","sourceRoot":"","sources":["../../src/subcommands/reindex.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,uCAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"reindex.init.js","sourceRoot":"","sources":["../../src/subcommands/reindex.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,uCAA2C;AAC3C,gDAA6D;AAC7D,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AACjC,KAAK,UAAU,WAAW,CAAC,YAAoB;IACpD,IAAI;QACF,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,8BAAa,CAAC,CAAC;QAEpD,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,cAAc,GAAG,GAAG,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;QAE/C,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,mBAAmB,GACvB,MAAM,cAAc,CAAC,oCAAoC,CAAC,YAAY,CAAC,CAAC;QAC1E,IAAI,mBAAmB,KAAK,YAAY,EAAE;YACxC,MAAM,CAAC,IAAI,CACT,6BAA6B,YAAY,qCAAqC,mBAAmB,mBAAmB,mBAAmB,EAAE,CAC1I,CAAC;SACH;QACD,MAAM,cAAc,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;KACnD;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,2BAA2B,CAAC,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AArBD,kCAqBC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NestFactory } from '@nestjs/core';\nimport { getLogger, ReindexService } from '@subql/node-core';\nimport { ReindexModule } from './reindex.module';\n\nconst logger = getLogger('CLI-Reindex');\nexport async function reindexInit(targetHeight: number): Promise<void> {\n try {\n const app = await NestFactory.create(ReindexModule);\n\n await app.init();\n const reindexService = app.get(ReindexService);\n\n await reindexService.init();\n const actualReindexHeight =\n await reindexService.getTargetHeightWithUnfinalizedBlocks(targetHeight);\n if (actualReindexHeight !== targetHeight) {\n logger.info(\n `Found index target height ${targetHeight} beyond indexed unfinalized block ${actualReindexHeight}, will index to ${actualReindexHeight}`,\n );\n }\n await reindexService.reindex(actualReindexHeight);\n } catch (e) {\n logger.error(e, 'Reindex failed to execute');\n process.exit(1);\n }\n process.exit(0);\n}\n"]}
|
|
@@ -17,7 +17,6 @@ const configure_module_1 = require("../configure/configure.module");
|
|
|
17
17
|
const ds_processor_service_1 = require("../indexer/ds-processor.service");
|
|
18
18
|
const dynamic_ds_service_1 = require("../indexer/dynamic-ds.service");
|
|
19
19
|
const unfinalizedBlocks_service_1 = require("../indexer/unfinalizedBlocks.service");
|
|
20
|
-
const reindex_service_1 = require("./reindex.service");
|
|
21
20
|
let ReindexFeatureModule = class ReindexFeatureModule {
|
|
22
21
|
};
|
|
23
22
|
ReindexFeatureModule = __decorate([
|
|
@@ -25,12 +24,16 @@ ReindexFeatureModule = __decorate([
|
|
|
25
24
|
providers: [
|
|
26
25
|
node_core_1.StoreCacheService,
|
|
27
26
|
node_core_1.StoreService,
|
|
28
|
-
|
|
29
|
-
node_core_1.MmrService,
|
|
30
|
-
node_core_1.PgMmrCacheService,
|
|
27
|
+
node_core_1.ReindexService,
|
|
31
28
|
node_core_1.ForceCleanService,
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
{
|
|
30
|
+
provide: 'UnfinalizedBlocksService',
|
|
31
|
+
useClass: unfinalizedBlocks_service_1.UnfinalizedBlocksService,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
provide: 'DynamicDsService',
|
|
35
|
+
useClass: dynamic_ds_service_1.DynamicDsService,
|
|
36
|
+
},
|
|
34
37
|
ds_processor_service_1.DsProcessorService,
|
|
35
38
|
{
|
|
36
39
|
// Used to work with DI for unfinalizedBlocksService but not used with reindex
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reindex.module.js","sourceRoot":"","sources":["../../src/subcommands/reindex.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA2D;AAC3D,+CAAqD;AACrD,
|
|
1
|
+
{"version":3,"file":"reindex.module.js","sourceRoot":"","sources":["../../src/subcommands/reindex.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA2D;AAC3D,+CAAqD;AACrD,gDAO0B;AAC1B,oEAAgE;AAChE,0EAAqE;AACrE,sEAAiE;AACjE,oFAAgF;AA0BzE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oBAAoB;IAxBhC,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,6BAAiB;YACjB,wBAAY;YACZ,0BAAc;YACd,6BAAiB;YACjB;gBACE,OAAO,EAAE,0BAA0B;gBACnC,QAAQ,EAAE,oDAAwB;aACnC;YACD;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,QAAQ,EAAE,qCAAgB;aAC3B;YACD,yCAAkB;YAClB;gBACE,8EAA8E;gBAC9E,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS;aAC5B;YACD,4BAAiB;SAClB;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,oBAAoB,CAAG;AAAvB,oDAAoB;AAW1B,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,aAAa;IATzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAe,CAAC,QAAQ,EAAE;YAC1B,oBAAoB;YACpB,kCAAkB,CAAC,OAAO,EAAE;SAC7B;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,aAAa,CAAG;AAAhB,sCAAa","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\nimport {\n ApiService,\n DbModule,\n ForceCleanService,\n StoreCacheService,\n StoreService,\n ReindexService,\n} from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { DsProcessorService } from '../indexer/ds-processor.service';\nimport { DynamicDsService } from '../indexer/dynamic-ds.service';\nimport { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service';\n\n@Module({\n providers: [\n StoreCacheService,\n StoreService,\n ReindexService,\n ForceCleanService,\n {\n provide: 'UnfinalizedBlocksService',\n useClass: UnfinalizedBlocksService,\n },\n {\n provide: 'DynamicDsService',\n useClass: DynamicDsService,\n },\n DsProcessorService,\n {\n // Used to work with DI for unfinalizedBlocksService but not used with reindex\n provide: ApiService,\n useFactory: () => undefined,\n },\n SchedulerRegistry,\n ],\n controllers: [],\n})\nexport class ReindexFeatureModule {}\n\n@Module({\n imports: [\n DbModule.forRoot(),\n ConfigureModule.register(),\n ReindexFeatureModule,\n EventEmitterModule.forRoot(),\n ],\n controllers: [],\n})\nexport class ReindexModule {}\n"]}
|
|
@@ -9,10 +9,8 @@ const testing_service_1 = require("./testing.service");
|
|
|
9
9
|
const logger = (0, node_core_1.getLogger)('Testing');
|
|
10
10
|
async function testingInit() {
|
|
11
11
|
try {
|
|
12
|
-
const {
|
|
13
|
-
const
|
|
14
|
-
const testingService = new testing_service_1.TestingService(config, subqueryProject);
|
|
15
|
-
await testingService.init();
|
|
12
|
+
const { nodeConfig, project } = await configure_module_1.ConfigureModule.getInstance();
|
|
13
|
+
const testingService = new testing_service_1.TestingService(nodeConfig, project);
|
|
16
14
|
await testingService.run();
|
|
17
15
|
}
|
|
18
16
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.init.js","sourceRoot":"","sources":["../../src/subcommands/testing.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAAqE;AACrE,oEAAgE;AAIhE,uDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAC7B,KAAK,UAAU,WAAW;IAC/B,IAAI;QACF,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"testing.init.js","sourceRoot":"","sources":["../../src/subcommands/testing.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAAqE;AACrE,oEAAgE;AAIhE,uDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAC7B,KAAK,UAAU,WAAW;IAC/B,IAAI;QACF,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,kCAAe,CAAC,WAAW,EAAE,CAAC;QAEpE,MAAM,cAAc,GAAG,IAAI,gCAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC/D,MAAM,cAAc,CAAC,GAAG,EAAE,CAAC;KAC5B;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAXD,kCAWC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NestFactory } from '@nestjs/core';\nimport { ApiService, getLogger, NestLogger } from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { ProjectService } from '../indexer/project.service';\nimport { StellarApiService } from '../stellar';\nimport { TestingModule } from './testing.module';\nimport { TestingService } from './testing.service';\n\nconst logger = getLogger('Testing');\nexport async function testingInit(): Promise<void> {\n try {\n const { nodeConfig, project } = await ConfigureModule.getInstance();\n\n const testingService = new TestingService(nodeConfig, project);\n await testingService.run();\n } catch (e) {\n logger.error(e, 'Testing failed');\n process.exit(1);\n }\n process.exit(0);\n}\n"]}
|