@subql/node 6.3.6-1 → 6.4.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1
- package/package.json +6 -6
- package/dist/.tsbuildinfo +0 -1
- package/dist/app.module.d.ts +0 -2
- package/dist/app.module.js +0 -42
- package/dist/app.module.js.map +0 -1
- package/dist/blockchain.service.d.ts +0 -31
- package/dist/blockchain.service.js +0 -146
- package/dist/blockchain.service.js.map +0 -1
- package/dist/configure/NodeConfig.d.ts +0 -19
- package/dist/configure/NodeConfig.js +0 -28
- package/dist/configure/NodeConfig.js.map +0 -1
- package/dist/configure/SubqueryProject.d.ts +0 -13
- package/dist/configure/SubqueryProject.js +0 -29
- package/dist/configure/SubqueryProject.js.map +0 -1
- package/dist/configure/configure.module.d.ts +0 -11
- package/dist/configure/configure.module.js +0 -63
- package/dist/configure/configure.module.js.map +0 -1
- package/dist/indexer/api.service.d.ts +0 -36
- package/dist/indexer/api.service.js +0 -315
- package/dist/indexer/api.service.js.map +0 -1
- package/dist/indexer/apiPromise.connection.d.ts +0 -24
- package/dist/indexer/apiPromise.connection.js +0 -106
- package/dist/indexer/apiPromise.connection.js.map +0 -1
- package/dist/indexer/dictionary/index.d.ts +0 -2
- package/dist/indexer/dictionary/index.js +0 -21
- package/dist/indexer/dictionary/index.js.map +0 -1
- package/dist/indexer/dictionary/substrateDictionary.service.d.ts +0 -13
- package/dist/indexer/dictionary/substrateDictionary.service.js +0 -93
- package/dist/indexer/dictionary/substrateDictionary.service.js.map +0 -1
- package/dist/indexer/dictionary/types.d.ts +0 -10
- package/dist/indexer/dictionary/types.js +0 -5
- package/dist/indexer/dictionary/types.js.map +0 -1
- package/dist/indexer/dictionary/v1/index.d.ts +0 -1
- package/dist/indexer/dictionary/v1/index.js +0 -20
- package/dist/indexer/dictionary/v1/index.js.map +0 -1
- package/dist/indexer/dictionary/v1/substrateDictionaryV1.d.ts +0 -19
- package/dist/indexer/dictionary/v1/substrateDictionaryV1.js +0 -223
- package/dist/indexer/dictionary/v1/substrateDictionaryV1.js.map +0 -1
- package/dist/indexer/dictionary/v2/index.d.ts +0 -2
- package/dist/indexer/dictionary/v2/index.js +0 -21
- package/dist/indexer/dictionary/v2/index.js.map +0 -1
- package/dist/indexer/dictionary/v2/substrateDictionaryV2.d.ts +0 -20
- package/dist/indexer/dictionary/v2/substrateDictionaryV2.js +0 -46
- package/dist/indexer/dictionary/v2/substrateDictionaryV2.js.map +0 -1
- package/dist/indexer/dictionary/v2/types.d.ts +0 -5
- package/dist/indexer/dictionary/v2/types.js +0 -5
- package/dist/indexer/dictionary/v2/types.js.map +0 -1
- package/dist/indexer/fetch.module.d.ts +0 -2
- package/dist/indexer/fetch.module.js +0 -94
- package/dist/indexer/fetch.module.js.map +0 -1
- package/dist/indexer/indexer.manager.d.ts +0 -27
- package/dist/indexer/indexer.manager.js +0 -153
- package/dist/indexer/indexer.manager.js.map +0 -1
- package/dist/indexer/runtime/base-runtime.service.d.ts +0 -24
- package/dist/indexer/runtime/base-runtime.service.js +0 -136
- package/dist/indexer/runtime/base-runtime.service.js.map +0 -1
- package/dist/indexer/runtime/runtimeService.d.ts +0 -15
- package/dist/indexer/runtime/runtimeService.js +0 -94
- package/dist/indexer/runtime/runtimeService.js.map +0 -1
- package/dist/indexer/runtime/workerRuntimeService.d.ts +0 -9
- package/dist/indexer/runtime/workerRuntimeService.js +0 -43
- package/dist/indexer/runtime/workerRuntimeService.js.map +0 -1
- package/dist/indexer/types.d.ts +0 -20
- package/dist/indexer/types.js +0 -13
- package/dist/indexer/types.js.map +0 -1
- package/dist/indexer/worker/worker-fetch.module.d.ts +0 -5
- package/dist/indexer/worker/worker-fetch.module.js +0 -60
- package/dist/indexer/worker/worker-fetch.module.js.map +0 -1
- package/dist/indexer/worker/worker.d.ts +0 -9
- package/dist/indexer/worker/worker.js +0 -48
- package/dist/indexer/worker/worker.js.map +0 -1
- package/dist/indexer/worker/worker.module.d.ts +0 -2
- package/dist/indexer/worker/worker.module.js +0 -33
- package/dist/indexer/worker/worker.module.js.map +0 -1
- package/dist/indexer/worker/worker.service.d.ts +0 -26
- package/dist/indexer/worker/worker.service.js +0 -71
- package/dist/indexer/worker/worker.service.js.map +0 -1
- package/dist/indexer/x-provider/cachedProvider.d.ts +0 -2
- package/dist/indexer/x-provider/cachedProvider.js +0 -40
- package/dist/indexer/x-provider/cachedProvider.js.map +0 -1
- package/dist/indexer/x-provider/http.d.ts +0 -75
- package/dist/indexer/x-provider/http.js +0 -198
- package/dist/indexer/x-provider/http.js.map +0 -1
- package/dist/init.d.ts +0 -1
- package/dist/init.js +0 -41
- package/dist/init.js.map +0 -1
- package/dist/main.d.ts +0 -1
- package/dist/main.js +0 -19
- package/dist/main.js.map +0 -1
- package/dist/subcommands/forceClean.init.d.ts +0 -1
- package/dist/subcommands/forceClean.init.js +0 -10
- package/dist/subcommands/forceClean.init.js.map +0 -1
- package/dist/subcommands/forceClean.module.d.ts +0 -2
- package/dist/subcommands/forceClean.module.js +0 -28
- package/dist/subcommands/forceClean.module.js.map +0 -1
- package/dist/subcommands/reindex.init.d.ts +0 -3
- package/dist/subcommands/reindex.init.js +0 -33
- package/dist/subcommands/reindex.init.js.map +0 -1
- package/dist/subcommands/reindex.module.d.ts +0 -2
- package/dist/subcommands/reindex.module.js +0 -69
- package/dist/subcommands/reindex.module.js.map +0 -1
- package/dist/subcommands/testing.init.d.ts +0 -1
- package/dist/subcommands/testing.init.js +0 -21
- package/dist/subcommands/testing.init.js.map +0 -1
- package/dist/subcommands/testing.module.d.ts +0 -2
- package/dist/subcommands/testing.module.js +0 -65
- package/dist/subcommands/testing.module.js.map +0 -1
- package/dist/subcommands/testing.service.d.ts +0 -14
- package/dist/subcommands/testing.service.js +0 -60
- package/dist/subcommands/testing.service.js.map +0 -1
- package/dist/utils/project.d.ts +0 -9
- package/dist/utils/project.js +0 -116
- package/dist/utils/project.js.map +0 -1
- package/dist/utils/substrate.d.ts +0 -41
- package/dist/utils/substrate.js +0 -348
- package/dist/utils/substrate.js.map +0 -1
- package/dist/utils/test.utils.d.ts +0 -2
- package/dist/utils/test.utils.js +0 -70
- package/dist/utils/test.utils.js.map +0 -1
- package/dist/yargs.d.ts +0 -276
- package/dist/yargs.js +0 -27
- package/dist/yargs.js.map +0 -1
|
@@ -1,60 +0,0 @@
|
|
|
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.WorkerFetchModule = void 0;
|
|
12
|
-
const common_1 = require("@nestjs/common");
|
|
13
|
-
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
14
|
-
const node_core_1 = require("@subql/node-core");
|
|
15
|
-
const blockchain_service_1 = require("../../blockchain.service");
|
|
16
|
-
const api_service_1 = require("../api.service");
|
|
17
|
-
const indexer_manager_1 = require("../indexer.manager");
|
|
18
|
-
const workerRuntimeService_1 = require("../runtime/workerRuntimeService");
|
|
19
|
-
const worker_service_1 = require("./worker.service");
|
|
20
|
-
/**
|
|
21
|
-
* The alternative version of FetchModule for worker
|
|
22
|
-
*/
|
|
23
|
-
let WorkerFetchModule = class WorkerFetchModule {
|
|
24
|
-
};
|
|
25
|
-
exports.WorkerFetchModule = WorkerFetchModule;
|
|
26
|
-
exports.WorkerFetchModule = WorkerFetchModule = __decorate([
|
|
27
|
-
(0, common_1.Module)({
|
|
28
|
-
imports: [node_core_1.WorkerCoreModule],
|
|
29
|
-
providers: [
|
|
30
|
-
node_core_1.DsProcessorService,
|
|
31
|
-
indexer_manager_1.IndexerManager,
|
|
32
|
-
{
|
|
33
|
-
provide: 'APIService',
|
|
34
|
-
useFactory: api_service_1.ApiService.init,
|
|
35
|
-
inject: [
|
|
36
|
-
'ISubqueryProject',
|
|
37
|
-
node_core_1.ConnectionPoolService,
|
|
38
|
-
event_emitter_1.EventEmitter2,
|
|
39
|
-
node_core_1.NodeConfig,
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
provide: 'IProjectService',
|
|
44
|
-
useClass: node_core_1.ProjectService,
|
|
45
|
-
},
|
|
46
|
-
// This is aliased so it satisfies the BlockchainService, other services are updated to reflect this
|
|
47
|
-
{
|
|
48
|
-
provide: 'RuntimeService',
|
|
49
|
-
useClass: workerRuntimeService_1.WorkerRuntimeService,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
provide: 'IBlockchainService',
|
|
53
|
-
useClass: blockchain_service_1.BlockchainService,
|
|
54
|
-
},
|
|
55
|
-
worker_service_1.WorkerService,
|
|
56
|
-
],
|
|
57
|
-
exports: [],
|
|
58
|
-
})
|
|
59
|
-
], WorkerFetchModule);
|
|
60
|
-
//# sourceMappingURL=worker-fetch.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-fetch.module.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker-fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAAsD;AACtD,gDAM0B;AAC1B,iEAA6D;AAC7D,gDAA4C;AAC5C,wDAAoD;AACpD,0EAAuE;AACvE,qDAAiD;AAEjD;;GAEG;AAkCI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAAG,CAAA;AAApB,8CAAiB;4BAAjB,iBAAiB;IAhC7B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAgB,CAAC;QAC3B,SAAS,EAAE;YACT,8BAAkB;YAClB,gCAAc;YACd;gBACE,OAAO,EAAE,YAAY;gBACrB,UAAU,EAAE,wBAAU,CAAC,IAAI;gBAC3B,MAAM,EAAE;oBACN,kBAAkB;oBAClB,iCAAqB;oBACrB,6BAAa;oBACb,sBAAU;iBACX;aACF;YACD;gBACE,OAAO,EAAE,iBAAiB;gBAC1B,QAAQ,EAAE,0BAAc;aACzB;YACD,oGAAoG;YACpG;gBACE,OAAO,EAAE,gBAAgB;gBACzB,QAAQ,EAAE,2CAAoB;aAC/B;YACD;gBACE,OAAO,EAAE,oBAAoB;gBAC7B,QAAQ,EAAE,sCAAiB;aAC5B;YACD,8BAAa;SACd;QACD,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,iBAAiB,CAAG","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ConnectionPoolService,\n NodeConfig,\n WorkerCoreModule,\n ProjectService,\n DsProcessorService,\n} from '@subql/node-core';\nimport { BlockchainService } from '../../blockchain.service';\nimport { ApiService } from '../api.service';\nimport { IndexerManager } from '../indexer.manager';\nimport { WorkerRuntimeService } from '../runtime/workerRuntimeService';\nimport { WorkerService } from './worker.service';\n\n/**\n * The alternative version of FetchModule for worker\n */\n\n@Module({\n imports: [WorkerCoreModule],\n providers: [\n DsProcessorService,\n IndexerManager,\n {\n provide: 'APIService',\n useFactory: ApiService.init,\n inject: [\n 'ISubqueryProject',\n ConnectionPoolService,\n EventEmitter2,\n NodeConfig,\n ],\n },\n {\n provide: 'IProjectService',\n useClass: ProjectService,\n },\n // This is aliased so it satisfies the BlockchainService, other services are updated to reflect this\n {\n provide: 'RuntimeService',\n useClass: WorkerRuntimeService,\n },\n {\n provide: 'IBlockchainService',\n useClass: BlockchainService,\n },\n WorkerService,\n ],\n exports: [],\n})\nexport class WorkerFetchModule {}\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { IBaseIndexerWorker } from '@subql/node-core';
|
|
2
|
-
import { SpecVersion } from '../dictionary';
|
|
3
|
-
declare function getSpecFromMap(height: number): number | undefined;
|
|
4
|
-
declare function syncRuntimeService(specVersions: SpecVersion[], latestFinalizedHeight?: number): void;
|
|
5
|
-
export type IIndexerWorker = IBaseIndexerWorker & {
|
|
6
|
-
syncRuntimeService: typeof syncRuntimeService;
|
|
7
|
-
getSpecFromMap: typeof getSpecFromMap;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
// initlogger and yargs must be imported before all other imports
|
|
6
|
-
// making sure logger is defined before its called
|
|
7
|
-
// eslint-disable-next-line import/order
|
|
8
|
-
const logger_1 = require("@subql/node-core/logger");
|
|
9
|
-
// eslint-disable-next-line import/order
|
|
10
|
-
const yargs_1 = require("../../yargs");
|
|
11
|
-
const { argv } = yargs_1.yargsOptions;
|
|
12
|
-
(0, logger_1.initLogger)(argv.debug, argv.outputFmt, argv.logLevel);
|
|
13
|
-
const node_worker_threads_1 = require("node:worker_threads");
|
|
14
|
-
const core_1 = require("@nestjs/core");
|
|
15
|
-
const node_core_1 = require("@subql/node-core");
|
|
16
|
-
const worker_module_1 = require("./worker.module");
|
|
17
|
-
const worker_service_1 = require("./worker.service");
|
|
18
|
-
const logger = (0, node_core_1.getLogger)(`worker #${node_worker_threads_1.threadId}`);
|
|
19
|
-
async function initWorker(startHeight) {
|
|
20
|
-
try {
|
|
21
|
-
const app = await core_1.NestFactory.create(worker_module_1.WorkerModule, {
|
|
22
|
-
logger: new node_core_1.NestLogger(!!argv.debug), // TIP: If the worker is crashing comment out this line for better logging
|
|
23
|
-
});
|
|
24
|
-
await app.init();
|
|
25
|
-
const projectService = app.get('IProjectService');
|
|
26
|
-
// Initialise async services, we do this here rather than in factories so we can capture one off events
|
|
27
|
-
await projectService.init(startHeight);
|
|
28
|
-
const workerService = app.get(worker_service_1.WorkerService);
|
|
29
|
-
(0, node_core_1.initWorkerServices)(app, workerService);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
console.log('Failed to start worker', e);
|
|
33
|
-
logger.error(e, 'Failed to start worker');
|
|
34
|
-
throw e;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function getSpecFromMap(height) {
|
|
38
|
-
return (0, node_core_1.getWorkerService)().getSpecFromMap(height);
|
|
39
|
-
}
|
|
40
|
-
function syncRuntimeService(specVersions, latestFinalizedHeight) {
|
|
41
|
-
(0, node_core_1.getWorkerService)().syncRuntimeService(specVersions, latestFinalizedHeight);
|
|
42
|
-
}
|
|
43
|
-
global.host = (0, node_core_1.createWorkerHost)([], {
|
|
44
|
-
syncRuntimeService,
|
|
45
|
-
getSpecFromMap,
|
|
46
|
-
initWorker,
|
|
47
|
-
});
|
|
48
|
-
//# sourceMappingURL=worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,iEAAiE;AACjE,kDAAkD;AAClD,wCAAwC;AACxC,oDAAqD;AACrD,wCAAwC;AACxC,uCAA2C;AAE3C,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAY,CAAC;AAE9B,IAAA,mBAAU,EACR,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,SAA+B,EACpC,IAAI,CAAC,QAA8B,CACpC,CAA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kBAAkB;IAClB,cAAc;IACd,UAAU;CACX,CAAC,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\n// initlogger and yargs must be imported before all other imports\n// making sure logger is defined before its called\n// eslint-disable-next-line import/order\nimport { initLogger } from '@subql/node-core/logger';\n// eslint-disable-next-line import/order\nimport { yargsOptions } from '../../yargs';\n\nconst { argv } = yargsOptions;\n\ninitLogger(\n argv.debug,\n argv.outputFmt as 'json' | 'colored',\n argv.logLevel as string | undefined,\n);\n\nimport { threadId } from 'node:worker_threads';\nimport { NestFactory } from '@nestjs/core';\nimport {\n getLogger,\n NestLogger,\n createWorkerHost,\n initWorkerServices,\n getWorkerService,\n IBaseIndexerWorker,\n ProjectService,\n} from '@subql/node-core';\nimport { SpecVersion } from '../dictionary';\nimport { WorkerModule } from './worker.module';\nimport { WorkerService } from './worker.service';\n\nconst logger = getLogger(`worker #${threadId}`);\n\nasync function initWorker(startHeight?: number): Promise<void> {\n try {\n const app = await NestFactory.create(WorkerModule, {\n logger: new NestLogger(!!argv.debug), // TIP: If the worker is crashing comment out this line for better logging\n });\n\n await app.init();\n\n const projectService: ProjectService = app.get('IProjectService');\n // Initialise async services, we do this here rather than in factories so we can capture one off events\n await projectService.init(startHeight);\n const workerService = app.get(WorkerService);\n\n initWorkerServices(app, workerService);\n } catch (e: any) {\n console.log('Failed to start worker', e);\n logger.error(e, 'Failed to start worker');\n throw e;\n }\n}\n\nfunction getSpecFromMap(height: number): number | undefined {\n return getWorkerService<WorkerService>().getSpecFromMap(height);\n}\n\nfunction syncRuntimeService(\n specVersions: SpecVersion[],\n latestFinalizedHeight?: number,\n): void {\n getWorkerService<WorkerService>().syncRuntimeService(\n specVersions,\n latestFinalizedHeight,\n );\n}\n\nexport type IIndexerWorker = IBaseIndexerWorker & {\n syncRuntimeService: typeof syncRuntimeService;\n getSpecFromMap: typeof getSpecFromMap;\n};\n\n(global as any).host = createWorkerHost([], {\n syncRuntimeService,\n getSpecFromMap,\n initWorker,\n});\n"]}
|
|
@@ -1,33 +0,0 @@
|
|
|
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.WorkerModule = 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 worker_fetch_module_1 = require("./worker-fetch.module");
|
|
18
|
-
let WorkerModule = class WorkerModule {
|
|
19
|
-
};
|
|
20
|
-
exports.WorkerModule = WorkerModule;
|
|
21
|
-
exports.WorkerModule = WorkerModule = __decorate([
|
|
22
|
-
(0, common_1.Module)({
|
|
23
|
-
imports: [
|
|
24
|
-
event_emitter_1.EventEmitterModule.forRoot(),
|
|
25
|
-
configure_module_1.ConfigureModule.register(),
|
|
26
|
-
schedule_1.ScheduleModule.forRoot(),
|
|
27
|
-
node_core_1.WorkerCoreModule,
|
|
28
|
-
worker_fetch_module_1.WorkerFetchModule,
|
|
29
|
-
],
|
|
30
|
-
controllers: [],
|
|
31
|
-
})
|
|
32
|
-
], WorkerModule);
|
|
33
|
-
//# sourceMappingURL=worker.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.module.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA2D;AAC3D,+CAAkD;AAClD,gDAAoD;AACpD,uEAAmE;AACnE,+DAA0D;AAYnD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IAVxB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,kCAAkB,CAAC,OAAO,EAAE;YAC5B,kCAAe,CAAC,QAAQ,EAAE;YAC1B,yBAAc,CAAC,OAAO,EAAE;YACxB,4BAAgB;YAChB,uCAAiB;SAClB;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,YAAY,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 { WorkerCoreModule } from '@subql/node-core';\nimport { ConfigureModule } from '../../configure/configure.module';\nimport { WorkerFetchModule } from './worker-fetch.module';\n\n@Module({\n imports: [\n EventEmitterModule.forRoot(),\n ConfigureModule.register(),\n ScheduleModule.forRoot(),\n WorkerCoreModule,\n WorkerFetchModule,\n ],\n controllers: [],\n})\nexport class WorkerModule {}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { NodeConfig, IProjectService, ProcessBlockResponse, BaseWorkerService, IProjectUpgradeService, IBlock, Header } from '@subql/node-core';
|
|
2
|
-
import { SubstrateDatasource } from '@subql/types';
|
|
3
|
-
import { ApiService } from '../api.service';
|
|
4
|
-
import { SpecVersion } from '../dictionary';
|
|
5
|
-
import { IndexerManager } from '../indexer.manager';
|
|
6
|
-
import { WorkerRuntimeService } from '../runtime/workerRuntimeService';
|
|
7
|
-
import { BlockContent, LightBlockContent } from '../types';
|
|
8
|
-
export type FetchBlockResponse = Header & {
|
|
9
|
-
specVersion?: number;
|
|
10
|
-
};
|
|
11
|
-
export declare class WorkerService extends BaseWorkerService<BlockContent | LightBlockContent, FetchBlockResponse, SubstrateDatasource, {
|
|
12
|
-
specVersion: number;
|
|
13
|
-
}> {
|
|
14
|
-
private apiService;
|
|
15
|
-
private indexerManager;
|
|
16
|
-
private workerRuntimeService;
|
|
17
|
-
constructor(apiService: ApiService, indexerManager: IndexerManager, workerRuntimeService: WorkerRuntimeService, projectService: IProjectService<SubstrateDatasource>, projectUpgradeService: IProjectUpgradeService, nodeConfig: NodeConfig);
|
|
18
|
-
protected fetchChainBlock(height: number, { specVersion }: {
|
|
19
|
-
specVersion: number;
|
|
20
|
-
}): Promise<IBlock<BlockContent | LightBlockContent>>;
|
|
21
|
-
protected toBlockResponse(block: BlockContent): FetchBlockResponse;
|
|
22
|
-
protected getBlockSize(block: IBlock<BlockContent | LightBlockContent>): number;
|
|
23
|
-
protected processFetchedBlock(block: IBlock<BlockContent | LightBlockContent>, dataSources: SubstrateDatasource[]): Promise<ProcessBlockResponse>;
|
|
24
|
-
getSpecFromMap(height: number): number | undefined;
|
|
25
|
-
syncRuntimeService(specVersions: SpecVersion[], latestFinalizedHeight?: number): void;
|
|
26
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
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.WorkerService = void 0;
|
|
18
|
-
const common_1 = require("@nestjs/common");
|
|
19
|
-
const node_core_1 = require("@subql/node-core");
|
|
20
|
-
const substrate_1 = require("../../utils/substrate");
|
|
21
|
-
const api_service_1 = require("../api.service");
|
|
22
|
-
const indexer_manager_1 = require("../indexer.manager");
|
|
23
|
-
const workerRuntimeService_1 = require("../runtime/workerRuntimeService");
|
|
24
|
-
const types_1 = require("../types");
|
|
25
|
-
let WorkerService = class WorkerService extends node_core_1.BaseWorkerService {
|
|
26
|
-
apiService;
|
|
27
|
-
indexerManager;
|
|
28
|
-
workerRuntimeService;
|
|
29
|
-
constructor(apiService, indexerManager, workerRuntimeService, projectService, projectUpgradeService, nodeConfig) {
|
|
30
|
-
super(projectService, projectUpgradeService, nodeConfig);
|
|
31
|
-
this.apiService = apiService;
|
|
32
|
-
this.indexerManager = indexerManager;
|
|
33
|
-
this.workerRuntimeService = workerRuntimeService;
|
|
34
|
-
}
|
|
35
|
-
async fetchChainBlock(height, { specVersion }) {
|
|
36
|
-
const specChanged = await this.workerRuntimeService.specChanged(height, specVersion);
|
|
37
|
-
const [block] = await this.apiService.fetchBlocks([height], specChanged ? undefined : this.workerRuntimeService.parentSpecVersion);
|
|
38
|
-
return block;
|
|
39
|
-
}
|
|
40
|
-
// TODO test this with LightBlockContent
|
|
41
|
-
toBlockResponse(block /* | LightBlockContent*/) {
|
|
42
|
-
return {
|
|
43
|
-
...(0, substrate_1.substrateBlockToHeader)(block.block),
|
|
44
|
-
specVersion: block.block.specVersion,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
getBlockSize(block) {
|
|
48
|
-
return (0, types_1.getBlockSize)(block);
|
|
49
|
-
}
|
|
50
|
-
async processFetchedBlock(block, dataSources) {
|
|
51
|
-
return this.indexerManager.indexBlock(block, dataSources);
|
|
52
|
-
}
|
|
53
|
-
getSpecFromMap(height) {
|
|
54
|
-
return this.workerRuntimeService.getSpecFromMap(height, this.workerRuntimeService.specVersionMap);
|
|
55
|
-
}
|
|
56
|
-
syncRuntimeService(specVersions, latestFinalizedHeight) {
|
|
57
|
-
this.workerRuntimeService.syncSpecVersionMap(specVersions, latestFinalizedHeight);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
exports.WorkerService = WorkerService;
|
|
61
|
-
exports.WorkerService = WorkerService = __decorate([
|
|
62
|
-
(0, common_1.Injectable)(),
|
|
63
|
-
__param(0, (0, common_1.Inject)('APIService')),
|
|
64
|
-
__param(2, (0, common_1.Inject)('RuntimeService')),
|
|
65
|
-
__param(3, (0, common_1.Inject)('IProjectService')),
|
|
66
|
-
__param(4, (0, common_1.Inject)('IProjectUpgradeService')),
|
|
67
|
-
__metadata("design:paramtypes", [api_service_1.ApiService,
|
|
68
|
-
indexer_manager_1.IndexerManager,
|
|
69
|
-
workerRuntimeService_1.WorkerRuntimeService, Object, Object, node_core_1.NodeConfig])
|
|
70
|
-
], WorkerService);
|
|
71
|
-
//# sourceMappingURL=worker.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC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,WAAW,CAAC,CAAC;IAC5D,CAAC;IAED,cAAc,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAC7C,MAAM,EACN,IAAI,CAAC,oBAAoB,CAAC,cAAc,CACzC,CAAC;IACJ,CAAC;IAED,kBAAkB,CAChB,YAA2B,EAC3B,qBAA8B;QAE9B,IAAI,CAAC,oBAAoB,CAAC,kBAAkB,CAC1C,YAAY,EACZ,qBAAqB,CACtB,CAAC;IACJ,CAAC;CACF,CAAA;AA5EY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,YAAY,CAAC,CAAA;IAEpB,WAAA,IAAA,eAAM,EAAC,gBAAgB,CAAC,CAAA;IAExB,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCANS,wBAAU;QAC5B,gCAAc;QAER,2CAAoB,kBAKtC,sBAAU;GAfb,aAAa,CA4EzB","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport {\n NodeConfig,\n IProjectService,\n ProcessBlockResponse,\n BaseWorkerService,\n IProjectUpgradeService,\n IBlock,\n Header,\n} from '@subql/node-core';\nimport { SubstrateDatasource } from '@subql/types';\nimport { substrateBlockToHeader } from '../../utils/substrate';\nimport { ApiService } from '../api.service';\nimport { SpecVersion } from '../dictionary';\nimport { IndexerManager } from '../indexer.manager';\nimport { WorkerRuntimeService } from '../runtime/workerRuntimeService';\nimport { BlockContent, getBlockSize, LightBlockContent } from '../types';\n\nexport type FetchBlockResponse = Header & { specVersion?: number };\n\n@Injectable()\nexport class WorkerService extends BaseWorkerService<\n BlockContent | LightBlockContent,\n FetchBlockResponse,\n SubstrateDatasource,\n { specVersion: number }\n> {\n constructor(\n @Inject('APIService') private apiService: ApiService,\n private indexerManager: IndexerManager,\n @Inject('RuntimeService')\n private workerRuntimeService: WorkerRuntimeService,\n @Inject('IProjectService')\n projectService: IProjectService<SubstrateDatasource>,\n @Inject('IProjectUpgradeService')\n projectUpgradeService: IProjectUpgradeService,\n nodeConfig: NodeConfig,\n ) {\n super(projectService, projectUpgradeService, nodeConfig);\n }\n\n protected async fetchChainBlock(\n height: number,\n { specVersion }: { specVersion: number },\n ): Promise<IBlock<BlockContent | LightBlockContent>> {\n const specChanged = await this.workerRuntimeService.specChanged(\n height,\n specVersion,\n );\n\n const [block] = await this.apiService.fetchBlocks(\n [height],\n specChanged ? undefined : this.workerRuntimeService.parentSpecVersion,\n );\n\n return block;\n }\n\n // TODO test this with LightBlockContent\n protected toBlockResponse(\n block: BlockContent /* | LightBlockContent*/,\n ): FetchBlockResponse {\n return {\n ...substrateBlockToHeader(block.block),\n specVersion: block.block.specVersion,\n };\n }\n\n protected getBlockSize(\n block: IBlock<BlockContent | LightBlockContent>,\n ): number {\n return getBlockSize(block);\n }\n\n protected async processFetchedBlock(\n block: IBlock<BlockContent | LightBlockContent>,\n dataSources: SubstrateDatasource[],\n ): Promise<ProcessBlockResponse> {\n return this.indexerManager.indexBlock(block, dataSources);\n }\n\n getSpecFromMap(height: number): number | undefined {\n return this.workerRuntimeService.getSpecFromMap(\n height,\n this.workerRuntimeService.specVersionMap,\n );\n }\n\n syncRuntimeService(\n specVersions: SpecVersion[],\n latestFinalizedHeight?: number,\n ): void {\n this.workerRuntimeService.syncSpecVersionMap(\n specVersions,\n latestFinalizedHeight,\n );\n }\n}\n"]}
|
|
@@ -1,40 +0,0 @@
|
|
|
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.createCachedProvider = createCachedProvider;
|
|
6
|
-
const lru_cache_1 = require("lru-cache");
|
|
7
|
-
const MAX_CACHE_SIZE = 200;
|
|
8
|
-
const CACHE_TTL = 60 * 1000;
|
|
9
|
-
function createCachedProvider(provider) {
|
|
10
|
-
const cacheMap = new lru_cache_1.LRUCache({
|
|
11
|
-
max: MAX_CACHE_SIZE,
|
|
12
|
-
ttl: CACHE_TTL,
|
|
13
|
-
});
|
|
14
|
-
const cachedMethodHandler = (fn, args) => {
|
|
15
|
-
const [method, params] = args;
|
|
16
|
-
// If there are no parameters then we don't cache as we want the latest results
|
|
17
|
-
if (!params.length) {
|
|
18
|
-
return fn(...args);
|
|
19
|
-
}
|
|
20
|
-
const cacheKey = `${method}-${params[0]}`;
|
|
21
|
-
if (cacheMap.has(cacheKey)) {
|
|
22
|
-
return cacheMap.get(cacheKey);
|
|
23
|
-
}
|
|
24
|
-
const resultPromise = fn(...args);
|
|
25
|
-
cacheMap.set(cacheKey, resultPromise);
|
|
26
|
-
return resultPromise;
|
|
27
|
-
};
|
|
28
|
-
const originalSend = provider.send.bind(provider);
|
|
29
|
-
provider.send = (...args) => {
|
|
30
|
-
const [method] = args;
|
|
31
|
-
//caching state_getRuntimeVersion and chain_getHeader
|
|
32
|
-
//because they are fetched twice per block
|
|
33
|
-
if (['state_getRuntimeVersion', 'chain_getHeader'].includes(method)) {
|
|
34
|
-
return cachedMethodHandler(originalSend, args);
|
|
35
|
-
}
|
|
36
|
-
return originalSend(...args);
|
|
37
|
-
};
|
|
38
|
-
return provider;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=cachedProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cachedProvider.js","sourceRoot":"","sources":["../../../src/indexer/x-provider/cachedProvider.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAQnC,oDAyCC;AA9CD,yCAAqC;AAErC,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5B,SAAgB,o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AClB,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { ProviderInterface } from '@polkadot/rpc-provider/types';\nimport { LRUCache } from 'lru-cache';\n\nconst MAX_CACHE_SIZE = 200;\nconst CACHE_TTL = 60 * 1000;\n\nexport function createCachedProvider<\n P extends ProviderInterface = ProviderInterface,\n>(provider: P): P {\n const cacheMap = new LRUCache<string, Promise<any>>({\n max: MAX_CACHE_SIZE,\n ttl: CACHE_TTL,\n });\n\n const cachedMethodHandler = (\n fn: ProviderInterface['send'],\n args: Parameters<ProviderInterface['send']>,\n ) => {\n const [method, params] = args;\n // If there are no parameters then we don't cache as we want the latest results\n if (!params.length) {\n return fn(...args);\n }\n\n const cacheKey = `${method}-${params[0]}`;\n if (cacheMap.has(cacheKey)) {\n return cacheMap.get(cacheKey);\n }\n\n const resultPromise = fn(...args);\n cacheMap.set(cacheKey, resultPromise);\n return resultPromise;\n };\n\n const originalSend = provider.send.bind(provider);\n (provider as any).send = (...args: Parameters<ProviderInterface['send']>) => {\n const [method] = args;\n //caching state_getRuntimeVersion and chain_getHeader\n //because they are fetched twice per block\n if (['state_getRuntimeVersion', 'chain_getHeader'].includes(method)) {\n return cachedMethodHandler(originalSend, args);\n }\n\n return originalSend(...args);\n };\n\n return provider;\n}\n"]}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '@polkadot/rpc-provider/types';
|
|
2
|
-
/**
|
|
3
|
-
* # @polkadot/rpc-provider
|
|
4
|
-
*
|
|
5
|
-
* @name HttpProvider
|
|
6
|
-
*
|
|
7
|
-
* @description The HTTP Provider allows sending requests using HTTP to an HTTP RPC server TCP port. It does not support subscriptions so you won't be able to listen to events such as new blocks or balance changes. It is usually preferable using the [[WsProvider]].
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* <BR>
|
|
11
|
-
*
|
|
12
|
-
* ```javascript
|
|
13
|
-
* import Api from '@polkadot/api/promise';
|
|
14
|
-
* import { HttpProvider } from '@polkadot/rpc-provider';
|
|
15
|
-
*
|
|
16
|
-
* const provider = new HttpProvider('http://127.0.0.1:9933');
|
|
17
|
-
* const api = new Api(provider);
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @see [[WsProvider]]
|
|
21
|
-
*/
|
|
22
|
-
export declare class HttpProvider implements ProviderInterface {
|
|
23
|
-
#private;
|
|
24
|
-
/**
|
|
25
|
-
* @param {string} endpoint The endpoint url starting with http://
|
|
26
|
-
*/
|
|
27
|
-
constructor(endpoint?: string, headers?: Record<string, string>);
|
|
28
|
-
/**
|
|
29
|
-
* @summary `true` when this provider supports subscriptions
|
|
30
|
-
*/
|
|
31
|
-
get hasSubscriptions(): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* @description Returns a clone of the object
|
|
34
|
-
*/
|
|
35
|
-
clone(): HttpProvider;
|
|
36
|
-
/**
|
|
37
|
-
* @description Manually connect from the connection
|
|
38
|
-
*/
|
|
39
|
-
connect(): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* @description Manually disconnect from the connection
|
|
42
|
-
*/
|
|
43
|
-
disconnect(): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* @description Returns the connection stats
|
|
46
|
-
*/
|
|
47
|
-
get stats(): ProviderStats;
|
|
48
|
-
/**
|
|
49
|
-
* @summary `true` when this provider supports clone()
|
|
50
|
-
*/
|
|
51
|
-
get isClonable(): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* @summary Whether the node is connected or not.
|
|
54
|
-
* @return {boolean} true if connected
|
|
55
|
-
*/
|
|
56
|
-
get isConnected(): boolean;
|
|
57
|
-
/**
|
|
58
|
-
* @summary Events are not supported with the HttpProvider, see [[WsProvider]].
|
|
59
|
-
* @description HTTP Provider does not have 'on' emitters. WebSockets should be used instead.
|
|
60
|
-
*/
|
|
61
|
-
on(type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void;
|
|
62
|
-
/**
|
|
63
|
-
* @summary Send HTTP POST Request with Body to configured HTTP Endpoint.
|
|
64
|
-
*/
|
|
65
|
-
send<T>(method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
|
|
66
|
-
_send<T>(body: string): Promise<T>;
|
|
67
|
-
/**
|
|
68
|
-
* @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].
|
|
69
|
-
*/
|
|
70
|
-
subscribe(types: string, method: string, params: unknown[], cb: ProviderInterfaceCallback): Promise<number>;
|
|
71
|
-
/**
|
|
72
|
-
* @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].
|
|
73
|
-
*/
|
|
74
|
-
unsubscribe(type: string, method: string, id: number): Promise<boolean>;
|
|
75
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.HttpProvider = void 0;
|
|
9
|
-
// overwrite the official Polkadot HttpProvider: https://github.com/polkadot-js/api/blob/master/packages/rpc-provider/src/http/index.ts
|
|
10
|
-
// Use context and fetch to provide http1 keepAlive and maxSocket feature
|
|
11
|
-
const coder_1 = require("@polkadot/rpc-provider/coder");
|
|
12
|
-
const defaults_1 = __importDefault(require("@polkadot/rpc-provider/defaults"));
|
|
13
|
-
const lru_1 = require("@polkadot/rpc-provider/lru");
|
|
14
|
-
const node_core_1 = require("@subql/node-core");
|
|
15
|
-
const fetch_h2_1 = require("fetch-h2");
|
|
16
|
-
const ERROR_SUBSCRIBE = 'HTTP Provider does not have subscriptions, use WebSockets instead';
|
|
17
|
-
const l = (0, node_core_1.getLogger)('http-provider');
|
|
18
|
-
/**
|
|
19
|
-
* # @polkadot/rpc-provider
|
|
20
|
-
*
|
|
21
|
-
* @name HttpProvider
|
|
22
|
-
*
|
|
23
|
-
* @description The HTTP Provider allows sending requests using HTTP to an HTTP RPC server TCP port. It does not support subscriptions so you won't be able to listen to events such as new blocks or balance changes. It is usually preferable using the [[WsProvider]].
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* <BR>
|
|
27
|
-
*
|
|
28
|
-
* ```javascript
|
|
29
|
-
* import Api from '@polkadot/api/promise';
|
|
30
|
-
* import { HttpProvider } from '@polkadot/rpc-provider';
|
|
31
|
-
*
|
|
32
|
-
* const provider = new HttpProvider('http://127.0.0.1:9933');
|
|
33
|
-
* const api = new Api(provider);
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @see [[WsProvider]]
|
|
37
|
-
*/
|
|
38
|
-
class HttpProvider {
|
|
39
|
-
#callCache = new lru_1.LRUCache();
|
|
40
|
-
#coder;
|
|
41
|
-
#endpoint;
|
|
42
|
-
#headers;
|
|
43
|
-
#stats;
|
|
44
|
-
#ctx;
|
|
45
|
-
/**
|
|
46
|
-
* @param {string} endpoint The endpoint url starting with http://
|
|
47
|
-
*/
|
|
48
|
-
constructor(endpoint = defaults_1.default.HTTP_URL, headers = {}) {
|
|
49
|
-
if (!/^(https|http):\/\//.test(endpoint)) {
|
|
50
|
-
throw new Error(`Endpoint should start with 'http://' or 'https://', received '${endpoint}'`);
|
|
51
|
-
}
|
|
52
|
-
this.#ctx = (0, fetch_h2_1.context)({
|
|
53
|
-
http1: {
|
|
54
|
-
keepAlive: true,
|
|
55
|
-
maxSockets: 10,
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
this.#coder = new coder_1.RpcCoder();
|
|
59
|
-
this.#endpoint = endpoint;
|
|
60
|
-
this.#headers = headers;
|
|
61
|
-
this.#stats = {
|
|
62
|
-
active: { requests: 0, subscriptions: 0 },
|
|
63
|
-
total: {
|
|
64
|
-
bytesRecv: 0,
|
|
65
|
-
bytesSent: 0,
|
|
66
|
-
cached: 0,
|
|
67
|
-
errors: 0,
|
|
68
|
-
requests: 0,
|
|
69
|
-
subscriptions: 0,
|
|
70
|
-
timeout: 0,
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @summary `true` when this provider supports subscriptions
|
|
76
|
-
*/
|
|
77
|
-
get hasSubscriptions() {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @description Returns a clone of the object
|
|
82
|
-
*/
|
|
83
|
-
clone() {
|
|
84
|
-
return new HttpProvider(this.#endpoint, this.#headers);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* @description Manually connect from the connection
|
|
88
|
-
*/
|
|
89
|
-
async connect() {
|
|
90
|
-
// noop
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* @description Manually disconnect from the connection
|
|
94
|
-
*/
|
|
95
|
-
async disconnect() {
|
|
96
|
-
// noop
|
|
97
|
-
await this.#ctx.disconnectAll();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* @description Returns the connection stats
|
|
101
|
-
*/
|
|
102
|
-
get stats() {
|
|
103
|
-
return this.#stats;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* @summary `true` when this provider supports clone()
|
|
107
|
-
*/
|
|
108
|
-
get isClonable() {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* @summary Whether the node is connected or not.
|
|
113
|
-
* @return {boolean} true if connected
|
|
114
|
-
*/
|
|
115
|
-
get isConnected() {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* @summary Events are not supported with the HttpProvider, see [[WsProvider]].
|
|
120
|
-
* @description HTTP Provider does not have 'on' emitters. WebSockets should be used instead.
|
|
121
|
-
*/
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
123
|
-
on(type, sub) {
|
|
124
|
-
l.error("HTTP Provider does not have 'on' emitters, use WebSockets instead");
|
|
125
|
-
return () => {
|
|
126
|
-
// noop
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* @summary Send HTTP POST Request with Body to configured HTTP Endpoint.
|
|
131
|
-
*/
|
|
132
|
-
async send(method, params, isCacheable) {
|
|
133
|
-
this.#stats.total.requests++;
|
|
134
|
-
const [, body] = this.#coder.encodeJson(method, params);
|
|
135
|
-
let resultPromise = isCacheable
|
|
136
|
-
? this.#callCache.get(body)
|
|
137
|
-
: null;
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
139
|
-
if (!resultPromise) {
|
|
140
|
-
resultPromise = this._send(body);
|
|
141
|
-
if (isCacheable) {
|
|
142
|
-
this.#callCache.set(body, resultPromise);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
this.#stats.total.cached++;
|
|
147
|
-
}
|
|
148
|
-
return resultPromise;
|
|
149
|
-
}
|
|
150
|
-
async _send(body) {
|
|
151
|
-
this.#stats.active.requests++;
|
|
152
|
-
this.#stats.total.bytesSent += body.length;
|
|
153
|
-
try {
|
|
154
|
-
const response = await this.#ctx.fetch(this.#endpoint, {
|
|
155
|
-
body,
|
|
156
|
-
headers: {
|
|
157
|
-
Accept: 'application/json',
|
|
158
|
-
// Recommend dropped in HTTP2
|
|
159
|
-
// 'Content-Length': `${body.length}`,
|
|
160
|
-
'Content-Type': 'application/json',
|
|
161
|
-
...this.#headers,
|
|
162
|
-
},
|
|
163
|
-
method: 'POST',
|
|
164
|
-
});
|
|
165
|
-
if (!response.ok) {
|
|
166
|
-
throw new Error(`[${response.status}]: ${response.statusText}`);
|
|
167
|
-
}
|
|
168
|
-
const result = await response.text();
|
|
169
|
-
this.#stats.total.bytesRecv += result.length;
|
|
170
|
-
const decoded = this.#coder.decodeResponse(JSON.parse(result));
|
|
171
|
-
this.#stats.active.requests--;
|
|
172
|
-
return decoded;
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
this.#stats.active.requests--;
|
|
176
|
-
this.#stats.total.errors++;
|
|
177
|
-
throw e;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].
|
|
182
|
-
*/
|
|
183
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/require-await
|
|
184
|
-
async subscribe(types, method, params, cb) {
|
|
185
|
-
l.error(ERROR_SUBSCRIBE);
|
|
186
|
-
throw new Error(ERROR_SUBSCRIBE);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].
|
|
190
|
-
*/
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/require-await
|
|
192
|
-
async unsubscribe(type, method, id) {
|
|
193
|
-
l.error(ERROR_SUBSCRIBE);
|
|
194
|
-
throw new Error(ERROR_SUBSCRIBE);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.HttpProvider = HttpProvider;
|
|
198
|
-
//# sourceMappingURL=http.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/indexer/x-provider/http.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,uIAAuI;AACvI,yEAAyE;AAEzE,wDAAwD;AACxD,+EAAuD;AACvD,oDAAsD;AAStD,gDAA6C;AAC7C,uCAAmC;AAEnC,MAAM,eAAe,GACnB,mEAAmE,CAAC;AAEtE,MAAM,CAAC,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa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b,MAAc,EACd,MAAiB,EACjB,EAA6B;QAE7B,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAEzB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,8FAA8F;IAC9F,KAAK,CAAC,WAAW,CACf,IAAY,EACZ,MAAc,EACd,EAAU;QAEV,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAEzB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;CACF;AArND,oCAqNC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\n// overwrite the official Polkadot HttpProvider: https://github.com/polkadot-js/api/blob/master/packages/rpc-provider/src/http/index.ts\n// Use context and fetch to provide http1 keepAlive and maxSocket feature\n\nimport { RpcCoder } from '@polkadot/rpc-provider/coder';\nimport defaults from '@polkadot/rpc-provider/defaults';\nimport { LRUCache } from '@polkadot/rpc-provider/lru';\nimport type {\n JsonRpcResponse,\n ProviderInterface,\n ProviderInterfaceCallback,\n ProviderInterfaceEmitCb,\n ProviderInterfaceEmitted,\n ProviderStats,\n} from '@polkadot/rpc-provider/types';\nimport { getLogger } from '@subql/node-core';\nimport { context } from 'fetch-h2';\n\nconst ERROR_SUBSCRIBE =\n 'HTTP Provider does not have subscriptions, use WebSockets instead';\n\nconst l = getLogger('http-provider');\n\n/**\n * # @polkadot/rpc-provider\n *\n * @name HttpProvider\n *\n * @description The HTTP Provider allows sending requests using HTTP to an HTTP RPC server TCP port. It does not support subscriptions so you won't be able to listen to events such as new blocks or balance changes. It is usually preferable using the [[WsProvider]].\n *\n * @example\n * <BR>\n *\n * ```javascript\n * import Api from '@polkadot/api/promise';\n * import { HttpProvider } from '@polkadot/rpc-provider';\n *\n * const provider = new HttpProvider('http://127.0.0.1:9933');\n * const api = new Api(provider);\n * ```\n *\n * @see [[WsProvider]]\n */\nexport class HttpProvider implements ProviderInterface {\n readonly #callCache = new LRUCache();\n\n readonly #coder: RpcCoder;\n\n readonly #endpoint: string;\n\n readonly #headers: Record<string, string>;\n\n readonly #stats: ProviderStats;\n\n readonly #ctx: ReturnType<typeof context>;\n\n /**\n * @param {string} endpoint The endpoint url starting with http://\n */\n constructor(\n endpoint: string = defaults.HTTP_URL,\n headers: Record<string, string> = {},\n ) {\n if (!/^(https|http):\\/\\//.test(endpoint)) {\n throw new Error(\n `Endpoint should start with 'http://' or 'https://', received '${endpoint}'`,\n );\n }\n\n this.#ctx = context({\n http1: {\n keepAlive: true,\n maxSockets: 10,\n },\n });\n\n this.#coder = new RpcCoder();\n this.#endpoint = endpoint;\n this.#headers = headers;\n this.#stats = {\n active: { requests: 0, subscriptions: 0 },\n total: {\n bytesRecv: 0,\n bytesSent: 0,\n cached: 0,\n errors: 0,\n requests: 0,\n subscriptions: 0,\n timeout: 0,\n },\n };\n }\n\n /**\n * @summary `true` when this provider supports subscriptions\n */\n get hasSubscriptions(): boolean {\n return false;\n }\n\n /**\n * @description Returns a clone of the object\n */\n clone(): HttpProvider {\n return new HttpProvider(this.#endpoint, this.#headers);\n }\n\n /**\n * @description Manually connect from the connection\n */\n async connect(): Promise<void> {\n // noop\n }\n\n /**\n * @description Manually disconnect from the connection\n */\n async disconnect(): Promise<void> {\n // noop\n await this.#ctx.disconnectAll();\n }\n\n /**\n * @description Returns the connection stats\n */\n get stats(): ProviderStats {\n return this.#stats;\n }\n\n /**\n * @summary `true` when this provider supports clone()\n */\n get isClonable(): boolean {\n return true;\n }\n\n /**\n * @summary Whether the node is connected or not.\n * @return {boolean} true if connected\n */\n get isConnected(): boolean {\n return true;\n }\n\n /**\n * @summary Events are not supported with the HttpProvider, see [[WsProvider]].\n * @description HTTP Provider does not have 'on' emitters. WebSockets should be used instead.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n on(type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void {\n l.error(\n \"HTTP Provider does not have 'on' emitters, use WebSockets instead\",\n );\n\n return (): void => {\n // noop\n };\n }\n\n /**\n * @summary Send HTTP POST Request with Body to configured HTTP Endpoint.\n */\n async send<T>(\n method: string,\n params: unknown[],\n isCacheable?: boolean,\n ): Promise<T> {\n this.#stats.total.requests++;\n\n const [, body] = this.#coder.encodeJson(method, params);\n let resultPromise: Promise<T> | null = isCacheable\n ? (this.#callCache.get(body) as Promise<T>)\n : null;\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!resultPromise) {\n resultPromise = this._send(body);\n\n if (isCacheable) {\n this.#callCache.set(body, resultPromise);\n }\n } else {\n this.#stats.total.cached++;\n }\n\n return resultPromise;\n }\n\n async _send<T>(body: string): Promise<T> {\n this.#stats.active.requests++;\n this.#stats.total.bytesSent += body.length;\n\n try {\n const response = await this.#ctx.fetch(this.#endpoint, {\n body,\n headers: {\n Accept: 'application/json',\n // Recommend dropped in HTTP2\n // 'Content-Length': `${body.length}`,\n 'Content-Type': 'application/json',\n ...this.#headers,\n },\n method: 'POST',\n });\n\n if (!response.ok) {\n throw new Error(`[${response.status}]: ${response.statusText}`);\n }\n\n const result = await response.text();\n\n this.#stats.total.bytesRecv += result.length;\n\n const decoded = this.#coder.decodeResponse(\n JSON.parse(result) as JsonRpcResponse<T>,\n );\n\n this.#stats.active.requests--;\n\n return decoded;\n } catch (e) {\n this.#stats.active.requests--;\n this.#stats.total.errors++;\n\n throw e;\n }\n }\n\n /**\n * @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/require-await\n async subscribe(\n types: string,\n method: string,\n params: unknown[],\n cb: ProviderInterfaceCallback,\n ): Promise<number> {\n l.error(ERROR_SUBSCRIBE);\n\n throw new Error(ERROR_SUBSCRIBE);\n }\n\n /**\n * @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/require-await\n async unsubscribe(\n type: string,\n method: string,\n id: number,\n ): Promise<boolean> {\n l.error(ERROR_SUBSCRIBE);\n\n throw new Error(ERROR_SUBSCRIBE);\n }\n}\n"]}
|
package/dist/init.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function bootstrap(): Promise<void>;
|