@subql/node-ethereum 2.5.4-0 → 2.5.4-2
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 +2 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.connection.d.ts +18 -6
- package/dist/ethereum/api.connection.js +45 -8
- package/dist/ethereum/api.connection.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.d.ts +4 -3
- package/dist/ethereum/api.service.ethereum.js +14 -16
- package/dist/ethereum/api.service.ethereum.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.js +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.js.map +1 -1
- package/dist/indexer/fetch.module.js +2 -5
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.d.ts +10 -4
- package/dist/indexer/fetch.service.js +61 -47
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/fetch.service.spec.d.ts +1 -0
- package/dist/indexer/fetch.service.spec.js +37 -0
- package/dist/indexer/fetch.service.spec.js.map +1 -0
- package/dist/indexer/indexer.manager.d.ts +4 -3
- package/dist/indexer/indexer.manager.js +2 -1
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/project.service.d.ts +4 -3
- package/dist/indexer/project.service.js +2 -1
- package/dist/indexer/project.service.js.map +1 -1
- package/dist/indexer/sandbox.service.d.ts +3 -2
- package/dist/indexer/sandbox.service.js +2 -1
- package/dist/indexer/sandbox.service.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.d.ts +3 -3
- package/dist/indexer/unfinalizedBlocks.service.js +2 -1
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/init.js +2 -1
- package/dist/init.js.map +1 -1
- package/dist/subcommands/testing.init.js +2 -1
- package/dist/subcommands/testing.init.js.map +1 -1
- package/dist/subcommands/testing.service.d.ts +3 -1
- package/dist/subcommands/testing.service.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
2
|
-
import {
|
|
2
|
+
import { ApiConnectionError, IApiConnectionSpecific, NetworkMetadataPayload } from '@subql/node-core';
|
|
3
|
+
import { EthereumBlockWrapper } from '@subql/types-ethereum';
|
|
3
4
|
import { EthereumApi } from './api.ethereum';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import SafeEthProvider from './safe-api';
|
|
6
|
+
type FetchFunc = (api: EthereumApi, batch: number[]) => Promise<EthereumBlockWrapper[]>;
|
|
7
|
+
export declare class EthereumApiConnection implements IApiConnectionSpecific<EthereumApi, SafeEthProvider, EthereumBlockWrapper> {
|
|
8
|
+
unsafeApi: EthereumApi;
|
|
9
|
+
private fetchBlocksBatches;
|
|
10
|
+
readonly networkMeta: NetworkMetadataPayload;
|
|
11
|
+
constructor(unsafeApi: EthereumApi, fetchBlocksBatches: FetchFunc);
|
|
12
|
+
static create(endpoint: string, fetchBlockBatches: FetchFunc, eventEmitter: EventEmitter2): Promise<EthereumApiConnection>;
|
|
13
|
+
safeApi(height: number): SafeEthProvider;
|
|
9
14
|
apiConnect(): Promise<void>;
|
|
10
15
|
apiDisconnect(): Promise<void>;
|
|
16
|
+
fetchBlocks(heights: number[]): Promise<EthereumBlockWrapper[]>;
|
|
17
|
+
handleError: typeof EthereumApiConnection.handleError;
|
|
18
|
+
static handleError(e: Error): ApiConnectionError;
|
|
19
|
+
static handleRateLimitError(e: Error): ApiConnectionError;
|
|
20
|
+
static handleTimeoutError(e: Error): ApiConnectionError;
|
|
21
|
+
static handleDisconnectionError(e: Error): ApiConnectionError;
|
|
11
22
|
}
|
|
23
|
+
export {};
|
|
@@ -3,24 +3,61 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.EthereumApiConnection = void 0;
|
|
6
|
+
const node_core_1 = require("@subql/node-core");
|
|
6
7
|
const api_ethereum_1 = require("./api.ethereum");
|
|
7
8
|
class EthereumApiConnection {
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
9
|
+
constructor(unsafeApi, fetchBlocksBatches) {
|
|
10
|
+
this.unsafeApi = unsafeApi;
|
|
11
|
+
this.fetchBlocksBatches = fetchBlocksBatches;
|
|
12
|
+
this.handleError = EthereumApiConnection.handleError;
|
|
13
|
+
this.networkMeta = {
|
|
14
|
+
chain: unsafeApi.getChainId().toString(),
|
|
15
|
+
specName: unsafeApi.getSpecName(),
|
|
16
|
+
genesisHash: unsafeApi.getGenesisHash(),
|
|
17
|
+
};
|
|
10
18
|
}
|
|
11
|
-
static async create(endpoint, eventEmitter) {
|
|
19
|
+
static async create(endpoint, fetchBlockBatches, eventEmitter) {
|
|
12
20
|
const api = new api_ethereum_1.EthereumApi(endpoint, eventEmitter);
|
|
13
21
|
await api.init();
|
|
14
|
-
return new EthereumApiConnection(api);
|
|
22
|
+
return new EthereumApiConnection(api, fetchBlockBatches);
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
safeApi(height) {
|
|
25
|
+
throw new Error(`Not Implemented`);
|
|
18
26
|
}
|
|
19
27
|
async apiConnect() {
|
|
20
|
-
await this.
|
|
28
|
+
await this.unsafeApi.connect();
|
|
21
29
|
}
|
|
22
30
|
async apiDisconnect() {
|
|
23
|
-
await this.
|
|
31
|
+
await this.unsafeApi.disconnect();
|
|
32
|
+
}
|
|
33
|
+
async fetchBlocks(heights) {
|
|
34
|
+
const blocks = await this.fetchBlocksBatches(this.unsafeApi, heights);
|
|
35
|
+
return blocks;
|
|
36
|
+
}
|
|
37
|
+
static handleError(e) {
|
|
38
|
+
let formatted_error;
|
|
39
|
+
if (e.message.startsWith(`No response received from RPC endpoint in`)) {
|
|
40
|
+
formatted_error = EthereumApiConnection.handleTimeoutError(e);
|
|
41
|
+
}
|
|
42
|
+
else if (e.message.startsWith(`disconnected from `)) {
|
|
43
|
+
formatted_error = EthereumApiConnection.handleDisconnectionError(e);
|
|
44
|
+
}
|
|
45
|
+
else if (e.message.startsWith(`Rate Limited at endpoint`)) {
|
|
46
|
+
formatted_error = EthereumApiConnection.handleRateLimitError(e);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
formatted_error = new node_core_1.ApiConnectionError(e.name, e.message, node_core_1.ApiErrorType.Default);
|
|
50
|
+
}
|
|
51
|
+
return formatted_error;
|
|
52
|
+
}
|
|
53
|
+
static handleRateLimitError(e) {
|
|
54
|
+
return new node_core_1.ApiConnectionError('RateLimit', e.message, node_core_1.ApiErrorType.RateLimit);
|
|
55
|
+
}
|
|
56
|
+
static handleTimeoutError(e) {
|
|
57
|
+
return new node_core_1.ApiConnectionError('TimeoutError', e.message, node_core_1.ApiErrorType.Timeout);
|
|
58
|
+
}
|
|
59
|
+
static handleDisconnectionError(e) {
|
|
60
|
+
return new node_core_1.ApiConnectionError('ConnectionError', e.message, node_core_1.ApiErrorType.Connection);
|
|
24
61
|
}
|
|
25
62
|
}
|
|
26
63
|
exports.EthereumApiConnection = EthereumApiConnection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/ethereum/api.connection.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;
|
|
1
|
+
{"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/ethereum/api.connection.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;AAGtC,gDAK0B;AAE1B,iDAA6C;AAQ7C,MAAa,qBAAqB;IAMhC,YACS,SAAsB,EACrB,kBAA6B;QAD9B,cAAS,GAAT,SAAS,CAAa;QACrB,uBAAkB,GAAlB,kBAAkB,CAAW;QAsCvC,gBAAW,GAAG,qBAAqB,CAAC,WAAW,CAAC;QApC9C,IAAI,CAAC,WAAW,GAAG;YACjB,KAAK,EAAE,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,CAAC,UAAU,CAAC,0BAA0B,CAAC,EAAE;YAC3D,eAAe,GAAG,qBAAqB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;SACjE;aAAM;YACL,eAAe,GAAG,IAAI,8BAAkB,CACtC,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;SACH;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,CAAQ;QAClC,OAAO,IAAI,8BAAkB,CAC3B,WAAW,EACX,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,SAAS,CACvB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,CAAQ;QAChC,OAAO,IAAI,8BAAkB,CAC3B,cAAc,EACd,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,wBAAwB,CAAC,CAAQ;QACtC,OAAO,IAAI,8BAAkB,CAC3B,iBAAiB,EACjB,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,UAAU,CACxB,CAAC;IACJ,CAAC;CACF;AAzFD,sDAyFC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n IApiConnectionSpecific,\n NetworkMetadataPayload,\n} from '@subql/node-core';\nimport { EthereumBlockWrapper } from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\ntype FetchFunc = (\n api: EthereumApi,\n batch: number[],\n) => Promise<EthereumBlockWrapper[]>;\n\nexport class EthereumApiConnection\n implements\n IApiConnectionSpecific<EthereumApi, SafeEthProvider, EthereumBlockWrapper>\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n constructor(\n public unsafeApi: EthereumApi,\n private fetchBlocksBatches: FetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.getChainId().toString(),\n specName: unsafeApi.getSpecName(),\n genesisHash: unsafeApi.getGenesisHash(),\n };\n }\n\n static async create(\n endpoint: string,\n fetchBlockBatches: FetchFunc,\n eventEmitter: EventEmitter2,\n ): Promise<EthereumApiConnection> {\n const api = new EthereumApi(endpoint, eventEmitter);\n\n await api.init();\n\n return new EthereumApiConnection(api, fetchBlockBatches);\n }\n\n safeApi(height: number): SafeEthProvider {\n throw new Error(`Not Implemented`);\n }\n\n async apiConnect(): Promise<void> {\n await this.unsafeApi.connect();\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async fetchBlocks(heights: number[]): Promise<EthereumBlockWrapper[]> {\n const blocks = await this.fetchBlocksBatches(this.unsafeApi, heights);\n return blocks;\n }\n\n handleError = EthereumApiConnection.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 = EthereumApiConnection.handleTimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = EthereumApiConnection.handleDisconnectionError(e);\n } else if (e.message.startsWith(`Rate Limited at endpoint`)) {\n formatted_error = EthereumApiConnection.handleRateLimitError(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 static handleRateLimitError(e: Error): ApiConnectionError {\n return new ApiConnectionError(\n 'RateLimit',\n e.message,\n ApiErrorType.RateLimit,\n );\n }\n\n static handleTimeoutError(e: Error): ApiConnectionError {\n return new ApiConnectionError(\n 'TimeoutError',\n e.message,\n ApiErrorType.Timeout,\n );\n }\n\n static handleDisconnectionError(e: Error): ApiConnectionError {\n return new ApiConnectionError(\n 'ConnectionError',\n e.message,\n ApiErrorType.Connection,\n );\n }\n}\n"]}
|
|
@@ -4,13 +4,14 @@ import { EthereumBlockWrapper } from '@subql/types-ethereum';
|
|
|
4
4
|
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
5
5
|
import { EthereumApiConnection } from './api.connection';
|
|
6
6
|
import { EthereumApi } from './api.ethereum';
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import SafeEthProvider from './safe-api';
|
|
8
|
+
export declare class EthereumApiService extends ApiService<EthereumApi, SafeEthProvider, EthereumBlockWrapper> {
|
|
9
|
+
private project;
|
|
9
10
|
private eventEmitter;
|
|
10
11
|
constructor(project: SubqueryProject, connectionPoolService: ConnectionPoolService<EthereumApiConnection>, eventEmitter: EventEmitter2);
|
|
11
12
|
networkMeta: NetworkMetadataPayload;
|
|
12
13
|
init(): Promise<EthereumApiService>;
|
|
13
|
-
fetchBlocks(batch: number[]): Promise<EthereumBlockWrapper[]>;
|
|
14
14
|
private metadataMismatchError;
|
|
15
15
|
get api(): EthereumApi;
|
|
16
|
+
private fetchBlockBatches;
|
|
16
17
|
}
|
|
@@ -21,10 +21,11 @@ const node_core_1 = require("@subql/node-core");
|
|
|
21
21
|
const SubqueryProject_1 = require("../configure/SubqueryProject");
|
|
22
22
|
const api_connection_1 = require("./api.connection");
|
|
23
23
|
const logger = (0, node_core_1.getLogger)('api');
|
|
24
|
+
const MAX_RECONNECT_ATTEMPTS = 5;
|
|
24
25
|
let EthereumApiService = class EthereumApiService extends node_core_1.ApiService {
|
|
25
26
|
constructor(project, connectionPoolService, eventEmitter) {
|
|
26
|
-
super(
|
|
27
|
-
this.
|
|
27
|
+
super(connectionPoolService);
|
|
28
|
+
this.project = project;
|
|
28
29
|
this.eventEmitter = eventEmitter;
|
|
29
30
|
}
|
|
30
31
|
async init() {
|
|
@@ -40,27 +41,24 @@ let EthereumApiService = class EthereumApiService extends node_core_1.ApiService
|
|
|
40
41
|
const endpoints = Array.isArray(network.endpoint)
|
|
41
42
|
? network.endpoint
|
|
42
43
|
: [network.endpoint];
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const
|
|
44
|
+
const endpointToApiIndex = {};
|
|
45
|
+
await Promise.all(endpoints.map(async (endpoint, i) => {
|
|
46
|
+
const connection = await api_connection_1.EthereumApiConnection.create(endpoint, this.fetchBlockBatches, this.eventEmitter);
|
|
47
|
+
const api = connection.unsafeApi;
|
|
46
48
|
this.eventEmitter.emit(node_core_1.IndexerEvent.ApiConnected, {
|
|
47
49
|
value: 1,
|
|
48
50
|
apiIndex: i,
|
|
49
51
|
endpoint: endpoint,
|
|
50
52
|
});
|
|
51
53
|
if (!this.networkMeta) {
|
|
52
|
-
this.networkMeta =
|
|
53
|
-
chain: api.getChainId().toString(),
|
|
54
|
-
specName: api.getSpecName(),
|
|
55
|
-
genesisHash: api.getGenesisHash(),
|
|
56
|
-
};
|
|
54
|
+
this.networkMeta = connection.networkMeta;
|
|
57
55
|
}
|
|
58
56
|
if (network.chainId !== api.getChainId().toString()) {
|
|
59
57
|
throw this.metadataMismatchError('ChainId', network.chainId, api.getChainId().toString());
|
|
60
58
|
}
|
|
61
|
-
|
|
59
|
+
endpointToApiIndex[endpoint] = connection;
|
|
62
60
|
}));
|
|
63
|
-
this.connectionPoolService.addBatchToConnections(
|
|
61
|
+
this.connectionPoolService.addBatchToConnections(endpointToApiIndex);
|
|
64
62
|
return this;
|
|
65
63
|
}
|
|
66
64
|
catch (e) {
|
|
@@ -68,16 +66,16 @@ let EthereumApiService = class EthereumApiService extends node_core_1.ApiService
|
|
|
68
66
|
process.exit(1);
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
|
-
async fetchBlocks(batch) {
|
|
72
|
-
return this.fetchBlocksGeneric(() => (b) => this.api.fetchBlocks(b), batch);
|
|
73
|
-
}
|
|
74
69
|
metadataMismatchError(metadata, expected, actual) {
|
|
75
70
|
return Error(`Value of ${metadata} does not match across all endpoints. Please check that your endpoints are for the same network.\n
|
|
76
71
|
Expected: ${expected}
|
|
77
72
|
Actual: ${actual}`);
|
|
78
73
|
}
|
|
79
74
|
get api() {
|
|
80
|
-
return this.
|
|
75
|
+
return this.unsafeApi;
|
|
76
|
+
}
|
|
77
|
+
async fetchBlockBatches(api, batch) {
|
|
78
|
+
return api.fetchBlocks(batch);
|
|
81
79
|
}
|
|
82
80
|
};
|
|
83
81
|
EthereumApiService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;AAEtC,2CAAoD;AACpD,yDAAsD;AAEtD,gDAM0B;AAE1B,kEAA+D;AAC/D,qDAAyD;
|
|
1
|
+
{"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;AAEtC,2CAAoD;AACpD,yDAAsD;AAEtD,gDAM0B;AAE1B,kEAA+D;AAC/D,qDAAyD;AAIzD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAEhC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAG1B,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,sBAIvC;IACC,YACsC,OAAwB,EAC5D,qBAAmE,EAC3D,YAA2B;QAEnC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAJO,YAAO,GAAP,OAAO,CAAiB;QAEpD,iBAAY,GAAZ,YAAY,CAAe;IAGrC,CAAC;IAID,KAAK,CAAC,IAAI;QACR,IAAI;YACF,IAAI,OAA6B,CAAC;YAClC,IAAI;gBACF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;aAChC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,MAAM,SAAS,G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9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC;IAEO,qBAAqB,CAC3B,QAAgB,EAChB,QAAgB,EAChB,MAAc;QAEd,OAAO,KAAK,CACV,YAAY,QAAQ;mBACP,QAAQ;iBACV,MAAM,EAAE,CACpB,CAAC;IACJ,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAC7B,GAAgB,EAChB,KAAe;QAEf,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AA9FY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAAkB,iCAAe;QACrC,iCAAqB;QACtB,6BAAa;GAR1B,kBAAkB,CA8F9B;AA9FY,gDAAkB","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { ProjectNetworkV1_0_0 } from '@subql/common-ethereum';\nimport {\n ApiService,\n ConnectionPoolService,\n NetworkMetadataPayload,\n getLogger,\n IndexerEvent,\n} from '@subql/node-core';\nimport { EthereumBlockWrapper } from '@subql/types-ethereum';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiConnection } from './api.connection';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nconst logger = getLogger('api');\n\nconst MAX_RECONNECT_ATTEMPTS = 5;\n\n@Injectable()\nexport class EthereumApiService extends ApiService<\n EthereumApi,\n SafeEthProvider,\n EthereumBlockWrapper\n> {\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n private eventEmitter: EventEmitter2,\n ) {\n super(connectionPoolService);\n }\n\n networkMeta: NetworkMetadataPayload;\n\n async init(): Promise<EthereumApiService> {\n try {\n let network: ProjectNetworkV1_0_0;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const endpoints = Array.isArray(network.endpoint)\n ? network.endpoint\n : [network.endpoint];\n\n const endpointToApiIndex: Record<string, EthereumApiConnection> = {};\n\n await Promise.all(\n endpoints.map(async (endpoint, i) => {\n const connection = await EthereumApiConnection.create(\n endpoint,\n this.fetchBlockBatches,\n this.eventEmitter,\n );\n\n const api = connection.unsafeApi;\n\n this.eventEmitter.emit(IndexerEvent.ApiConnected, {\n value: 1,\n apiIndex: i,\n endpoint: endpoint,\n });\n\n if (!this.networkMeta) {\n this.networkMeta = connection.networkMeta;\n }\n\n if (network.chainId !== api.getChainId().toString()) {\n throw this.metadataMismatchError(\n 'ChainId',\n network.chainId,\n api.getChainId().toString(),\n );\n }\n\n endpointToApiIndex[endpoint] = connection;\n }),\n );\n\n this.connectionPoolService.addBatchToConnections(endpointToApiIndex);\n\n return this;\n } catch (e) {\n logger.error(e, 'Failed to init api service');\n process.exit(1);\n }\n }\n\n private metadataMismatchError(\n metadata: string,\n expected: string,\n actual: string,\n ): Error {\n return Error(\n `Value of ${metadata} does not match across all endpoints. Please check that your endpoints are for the same network.\\n\n Expected: ${expected}\n Actual: ${actual}`,\n );\n }\n\n get api(): EthereumApi {\n return this.unsafeApi;\n }\n\n private async fetchBlockBatches(\n api: EthereumApi,\n batch: number[],\n ): Promise<EthereumBlockWrapper[]> {\n return api.fetchBlocks(batch);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-batch-provider.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,0DAAqD;AAErD,wDAA2D;AAE3D,+BAAkD;AAClD,gDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,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AAC,SAAS,EAAE,OAAO,EAAE,EAAE;gBACrD,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC;gBAChC,OAAO,SAAS,CAAC;YACnB,CAAC,EAAE,EAA+B,CAAC,CAAC;YAEpC,6DAA6D;YAC7D,uCAAuC;YACvC,KAAK,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;gBAChC,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACtD,IAAI,OAAO,CAAC,KAAK,EAAE;oBACjB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;oBACzC,KAAM,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;oBACjC,KAAM,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;oBACvC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBAC/B;qBAAM;oBACL,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;iBACzC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACjB,MAAM,EAAE,UAAU;gBAClB,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YAEH,
|
|
1
|
+
{"version":3,"file":"json-rpc-batch-provider.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,0DAAqD;AAErD,wDAA2D;AAE3D,+BAAkD;AAClD,gDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,sBAAsB,CAAC,CAAC;AAajD,eAAe;AAEf,MAAa,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AC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC;gBAChC,OAAO,SAAS,CAAC;YACnB,CAAC,EAAE,EAA+B,CAAC,CAAC;YAEpC,6DAA6D;YAC7D,uCAAuC;YACvC,KAAK,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;gBAChC,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACtD,IAAI,OAAO,CAAC,KAAK,EAAE;oBACjB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;oBACzC,KAAM,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;oBACjC,KAAM,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;oBACvC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBAC/B;qBAAM;oBACL,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;iBACzC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACjB,MAAM,EAAE,UAAU;gBAClB,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YAEH,sBAAsB;YAEtB,KAAK,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;gBAChC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AA/HD,oDA+HC","sourcesContent":["/* eslint-disable */\nimport { deepCopy } from '@ethersproject/properties';\n\nimport { JsonRpcProvider } from '@ethersproject/providers';\nimport { Networkish } from '@ethersproject/networks';\nimport { ConnectionInfo, fetchJson } from './web';\nimport { getLogger } from '@subql/node-core';\n\nconst logger = getLogger('JsonRpcBatchProvider');\n\ninterface RpcResult {\n jsonrpc: '2.0';\n id: number;\n result?: string;\n error?: {\n code: number;\n message: string;\n data?: any;\n };\n}\n\n// Experimental\n\nexport class JsonRpcBatchProvider extends JsonRpcProvider {\n _pendingBatchAggregator: NodeJS.Timer;\n _pendingBatch: Array<{\n request: { method: string; params: Array<any>; id: number; jsonrpc: '2.0' };\n resolve: (result: any) => void;\n reject: (error: Error) => void;\n }>;\n\n constructor(url: string | ConnectionInfo, network?: Networkish) {\n super(url, network);\n }\n\n send(method: string, params: Array<any>): Promise<any> {\n const request = {\n method: method,\n params: params,\n id: this._nextId++,\n jsonrpc: '2.0',\n };\n\n if (this._pendingBatch == null) {\n this._pendingBatch = [];\n }\n\n const inflightRequest: any = { request, resolve: null, reject: null };\n\n const promise = new Promise((resolve, reject) => {\n inflightRequest.resolve = resolve;\n inflightRequest.reject = reject;\n });\n\n this._pendingBatch.push(inflightRequest);\n\n if (!this._pendingBatchAggregator) {\n // Schedule batch for next event loop + short duration\n this._pendingBatchAggregator = setTimeout(() => {\n this.runRequests();\n }, 1);\n }\n\n if (this._pendingBatch.length > 10) {\n this.flush();\n }\n\n return promise;\n }\n\n flush(): void {\n if (this._pendingBatchAggregator) {\n clearTimeout(this._pendingBatchAggregator);\n this.runRequests();\n }\n }\n\n private runRequests() {\n // Get teh current batch and clear it, so new requests\n // go into the next batch\n const batch = this._pendingBatch;\n this._pendingBatch = null;\n this._pendingBatchAggregator = null;\n\n // Get the request as an array of requests\n const request = batch.map((inflight) => inflight.request);\n\n this.emit('debug', {\n action: 'requestBatch',\n request: deepCopy(request),\n provider: this,\n });\n\n return fetchJson(this.connection, JSON.stringify(request))\n .then((result: RpcResult[]) => {\n this.emit('debug', {\n action: 'response',\n request: request,\n response: result,\n provider: this,\n });\n\n // if (!Array.isArray(result)) {\n // result = [result];\n // }\n\n // https://github.com/ethers-io/ethers.js/pull/2657\n if (!Array.isArray(result)) {\n const error = new Error(\n 'Invalid response \\n' + JSON.stringify(result),\n );\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(error);\n });\n return;\n }\n const resultMap = result.reduce((resultMap, payload) => {\n resultMap[payload.id] = payload;\n return resultMap;\n }, {} as Record<number, RpcResult>);\n\n // For each result, feed it to the correct Promise, depending\n // on whether it was a success or error\n batch.forEach((inflightRequest) => {\n const payload = resultMap[inflightRequest.request.id];\n if (payload.error) {\n const error = new Error(payload.error.message);\n (<any>error).code = payload.error.code;\n (<any>error).data = payload.error.data;\n inflightRequest.reject(error);\n } else {\n inflightRequest.resolve(payload.result);\n }\n });\n })\n .catch((error) => {\n this.emit('debug', {\n action: 'response',\n error: error,\n request: request,\n provider: this,\n });\n\n //logger.error(error);\n\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(error);\n });\n });\n }\n}\n"]}
|
|
@@ -29,10 +29,7 @@ FetchModule = __decorate([
|
|
|
29
29
|
providers: [
|
|
30
30
|
node_core_1.StoreService,
|
|
31
31
|
node_core_1.StoreCacheService,
|
|
32
|
-
|
|
33
|
-
provide: node_core_1.ApiService,
|
|
34
|
-
useClass: api_service_ethereum_1.EthereumApiService,
|
|
35
|
-
},
|
|
32
|
+
api_service_ethereum_1.EthereumApiService,
|
|
36
33
|
indexer_manager_1.IndexerManager,
|
|
37
34
|
node_core_1.ConnectionPoolService,
|
|
38
35
|
{
|
|
@@ -58,7 +55,7 @@ FetchModule = __decorate([
|
|
|
58
55
|
node_core_1.NodeConfig,
|
|
59
56
|
event_emitter_1.EventEmitter2,
|
|
60
57
|
'IProjectService',
|
|
61
|
-
|
|
58
|
+
api_service_ethereum_1.EthereumApiService,
|
|
62
59
|
indexer_manager_1.IndexerManager,
|
|
63
60
|
node_core_1.SmartBatchService,
|
|
64
61
|
node_core_1.StoreService,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.module.js","sourceRoot":"","sources":["../../src/indexer/fetch.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;AAEtC,2CAAwC;AACxC,yDAAsD;AACtD,gDAU0B;AAE1B,2EAAsE;AACtE,uDAG2B;AAC3B,6DAAyD;AACzD,iEAA4D;AAC5D,6DAAwD;AACxD,mDAA+C;AAC/C,uDAAmD;AACnD,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;
|
|
1
|
+
{"version":3,"file":"fetch.module.js","sourceRoot":"","sources":["../../src/indexer/fetch.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;AAEtC,2CAAwC;AACxC,yDAAsD;AACtD,gDAU0B;AAE1B,2EAAsE;AACtE,uDAG2B;AAC3B,6DAAyD;AACzD,iEAA4D;AAC5D,6DAAwD;AACxD,mDAA+C;AAC/C,uDAAmD;AACnD,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;AAwGhE,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,WAAW;IAtGvB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,wBAAY;YACZ,6BAAiB;YACjB,yCAAkB;YAClB,gCAAc;YACd,iCAAqB;YACrB;gBACE,OAAO,EAAE,6BAAiB;gBAC1B,UAAU,EAAE,CAAC,UAAsB,EAAE,EAAE;oBACrC,OAAO,IAAI,6BAAiB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;gBACrD,CAAC;gBACD,MAAM,EAAE,CAAC,sBAAU,CAAC;aACrB;YACD;gBACE,OAAO,EAAE,6BAAiB;gBAC1B,UAAU,EAAE,CAAC,UAAsB,EAAE,EAAE;oBACrC,OAAO,IAAI,6BAAiB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;gBACrD,CAAC;gBACD,MAAM,EAAE,CAAC,sBAAU,CAAC;aACrB;YACD;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,UAAU,EAAE,CACV,UAAsB,EACtB,YAA2B,EAC3B,cAA8B,EAC9B,UAA8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BAAY,EAAE,sBAAU,EAAE,6BAAiB,CAAC;KACvD,CAAC;GACW,WAAW,CAAG;AAAd,kCAAW","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n BenchmarkService,\n MmrService,\n StoreService,\n PoiService,\n ApiService,\n NodeConfig,\n ConnectionPoolService,\n SmartBatchService,\n StoreCacheService,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiService } from '../ethereum/api.service.ethereum';\nimport {\n BlockDispatcherService,\n WorkerBlockDispatcherService,\n} from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { FetchService } from './fetch.service';\nimport { IndexerManager } from './indexer.manager';\nimport { ProjectService } from './project.service';\nimport { SandboxService } from './sandbox.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n@Module({\n providers: [\n StoreService,\n StoreCacheService,\n EthereumApiService,\n IndexerManager,\n ConnectionPoolService,\n {\n provide: SmartBatchService,\n useFactory: (nodeConfig: NodeConfig) => {\n return new SmartBatchService(nodeConfig.batchSize);\n },\n inject: [NodeConfig],\n },\n {\n provide: SmartBatchService,\n useFactory: (nodeConfig: NodeConfig) => {\n return new SmartBatchService(nodeConfig.batchSize);\n },\n inject: [NodeConfig],\n },\n {\n provide: 'IBlockDispatcher',\n useFactory: (\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n projectService: ProjectService,\n apiService: EthereumApiService,\n indexerManager: IndexerManager,\n smartBatchService: SmartBatchService,\n storeService: StoreService,\n storeCacheService: StoreCacheService,\n poiService: PoiService,\n project: SubqueryProject,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocks: UnfinalizedBlocksService,\n ) =>\n nodeConfig.workers !== undefined\n ? new WorkerBlockDispatcherService(\n nodeConfig,\n eventEmitter,\n projectService,\n smartBatchService,\n storeService,\n storeCacheService,\n poiService,\n project,\n dynamicDsService,\n unfinalizedBlocks,\n )\n : new BlockDispatcherService(\n apiService,\n nodeConfig,\n indexerManager,\n eventEmitter,\n projectService,\n smartBatchService,\n storeService,\n storeCacheService,\n poiService,\n project,\n dynamicDsService,\n ),\n inject: [\n NodeConfig,\n EventEmitter2,\n 'IProjectService',\n EthereumApiService,\n IndexerManager,\n SmartBatchService,\n StoreService,\n StoreCacheService,\n PoiService,\n 'ISubqueryProject',\n DynamicDsService,\n UnfinalizedBlocksService,\n ],\n },\n FetchService,\n BenchmarkService,\n {\n provide: DictionaryService,\n useFactory: async (project: SubqueryProject, nodeConfig: NodeConfig) => {\n const dictionaryService = new DictionaryService(project, nodeConfig);\n await dictionaryService.init();\n return dictionaryService;\n },\n inject: ['ISubqueryProject', NodeConfig],\n },\n SandboxService,\n DsProcessorService,\n DynamicDsService,\n PoiService,\n MmrService,\n {\n useClass: ProjectService,\n provide: 'IProjectService',\n },\n UnfinalizedBlocksService,\n ],\n exports: [StoreService, MmrService, StoreCacheService],\n})\nexport class FetchModule {}\n"]}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
2
2
|
import { SchedulerRegistry } from '@nestjs/schedule';
|
|
3
|
-
import {
|
|
3
|
+
import { SubqlEthereumProcessorOptions } from '@subql/common-ethereum';
|
|
4
|
+
import { NodeConfig, BaseFetchService } from '@subql/node-core';
|
|
4
5
|
import { DictionaryQueryEntry } from '@subql/types';
|
|
5
6
|
import { SubqlDatasource } from '@subql/types-ethereum';
|
|
6
7
|
import { MetaData } from '@subql/utils';
|
|
7
8
|
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
8
|
-
import { EthereumApi } from '../ethereum';
|
|
9
|
+
import { EthereumApi, EthereumApiService } from '../ethereum';
|
|
9
10
|
import { IEthereumBlockDispatcher } from './blockDispatcher';
|
|
10
11
|
import { DictionaryService } from './dictionary.service';
|
|
11
12
|
import { DsProcessorService } from './ds-processor.service';
|
|
12
13
|
import { DynamicDsService } from './dynamic-ds.service';
|
|
13
14
|
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
|
|
14
|
-
|
|
15
|
+
type GroupedSubqlProjectDs = SubqlDatasource & {
|
|
16
|
+
groupedOptions?: SubqlEthereumProcessorOptions[];
|
|
17
|
+
};
|
|
18
|
+
export declare function buildDictionaryQueryEntries(dataSources: GroupedSubqlProjectDs[], startBlock: number): DictionaryQueryEntry[];
|
|
19
|
+
export declare class FetchService extends BaseFetchService<EthereumApiService, SubqlDatasource, IEthereumBlockDispatcher, DictionaryService> {
|
|
15
20
|
private unfinalizedBlocksService;
|
|
16
|
-
constructor(apiService:
|
|
21
|
+
constructor(apiService: EthereumApiService, nodeConfig: NodeConfig, project: SubqueryProject, blockDispatcher: IEthereumBlockDispatcher, dictionaryService: DictionaryService, dsProcessorService: DsProcessorService, dynamicDsService: DynamicDsService, unfinalizedBlocksService: UnfinalizedBlocksService, eventEmitter: EventEmitter2, schedulerRegistry: SchedulerRegistry);
|
|
17
22
|
get api(): EthereumApi;
|
|
18
23
|
buildDictionaryQueryEntries(startBlock: number): DictionaryQueryEntry[];
|
|
19
24
|
protected getFinalizedHeight(): Promise<number>;
|
|
@@ -25,3 +30,4 @@ export declare class FetchService extends BaseFetchService<SubqlDatasource, IEth
|
|
|
25
30
|
protected validatateDictionaryMeta(metaData: MetaData): Promise<boolean>;
|
|
26
31
|
protected preLoopHook(): Promise<void>;
|
|
27
32
|
}
|
|
33
|
+
export {};
|
|
@@ -14,7 +14,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.FetchService = void 0;
|
|
17
|
+
exports.FetchService = exports.buildDictionaryQueryEntries = void 0;
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
19
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
20
20
|
const schedule_1 = require("@nestjs/schedule");
|
|
@@ -22,6 +22,7 @@ const common_ethereum_1 = require("@subql/common-ethereum");
|
|
|
22
22
|
const node_core_1 = require("@subql/node-core");
|
|
23
23
|
const lodash_1 = require("lodash");
|
|
24
24
|
const SubqueryProject_1 = require("../configure/SubqueryProject");
|
|
25
|
+
const ethereum_1 = require("../ethereum");
|
|
25
26
|
const utils_ethereum_1 = require("../ethereum/utils.ethereum");
|
|
26
27
|
const string_1 = require("../utils/string");
|
|
27
28
|
const dictionary_service_1 = require("./dictionary.service");
|
|
@@ -87,6 +88,13 @@ function callFilterToQueryEntry(filter) {
|
|
|
87
88
|
matcher: 'equalTo',
|
|
88
89
|
});
|
|
89
90
|
}
|
|
91
|
+
else if (filter.to === null) {
|
|
92
|
+
conditions.push({
|
|
93
|
+
field: 'to',
|
|
94
|
+
value: true,
|
|
95
|
+
matcher: 'isNull',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
90
98
|
if (filter.function) {
|
|
91
99
|
conditions.push({
|
|
92
100
|
field: 'func',
|
|
@@ -99,17 +107,63 @@ function callFilterToQueryEntry(filter) {
|
|
|
99
107
|
conditions,
|
|
100
108
|
};
|
|
101
109
|
}
|
|
110
|
+
function buildDictionaryQueryEntries(dataSources, startBlock) {
|
|
111
|
+
var _a;
|
|
112
|
+
const queryEntries = [];
|
|
113
|
+
// Only run the ds that is equal or less than startBlock
|
|
114
|
+
// sort array from lowest ds.startBlock to highest
|
|
115
|
+
const filteredDs = dataSources
|
|
116
|
+
.filter((ds) => ds.startBlock <= startBlock)
|
|
117
|
+
.sort((a, b) => a.startBlock - b.startBlock);
|
|
118
|
+
for (const ds of filteredDs) {
|
|
119
|
+
for (const handler of ds.mapping.handlers) {
|
|
120
|
+
// No filters, cant use dictionary
|
|
121
|
+
if (!handler.filter)
|
|
122
|
+
return [];
|
|
123
|
+
switch (handler.kind) {
|
|
124
|
+
case common_ethereum_1.EthereumHandlerKind.Block:
|
|
125
|
+
return [];
|
|
126
|
+
case common_ethereum_1.EthereumHandlerKind.Call: {
|
|
127
|
+
const filter = handler.filter;
|
|
128
|
+
if (filter.from !== undefined ||
|
|
129
|
+
filter.to !== undefined ||
|
|
130
|
+
filter.function) {
|
|
131
|
+
queryEntries.push(callFilterToQueryEntry(filter));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case common_ethereum_1.EthereumHandlerKind.Event: {
|
|
139
|
+
const filter = handler.filter;
|
|
140
|
+
if (ds.groupedOptions) {
|
|
141
|
+
queryEntries.push(eventFilterToQueryEntry(filter, ds.groupedOptions));
|
|
142
|
+
}
|
|
143
|
+
else if (((_a = ds.options) === null || _a === void 0 ? void 0 : _a.address) || filter.topics) {
|
|
144
|
+
queryEntries.push(eventFilterToQueryEntry(filter, ds.options));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
default:
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return (0, lodash_1.uniqBy)(queryEntries, (item) => `${item.entity}|${JSON.stringify((0, lodash_1.sortBy)(item.conditions, (c) => c.field))}`);
|
|
156
|
+
}
|
|
157
|
+
exports.buildDictionaryQueryEntries = buildDictionaryQueryEntries;
|
|
102
158
|
let FetchService = class FetchService extends node_core_1.BaseFetchService {
|
|
103
159
|
constructor(apiService, nodeConfig, project, blockDispatcher, dictionaryService, dsProcessorService, dynamicDsService, unfinalizedBlocksService, eventEmitter, schedulerRegistry) {
|
|
104
160
|
super(apiService, nodeConfig, project, blockDispatcher, dictionaryService, dsProcessorService, dynamicDsService, eventEmitter, schedulerRegistry);
|
|
105
161
|
this.unfinalizedBlocksService = unfinalizedBlocksService;
|
|
106
162
|
}
|
|
107
163
|
get api() {
|
|
108
|
-
return this.apiService.
|
|
164
|
+
return this.apiService.unsafeApi;
|
|
109
165
|
}
|
|
110
166
|
buildDictionaryQueryEntries(startBlock) {
|
|
111
|
-
var _a;
|
|
112
|
-
const queryEntries = [];
|
|
113
167
|
const groupdDynamicDs = Object.values((0, lodash_1.groupBy)(this.templateDynamicDatasouces, (ds) => ds.name)).map((grouped) => {
|
|
114
168
|
const options = grouped.map((ds) => ds.options);
|
|
115
169
|
const ref = grouped[0];
|
|
@@ -117,48 +171,8 @@ let FetchService = class FetchService extends node_core_1.BaseFetchService {
|
|
|
117
171
|
});
|
|
118
172
|
// Only run the ds that is equal or less than startBlock
|
|
119
173
|
// sort array from lowest ds.startBlock to highest
|
|
120
|
-
const filteredDs = this.project.dataSources
|
|
121
|
-
|
|
122
|
-
.filter((ds) => ds.startBlock <= startBlock)
|
|
123
|
-
.sort((a, b) => a.startBlock - b.startBlock);
|
|
124
|
-
for (const ds of filteredDs) {
|
|
125
|
-
for (const handler of ds.mapping.handlers) {
|
|
126
|
-
// No filters, cant use dictionary
|
|
127
|
-
if (!handler.filter)
|
|
128
|
-
return [];
|
|
129
|
-
switch (handler.kind) {
|
|
130
|
-
case common_ethereum_1.EthereumHandlerKind.Block:
|
|
131
|
-
return [];
|
|
132
|
-
case common_ethereum_1.EthereumHandlerKind.Call: {
|
|
133
|
-
const filter = handler.filter;
|
|
134
|
-
if (filter.from !== undefined ||
|
|
135
|
-
filter.to !== undefined ||
|
|
136
|
-
filter.function) {
|
|
137
|
-
queryEntries.push(callFilterToQueryEntry(filter));
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return [];
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case common_ethereum_1.EthereumHandlerKind.Event: {
|
|
145
|
-
const filter = handler.filter;
|
|
146
|
-
if (ds.groupedOptions) {
|
|
147
|
-
queryEntries.push(eventFilterToQueryEntry(filter, ds.groupedOptions));
|
|
148
|
-
}
|
|
149
|
-
else if (((_a = ds.options) === null || _a === void 0 ? void 0 : _a.address) || filter.topics) {
|
|
150
|
-
queryEntries.push(eventFilterToQueryEntry(filter, ds.options));
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
return [];
|
|
154
|
-
}
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
default:
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return (0, lodash_1.uniqBy)(queryEntries, (item) => `${item.entity}|${JSON.stringify((0, lodash_1.sortBy)(item.conditions, (c) => c.field))}`);
|
|
174
|
+
const filteredDs = this.project.dataSources.concat(groupdDynamicDs);
|
|
175
|
+
return buildDictionaryQueryEntries(filteredDs, startBlock);
|
|
162
176
|
}
|
|
163
177
|
async getFinalizedHeight() {
|
|
164
178
|
const block = await this.api.getFinalizedBlock();
|
|
@@ -212,7 +226,7 @@ FetchService = __decorate([
|
|
|
212
226
|
(0, common_1.Injectable)(),
|
|
213
227
|
__param(2, (0, common_1.Inject)('ISubqueryProject')),
|
|
214
228
|
__param(3, (0, common_1.Inject)('IBlockDispatcher')),
|
|
215
|
-
__metadata("design:paramtypes", [
|
|
229
|
+
__metadata("design:paramtypes", [ethereum_1.EthereumApiService,
|
|
216
230
|
node_core_1.NodeConfig,
|
|
217
231
|
SubqueryProject_1.SubqueryProject, Object, dictionary_service_1.DictionaryService,
|
|
218
232
|
ds_processor_service_1.DsProcessorService,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.service.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;AAEtC,2CAAoD;AACpD,yDAAsD;AACtD,+CAAqD;AAErD,4DAMgC;AAChC,gDAA4E;AAQ5E,mCAAiD;AACjD,kEAA+E;AAE/E,+DAA0D;AAC1D,4CAAkE;AAElE,6DAAyD;AACz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,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;IAES,KAAK,CAAC,wBAAwB,CACtC,QAAkB;QAElB,OAAO,OAAO,CAAC,OAAO;QACpB,yBAAyB;QACzB,QAAQ,CAAC,WAAW,KAAK,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE;YAChD,6BAA6B;YAC7B,QAAQ,CAAC,WAAW,KAAK,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAC1D,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,WAAW;QACzB,4CAA4C;QAC5C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AA3KY,YAAY;IADxB,IAAA,mBAAU,GAAE;IASR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAHf,sBAAU;QACV,sBAAU;QACe,iCAAe,UAGjC,sCAAiB;QAChB,yCAAkB;QACpB,qCAAgB;QACA,oDAAwB;QAC5C,6BAAa;QACR,4BAAiB;GAhB3B,YAAY,CA2KxB;AA3KY,oCAAY","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\n\nimport {\n isCustomDs,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlEthereumProcessorOptions,\n EthereumTransactionFilter,\n} from '@subql/common-ethereum';\nimport { ApiService, NodeConfig, BaseFetchService } from '@subql/node-core';\nimport { DictionaryQueryCondition, DictionaryQueryEntry } from '@subql/types';\nimport {\n // DictionaryQueryCondition,\n // DictionaryQueryEntry,\n SubqlDatasource,\n} from '@subql/types-ethereum';\nimport { MetaData } from '@subql/utils';\nimport { groupBy, sortBy, uniqBy } from 'lodash';\nimport { SubqlProjectDs, SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApi } from '../ethereum';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { IEthereumBlockDispatcher } from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport {\n blockToHeader,\n UnfinalizedBlocksService,\n} from './unfinalizedBlocks.service';\n\nconst BLOCK_TIME_VARIANCE = 5000;\n\nconst INTERVAL_PERCENT = 0.9;\nconst QUERY_ADDRESS_LIMIT = 50;\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length !== 0 && addresses.length <= QUERY_ADDRESS_LIMIT) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'in',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n }\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\n@Injectable()\nexport class FetchService extends BaseFetchService<\n SubqlDatasource,\n IEthereumBlockDispatcher,\n DictionaryService\n> {\n constructor(\n apiService: ApiService,\n nodeConfig: NodeConfig,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IBlockDispatcher')\n blockDispatcher: IEthereumBlockDispatcher,\n dictionaryService: DictionaryService,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n eventEmitter: EventEmitter2,\n schedulerRegistry: SchedulerRegistry,\n ) {\n super(\n apiService,\n nodeConfig,\n project,\n blockDispatcher,\n dictionaryService,\n dsProcessorService,\n dynamicDsService,\n eventEmitter,\n schedulerRegistry,\n );\n }\n\n get api(): EthereumApi {\n return this.apiService.api;\n }\n\n buildDictionaryQueryEntries(startBlock: number): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\n\n type GroupedSubqlProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n };\n\n const groupdDynamicDs: GroupedSubqlProjectDs[] = Object.values(\n groupBy(this.templateDynamicDatasouces, (ds) => ds.name),\n ).map((grouped: SubqlProjectDs[]) => {\n const options = grouped.map((ds) => ds.options);\n const ref = grouped[0];\n\n return {\n ...ref,\n groupedOptions: options,\n };\n });\n\n // Only run the ds that is equal or less than startBlock\n // sort array from lowest ds.startBlock to highest\n const filteredDs: GroupedSubqlProjectDs[] = this.project.dataSources\n .concat(groupdDynamicDs)\n .filter((ds) => ds.startBlock <= startBlock)\n .sort((a, b) => a.startBlock - b.startBlock);\n\n for (const ds of filteredDs) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return [];\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n return [];\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function\n ) {\n queryEntries.push(callFilterToQueryEntry(filter));\n } else {\n return [];\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n }\n\n protected async getFinalizedHeight(): Promise<number> {\n const block = await this.api.getFinalizedBlock();\n\n const header = blockToHeader(block);\n\n this.unfinalizedBlocksService.registerFinalizedBlock(header);\n return header.blockHeight;\n }\n\n protected async getBestHeight(): Promise<number> {\n return this.api.getBestBlockHeight();\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async getChainInterval(): Promise<number> {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n return Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n }\n\n protected async getChainId(): Promise<string> {\n return Promise.resolve(this.api.getChainId().toString());\n }\n\n protected getModulos(): number[] {\n const modulos: number[] = [];\n for (const ds of this.project.dataSources) {\n if (isCustomDs(ds)) {\n continue;\n }\n for (const handler of ds.mapping.handlers) {\n if (\n handler.kind === EthereumHandlerKind.Block &&\n handler.filter &&\n handler.filter.modulo\n ) {\n modulos.push(handler.filter.modulo);\n }\n }\n }\n return modulos;\n }\n\n protected async initBlockDispatcher(): Promise<void> {\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n }\n\n protected async validatateDictionaryMeta(\n metaData: MetaData,\n ): Promise<boolean> {\n return Promise.resolve(\n // When alias is not used\n metaData.genesisHash !== this.api.getGenesisHash() &&\n // Case when an alias is used\n metaData.genesisHash !== this.dictionaryService.chainId,\n );\n }\n\n protected async preLoopHook(): Promise<void> {\n // Ethereum doesn't need to do anything here\n return Promise.resolve();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.service.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;AAEtC,2CAAoD;AACpD,yDAAsD;AACtD,+CAAqD;AAErD,4DAMgC;AAChC,gDAAgE;AAIhE,mCAAiD;AACjD,kEAA+E;AAC/E,0CAA8D;AAE9D,+DAA0D;AAC1D,4CAAkE;AAElE,6DAAyD;AACzD,iEAA4D;AAC5D,6DAAwD;AACxD,2EAGqC;AAErC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,SAAS,uBAAuB,CAC9B,MAAyB,EACzB,SAA0E;IAE1E,MAAM,UAAU,GAA+B,EAAE,CAAC;IAElD,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC5B,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE5E,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,IAAI,mBAAmB,EAAE;YACrE,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,SAAS;gBAChB,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;SACJ;KACF;SAAM;QACL,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,EAAE;YACtB,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE;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AM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAHf,6BAAkB;QAClB,sBAAU;QACe,iCAAe,UAGjC,sCAAiB;QAChB,yCAAkB;QACpB,qCAAgB;QACA,oDAAwB;QAC5C,6BAAa;QACR,4BAAiB;GAjB3B,YAAY,CAuHxB;AAvHY,oCAAY","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\n\nimport {\n isCustomDs,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlEthereumProcessorOptions,\n EthereumTransactionFilter,\n} from '@subql/common-ethereum';\nimport { NodeConfig, BaseFetchService } from '@subql/node-core';\nimport { DictionaryQueryCondition, DictionaryQueryEntry } from '@subql/types';\nimport { SubqlDatasource } from '@subql/types-ethereum';\nimport { MetaData } from '@subql/utils';\nimport { groupBy, sortBy, uniqBy } from 'lodash';\nimport { SubqlProjectDs, SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApi, EthereumApiService } from '../ethereum';\nimport SafeEthProvider from '../ethereum/safe-api';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { IEthereumBlockDispatcher } from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport {\n blockToHeader,\n UnfinalizedBlocksService,\n} from './unfinalizedBlocks.service';\n\nconst BLOCK_TIME_VARIANCE = 5000;\n\nconst INTERVAL_PERCENT = 0.9;\nconst QUERY_ADDRESS_LIMIT = 50;\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length !== 0 && addresses.length <= QUERY_ADDRESS_LIMIT) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'in',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n }\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n matcher: 'equalTo',\n });\n } else if (filter.to === null) {\n conditions.push({\n field: 'to',\n value: true as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n }\n if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\ntype GroupedSubqlProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\nexport function buildDictionaryQueryEntries(\n dataSources: GroupedSubqlProjectDs[],\n startBlock: number,\n): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\n\n // Only run the ds that is equal or less than startBlock\n // sort array from lowest ds.startBlock to highest\n const filteredDs = dataSources\n .filter((ds) => ds.startBlock <= startBlock)\n .sort((a, b) => a.startBlock - b.startBlock);\n\n for (const ds of filteredDs) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return [];\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n return [];\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function\n ) {\n queryEntries.push(callFilterToQueryEntry(filter));\n } else {\n return [];\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n}\n\n@Injectable()\nexport class FetchService extends BaseFetchService<\n EthereumApiService,\n SubqlDatasource,\n IEthereumBlockDispatcher,\n DictionaryService\n> {\n constructor(\n apiService: EthereumApiService,\n nodeConfig: NodeConfig,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IBlockDispatcher')\n blockDispatcher: IEthereumBlockDispatcher,\n dictionaryService: DictionaryService,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n eventEmitter: EventEmitter2,\n schedulerRegistry: SchedulerRegistry,\n ) {\n super(\n apiService,\n nodeConfig,\n project,\n blockDispatcher,\n dictionaryService,\n dsProcessorService,\n dynamicDsService,\n eventEmitter,\n schedulerRegistry,\n );\n }\n\n get api(): EthereumApi {\n return this.apiService.unsafeApi;\n }\n\n buildDictionaryQueryEntries(startBlock: number): DictionaryQueryEntry[] {\n const groupdDynamicDs: GroupedSubqlProjectDs[] = Object.values(\n groupBy(this.templateDynamicDatasouces, (ds) => ds.name),\n ).map((grouped: SubqlProjectDs[]) => {\n const options = grouped.map((ds) => ds.options);\n const ref = grouped[0];\n\n return {\n ...ref,\n groupedOptions: options,\n };\n });\n\n // Only run the ds that is equal or less than startBlock\n // sort array from lowest ds.startBlock to highest\n const filteredDs: GroupedSubqlProjectDs[] =\n this.project.dataSources.concat(groupdDynamicDs);\n\n return buildDictionaryQueryEntries(filteredDs, startBlock);\n }\n\n protected async getFinalizedHeight(): Promise<number> {\n const block = await this.api.getFinalizedBlock();\n\n const header = blockToHeader(block);\n\n this.unfinalizedBlocksService.registerFinalizedBlock(header);\n return header.blockHeight;\n }\n\n protected async getBestHeight(): Promise<number> {\n return this.api.getBestBlockHeight();\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async getChainInterval(): Promise<number> {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n return Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n }\n\n protected async getChainId(): Promise<string> {\n return Promise.resolve(this.api.getChainId().toString());\n }\n\n protected getModulos(): number[] {\n const modulos: number[] = [];\n for (const ds of this.project.dataSources) {\n if (isCustomDs(ds)) {\n continue;\n }\n for (const handler of ds.mapping.handlers) {\n if (\n handler.kind === EthereumHandlerKind.Block &&\n handler.filter &&\n handler.filter.modulo\n ) {\n modulos.push(handler.filter.modulo);\n }\n }\n }\n return modulos;\n }\n\n protected async initBlockDispatcher(): Promise<void> {\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n }\n\n protected async validatateDictionaryMeta(\n metaData: MetaData,\n ): Promise<boolean> {\n return Promise.resolve(\n // When alias is not used\n metaData.genesisHash !== this.api.getGenesisHash() &&\n // Case when an alias is used\n metaData.genesisHash !== this.dictionaryService.chainId,\n );\n }\n\n protected async preLoopHook(): Promise<void> {\n // Ethereum doesn't need to do anything here\n return Promise.resolve();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|