@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.
Files changed (123) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/package.json +6 -6
  3. package/dist/.tsbuildinfo +0 -1
  4. package/dist/app.module.d.ts +0 -2
  5. package/dist/app.module.js +0 -42
  6. package/dist/app.module.js.map +0 -1
  7. package/dist/blockchain.service.d.ts +0 -31
  8. package/dist/blockchain.service.js +0 -146
  9. package/dist/blockchain.service.js.map +0 -1
  10. package/dist/configure/NodeConfig.d.ts +0 -19
  11. package/dist/configure/NodeConfig.js +0 -28
  12. package/dist/configure/NodeConfig.js.map +0 -1
  13. package/dist/configure/SubqueryProject.d.ts +0 -13
  14. package/dist/configure/SubqueryProject.js +0 -29
  15. package/dist/configure/SubqueryProject.js.map +0 -1
  16. package/dist/configure/configure.module.d.ts +0 -11
  17. package/dist/configure/configure.module.js +0 -63
  18. package/dist/configure/configure.module.js.map +0 -1
  19. package/dist/indexer/api.service.d.ts +0 -36
  20. package/dist/indexer/api.service.js +0 -315
  21. package/dist/indexer/api.service.js.map +0 -1
  22. package/dist/indexer/apiPromise.connection.d.ts +0 -24
  23. package/dist/indexer/apiPromise.connection.js +0 -106
  24. package/dist/indexer/apiPromise.connection.js.map +0 -1
  25. package/dist/indexer/dictionary/index.d.ts +0 -2
  26. package/dist/indexer/dictionary/index.js +0 -21
  27. package/dist/indexer/dictionary/index.js.map +0 -1
  28. package/dist/indexer/dictionary/substrateDictionary.service.d.ts +0 -13
  29. package/dist/indexer/dictionary/substrateDictionary.service.js +0 -93
  30. package/dist/indexer/dictionary/substrateDictionary.service.js.map +0 -1
  31. package/dist/indexer/dictionary/types.d.ts +0 -10
  32. package/dist/indexer/dictionary/types.js +0 -5
  33. package/dist/indexer/dictionary/types.js.map +0 -1
  34. package/dist/indexer/dictionary/v1/index.d.ts +0 -1
  35. package/dist/indexer/dictionary/v1/index.js +0 -20
  36. package/dist/indexer/dictionary/v1/index.js.map +0 -1
  37. package/dist/indexer/dictionary/v1/substrateDictionaryV1.d.ts +0 -19
  38. package/dist/indexer/dictionary/v1/substrateDictionaryV1.js +0 -223
  39. package/dist/indexer/dictionary/v1/substrateDictionaryV1.js.map +0 -1
  40. package/dist/indexer/dictionary/v2/index.d.ts +0 -2
  41. package/dist/indexer/dictionary/v2/index.js +0 -21
  42. package/dist/indexer/dictionary/v2/index.js.map +0 -1
  43. package/dist/indexer/dictionary/v2/substrateDictionaryV2.d.ts +0 -20
  44. package/dist/indexer/dictionary/v2/substrateDictionaryV2.js +0 -46
  45. package/dist/indexer/dictionary/v2/substrateDictionaryV2.js.map +0 -1
  46. package/dist/indexer/dictionary/v2/types.d.ts +0 -5
  47. package/dist/indexer/dictionary/v2/types.js +0 -5
  48. package/dist/indexer/dictionary/v2/types.js.map +0 -1
  49. package/dist/indexer/fetch.module.d.ts +0 -2
  50. package/dist/indexer/fetch.module.js +0 -94
  51. package/dist/indexer/fetch.module.js.map +0 -1
  52. package/dist/indexer/indexer.manager.d.ts +0 -27
  53. package/dist/indexer/indexer.manager.js +0 -153
  54. package/dist/indexer/indexer.manager.js.map +0 -1
  55. package/dist/indexer/runtime/base-runtime.service.d.ts +0 -24
  56. package/dist/indexer/runtime/base-runtime.service.js +0 -136
  57. package/dist/indexer/runtime/base-runtime.service.js.map +0 -1
  58. package/dist/indexer/runtime/runtimeService.d.ts +0 -15
  59. package/dist/indexer/runtime/runtimeService.js +0 -94
  60. package/dist/indexer/runtime/runtimeService.js.map +0 -1
  61. package/dist/indexer/runtime/workerRuntimeService.d.ts +0 -9
  62. package/dist/indexer/runtime/workerRuntimeService.js +0 -43
  63. package/dist/indexer/runtime/workerRuntimeService.js.map +0 -1
  64. package/dist/indexer/types.d.ts +0 -20
  65. package/dist/indexer/types.js +0 -13
  66. package/dist/indexer/types.js.map +0 -1
  67. package/dist/indexer/worker/worker-fetch.module.d.ts +0 -5
  68. package/dist/indexer/worker/worker-fetch.module.js +0 -60
  69. package/dist/indexer/worker/worker-fetch.module.js.map +0 -1
  70. package/dist/indexer/worker/worker.d.ts +0 -9
  71. package/dist/indexer/worker/worker.js +0 -48
  72. package/dist/indexer/worker/worker.js.map +0 -1
  73. package/dist/indexer/worker/worker.module.d.ts +0 -2
  74. package/dist/indexer/worker/worker.module.js +0 -33
  75. package/dist/indexer/worker/worker.module.js.map +0 -1
  76. package/dist/indexer/worker/worker.service.d.ts +0 -26
  77. package/dist/indexer/worker/worker.service.js +0 -71
  78. package/dist/indexer/worker/worker.service.js.map +0 -1
  79. package/dist/indexer/x-provider/cachedProvider.d.ts +0 -2
  80. package/dist/indexer/x-provider/cachedProvider.js +0 -40
  81. package/dist/indexer/x-provider/cachedProvider.js.map +0 -1
  82. package/dist/indexer/x-provider/http.d.ts +0 -75
  83. package/dist/indexer/x-provider/http.js +0 -198
  84. package/dist/indexer/x-provider/http.js.map +0 -1
  85. package/dist/init.d.ts +0 -1
  86. package/dist/init.js +0 -41
  87. package/dist/init.js.map +0 -1
  88. package/dist/main.d.ts +0 -1
  89. package/dist/main.js +0 -19
  90. package/dist/main.js.map +0 -1
  91. package/dist/subcommands/forceClean.init.d.ts +0 -1
  92. package/dist/subcommands/forceClean.init.js +0 -10
  93. package/dist/subcommands/forceClean.init.js.map +0 -1
  94. package/dist/subcommands/forceClean.module.d.ts +0 -2
  95. package/dist/subcommands/forceClean.module.js +0 -28
  96. package/dist/subcommands/forceClean.module.js.map +0 -1
  97. package/dist/subcommands/reindex.init.d.ts +0 -3
  98. package/dist/subcommands/reindex.init.js +0 -33
  99. package/dist/subcommands/reindex.init.js.map +0 -1
  100. package/dist/subcommands/reindex.module.d.ts +0 -2
  101. package/dist/subcommands/reindex.module.js +0 -69
  102. package/dist/subcommands/reindex.module.js.map +0 -1
  103. package/dist/subcommands/testing.init.d.ts +0 -1
  104. package/dist/subcommands/testing.init.js +0 -21
  105. package/dist/subcommands/testing.init.js.map +0 -1
  106. package/dist/subcommands/testing.module.d.ts +0 -2
  107. package/dist/subcommands/testing.module.js +0 -65
  108. package/dist/subcommands/testing.module.js.map +0 -1
  109. package/dist/subcommands/testing.service.d.ts +0 -14
  110. package/dist/subcommands/testing.service.js +0 -60
  111. package/dist/subcommands/testing.service.js.map +0 -1
  112. package/dist/utils/project.d.ts +0 -9
  113. package/dist/utils/project.js +0 -116
  114. package/dist/utils/project.js.map +0 -1
  115. package/dist/utils/substrate.d.ts +0 -41
  116. package/dist/utils/substrate.js +0 -348
  117. package/dist/utils/substrate.js.map +0 -1
  118. package/dist/utils/test.utils.d.ts +0 -2
  119. package/dist/utils/test.utils.js +0 -70
  120. package/dist/utils/test.utils.js.map +0 -1
  121. package/dist/yargs.d.ts +0 -276
  122. package/dist/yargs.js +0 -27
  123. package/dist/yargs.js.map +0 -1
@@ -1,315 +0,0 @@
1
- "use strict";
2
- // Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
3
- // SPDX-License-Identifier: GPL-3.0
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v });
17
- }) : function(o, v) {
18
- o["default"] = v;
19
- });
20
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
21
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
22
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
23
- 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;
24
- return c > 3 && r && Object.defineProperty(target, key, r), r;
25
- };
26
- var __importStar = (this && this.__importStar) || (function () {
27
- var ownKeys = function(o) {
28
- ownKeys = Object.getOwnPropertyNames || function (o) {
29
- var ar = [];
30
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
- return ar;
32
- };
33
- return ownKeys(o);
34
- };
35
- return function (mod) {
36
- if (mod && mod.__esModule) return mod;
37
- var result = {};
38
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
- __setModuleDefault(result, mod);
40
- return result;
41
- };
42
- })();
43
- var __metadata = (this && this.__metadata) || function (k, v) {
44
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
45
- };
46
- var __param = (this && this.__param) || function (paramIndex, decorator) {
47
- return function (target, key) { decorator(target, key, paramIndex); }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- var ApiService_1;
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.ApiService = void 0;
55
- const assert_1 = __importDefault(require("assert"));
56
- const common_1 = require("@nestjs/common");
57
- const event_emitter_1 = require("@nestjs/event-emitter");
58
- const node_core_1 = require("@subql/node-core");
59
- const NodeConfig_1 = require("../configure/NodeConfig");
60
- const project_1 = require("../utils/project");
61
- const SubstrateUtil = __importStar(require("../utils/substrate"));
62
- const apiPromise_connection_1 = require("./apiPromise.connection");
63
- const NOT_SUPPORT = (name) => () => {
64
- throw new Error(`${name}() is not supported`);
65
- };
66
- // https://github.com/polkadot-js/api/blob/12750bc83d8d7f01957896a80a7ba948ba3690b7/packages/rpc-provider/src/ws/index.ts#L43
67
- const MAX_RECONNECT_ATTEMPTS = 5;
68
- const logger = (0, node_core_1.getLogger)('api');
69
- // This is a temp fix for https://github.com/polkadot-js/api/issues/5871
70
- function overrideConsoleWarn() {
71
- // Ensure its only run once
72
- if (console.oldWarn) {
73
- return;
74
- }
75
- console.oldWarn = console.warn;
76
- console.warn = function () {
77
- // eslint-disable-next-line prefer-rest-params
78
- const args = Array.from(arguments);
79
- if (args.length > 0 &&
80
- args[0].includes('Unable to map [u8; 32] to a lookup index')) {
81
- return;
82
- }
83
- console.oldWarn.apply(console, args);
84
- };
85
- }
86
- async function dynamicImportHasher(methodName) {
87
- const module = await Promise.resolve().then(() => __importStar(require('@polkadot/util-crypto')));
88
- const method = module[methodName];
89
- if (method) {
90
- return method;
91
- }
92
- else {
93
- throw new Error(`Hasher Method ${methodName} not found in @polkadot/util-crypto`);
94
- }
95
- }
96
- async function updateChainTypesHasher(chainTypes) {
97
- if (!chainTypes) {
98
- return undefined;
99
- }
100
- if (chainTypes.hasher && typeof chainTypes.hasher === 'string') {
101
- logger.info(`Set overall spec hasher to ${chainTypes.hasher}`);
102
- chainTypes.hasher = await dynamicImportHasher(chainTypes.hasher);
103
- }
104
- const typesBundleSpecs = chainTypes.typesBundle?.spec;
105
- if (typesBundleSpecs) {
106
- for (const [key, spec] of Object.entries(typesBundleSpecs)) {
107
- if (spec.hasher && typeof spec.hasher === 'string') {
108
- logger.info(`Set spec ${key} hasher to ${spec.hasher}`);
109
- spec.hasher = await dynamicImportHasher(spec.hasher);
110
- }
111
- }
112
- }
113
- return chainTypes;
114
- }
115
- let ApiService = ApiService_1 = class ApiService extends node_core_1.ApiService {
116
- project;
117
- _fetchBlocksFunction;
118
- fetchBlocksBatches = () => this.fetchBlocksFunction;
119
- _currentBlockHash;
120
- _currentBlockNumber;
121
- nodeConfig;
122
- constructor(project, connectionPoolService, eventEmitter, nodeConfig) {
123
- super(connectionPoolService, eventEmitter);
124
- this.project = project;
125
- this.nodeConfig = new NodeConfig_1.SubstrateNodeConfig(nodeConfig);
126
- this.updateBlockFetching();
127
- }
128
- get fetchBlocksFunction() {
129
- (0, assert_1.default)(this._fetchBlocksFunction, 'fetchBlocksFunction not initialized');
130
- return this._fetchBlocksFunction;
131
- }
132
- get currentBlockHash() {
133
- (0, assert_1.default)(this._currentBlockHash, 'currentBlockHash not initialized');
134
- return this._currentBlockHash;
135
- }
136
- set currentBlockHash(value) {
137
- this._currentBlockHash = value;
138
- }
139
- get currentBlockNumber() {
140
- (0, assert_1.default)(this._currentBlockNumber, 'currentBlockNumber not initialized');
141
- return this._currentBlockNumber;
142
- }
143
- set currentBlockNumber(value) {
144
- this._currentBlockNumber = value;
145
- }
146
- async onApplicationShutdown() {
147
- await this.connectionPoolService.onApplicationShutdown();
148
- }
149
- static async init(project, connectionPoolService, eventEmitter, nodeConfig) {
150
- const apiService = new ApiService_1(project, connectionPoolService, eventEmitter, nodeConfig);
151
- overrideConsoleWarn();
152
- let chainTypes;
153
- let network;
154
- try {
155
- chainTypes = await updateChainTypesHasher(project.chainTypes);
156
- network = project.network;
157
- if (apiService.nodeConfig.primaryNetworkEndpoint) {
158
- const [endpoint, config] = apiService.nodeConfig.primaryNetworkEndpoint;
159
- network.endpoint[endpoint] =
160
- config;
161
- }
162
- }
163
- catch (e) {
164
- (0, node_core_1.exitWithError)(new Error(`Failed to init api`, { cause: e }), logger);
165
- }
166
- if (chainTypes) {
167
- logger.info('Using provided chain types');
168
- }
169
- await apiService.createConnections(network,
170
- //createConnection
171
- (endpoint, config) => apiPromise_connection_1.ApiPromiseConnection.create(endpoint, apiService.fetchBlocksBatches, {
172
- chainTypes,
173
- }, config),
174
- //postConnectedHook
175
- (connection, endpoint, index) => {
176
- const api = connection.unsafeApi;
177
- api.on('connected', () => {
178
- eventEmitter.emit(node_core_1.IndexerEvent.ApiConnected, {
179
- value: 1,
180
- apiIndex: index,
181
- endpoint: endpoint,
182
- });
183
- });
184
- api.on('disconnected', () => {
185
- eventEmitter.emit(node_core_1.IndexerEvent.ApiConnected, {
186
- value: 0,
187
- apiIndex: index,
188
- endpoint: endpoint,
189
- });
190
- });
191
- });
192
- return apiService;
193
- }
194
- async updateChainTypes() {
195
- const chainTypes = await updateChainTypesHasher(this.project.chainTypes);
196
- await this.connectionPoolService.updateChainTypes(chainTypes);
197
- }
198
- updateBlockFetching() {
199
- const onlyEventHandlers = (0, project_1.isOnlyEventHandlers)(this.project);
200
- const skipTransactions = this.nodeConfig.skipTransactions && onlyEventHandlers;
201
- if (this.nodeConfig.skipTransactions) {
202
- if (onlyEventHandlers) {
203
- logger.info('skipTransactions is enabled, only events and block headers will be fetched.');
204
- }
205
- else {
206
- logger.info(`skipTransactions is disabled, the project contains handlers that aren't event handlers.`);
207
- }
208
- }
209
- else {
210
- if (onlyEventHandlers) {
211
- logger.warn('skipTransactions is disabled, the project contains only event handlers, it could be enabled to improve indexing performance.');
212
- }
213
- else {
214
- logger.info(`skipTransactions is disabled.`);
215
- }
216
- }
217
- const fetchFunc = skipTransactions
218
- ? SubstrateUtil.fetchBlocksBatchesLight
219
- : SubstrateUtil.fetchBlocksBatches;
220
- if (this.nodeConfig?.profiler) {
221
- this._fetchBlocksFunction = (0, node_core_1.profilerWrap)(fetchFunc, 'SubstrateUtil', 'fetchBlocksBatches');
222
- }
223
- else {
224
- this._fetchBlocksFunction = fetchFunc;
225
- }
226
- }
227
- get api() {
228
- return this.unsafeApi;
229
- }
230
- async getPatchedApi(header, runtimeVersion) {
231
- this._currentBlockHash = header.hash.toString();
232
- this._currentBlockNumber = header.number.toNumber();
233
- const api = this.api;
234
- const apiAt = (await api.at(this.currentBlockHash, runtimeVersion));
235
- this.patchApiRpc(api, apiAt);
236
- return apiAt;
237
- }
238
- redecorateRpcFunction(original) {
239
- const methodName = this.getRPCFunctionName(original);
240
- if (original.meta.params) {
241
- const hashIndex = original.meta.params.findIndex(({ isHistoric }) => isHistoric);
242
- if (hashIndex > -1) {
243
- const isBlockNumber = original.meta.params[hashIndex].type === 'BlockNumber';
244
- const ret = (async (...args) => {
245
- const argsClone = [...args];
246
- if (isBlockNumber) {
247
- if (argsClone[hashIndex] === undefined) {
248
- argsClone[hashIndex] = this.currentBlockNumber;
249
- }
250
- else if (argsClone[hashIndex] > this.currentBlockNumber) {
251
- throw new Error(`input block ${argsClone[hashIndex]} ahead of current block ${this.currentBlockNumber} is not supported`);
252
- }
253
- }
254
- // is block hash
255
- else {
256
- if (argsClone[hashIndex] === undefined) {
257
- argsClone[hashIndex] = this.currentBlockHash;
258
- }
259
- else {
260
- const atBlock = await this.api.rpc.chain.getBlock(argsClone[hashIndex]);
261
- const atBlockNumber = atBlock.block.header.number.toNumber();
262
- if (atBlockNumber > this.currentBlockNumber) {
263
- throw new Error(`input block hash ${argsClone[hashIndex]} ahead of current block ${this.currentBlockNumber} is not supported`);
264
- }
265
- }
266
- }
267
- return original(...argsClone);
268
- });
269
- ret.raw = NOT_SUPPORT(`${methodName}.raw`);
270
- ret.meta = original.meta;
271
- return ret;
272
- }
273
- }
274
- const ret = NOT_SUPPORT(methodName);
275
- ret.raw = NOT_SUPPORT(`${methodName}.raw`);
276
- ret.meta = original.meta;
277
- return ret;
278
- }
279
- patchApiRpc(api, apiAt) {
280
- apiAt.rpc = Object.entries(api.rpc).reduce((acc, [module, rpcMethods]) => {
281
- acc[module] = Object.entries(rpcMethods).reduce((accInner, [name, rpcPromiseResult]) => {
282
- accInner[name] = this.redecorateRpcFunction(rpcPromiseResult);
283
- return accInner;
284
- }, {});
285
- return acc;
286
- }, {});
287
- }
288
- getRPCFunctionName(original) {
289
- const ext = original.meta;
290
- return `api.rpc.${ext?.section ?? '*'}.${ext?.method ?? '*'}`;
291
- }
292
- // Overrides the super function because of the specVer
293
- async fetchBlocks(heights, overallSpecVer, numAttempts = MAX_RECONNECT_ATTEMPTS) {
294
- return this.retryFetch(async () => {
295
- // Get the latest fetch function from the provider
296
- const apiInstance = this.connectionPoolService.api;
297
- return apiInstance.fetchBlocks(heights, overallSpecVer);
298
- }, numAttempts);
299
- }
300
- // Polkadot uses genesis hash instead of chainId
301
- assertChainId(network, connection) {
302
- if (network.chainId !== connection.networkMeta.genesisHash) {
303
- throw new node_core_1.MetadataMismatchError('ChainId', network.chainId, connection.networkMeta.genesisHash);
304
- }
305
- }
306
- };
307
- exports.ApiService = ApiService;
308
- exports.ApiService = ApiService = ApiService_1 = __decorate([
309
- (0, common_1.Injectable)(),
310
- __param(0, (0, common_1.Inject)('ISubqueryProject')),
311
- __metadata("design:paramtypes", [Object, node_core_1.ConnectionPoolService,
312
- event_emitter_1.EventEmitter2,
313
- node_core_1.NodeConfig])
314
- ], ApiService);
315
- //# sourceMappingURL=api.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.service.js","sourceRoot":"","sources":["../../src/indexer/api.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnC,oDAA4B;AAC5B,2CAA2E;AAC3E,yDAAsD;AActD,gDAU0B;AAG1B,wDAA8D;AAE9D,8CAAuD;AACvD,kEAAoD;AACpD,mEAIiC;AAGjC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,GAAG,EAAE;IACzC,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,6HAA6H;AAC7H,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAEhC,wEAAwE;AACxE,SAAS,mBAAmB;IAC1B,2BAA2B;IAC3B,IAAK,OAAe,CAAC,OAAO,EAAE,CAAC;QAC7B,OAAO;IACT,CAAC;IACA,OAAe,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IACxC,OAAO,CAAC,IAAI,GAAG;QACb,8CAA8C;QAC9C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEnC,IACE,IAAI,CAAC,MAAM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G,QAAQ,CAAC,IAAmC,CAAC;QAEzD,OAAO,WAAW,GAAG,EAAE,OAAO,IAAI,GAAG,IAAI,GAAG,EAAE,MAAM,IAAI,GAAG,EAAE,CAAC;IAChE,CAAC;IAED,sDAAsD;IACtD,KAAK,CAAC,WAAW,CACf,OAAiB,EACjB,cAAuB,EACvB,WAAW,GAAG,sBAAsB;QAEpC,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE;YAChC,kDAAkD;YAClD,MAAM,WAAW,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC;YACnD,OAAO,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAC1D,CAAC,EAAE,WAAW,CAAC,CAAC;IAClB,CAAC;IAED,gDAAgD;IACtC,aAAa,CACrB,OAA4B,EAC5B,UAAgC;QAEhC,IAAI,OAAO,CAAC,OAAO,KAAK,UAAU,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;YAC3D,MAAM,IAAI,iCAAqB,CAC7B,SAAS,EACT,OAAO,CAAC,OAAO,EACf,UAAU,CAAC,WAAW,CAAC,WAAW,CACnC,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AA9SY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;IAkBR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;6CACJ,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GApBb,UAAU,CA8StB","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { ApiPromise } from '@polkadot/api';\nimport {\n ApiTypes,\n DecoratedRpcSection,\n RpcMethodResult,\n} from '@polkadot/api/types';\nimport { RuntimeVersion, Header } from '@polkadot/types/interfaces';\nimport {\n AnyFunction,\n DefinitionRpcExt,\n RegisteredTypes,\n} from '@polkadot/types/types';\nimport { OverrideBundleDefinition } from '@polkadot/types/types/registry';\nimport {\n IndexerEvent,\n getLogger,\n NodeConfig,\n profilerWrap,\n ConnectionPoolService,\n ApiService as BaseApiService,\n IBlock,\n MetadataMismatchError,\n exitWithError,\n} from '@subql/node-core';\nimport { SubstrateNetworkConfig } from '@subql/types';\nimport { IEndpointConfig } from '@subql/types-core';\nimport { SubstrateNodeConfig } from '../configure/NodeConfig';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { isOnlyEventHandlers } from '../utils/project';\nimport * as SubstrateUtil from '../utils/substrate';\nimport {\n ApiPromiseConnection,\n FetchFunc,\n GetFetchFunc,\n} from './apiPromise.connection';\nimport { ApiAt, BlockContent, LightBlockContent } from './types';\n\nconst NOT_SUPPORT = (name: string) => () => {\n throw new Error(`${name}() is not supported`);\n};\n\n// https://github.com/polkadot-js/api/blob/12750bc83d8d7f01957896a80a7ba948ba3690b7/packages/rpc-provider/src/ws/index.ts#L43\nconst MAX_RECONNECT_ATTEMPTS = 5;\n\nconst logger = getLogger('api');\n\n// This is a temp fix for https://github.com/polkadot-js/api/issues/5871\nfunction overrideConsoleWarn(): void {\n // Ensure its only run once\n if ((console as any).oldWarn) {\n return;\n }\n (console as any).oldWarn = console.warn;\n console.warn = function () {\n // eslint-disable-next-line prefer-rest-params\n const args = Array.from(arguments);\n\n if (\n args.length > 0 &&\n args[0].includes('Unable to map [u8; 32] to a lookup index')\n ) {\n return;\n }\n (console as any).oldWarn.apply(console, args);\n };\n}\n\nasync function dynamicImportHasher(\n methodName: string,\n): Promise<(data: Uint8Array) => Uint8Array> {\n const module = await import('@polkadot/util-crypto');\n const method = module[methodName as keyof typeof module];\n if (method) {\n return method as (data: Uint8Array) => Uint8Array;\n } else {\n throw new Error(\n `Hasher Method ${methodName} not found in @polkadot/util-crypto`,\n );\n }\n}\n\nasync function updateChainTypesHasher(\n chainTypes: any,\n): Promise<RegisteredTypes | undefined> {\n if (!chainTypes) {\n return undefined;\n }\n if (chainTypes.hasher && typeof chainTypes.hasher === 'string') {\n logger.info(`Set overall spec hasher to ${chainTypes.hasher}`);\n chainTypes.hasher = await dynamicImportHasher(chainTypes.hasher);\n }\n const typesBundleSpecs: Record<string, OverrideBundleDefinition> | undefined =\n chainTypes.typesBundle?.spec;\n if (typesBundleSpecs) {\n for (const [key, spec] of Object.entries(typesBundleSpecs)) {\n if (spec.hasher && typeof spec.hasher === 'string') {\n logger.info(`Set spec ${key} hasher to ${spec.hasher}`);\n spec.hasher = await dynamicImportHasher(spec.hasher);\n }\n }\n }\n return chainTypes;\n}\n\n@Injectable()\nexport class ApiService\n extends BaseApiService<\n ApiPromise,\n ApiAt,\n IBlock<BlockContent>[] | IBlock<LightBlockContent>[],\n ApiPromiseConnection,\n IEndpointConfig\n >\n implements OnApplicationShutdown {\n private _fetchBlocksFunction?: FetchFunc;\n private fetchBlocksBatches: GetFetchFunc = () => this.fetchBlocksFunction;\n private _currentBlockHash?: string;\n private _currentBlockNumber?: number;\n\n private nodeConfig: SubstrateNodeConfig;\n\n private constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<ApiPromiseConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) {\n super(connectionPoolService, eventEmitter);\n this.nodeConfig = new SubstrateNodeConfig(nodeConfig);\n\n this.updateBlockFetching();\n }\n\n private get fetchBlocksFunction(): FetchFunc {\n assert(this._fetchBlocksFunction, 'fetchBlocksFunction not initialized');\n return this._fetchBlocksFunction;\n }\n\n private get currentBlockHash(): string {\n assert(this._currentBlockHash, 'currentBlockHash not initialized');\n return this._currentBlockHash;\n }\n\n private set currentBlockHash(value: string) {\n this._currentBlockHash = value;\n }\n\n private get currentBlockNumber(): number {\n assert(this._currentBlockNumber, 'currentBlockNumber not initialized');\n return this._currentBlockNumber;\n }\n\n private set currentBlockNumber(value: number) {\n this._currentBlockNumber = value;\n }\n\n async onApplicationShutdown(): Promise<void> {\n await this.connectionPoolService.onApplicationShutdown();\n }\n\n static async init(\n project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<ApiPromiseConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ): Promise<ApiService> {\n const apiService = new ApiService(\n project,\n connectionPoolService,\n eventEmitter,\n nodeConfig,\n );\n\n overrideConsoleWarn();\n let chainTypes: RegisteredTypes | undefined;\n let network: SubstrateNetworkConfig;\n try {\n chainTypes = await updateChainTypesHasher(project.chainTypes);\n network = project.network;\n\n if (apiService.nodeConfig.primaryNetworkEndpoint) {\n const [endpoint, config] = apiService.nodeConfig.primaryNetworkEndpoint;\n (network.endpoint as Record<string, IEndpointConfig>)[endpoint] =\n config;\n }\n } catch (e) {\n exitWithError(new Error(`Failed to init api`, { cause: e }), logger);\n }\n\n if (chainTypes) {\n logger.info('Using provided chain types');\n }\n\n await apiService.createConnections(\n network,\n //createConnection\n (endpoint, config) =>\n ApiPromiseConnection.create(\n endpoint,\n apiService.fetchBlocksBatches,\n {\n chainTypes,\n },\n config,\n ),\n //postConnectedHook\n (connection: ApiPromiseConnection, endpoint: string, index: number) => {\n const api = connection.unsafeApi;\n api.on('connected', () => {\n eventEmitter.emit(IndexerEvent.ApiConnected, {\n value: 1,\n apiIndex: index,\n endpoint: endpoint,\n });\n });\n api.on('disconnected', () => {\n eventEmitter.emit(IndexerEvent.ApiConnected, {\n value: 0,\n apiIndex: index,\n endpoint: endpoint,\n });\n });\n },\n );\n return apiService;\n }\n\n async updateChainTypes(): Promise<void> {\n const chainTypes = await updateChainTypesHasher(this.project.chainTypes);\n await this.connectionPoolService.updateChainTypes(chainTypes);\n }\n\n updateBlockFetching(): void {\n const onlyEventHandlers = isOnlyEventHandlers(this.project);\n const skipTransactions =\n this.nodeConfig.skipTransactions && onlyEventHandlers;\n\n if (this.nodeConfig.skipTransactions) {\n if (onlyEventHandlers) {\n logger.info(\n 'skipTransactions is enabled, only events and block headers will be fetched.',\n );\n } else {\n logger.info(\n `skipTransactions is disabled, the project contains handlers that aren't event handlers.`,\n );\n }\n } else {\n if (onlyEventHandlers) {\n logger.warn(\n 'skipTransactions is disabled, the project contains only event handlers, it could be enabled to improve indexing performance.',\n );\n } else {\n logger.info(`skipTransactions is disabled.`);\n }\n }\n\n const fetchFunc = skipTransactions\n ? SubstrateUtil.fetchBlocksBatchesLight\n : SubstrateUtil.fetchBlocksBatches;\n\n if (this.nodeConfig?.profiler) {\n this._fetchBlocksFunction = profilerWrap(\n fetchFunc,\n 'SubstrateUtil',\n 'fetchBlocksBatches',\n );\n } else {\n this._fetchBlocksFunction = fetchFunc;\n }\n }\n\n get api(): ApiPromise {\n return this.unsafeApi;\n }\n\n async getPatchedApi(\n header: Header,\n runtimeVersion?: RuntimeVersion,\n ): Promise<ApiAt> {\n this._currentBlockHash = header.hash.toString();\n this._currentBlockNumber = header.number.toNumber();\n\n const api = this.api;\n const apiAt = (await api.at(\n this.currentBlockHash,\n runtimeVersion,\n )) as ApiAt;\n this.patchApiRpc(api, apiAt);\n return apiAt;\n }\n\n private redecorateRpcFunction<T extends ApiTypes>(\n original: RpcMethodResult<T, AnyFunction>,\n ): RpcMethodResult<T, AnyFunction> {\n const methodName = this.getRPCFunctionName(original);\n if (original.meta.params) {\n const hashIndex = original.meta.params.findIndex(\n ({ isHistoric }) => isHistoric,\n );\n if (hashIndex > -1) {\n const isBlockNumber =\n original.meta.params[hashIndex].type === 'BlockNumber';\n\n const ret = (async (...args: any[]) => {\n const argsClone = [...args];\n\n if (isBlockNumber) {\n if (argsClone[hashIndex] === undefined) {\n argsClone[hashIndex] = this.currentBlockNumber;\n } else if (argsClone[hashIndex] > this.currentBlockNumber) {\n throw new Error(\n `input block ${argsClone[hashIndex]} ahead of current block ${this.currentBlockNumber} is not supported`,\n );\n }\n }\n // is block hash\n else {\n if (argsClone[hashIndex] === undefined) {\n argsClone[hashIndex] = this.currentBlockHash;\n } else {\n const atBlock = await this.api.rpc.chain.getBlock(\n argsClone[hashIndex],\n );\n const atBlockNumber = atBlock.block.header.number.toNumber();\n if (atBlockNumber > this.currentBlockNumber) {\n throw new Error(\n `input block hash ${argsClone[hashIndex]} ahead of current block ${this.currentBlockNumber} is not supported`,\n );\n }\n }\n }\n\n return original(...argsClone);\n }) as RpcMethodResult<T, AnyFunction>;\n ret.raw = NOT_SUPPORT(`${methodName}.raw`);\n ret.meta = original.meta;\n return ret;\n }\n }\n\n const ret = NOT_SUPPORT(methodName) as unknown as RpcMethodResult<\n T,\n AnyFunction\n >;\n ret.raw = NOT_SUPPORT(`${methodName}.raw`);\n ret.meta = original.meta;\n return ret;\n }\n\n private patchApiRpc<T extends ApiTypes = 'promise'>(\n api: ApiPromise,\n apiAt: ApiAt,\n ): void {\n apiAt.rpc = Object.entries(api.rpc).reduce(\n (acc, [module, rpcMethods]) => {\n acc[module as keyof ApiPromise['rpc']] = Object.entries(\n rpcMethods,\n ).reduce(\n (accInner, [name, rpcPromiseResult]) => {\n accInner[name] = this.redecorateRpcFunction<T>(\n rpcPromiseResult as RpcMethodResult<T, AnyFunction>,\n );\n return accInner;\n },\n {} as DecoratedRpcSection<T, any>,\n ) as any;\n return acc;\n },\n {} as ApiPromise['rpc'],\n );\n }\n\n private getRPCFunctionName<T extends 'promise' | 'rxjs'>(\n original: RpcMethodResult<T, AnyFunction>,\n ): string {\n const ext = original.meta as unknown as DefinitionRpcExt;\n\n return `api.rpc.${ext?.section ?? '*'}.${ext?.method ?? '*'}`;\n }\n\n // Overrides the super function because of the specVer\n async fetchBlocks(\n heights: number[],\n overallSpecVer?: number,\n numAttempts = MAX_RECONNECT_ATTEMPTS,\n ): Promise<IBlock<LightBlockContent>[] | IBlock<BlockContent>[]> {\n return this.retryFetch(async () => {\n // Get the latest fetch function from the provider\n const apiInstance = this.connectionPoolService.api;\n return apiInstance.fetchBlocks(heights, overallSpecVer);\n }, numAttempts);\n }\n\n // Polkadot uses genesis hash instead of chainId\n protected assertChainId(\n network: { chainId: string },\n connection: ApiPromiseConnection,\n ): void {\n if (network.chainId !== connection.networkMeta.genesisHash) {\n throw new MetadataMismatchError(\n 'ChainId',\n network.chainId,\n connection.networkMeta.genesisHash,\n );\n }\n }\n}\n"]}
@@ -1,24 +0,0 @@
1
- import { ApiPromise } from '@polkadot/api';
2
- import { RegisteredTypes } from '@polkadot/types/types';
3
- import { ApiConnectionError, NetworkMetadataPayload, IApiConnectionSpecific, IBlock } from '@subql/node-core';
4
- import { IEndpointConfig } from '@subql/types-core';
5
- import * as SubstrateUtil from '../utils/substrate';
6
- import { ApiAt, BlockContent, LightBlockContent } from './types';
7
- export type FetchFunc = typeof SubstrateUtil.fetchBlocksBatches | typeof SubstrateUtil.fetchBlocksBatchesLight;
8
- export type GetFetchFunc = () => FetchFunc;
9
- export declare class ApiPromiseConnection implements IApiConnectionSpecific<ApiPromise, ApiAt, IBlock<BlockContent>[] | IBlock<LightBlockContent>[]> {
10
- unsafeApi: ApiPromise;
11
- private fetchBlocksBatches;
12
- readonly networkMeta: NetworkMetadataPayload;
13
- private constructor();
14
- static create(endpoint: string, fetchBlocksBatches: GetFetchFunc, args: {
15
- chainTypes?: RegisteredTypes;
16
- }, config: IEndpointConfig): Promise<ApiPromiseConnection>;
17
- safeApi(height: number): ApiAt;
18
- fetchBlocks(heights: number[], overallSpecVer?: number): Promise<IBlock<BlockContent>[] | IBlock<LightBlockContent>[]>;
19
- apiConnect(): Promise<void>;
20
- apiDisconnect(): Promise<void>;
21
- updateChainTypes(chainTypes: RegisteredTypes): Promise<void>;
22
- handleError: typeof ApiPromiseConnection.handleError;
23
- static handleError(e: Error): ApiConnectionError;
24
- }
@@ -1,106 +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.ApiPromiseConnection = void 0;
6
- const api_1 = require("@polkadot/api");
7
- const node_core_1 = require("@subql/node-core");
8
- const cachedProvider_1 = require("./x-provider/cachedProvider");
9
- const http_1 = require("./x-provider/http");
10
- // eslint-disable-next-line @typescript-eslint/no-var-requires
11
- const { version: packageVersion } = require('../../package.json');
12
- const RETRY_DELAY = 2_500;
13
- class ApiPromiseConnection {
14
- unsafeApi;
15
- fetchBlocksBatches;
16
- networkMeta;
17
- constructor(unsafeApi, fetchBlocksBatches) {
18
- this.unsafeApi = unsafeApi;
19
- this.fetchBlocksBatches = fetchBlocksBatches;
20
- this.networkMeta = {
21
- chain: unsafeApi.runtimeChain.toString(),
22
- specName: unsafeApi.runtimeVersion.specName.toString(),
23
- genesisHash: unsafeApi.genesisHash.toString(),
24
- };
25
- }
26
- static async create(endpoint, fetchBlocksBatches, args, config) {
27
- let provider;
28
- let throwOnConnect = false;
29
- const headers = {
30
- 'User-Agent': `SubQuery-Node ${packageVersion}`,
31
- ...config.headers,
32
- };
33
- if (endpoint.startsWith('ws')) {
34
- provider = (0, cachedProvider_1.createCachedProvider)(new api_1.WsProvider(endpoint, RETRY_DELAY, headers));
35
- }
36
- else if (endpoint.startsWith('http')) {
37
- provider = (0, cachedProvider_1.createCachedProvider)(new http_1.HttpProvider(endpoint, headers));
38
- throwOnConnect = true;
39
- }
40
- else {
41
- throw new Error(`Invalid endpoint: ${endpoint}`);
42
- }
43
- const apiOption = {
44
- provider,
45
- throwOnConnect,
46
- noInitWarn: true,
47
- ...args.chainTypes,
48
- };
49
- const api = await api_1.ApiPromise.create(apiOption);
50
- return new ApiPromiseConnection(api, fetchBlocksBatches);
51
- }
52
- safeApi(height) {
53
- throw new Error(`Not Implemented`);
54
- }
55
- async fetchBlocks(heights, overallSpecVer) {
56
- const blocks = await this.fetchBlocksBatches()(this.unsafeApi, heights, overallSpecVer);
57
- return blocks;
58
- }
59
- async apiConnect() {
60
- return new Promise((resolve) => {
61
- if (this.unsafeApi.isConnected) {
62
- resolve();
63
- }
64
- this.unsafeApi.on('connected', () => {
65
- resolve();
66
- });
67
- if (!this.unsafeApi.isConnected) {
68
- this.unsafeApi.connect();
69
- }
70
- });
71
- }
72
- async apiDisconnect() {
73
- await this.unsafeApi.disconnect();
74
- }
75
- async updateChainTypes(chainTypes) {
76
- // Typeof Decorate<'promise' | 'rxjs'>, but we need to access this private method
77
- const currentApiOptions = this.unsafeApi._options;
78
- const apiOption = {
79
- ...currentApiOptions,
80
- ...chainTypes,
81
- };
82
- this.unsafeApi = await api_1.ApiPromise.create(apiOption);
83
- }
84
- handleError = ApiPromiseConnection.handleError;
85
- static handleError(e) {
86
- let formatted_error;
87
- if (e.message.startsWith(`No response received from RPC endpoint in`)) {
88
- formatted_error = new node_core_1.TimeoutError(e);
89
- }
90
- else if (e.message.startsWith(`disconnected from `)) {
91
- formatted_error = new node_core_1.DisconnectionError(e);
92
- }
93
- else if (e.message.startsWith(`-32029: Too Many Requests`)) {
94
- formatted_error = new node_core_1.RateLimitError(e);
95
- }
96
- else if (e.message.includes(`Exceeded max limit of`)) {
97
- formatted_error = new node_core_1.LargeResponseError(e);
98
- }
99
- else {
100
- formatted_error = new node_core_1.ApiConnectionError(e.name, e.message, node_core_1.ApiErrorType.Default);
101
- }
102
- return formatted_error;
103
- }
104
- }
105
- exports.ApiPromiseConnection = ApiPromiseConnection;
106
- //# sourceMappingURL=apiPromise.connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apiPromise.connection.js","sourceRoot":"","sources":["../../src/indexer/apiPromise.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,uCAAuD;AAIvD,gDAU0B;AAI1B,gEAAmE;AACnE,4CAAiD;AAEjD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,WAAW,GAAG,KAAK,CAAC;AAS1B,MAAa,oBAAoB;IAWtB;IACC;IAJD,WAAW,CAAyB;IAE7C,YACS,SAAqB,EACpB,kBAAgC;QADjC,cAAS,GAAT,SAAS,C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CAAC;QACxC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,2CAA2C,CAAC,EAAE,CAAC;YACtE,eAAe,GAAG,IAAI,wBAAY,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;aAAM,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;YACtD,eAAe,GAAG,IAAI,8BAAkB,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC;aAAM,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,2BAA2B,CAAC,EAAE,CAAC;YAC7D,eAAe,GAAG,IAAI,0BAAc,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC;aAAM,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC;YACvD,eAAe,GAAG,IAAI,8BAAkB,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,eAAe,GAAG,IAAI,8BAAkB,CACtC,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;QACJ,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA3HD,oDA2HC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { ApiPromise, WsProvider } from '@polkadot/api';\nimport { ApiOptions } from '@polkadot/api/types';\nimport { ProviderInterface } from '@polkadot/rpc-provider/types';\nimport { RegisteredTypes } from '@polkadot/types/types';\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n NetworkMetadataPayload,\n RateLimitError,\n TimeoutError,\n IApiConnectionSpecific,\n IBlock,\n} from '@subql/node-core';\nimport { IEndpointConfig } from '@subql/types-core';\nimport * as SubstrateUtil from '../utils/substrate';\nimport { ApiAt, BlockContent, LightBlockContent } from './types';\nimport { createCachedProvider } from './x-provider/cachedProvider';\nimport { HttpProvider } from './x-provider/http';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst RETRY_DELAY = 2_500;\n\nexport type FetchFunc =\n | typeof SubstrateUtil.fetchBlocksBatches\n | typeof SubstrateUtil.fetchBlocksBatchesLight;\n\n// We use a function to get the fetch function because it can change depending on the skipTransactions feature\nexport type GetFetchFunc = () => FetchFunc;\n\nexport class ApiPromiseConnection\n implements\n IApiConnectionSpecific<\n ApiPromise,\n ApiAt,\n IBlock<BlockContent>[] | IBlock<LightBlockContent>[]\n >\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n private constructor(\n public unsafeApi: ApiPromise,\n private fetchBlocksBatches: GetFetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.runtimeChain.toString(),\n specName: unsafeApi.runtimeVersion.specName.toString(),\n genesisHash: unsafeApi.genesisHash.toString(),\n };\n }\n\n static async create(\n endpoint: string,\n fetchBlocksBatches: GetFetchFunc,\n args: { chainTypes?: RegisteredTypes },\n config: IEndpointConfig,\n ): Promise<ApiPromiseConnection> {\n let provider: ProviderInterface;\n let throwOnConnect = false;\n\n const headers = {\n 'User-Agent': `SubQuery-Node ${packageVersion}`,\n ...config.headers,\n };\n\n if (endpoint.startsWith('ws')) {\n provider = createCachedProvider(\n new WsProvider(endpoint, RETRY_DELAY, headers),\n );\n } else if (endpoint.startsWith('http')) {\n provider = createCachedProvider(new HttpProvider(endpoint, headers));\n throwOnConnect = true;\n } else {\n throw new Error(`Invalid endpoint: ${endpoint}`);\n }\n\n const apiOption = {\n provider,\n throwOnConnect,\n noInitWarn: true,\n ...args.chainTypes,\n };\n const api = await ApiPromise.create(apiOption);\n return new ApiPromiseConnection(api, fetchBlocksBatches);\n }\n\n safeApi(height: number): ApiAt {\n throw new Error(`Not Implemented`);\n }\n\n async fetchBlocks(\n heights: number[],\n overallSpecVer?: number,\n ): Promise<IBlock<BlockContent>[] | IBlock<LightBlockContent>[]> {\n const blocks = await this.fetchBlocksBatches()(\n this.unsafeApi,\n heights,\n overallSpecVer,\n );\n return blocks;\n }\n\n async apiConnect(): Promise<void> {\n return new Promise<void>((resolve) => {\n if (this.unsafeApi.isConnected) {\n resolve();\n }\n\n this.unsafeApi.on('connected', () => {\n resolve();\n });\n\n if (!this.unsafeApi.isConnected) {\n this.unsafeApi.connect();\n }\n });\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async updateChainTypes(chainTypes: RegisteredTypes): Promise<void> {\n // Typeof Decorate<'promise' | 'rxjs'>, but we need to access this private method\n const currentApiOptions = (this.unsafeApi as any)._options as ApiOptions;\n const apiOption = {\n ...currentApiOptions,\n ...chainTypes,\n };\n this.unsafeApi = await ApiPromise.create(apiOption);\n }\n\n handleError = ApiPromiseConnection.handleError;\n\n static handleError(e: Error): ApiConnectionError {\n let formatted_error: ApiConnectionError;\n if (e.message.startsWith(`No response received from RPC endpoint in`)) {\n formatted_error = new TimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = new DisconnectionError(e);\n } else if (e.message.startsWith(`-32029: Too Many Requests`)) {\n formatted_error = new RateLimitError(e);\n } else if (e.message.includes(`Exceeded max limit of`)) {\n formatted_error = new LargeResponseError(e);\n } else {\n formatted_error = new ApiConnectionError(\n e.name,\n e.message,\n ApiErrorType.Default,\n );\n }\n return formatted_error;\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './substrateDictionary.service';
@@ -1,21 +0,0 @@
1
- "use strict";
2
- // Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
3
- // SPDX-License-Identifier: GPL-3.0
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./substrateDictionary.service"), exports);
21
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/indexer/dictionary/index.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;AAEnC,0CAAwB;AACxB,gEAA8C","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nexport * from './types';\nexport * from './substrateDictionary.service';\n"]}
@@ -1,13 +0,0 @@
1
- import { EventEmitter2 } from '@nestjs/event-emitter';
2
- import { NodeConfig, DictionaryService, DsProcessorService } from '@subql/node-core';
3
- import { SubstrateBlock, SubstrateDatasource } from '@subql/types';
4
- import { SubqueryProject } from '../../configure/SubqueryProject';
5
- import { SpecVersion } from './types';
6
- export declare class SubstrateDictionaryService extends DictionaryService<SubstrateDatasource, SubstrateBlock> {
7
- protected project: SubqueryProject;
8
- protected dsProcessorService: DsProcessorService;
9
- initDictionaries(): Promise<void>;
10
- constructor(project: SubqueryProject, nodeConfig: NodeConfig, eventEmitter: EventEmitter2, dsProcessorService: DsProcessorService);
11
- private getV1Dictionary;
12
- getSpecVersions(): Promise<SpecVersion[] | undefined>;
13
- }
@@ -1,93 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.SubstrateDictionaryService = void 0;
21
- const assert_1 = __importDefault(require("assert"));
22
- const common_1 = require("@nestjs/common");
23
- const event_emitter_1 = require("@nestjs/event-emitter");
24
- const common_2 = require("@subql/common");
25
- const node_core_1 = require("@subql/node-core");
26
- const v1_1 = require("./v1");
27
- const v2_1 = require("./v2");
28
- const logger = (0, node_core_1.getLogger)('SubstrateDictionary');
29
- let SubstrateDictionaryService = class SubstrateDictionaryService extends node_core_1.DictionaryService {
30
- project;
31
- dsProcessorService;
32
- async initDictionaries() {
33
- const dictionariesV1 = [];
34
- const dictionariesV2 = [];
35
- if (!this.project) {
36
- throw new Error(`Project in Dictionary service not initialized `);
37
- }
38
- const registryDictionaries = await this.resolveDictionary(common_2.NETWORK_FAMILY.substrate, this.project.network.chainId, this.nodeConfig.dictionaryRegistry);
39
- logger.debug(`Dictionary registry endpoints: ${registryDictionaries}`);
40
- const dictionaryEndpoints = (!Array.isArray(this.project.network.dictionary)
41
- ? !this.project.network.dictionary
42
- ? []
43
- : [this.project.network.dictionary]
44
- : this.project.network.dictionary).concat(registryDictionaries);
45
- for (const endpoint of dictionaryEndpoints) {
46
- try {
47
- const dictionaryV2 = await v2_1.SubstrateDictionaryV2.create(endpoint, this.nodeConfig, this.project, this.project.network.chainId);
48
- dictionariesV2.push(dictionaryV2);
49
- }
50
- catch (e) {
51
- try {
52
- const dictionaryV1 = await v1_1.SubstrateDictionaryV1.create(this.project, this.nodeConfig, this.dsProcessorService.getDsProcessor.bind(this.dsProcessorService), endpoint);
53
- dictionariesV1.push(dictionaryV1);
54
- }
55
- catch (e) {
56
- logger.warn(`Dictionary endpoint "${endpoint}" is not a valid dictionary`);
57
- }
58
- }
59
- }
60
- // v2 should be prioritised
61
- this.init([...dictionariesV2, ...dictionariesV1]);
62
- }
63
- constructor(project, nodeConfig, eventEmitter, dsProcessorService) {
64
- super(project.network.chainId, nodeConfig, eventEmitter);
65
- this.project = project;
66
- this.dsProcessorService = dsProcessorService;
67
- }
68
- getV1Dictionary() {
69
- // TODO this needs to be removed once Substrate supports V2 dictionaries
70
- if (this._currentDictionaryIndex === undefined)
71
- return undefined;
72
- const dict = this._dictionaries[this._currentDictionaryIndex];
73
- if (!dict)
74
- return undefined;
75
- (0, assert_1.default)(dict instanceof v1_1.SubstrateDictionaryV1, `Getting v1 dict returned a dictinoary that wasn't v1`);
76
- return dict;
77
- }
78
- async getSpecVersions() {
79
- const dict = this.getV1Dictionary();
80
- if (!dict)
81
- return undefined;
82
- return dict.getSpecVersions();
83
- }
84
- };
85
- exports.SubstrateDictionaryService = SubstrateDictionaryService;
86
- exports.SubstrateDictionaryService = SubstrateDictionaryService = __decorate([
87
- (0, common_1.Injectable)(),
88
- __param(0, (0, common_1.Inject)('ISubqueryProject')),
89
- __metadata("design:paramtypes", [Object, node_core_1.NodeConfig,
90
- event_emitter_1.EventEmitter2,
91
- node_core_1.DsProcessorService])
92
- ], SubstrateDictionaryService);
93
- //# sourceMappingURL=substrateDictionary.service.js.map