@subql/node 6.4.1-0 → 6.4.4-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 +13 -1
- package/dist/.tsbuildinfo +1 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.module.js +42 -0
- package/dist/app.module.js.map +1 -0
- package/dist/blockchain.service.d.ts +31 -0
- package/dist/blockchain.service.js +146 -0
- package/dist/blockchain.service.js.map +1 -0
- package/dist/configure/NodeConfig.d.ts +19 -0
- package/dist/configure/NodeConfig.js +28 -0
- package/dist/configure/NodeConfig.js.map +1 -0
- package/dist/configure/SubqueryProject.d.ts +13 -0
- package/dist/configure/SubqueryProject.js +29 -0
- package/dist/configure/SubqueryProject.js.map +1 -0
- package/dist/configure/configure.module.d.ts +11 -0
- package/dist/configure/configure.module.js +63 -0
- package/dist/configure/configure.module.js.map +1 -0
- package/dist/indexer/api.service.d.ts +36 -0
- package/dist/indexer/api.service.js +315 -0
- package/dist/indexer/api.service.js.map +1 -0
- package/dist/indexer/apiPromise.connection.d.ts +24 -0
- package/dist/indexer/apiPromise.connection.js +106 -0
- package/dist/indexer/apiPromise.connection.js.map +1 -0
- package/dist/indexer/dictionary/index.d.ts +2 -0
- package/dist/indexer/dictionary/index.js +21 -0
- package/dist/indexer/dictionary/index.js.map +1 -0
- package/dist/indexer/dictionary/substrateDictionary.service.d.ts +13 -0
- package/dist/indexer/dictionary/substrateDictionary.service.js +93 -0
- package/dist/indexer/dictionary/substrateDictionary.service.js.map +1 -0
- package/dist/indexer/dictionary/types.d.ts +10 -0
- package/dist/indexer/dictionary/types.js +5 -0
- package/dist/indexer/dictionary/types.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/substrateDictionaryV1.d.ts +19 -0
- package/dist/indexer/dictionary/v1/substrateDictionaryV1.js +223 -0
- package/dist/indexer/dictionary/v1/substrateDictionaryV1.js.map +1 -0
- package/dist/indexer/dictionary/v2/index.d.ts +2 -0
- package/dist/indexer/dictionary/v2/index.js +21 -0
- package/dist/indexer/dictionary/v2/index.js.map +1 -0
- package/dist/indexer/dictionary/v2/substrateDictionaryV2.d.ts +20 -0
- package/dist/indexer/dictionary/v2/substrateDictionaryV2.js +46 -0
- package/dist/indexer/dictionary/v2/substrateDictionaryV2.js.map +1 -0
- package/dist/indexer/dictionary/v2/types.d.ts +5 -0
- package/dist/indexer/dictionary/v2/types.js +5 -0
- package/dist/indexer/dictionary/v2/types.js.map +1 -0
- package/dist/indexer/fetch.module.d.ts +2 -0
- package/dist/indexer/fetch.module.js +94 -0
- package/dist/indexer/fetch.module.js.map +1 -0
- package/dist/indexer/indexer.manager.d.ts +27 -0
- package/dist/indexer/indexer.manager.js +153 -0
- package/dist/indexer/indexer.manager.js.map +1 -0
- package/dist/indexer/runtime/base-runtime.service.d.ts +24 -0
- package/dist/indexer/runtime/base-runtime.service.js +136 -0
- package/dist/indexer/runtime/base-runtime.service.js.map +1 -0
- package/dist/indexer/runtime/runtimeService.d.ts +15 -0
- package/dist/indexer/runtime/runtimeService.js +94 -0
- package/dist/indexer/runtime/runtimeService.js.map +1 -0
- package/dist/indexer/runtime/workerRuntimeService.d.ts +9 -0
- package/dist/indexer/runtime/workerRuntimeService.js +43 -0
- package/dist/indexer/runtime/workerRuntimeService.js.map +1 -0
- package/dist/indexer/types.d.ts +20 -0
- package/dist/indexer/types.js +13 -0
- package/dist/indexer/types.js.map +1 -0
- package/dist/indexer/worker/worker-fetch.module.d.ts +5 -0
- package/dist/indexer/worker/worker-fetch.module.js +60 -0
- package/dist/indexer/worker/worker-fetch.module.js.map +1 -0
- package/dist/indexer/worker/worker.d.ts +9 -0
- package/dist/indexer/worker/worker.js +48 -0
- package/dist/indexer/worker/worker.js.map +1 -0
- package/dist/indexer/worker/worker.module.d.ts +2 -0
- package/dist/indexer/worker/worker.module.js +33 -0
- package/dist/indexer/worker/worker.module.js.map +1 -0
- package/dist/indexer/worker/worker.service.d.ts +26 -0
- package/dist/indexer/worker/worker.service.js +71 -0
- package/dist/indexer/worker/worker.service.js.map +1 -0
- package/dist/indexer/x-provider/cachedProvider.d.ts +2 -0
- package/dist/indexer/x-provider/cachedProvider.js +40 -0
- package/dist/indexer/x-provider/cachedProvider.js.map +1 -0
- package/dist/indexer/x-provider/http.d.ts +75 -0
- package/dist/indexer/x-provider/http.js +198 -0
- package/dist/indexer/x-provider/http.js.map +1 -0
- package/dist/init.d.ts +1 -0
- package/dist/init.js +41 -0
- package/dist/init.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +19 -0
- package/dist/main.js.map +1 -0
- package/dist/subcommands/forceClean.init.d.ts +1 -0
- package/dist/subcommands/forceClean.init.js +10 -0
- package/dist/subcommands/forceClean.init.js.map +1 -0
- package/dist/subcommands/forceClean.module.d.ts +2 -0
- package/dist/subcommands/forceClean.module.js +28 -0
- package/dist/subcommands/forceClean.module.js.map +1 -0
- package/dist/subcommands/reindex.init.d.ts +3 -0
- package/dist/subcommands/reindex.init.js +33 -0
- package/dist/subcommands/reindex.init.js.map +1 -0
- package/dist/subcommands/reindex.module.d.ts +2 -0
- package/dist/subcommands/reindex.module.js +69 -0
- package/dist/subcommands/reindex.module.js.map +1 -0
- package/dist/subcommands/testing.init.d.ts +1 -0
- package/dist/subcommands/testing.init.js +21 -0
- package/dist/subcommands/testing.init.js.map +1 -0
- package/dist/subcommands/testing.module.d.ts +2 -0
- package/dist/subcommands/testing.module.js +65 -0
- package/dist/subcommands/testing.module.js.map +1 -0
- package/dist/subcommands/testing.service.d.ts +14 -0
- package/dist/subcommands/testing.service.js +60 -0
- package/dist/subcommands/testing.service.js.map +1 -0
- package/dist/utils/project.d.ts +9 -0
- package/dist/utils/project.js +116 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/substrate.d.ts +41 -0
- package/dist/utils/substrate.js +348 -0
- package/dist/utils/substrate.js.map +1 -0
- package/dist/utils/test.utils.d.ts +2 -0
- package/dist/utils/test.utils.js +70 -0
- package/dist/utils/test.utils.js.map +1 -0
- package/dist/yargs.d.ts +276 -0
- package/dist/yargs.js +27 -0
- package/dist/yargs.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.AppModule = void 0;
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
13
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
14
|
+
const schedule_1 = require("@nestjs/schedule");
|
|
15
|
+
const node_core_1 = require("@subql/node-core");
|
|
16
|
+
const configure_module_1 = require("./configure/configure.module");
|
|
17
|
+
const fetch_module_1 = require("./indexer/fetch.module");
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19
|
+
const { version: polkadotSdkVersion } = require('@polkadot/api/package.json');
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
21
|
+
const { version: packageVersion } = require('../package.json');
|
|
22
|
+
let AppModule = class AppModule {
|
|
23
|
+
};
|
|
24
|
+
exports.AppModule = AppModule;
|
|
25
|
+
exports.AppModule = AppModule = __decorate([
|
|
26
|
+
(0, common_1.Module)({
|
|
27
|
+
imports: [
|
|
28
|
+
node_core_1.DbModule.forRoot(),
|
|
29
|
+
event_emitter_1.EventEmitterModule.forRoot(),
|
|
30
|
+
configure_module_1.ConfigureModule.register(),
|
|
31
|
+
schedule_1.ScheduleModule.forRoot(),
|
|
32
|
+
node_core_1.CoreModule,
|
|
33
|
+
fetch_module_1.FetchModule,
|
|
34
|
+
node_core_1.MetaModule.forRoot({
|
|
35
|
+
version: packageVersion,
|
|
36
|
+
sdkVersion: { name: '@polkadot/api', version: polkadotSdkVersion },
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
controllers: [],
|
|
40
|
+
})
|
|
41
|
+
], AppModule);
|
|
42
|
+
//# sourceMappingURL=app.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA2D;AAC3D,+CAAkD;AAClD,gDAAoE;AACpE,mEAA+D;AAC/D,yDAAqD;AAErD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC9E,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAiBxD,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAfrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAkB,CAAC,OAAO,EAAE;YAC5B,kCAAe,CAAC,QAAQ,EAAE;YAC1B,yBAAc,CAAC,OAAO,EAAE;YACxB,sBAAU;YACV,0BAAW;YACX,sBAAU,CAAC,OAAO,CAAC;gBACjB,OAAO,EAAE,cAAc;gBACvB,UAAU,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,EAAE;aACnE,CAAC;SACH;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,SAAS,CAAG","sourcesContent":["// Copyright 2020-2025 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 { ScheduleModule } from '@nestjs/schedule';\nimport { CoreModule, DbModule, MetaModule } from '@subql/node-core';\nimport { ConfigureModule } from './configure/configure.module';\nimport { FetchModule } from './indexer/fetch.module';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: polkadotSdkVersion } = require('@polkadot/api/package.json');\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../package.json');\n\n@Module({\n imports: [\n DbModule.forRoot(),\n EventEmitterModule.forRoot(),\n ConfigureModule.register(),\n ScheduleModule.forRoot(),\n CoreModule,\n FetchModule,\n MetaModule.forRoot({\n version: packageVersion,\n sdkVersion: { name: '@polkadot/api', version: polkadotSdkVersion },\n }),\n ],\n controllers: [],\n})\nexport class AppModule {}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isCustomDs, isRuntimeDs } from '@subql/common-substrate';
|
|
2
|
+
import { DatasourceParams, Header, IBlock, IBlockchainService } from '@subql/node-core';
|
|
3
|
+
import { SubstrateCustomDatasource, SubstrateCustomHandler, SubstrateDatasource, SubstrateHandlerKind, SubstrateMapping } from '@subql/types';
|
|
4
|
+
import { SubqueryProject, SubstrateProjectDs } from './configure/SubqueryProject';
|
|
5
|
+
import { ApiService } from './indexer/api.service';
|
|
6
|
+
import { RuntimeService } from './indexer/runtime/runtimeService';
|
|
7
|
+
import { ApiAt, BlockContent, LightBlockContent } from './indexer/types';
|
|
8
|
+
import { IIndexerWorker } from './indexer/worker/worker';
|
|
9
|
+
export declare class BlockchainService implements IBlockchainService<SubstrateDatasource, SubstrateCustomDatasource<string, SubstrateMapping<SubstrateCustomHandler>>, SubqueryProject, ApiAt, LightBlockContent, BlockContent, IIndexerWorker> {
|
|
10
|
+
private apiService;
|
|
11
|
+
private runtimeService;
|
|
12
|
+
constructor(apiService: ApiService, runtimeService: RuntimeService);
|
|
13
|
+
isCustomDs: typeof isCustomDs;
|
|
14
|
+
isRuntimeDs: typeof isRuntimeDs;
|
|
15
|
+
blockHandlerKind: SubstrateHandlerKind;
|
|
16
|
+
packageVersion: any;
|
|
17
|
+
fetchBlocks(blockNums: number[]): Promise<IBlock<BlockContent>[] | IBlock<LightBlockContent>[]>;
|
|
18
|
+
fetchBlockWorker(worker: IIndexerWorker, height: number, context: {
|
|
19
|
+
workers: IIndexerWorker[];
|
|
20
|
+
}): Promise<Header>;
|
|
21
|
+
onProjectChange(project: SubqueryProject): Promise<void>;
|
|
22
|
+
getBlockTimestamp(height: number): Promise<Date>;
|
|
23
|
+
getBlockSize(block: IBlock): number;
|
|
24
|
+
getFinalizedHeader(): Promise<Header>;
|
|
25
|
+
getBestHeight(): Promise<number>;
|
|
26
|
+
getChainInterval(): Promise<number>;
|
|
27
|
+
getHeaderForHash(hash: string): Promise<Header>;
|
|
28
|
+
getHeaderForHeight(height: number): Promise<Header>;
|
|
29
|
+
updateDynamicDs(params: DatasourceParams, dsObj: SubstrateProjectDs): Promise<void>;
|
|
30
|
+
getSafeApi(block: LightBlockContent | BlockContent): Promise<ApiAt>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
+
};
|
|
13
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
14
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.BlockchainService = void 0;
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const common_substrate_1 = require("@subql/common-substrate");
|
|
20
|
+
const node_core_1 = require("@subql/node-core");
|
|
21
|
+
const types_1 = require("@subql/types");
|
|
22
|
+
const api_service_1 = require("./indexer/api.service");
|
|
23
|
+
const runtimeService_1 = require("./indexer/runtime/runtimeService");
|
|
24
|
+
const types_2 = require("./indexer/types");
|
|
25
|
+
const substrate_1 = require("./utils/substrate");
|
|
26
|
+
const BLOCK_TIME_VARIANCE = 5000; //ms
|
|
27
|
+
const INTERVAL_PERCENT = 0.9;
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
29
|
+
const { version: packageVersion } = require('../package.json');
|
|
30
|
+
let BlockchainService = class BlockchainService {
|
|
31
|
+
apiService;
|
|
32
|
+
runtimeService;
|
|
33
|
+
constructor(apiService, runtimeService) {
|
|
34
|
+
this.apiService = apiService;
|
|
35
|
+
this.runtimeService = runtimeService;
|
|
36
|
+
}
|
|
37
|
+
isCustomDs = common_substrate_1.isCustomDs;
|
|
38
|
+
isRuntimeDs = common_substrate_1.isRuntimeDs;
|
|
39
|
+
blockHandlerKind = types_1.SubstrateHandlerKind.Block;
|
|
40
|
+
packageVersion = packageVersion;
|
|
41
|
+
async fetchBlocks(blockNums) {
|
|
42
|
+
const specChanged = await this.runtimeService.specChanged(blockNums[blockNums.length - 1]);
|
|
43
|
+
// If specVersion not changed, a known overallSpecVer will be pass in
|
|
44
|
+
// Otherwise use api to fetch runtimes
|
|
45
|
+
return this.apiService.fetchBlocks(blockNums, specChanged ? undefined : this.runtimeService.parentSpecVersion);
|
|
46
|
+
}
|
|
47
|
+
async fetchBlockWorker(worker, height, context) {
|
|
48
|
+
// get SpecVersion from main runtime service
|
|
49
|
+
const { blockSpecVersion, syncedDictionary } = await this.runtimeService.getSpecVersion(height);
|
|
50
|
+
// if main runtime specVersion has been updated, then sync with all workers specVersion map, and lastFinalizedBlock
|
|
51
|
+
if (syncedDictionary) {
|
|
52
|
+
context.workers.map((w) => w.syncRuntimeService(this.runtimeService.specVersionMap, this.runtimeService.latestFinalizedHeight));
|
|
53
|
+
}
|
|
54
|
+
// const start = new Date();
|
|
55
|
+
return worker.fetchBlock(height, blockSpecVersion);
|
|
56
|
+
}
|
|
57
|
+
async onProjectChange(project) {
|
|
58
|
+
// Only network with chainTypes require to reload
|
|
59
|
+
await this.apiService.updateChainTypes();
|
|
60
|
+
this.apiService.updateBlockFetching();
|
|
61
|
+
}
|
|
62
|
+
async getBlockTimestamp(height) {
|
|
63
|
+
const block = await (0, substrate_1.getBlockByHeight)(this.apiService.api, height);
|
|
64
|
+
let timestamp = (0, substrate_1.getTimestamp)(block);
|
|
65
|
+
if (!timestamp) {
|
|
66
|
+
// Not all networks have a block timestamp, e.g. Shiden
|
|
67
|
+
const blockTimestamp = await (await this.apiService.unsafeApi.at(block.hash)).query.timestamp.now();
|
|
68
|
+
timestamp = new Date(blockTimestamp.toNumber());
|
|
69
|
+
}
|
|
70
|
+
return timestamp;
|
|
71
|
+
}
|
|
72
|
+
getBlockSize(block) {
|
|
73
|
+
return (0, types_2.getBlockSize)(block);
|
|
74
|
+
}
|
|
75
|
+
async getFinalizedHeader() {
|
|
76
|
+
const finalizedHash = await this.apiService.unsafeApi.rpc.chain.getFinalizedHead();
|
|
77
|
+
return this.getHeaderForHash(finalizedHash.toHex());
|
|
78
|
+
}
|
|
79
|
+
async getBestHeight() {
|
|
80
|
+
const bestHeader = await this.apiService.unsafeApi.rpc.chain.getHeader();
|
|
81
|
+
return bestHeader.number.toNumber();
|
|
82
|
+
}
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
84
|
+
async getChainInterval() {
|
|
85
|
+
const chainInterval = (0, substrate_1.calcInterval)(this.apiService.unsafeApi)
|
|
86
|
+
.muln(INTERVAL_PERCENT)
|
|
87
|
+
.toNumber();
|
|
88
|
+
return Math.min(BLOCK_TIME_VARIANCE, chainInterval);
|
|
89
|
+
}
|
|
90
|
+
// TODO can this decorator be in unfinalizedBlocks Service?
|
|
91
|
+
async getHeaderForHash(hash) {
|
|
92
|
+
return (0, substrate_1.getHeaderForHash)(this.apiService.unsafeApi, hash);
|
|
93
|
+
}
|
|
94
|
+
// TODO can this decorator be in unfinalizedBlocks Service?
|
|
95
|
+
async getHeaderForHeight(height) {
|
|
96
|
+
const hash = await this.apiService.unsafeApi.rpc.chain.getBlockHash(height);
|
|
97
|
+
return this.getHeaderForHash(hash.toHex());
|
|
98
|
+
}
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
100
|
+
async updateDynamicDs(params, dsObj) {
|
|
101
|
+
if ((0, common_substrate_1.isCustomDs)(dsObj)) {
|
|
102
|
+
dsObj.processor.options = {
|
|
103
|
+
...dsObj.processor.options,
|
|
104
|
+
...params.args,
|
|
105
|
+
};
|
|
106
|
+
// TODO needs dsProcessorService
|
|
107
|
+
// await this.dsProcessorService.validateCustomDs([dsObj]);
|
|
108
|
+
}
|
|
109
|
+
else if ((0, common_substrate_1.isRuntimeDs)(dsObj)) {
|
|
110
|
+
// XXX add any modifications to the ds here
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async getSafeApi(block) {
|
|
114
|
+
const runtimeVersion = !(0, types_2.isFullBlock)(block)
|
|
115
|
+
? undefined
|
|
116
|
+
: await this.runtimeService.getRuntimeVersion(block.block);
|
|
117
|
+
return this.apiService.getPatchedApi(block.block.block.header, runtimeVersion);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
exports.BlockchainService = BlockchainService;
|
|
121
|
+
__decorate([
|
|
122
|
+
(0, node_core_1.mainThreadOnly)(),
|
|
123
|
+
__metadata("design:type", Function),
|
|
124
|
+
__metadata("design:paramtypes", [Array]),
|
|
125
|
+
__metadata("design:returntype", Promise)
|
|
126
|
+
], BlockchainService.prototype, "fetchBlocks", null);
|
|
127
|
+
__decorate([
|
|
128
|
+
(0, node_core_1.mainThreadOnly)(),
|
|
129
|
+
__metadata("design:type", Function),
|
|
130
|
+
__metadata("design:paramtypes", [String]),
|
|
131
|
+
__metadata("design:returntype", Promise)
|
|
132
|
+
], BlockchainService.prototype, "getHeaderForHash", null);
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, node_core_1.mainThreadOnly)(),
|
|
135
|
+
__metadata("design:type", Function),
|
|
136
|
+
__metadata("design:paramtypes", [Number]),
|
|
137
|
+
__metadata("design:returntype", Promise)
|
|
138
|
+
], BlockchainService.prototype, "getHeaderForHeight", null);
|
|
139
|
+
exports.BlockchainService = BlockchainService = __decorate([
|
|
140
|
+
(0, common_1.Injectable)(),
|
|
141
|
+
__param(0, (0, common_1.Inject)('APIService')),
|
|
142
|
+
__param(1, (0, common_1.Inject)('RuntimeService')),
|
|
143
|
+
__metadata("design:paramtypes", [api_service_1.ApiService,
|
|
144
|
+
runtimeService_1.RuntimeService])
|
|
145
|
+
], BlockchainService);
|
|
146
|
+
//# sourceMappingURL=blockchain.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockchain.service.js","sourceRoot":"","sources":["../src/blockchain.service.ts"],"names":[],"mapp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M,CAAC,IAAI;aACf,CAAC;YACF,gCAAgC;YAChC,2DAA2D;QAC7D,CAAC;aAAM,IAAI,IAAA,8BAAW,EAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,2CAA2C;QAC7C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAuC;QACtD,MAAM,cAAc,GAAG,CAAC,IAAA,mBAAW,EAAC,KAAK,CAAC;YACxC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAE7D,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAClC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EACxB,cAAc,CACf,CAAC;IACJ,CAAC;CACF,CAAA;AAtJY,8CAAiB;AA0BtB;IADL,IAAA,0BAAc,GAAE;;;;oDAchB;AAyEK;IADL,IAAA,0BAAc,GAAE;;;;yDAGhB;AAIK;IADL,IAAA,0BAAc,GAAE;;;;2DAIhB;4BAzHU,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAiBR,WAAA,IAAA,eAAM,EAAC,YAAY,CAAC,CAAA;IACpB,WAAA,IAAA,eAAM,EAAC,gBAAgB,CAAC,CAAA;qCADiB,wBAAU;QACF,+BAAc;GAjBvD,iBAAiB,CAsJ7B","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { isCustomDs, isRuntimeDs } from '@subql/common-substrate';\nimport {\n DatasourceParams,\n Header,\n IBlock,\n IBlockchainService,\n mainThreadOnly,\n} from '@subql/node-core';\nimport {\n SubstrateCustomDatasource,\n SubstrateCustomHandler,\n SubstrateDatasource,\n SubstrateHandlerKind,\n SubstrateMapping,\n} from '@subql/types';\nimport {\n SubqueryProject,\n SubstrateProjectDs,\n} from './configure/SubqueryProject';\nimport { ApiService } from './indexer/api.service';\nimport { RuntimeService } from './indexer/runtime/runtimeService';\nimport {\n ApiAt,\n BlockContent,\n getBlockSize,\n isFullBlock,\n LightBlockContent,\n} from './indexer/types';\nimport { IIndexerWorker } from './indexer/worker/worker';\nimport {\n calcInterval,\n getBlockByHeight,\n getTimestamp,\n getHeaderForHash,\n} from './utils/substrate';\n\nconst BLOCK_TIME_VARIANCE = 5000; //ms\nconst INTERVAL_PERCENT = 0.9;\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../package.json');\n\n@Injectable()\nexport class BlockchainService\n implements\n IBlockchainService<\n SubstrateDatasource,\n SubstrateCustomDatasource<\n string,\n SubstrateMapping<SubstrateCustomHandler>\n >,\n SubqueryProject,\n ApiAt,\n LightBlockContent,\n BlockContent,\n IIndexerWorker\n >\n{\n constructor(\n @Inject('APIService') private apiService: ApiService,\n @Inject('RuntimeService') private runtimeService: RuntimeService,\n ) {}\n\n isCustomDs = isCustomDs;\n isRuntimeDs = isRuntimeDs;\n blockHandlerKind = SubstrateHandlerKind.Block;\n packageVersion = packageVersion;\n\n @mainThreadOnly()\n async fetchBlocks(\n blockNums: number[],\n ): Promise<IBlock<BlockContent>[] | IBlock<LightBlockContent>[]> {\n const specChanged = await this.runtimeService.specChanged(\n blockNums[blockNums.length - 1],\n );\n\n // If specVersion not changed, a known overallSpecVer will be pass in\n // Otherwise use api to fetch runtimes\n return this.apiService.fetchBlocks(\n blockNums,\n specChanged ? undefined : this.runtimeService.parentSpecVersion,\n );\n }\n\n async fetchBlockWorker(\n worker: IIndexerWorker,\n height: number,\n context: { workers: IIndexerWorker[] },\n ): Promise<Header> {\n // get SpecVersion from main runtime service\n const { blockSpecVersion, syncedDictionary } =\n await this.runtimeService.getSpecVersion(height);\n\n // if main runtime specVersion has been updated, then sync with all workers specVersion map, and lastFinalizedBlock\n if (syncedDictionary) {\n context.workers.map((w) =>\n w.syncRuntimeService(\n this.runtimeService.specVersionMap,\n this.runtimeService.latestFinalizedHeight,\n ),\n );\n }\n\n // const start = new Date();\n return worker.fetchBlock(height, blockSpecVersion);\n }\n\n async onProjectChange(project: SubqueryProject): Promise<void> {\n // Only network with chainTypes require to reload\n await this.apiService.updateChainTypes();\n this.apiService.updateBlockFetching();\n }\n\n async getBlockTimestamp(height: number): Promise<Date> {\n const block = await getBlockByHeight(this.apiService.api, height);\n\n let timestamp = getTimestamp(block);\n if (!timestamp) {\n // Not all networks have a block timestamp, e.g. Shiden\n const blockTimestamp = await (\n await this.apiService.unsafeApi.at(block.hash)\n ).query.timestamp.now();\n\n timestamp = new Date(blockTimestamp.toNumber());\n }\n\n return timestamp;\n }\n\n getBlockSize(block: IBlock): number {\n return getBlockSize(block);\n }\n\n async getFinalizedHeader(): Promise<Header> {\n const finalizedHash =\n await this.apiService.unsafeApi.rpc.chain.getFinalizedHead();\n\n return this.getHeaderForHash(finalizedHash.toHex());\n }\n\n async getBestHeight(): Promise<number> {\n const bestHeader = await this.apiService.unsafeApi.rpc.chain.getHeader();\n return bestHeader.number.toNumber();\n }\n // eslint-disable-next-line @typescript-eslint/require-await\n async getChainInterval(): Promise<number> {\n const chainInterval = calcInterval(this.apiService.unsafeApi)\n .muln(INTERVAL_PERCENT)\n .toNumber();\n\n return Math.min(BLOCK_TIME_VARIANCE, chainInterval);\n }\n\n // TODO can this decorator be in unfinalizedBlocks Service?\n @mainThreadOnly()\n async getHeaderForHash(hash: string): Promise<Header> {\n return getHeaderForHash(this.apiService.unsafeApi, hash);\n }\n\n // TODO can this decorator be in unfinalizedBlocks Service?\n @mainThreadOnly()\n async getHeaderForHeight(height: number): Promise<Header> {\n const hash = await this.apiService.unsafeApi.rpc.chain.getBlockHash(height);\n return this.getHeaderForHash(hash.toHex());\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async updateDynamicDs(\n params: DatasourceParams,\n dsObj: SubstrateProjectDs,\n ): Promise<void> {\n if (isCustomDs(dsObj)) {\n dsObj.processor.options = {\n ...dsObj.processor.options,\n ...params.args,\n };\n // TODO needs dsProcessorService\n // await this.dsProcessorService.validateCustomDs([dsObj]);\n } else if (isRuntimeDs(dsObj)) {\n // XXX add any modifications to the ds here\n }\n }\n\n async getSafeApi(block: LightBlockContent | BlockContent): Promise<ApiAt> {\n const runtimeVersion = !isFullBlock(block)\n ? undefined\n : await this.runtimeService.getRuntimeVersion(block.block);\n\n return this.apiService.getPatchedApi(\n block.block.block.header,\n runtimeVersion,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IConfig, NodeConfig } from '@subql/node-core';
|
|
2
|
+
export interface ISubstrateConfig extends IConfig {
|
|
3
|
+
skipTransactions: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class SubstrateNodeConfig extends NodeConfig<ISubstrateConfig> {
|
|
6
|
+
/**
|
|
7
|
+
* This is a wrapper around the core NodeConfig to get additional properties that are provided through args or node runner options
|
|
8
|
+
* NOTE: This isn't injected anywhere so you need to wrap the injected node config
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* constructor(
|
|
12
|
+
* nodeConfig: NodeConfig,
|
|
13
|
+
* ) {
|
|
14
|
+
* this.nodeConfig = new SubstrateNodeConfig(nodeConfig);
|
|
15
|
+
* }
|
|
16
|
+
* */
|
|
17
|
+
constructor(config: NodeConfig);
|
|
18
|
+
get skipTransactions(): boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.SubstrateNodeConfig = void 0;
|
|
6
|
+
const node_core_1 = require("@subql/node-core");
|
|
7
|
+
class SubstrateNodeConfig extends node_core_1.NodeConfig {
|
|
8
|
+
/**
|
|
9
|
+
* This is a wrapper around the core NodeConfig to get additional properties that are provided through args or node runner options
|
|
10
|
+
* NOTE: This isn't injected anywhere so you need to wrap the injected node config
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* constructor(
|
|
14
|
+
* nodeConfig: NodeConfig,
|
|
15
|
+
* ) {
|
|
16
|
+
* this.nodeConfig = new SubstrateNodeConfig(nodeConfig);
|
|
17
|
+
* }
|
|
18
|
+
* */
|
|
19
|
+
constructor(config) {
|
|
20
|
+
// Rebuild with internal config
|
|
21
|
+
super(config._config, config._isTest);
|
|
22
|
+
}
|
|
23
|
+
get skipTransactions() {
|
|
24
|
+
return !!this._config.skipTransactions;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SubstrateNodeConfig = SubstrateNodeConfig;
|
|
28
|
+
//# sourceMappingURL=NodeConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeConfig.js","sourceRoot":"","sources":["../../src/configure/NodeConfig.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAAuD;AAMvD,MAAa,mBAAoB,SAAQ,sBAA4B;IACnE;;;;;;;;;;SAUK;IACL,YAAY,MAAkB;QAC5B,+BAA+B;QAC/B,KAAK,CAAE,MAAc,CAAC,OAAO,EAAG,MAAc,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACzC,CAAC;CACF;AApBD,kDAoBC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { IConfig, NodeConfig } from '@subql/node-core';\n\nexport interface ISubstrateConfig extends IConfig {\n skipTransactions: boolean;\n}\n\nexport class SubstrateNodeConfig extends NodeConfig<ISubstrateConfig> {\n /**\n * This is a wrapper around the core NodeConfig to get additional properties that are provided through args or node runner options\n * NOTE: This isn't injected anywhere so you need to wrap the injected node config\n *\n * @example\n * constructor(\n * nodeConfig: NodeConfig,\n * ) {\n * this.nodeConfig = new SubstrateNodeConfig(nodeConfig);\n * }\n * */\n constructor(config: NodeConfig) {\n // Rebuild with internal config\n super((config as any)._config, (config as any)._isTest);\n }\n\n get skipTransactions(): boolean {\n return !!this._config.skipTransactions;\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RegisteredTypes } from '@polkadot/types/types';
|
|
2
|
+
import { SubstrateBlockFilter } from '@subql/common-substrate';
|
|
3
|
+
import { CronFilter, BaseSubqueryProject } from '@subql/node-core';
|
|
4
|
+
import { SubstrateDatasource, RuntimeDatasourceTemplate, CustomDatasourceTemplate, SubstrateNetworkConfig } from '@subql/types';
|
|
5
|
+
import { Reader } from '@subql/types-core';
|
|
6
|
+
export type SubstrateProjectDs = SubstrateDatasource;
|
|
7
|
+
export type SubqlProjectDsTemplate = RuntimeDatasourceTemplate | CustomDatasourceTemplate;
|
|
8
|
+
export type SubqlProjectBlockFilter = SubstrateBlockFilter & CronFilter;
|
|
9
|
+
export type SubqueryProject = BaseSubqueryProject<SubstrateProjectDs, SubqlProjectDsTemplate, SubstrateNetworkConfig> & {
|
|
10
|
+
chainTypes?: RegisteredTypes;
|
|
11
|
+
};
|
|
12
|
+
export declare function createSubQueryProject(path: string, rawManifest: unknown, reader: Reader, root: string, // If project local then directory otherwise temp directory
|
|
13
|
+
networkOverrides?: Partial<SubstrateNetworkConfig>): Promise<SubqueryProject>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createSubQueryProject = createSubQueryProject;
|
|
6
|
+
const common_substrate_1 = require("@subql/common-substrate");
|
|
7
|
+
const node_core_1 = require("@subql/node-core");
|
|
8
|
+
const project_1 = require("../utils/project");
|
|
9
|
+
const { version: packageVersion } = require('../../package.json');
|
|
10
|
+
async function createSubQueryProject(path, rawManifest, reader, root, // If project local then directory otherwise temp directory
|
|
11
|
+
networkOverrides) {
|
|
12
|
+
const project = await node_core_1.BaseSubqueryProject.create({
|
|
13
|
+
parseManifest: (raw) => (0, common_substrate_1.parseSubstrateProjectManifest)(raw).asV1_0_0,
|
|
14
|
+
path,
|
|
15
|
+
rawManifest,
|
|
16
|
+
reader,
|
|
17
|
+
root,
|
|
18
|
+
nodeSemver: packageVersion,
|
|
19
|
+
blockHandlerKind: common_substrate_1.SubstrateHandlerKind.Block,
|
|
20
|
+
networkOverrides,
|
|
21
|
+
isRuntimeDs: common_substrate_1.isRuntimeDs,
|
|
22
|
+
isCustomDs: common_substrate_1.isCustomDs,
|
|
23
|
+
});
|
|
24
|
+
project.chainTypes = project.network.chaintypes
|
|
25
|
+
? await (0, project_1.getChainTypes)(reader, root, project.network.chaintypes.file)
|
|
26
|
+
: undefined;
|
|
27
|
+
return project;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=SubqueryProject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubqueryProject.js","sourceRoot":"","sources":["../../src/configure/SubqueryProject.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAmCnC,sDAyBC;AAzDD,8DAMiC;AACjC,gDAAmE;AAQnE,8CAAiD;AAEjD,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAe3D,KAAK,UAAU,qBAAqB,CACzC,IAAY,EACZ,WAAoB,EACpB,MAAc,EACd,IAAY,EAAE,2DAA2D;AACzE,gBAAkD;IAElD,MAAM,OAAO,GAAG,MAAM,+BAAmB,CAAC,MAAM,CAAkB;QAChE,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,gDAA6B,EAAC,GAAG,CAAC,CAAC,QAAQ;QACnE,IAAI;QACJ,WAAW;QACX,MAAM;QACN,IAAI;QACJ,UAAU,EAAE,cAAc;QAC1B,gBAAgB,EAAE,uCAAoB,CAAC,KAAK;QAC5C,gBAAgB;QAChB,WAAW,EAAX,8BAAW;QACX,UAAU,EAAV,6BAAU;KACX,CAAC,CAAC;IAEH,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU;QAC7C,CAAC,CAAC,MAAM,IAAA,uBAAa,EAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;QACpE,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { RegisteredTypes } from '@polkadot/types/types';\nimport {\n parseSubstrateProjectManifest,\n SubstrateBlockFilter,\n isRuntimeDs,\n SubstrateHandlerKind,\n isCustomDs,\n} from '@subql/common-substrate';\nimport { CronFilter, BaseSubqueryProject } from '@subql/node-core';\nimport {\n SubstrateDatasource,\n RuntimeDatasourceTemplate,\n CustomDatasourceTemplate,\n SubstrateNetworkConfig,\n} from '@subql/types';\nimport { Reader } from '@subql/types-core';\nimport { getChainTypes } from '../utils/project';\n\nconst { version: packageVersion } = require('../../package.json');\n\nexport type SubstrateProjectDs = SubstrateDatasource;\nexport type SubqlProjectDsTemplate =\n | RuntimeDatasourceTemplate\n | CustomDatasourceTemplate;\n\nexport type SubqlProjectBlockFilter = SubstrateBlockFilter & CronFilter;\n\nexport type SubqueryProject = BaseSubqueryProject<\n SubstrateProjectDs,\n SubqlProjectDsTemplate,\n SubstrateNetworkConfig\n> & { chainTypes?: RegisteredTypes };\n\nexport async function createSubQueryProject(\n path: string,\n rawManifest: unknown,\n reader: Reader,\n root: string, // If project local then directory otherwise temp directory\n networkOverrides?: Partial<SubstrateNetworkConfig>,\n): Promise<SubqueryProject> {\n const project = await BaseSubqueryProject.create<SubqueryProject>({\n parseManifest: (raw) => parseSubstrateProjectManifest(raw).asV1_0_0,\n path,\n rawManifest,\n reader,\n root,\n nodeSemver: packageVersion,\n blockHandlerKind: SubstrateHandlerKind.Block,\n networkOverrides,\n isRuntimeDs,\n isCustomDs,\n });\n\n project.chainTypes = project.network.chaintypes\n ? await getChainTypes(reader, root, project.network.chaintypes.file)\n : undefined;\n\n return project;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { NodeConfig } from '@subql/node-core';
|
|
3
|
+
import { SubqueryProject } from './SubqueryProject';
|
|
4
|
+
export declare class ConfigureModule {
|
|
5
|
+
static getInstance(): Promise<{
|
|
6
|
+
nodeConfig: NodeConfig;
|
|
7
|
+
project: SubqueryProject;
|
|
8
|
+
}>;
|
|
9
|
+
static register(): Promise<DynamicModule>;
|
|
10
|
+
static registerManual(nodeConfig: NodeConfig, project: SubqueryProject): DynamicModule;
|
|
11
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
var ConfigureModule_1;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ConfigureModule = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const node_core_1 = require("@subql/node-core");
|
|
15
|
+
const yargs_1 = require("../yargs");
|
|
16
|
+
const SubqueryProject_1 = require("./SubqueryProject");
|
|
17
|
+
const pjson = require('../../package.json');
|
|
18
|
+
let ConfigureModule = ConfigureModule_1 = class ConfigureModule {
|
|
19
|
+
static async getInstance() {
|
|
20
|
+
const { argv } = yargs_1.yargsOptions;
|
|
21
|
+
return (0, node_core_1.registerApp)(argv, SubqueryProject_1.createSubQueryProject, yargs_1.yargsOptions.showHelp.bind(yargs_1.yargsOptions), pjson);
|
|
22
|
+
}
|
|
23
|
+
static async register() {
|
|
24
|
+
const { nodeConfig, project } = await ConfigureModule_1.getInstance();
|
|
25
|
+
return this.registerManual(nodeConfig, project);
|
|
26
|
+
}
|
|
27
|
+
// Used for testing where args/yargs cannot be used
|
|
28
|
+
static registerManual(nodeConfig, project) {
|
|
29
|
+
return {
|
|
30
|
+
module: ConfigureModule_1,
|
|
31
|
+
providers: [
|
|
32
|
+
{
|
|
33
|
+
provide: node_core_1.NodeConfig,
|
|
34
|
+
useValue: nodeConfig,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
provide: 'ISubqueryProject',
|
|
38
|
+
useValue: project,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
provide: 'IProjectUpgradeService',
|
|
42
|
+
useValue: project,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
provide: 'Null',
|
|
46
|
+
useValue: null,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
exports: [
|
|
50
|
+
node_core_1.NodeConfig,
|
|
51
|
+
'ISubqueryProject',
|
|
52
|
+
'IProjectUpgradeService',
|
|
53
|
+
'Null',
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.ConfigureModule = ConfigureModule;
|
|
59
|
+
exports.ConfigureModule = ConfigureModule = ConfigureModule_1 = __decorate([
|
|
60
|
+
(0, common_1.Global)(),
|
|
61
|
+
(0, common_1.Module)({})
|
|
62
|
+
], ConfigureModule);
|
|
63
|
+
//# sourceMappingURL=configure.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configure.module.js","sourceRoot":"","sources":["../../src/configure/configure.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;AAEnC,2CAA+D;AAC/D,gDAA2D;AAC3D,oCAAwC;AACxC,uDAA2E;AAE3E,MAAM,KAAK,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAIrC,IAAM,eAAe,uBAArB,MAAM,eAAe;IAC1B,MAAM,CAAC,KAAK,CAAC,WAAW;QAItB,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAY,CAAC;QAC9B,OAAO,IAAA,uBAAW,EAChB,IAAI,EACJ,uCAAqB,EACrB,oBAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,oBAAY,CAAC,EACxC,KAAK,CACN,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,QAAQ;QACnB,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,iBAAe,CAAC,WAAW,EAAE,CAAC;QAEpE,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IACD,mDAAmD;IACnD,MAAM,CAAC,cAAc,CACnB,UAAsB,EACtB,OAAwB;QAExB,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,sBAAU;oBACnB,QAAQ,EAAE,UAAU;iBACrB;gBACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,wBAAwB;oBACjC,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,MAAM;oBACf,QAAQ,EAAE,IAAI;iBACf;aACF;YACD,OAAO,EAAE;gBACP,sBAAU;gBACV,kBAAkB;gBAClB,wBAAwB;gBACxB,MAAM;aACP;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAnDY,0CAAe;0BAAf,eAAe;IAF3B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CAmD3B","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { DynamicModule, Global, Module } from '@nestjs/common';\nimport { NodeConfig, registerApp } from '@subql/node-core';\nimport { yargsOptions } from '../yargs';\nimport { createSubQueryProject, SubqueryProject } from './SubqueryProject';\n\nconst pjson = require('../../package.json');\n\n@Global()\n@Module({})\nexport class ConfigureModule {\n static async getInstance(): Promise<{\n nodeConfig: NodeConfig;\n project: SubqueryProject;\n }> {\n const { argv } = yargsOptions;\n return registerApp<SubqueryProject>(\n argv,\n createSubQueryProject,\n yargsOptions.showHelp.bind(yargsOptions),\n pjson,\n );\n }\n static async register(): Promise<DynamicModule> {\n const { nodeConfig, project } = await ConfigureModule.getInstance();\n\n return this.registerManual(nodeConfig, project);\n }\n // Used for testing where args/yargs cannot be used\n static registerManual(\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n ): DynamicModule {\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: nodeConfig,\n },\n {\n provide: 'ISubqueryProject',\n useValue: project,\n },\n {\n provide: 'IProjectUpgradeService',\n useValue: project,\n },\n {\n provide: 'Null',\n useValue: null,\n },\n ],\n exports: [\n NodeConfig,\n 'ISubqueryProject',\n 'IProjectUpgradeService',\n 'Null',\n ],\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
3
|
+
import { ApiPromise } from '@polkadot/api';
|
|
4
|
+
import { RuntimeVersion, Header } from '@polkadot/types/interfaces';
|
|
5
|
+
import { NodeConfig, ConnectionPoolService, ApiService as BaseApiService, IBlock } from '@subql/node-core';
|
|
6
|
+
import { IEndpointConfig } from '@subql/types-core';
|
|
7
|
+
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
8
|
+
import { ApiPromiseConnection } from './apiPromise.connection';
|
|
9
|
+
import { ApiAt, BlockContent, LightBlockContent } from './types';
|
|
10
|
+
export declare class ApiService extends BaseApiService<ApiPromise, ApiAt, IBlock<BlockContent>[] | IBlock<LightBlockContent>[], ApiPromiseConnection, IEndpointConfig> implements OnApplicationShutdown {
|
|
11
|
+
private project;
|
|
12
|
+
private _fetchBlocksFunction?;
|
|
13
|
+
private fetchBlocksBatches;
|
|
14
|
+
private _currentBlockHash?;
|
|
15
|
+
private _currentBlockNumber?;
|
|
16
|
+
private nodeConfig;
|
|
17
|
+
private constructor();
|
|
18
|
+
private get fetchBlocksFunction();
|
|
19
|
+
private get currentBlockHash();
|
|
20
|
+
private set currentBlockHash(value);
|
|
21
|
+
private get currentBlockNumber();
|
|
22
|
+
private set currentBlockNumber(value);
|
|
23
|
+
onApplicationShutdown(): Promise<void>;
|
|
24
|
+
static init(project: SubqueryProject, connectionPoolService: ConnectionPoolService<ApiPromiseConnection>, eventEmitter: EventEmitter2, nodeConfig: NodeConfig): Promise<ApiService>;
|
|
25
|
+
updateChainTypes(): Promise<void>;
|
|
26
|
+
updateBlockFetching(): void;
|
|
27
|
+
get api(): ApiPromise;
|
|
28
|
+
getPatchedApi(header: Header, runtimeVersion?: RuntimeVersion): Promise<ApiAt>;
|
|
29
|
+
private redecorateRpcFunction;
|
|
30
|
+
private patchApiRpc;
|
|
31
|
+
private getRPCFunctionName;
|
|
32
|
+
fetchBlocks(heights: number[], overallSpecVer?: number, numAttempts?: number): Promise<IBlock<LightBlockContent>[] | IBlock<BlockContent>[]>;
|
|
33
|
+
protected assertChainId(network: {
|
|
34
|
+
chainId: string;
|
|
35
|
+
}, connection: ApiPromiseConnection): void;
|
|
36
|
+
}
|