@subql/node-ethereum 4.3.2 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/admin/admin.module.d.ts +2 -0
- package/dist/admin/admin.module.js +25 -0
- package/dist/admin/admin.module.js.map +1 -0
- package/dist/app.module.js +2 -0
- package/dist/app.module.js.map +1 -1
- package/dist/configure/SubqueryProject.js +15 -18
- package/dist/configure/SubqueryProject.js.map +1 -1
- package/dist/ethereum/api.connection.js +4 -1
- package/dist/ethereum/api.connection.js.map +1 -1
- package/dist/ethereum/api.ethereum.js +26 -11
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.js +7 -6
- package/dist/ethereum/api.service.ethereum.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.test.js +1 -1
- package/dist/ethereum/api.service.ethereum.test.js.map +1 -1
- package/dist/ethereum/block.ethereum.js +1 -1
- package/dist/ethereum/block.ethereum.js.map +1 -1
- package/dist/ethereum/ethers/celo/celo-provider.js +15 -20
- package/dist/ethereum/ethers/celo/celo-provider.js.map +1 -1
- package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js +1 -1
- package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.js +9 -9
- package/dist/ethereum/ethers/json-rpc-batch-provider.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.spec.js +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.spec.js.map +1 -1
- package/dist/ethereum/ethers/op/op-provider.js +7 -1
- package/dist/ethereum/ethers/op/op-provider.js.map +1 -1
- package/dist/ethereum/ethers/web/geturl.js +2 -3
- package/dist/ethereum/ethers/web/geturl.js.map +1 -1
- package/dist/ethereum/safe-api.js +3 -0
- package/dist/ethereum/safe-api.js.map +1 -1
- package/dist/ethereum/utils.ethereum.js +58 -13
- package/dist/ethereum/utils.ethereum.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -0
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +2 -2
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +3 -3
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary/ethDictionary.service.js +2 -0
- package/dist/indexer/dictionary/ethDictionary.service.js.map +1 -1
- package/dist/indexer/dictionary/utils.js +5 -2
- package/dist/indexer/dictionary/utils.js.map +1 -1
- package/dist/indexer/dictionary/utils.spec.js +3 -3
- package/dist/indexer/dictionary/utils.spec.js.map +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js +3 -4
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js.map +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js +3 -3
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js.map +1 -1
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js +7 -20
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js.map +1 -1
- package/dist/indexer/dictionary/v2/utils.js +12 -6
- package/dist/indexer/dictionary/v2/utils.js.map +1 -1
- package/dist/indexer/dictionary/v2/utils.spec.js +4 -15
- package/dist/indexer/dictionary/v2/utils.spec.js.map +1 -1
- package/dist/indexer/ds-processor.service.js +1 -4
- package/dist/indexer/ds-processor.service.js.map +1 -1
- package/dist/indexer/dynamic-ds.service.js +9 -2
- package/dist/indexer/dynamic-ds.service.js.map +1 -1
- package/dist/indexer/fetch.module.js +5 -3
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.js +2 -0
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/indexer.manager.js +7 -8
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/project.service.js +1 -1
- package/dist/indexer/project.service.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.js +3 -1
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker-fetch.module.js +4 -0
- package/dist/indexer/worker/worker-fetch.module.js.map +1 -1
- package/dist/indexer/worker/worker.service.js +2 -0
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/init.js +3 -6
- package/dist/init.js.map +1 -1
- package/dist/meta/meta.controller.js +1 -0
- package/dist/meta/meta.controller.js.map +1 -1
- package/dist/meta/meta.service.js +11 -9
- package/dist/meta/meta.service.js.map +1 -1
- package/dist/subcommands/testing.init.js +1 -2
- package/dist/subcommands/testing.init.js.map +1 -1
- package/dist/utils/project.js +1 -1
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/string.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAA2E;AAC3E,yDAAsD;AACtD,gDAW0B;AAC1B,qEAGyC;AACzC,wDAAoD;AAGpD;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBACX,SAAQ,2BAAgD;
|
|
1
|
+
{"version":3,"file":"block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAA2E;AAC3E,yDAAsD;AACtD,gDAW0B;AAC1B,qEAGyC;AACzC,wDAAoD;AAGpD;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBACX,SAAQ,2BAAgD;IAM9C;IAHV,YACE,UAAsB,EACtB,UAAsB,EACd,cAA8B,EACtC,YAA2B,EAE3B,cAAkD,EAElD,qBAA6C,EAC7C,YAA0B,EAC1B,iBAAoC,EACpC,cAA8B,EACF,OAAwB;QAEpD,KAAK,CACH,UAAU,EACV,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CACxC,CAAC;QArBM,mBAAc,GAAd,cAAc,CAAgB;IAsBxC,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,KAA2B;QAE3B,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CACnC,KAAK,EACL,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,WAAW,CAAC,CACxE,CAAC;IACJ,CAAC;CACF,CAAA;AAvCY,sBAAsB;IADlC,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;IAKhC,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAXf,sBAAU;QACV,sBAAU;QACE,gCAAc;QACxB,6BAAa,kBAKb,wBAAY;QACP,6BAAiB;QACpB,0BAAc;QACO,iCAAe;GAhB3C,sBAAsB,CAuClC;AAvCY,wDAAsB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n NodeConfig,\n StoreCacheService,\n StoreService,\n IProjectService,\n BlockDispatcher,\n ProcessBlockResponse,\n ApiService,\n IProjectUpgradeService,\n PoiSyncService,\n IBlock,\n} from '@subql/node-core';\nimport {\n EthereumProjectDs,\n SubqueryProject,\n} from '../../configure/SubqueryProject';\nimport { IndexerManager } from '../indexer.manager';\nimport { BlockContent } from '../types';\n\n/**\n * @description Intended to behave the same as WorkerBlockDispatcherService but doesn't use worker threads or any parallel processing\n */\n@Injectable()\nexport class BlockDispatcherService\n extends BlockDispatcher<BlockContent, EthereumProjectDs>\n implements OnApplicationShutdown\n{\n constructor(\n apiService: ApiService,\n nodeConfig: NodeConfig,\n private indexerManager: IndexerManager,\n eventEmitter: EventEmitter2,\n @Inject('IProjectService')\n projectService: IProjectService<EthereumProjectDs>,\n @Inject('IProjectUpgradeService')\n projectUpgradeService: IProjectUpgradeService,\n storeService: StoreService,\n storeCacheService: StoreCacheService,\n poiSyncService: PoiSyncService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n ) {\n super(\n nodeConfig,\n eventEmitter,\n projectService,\n projectUpgradeService,\n storeService,\n storeCacheService,\n poiSyncService,\n project,\n apiService.fetchBlocks.bind(apiService),\n );\n }\n\n protected async indexBlock(\n block: IBlock<BlockContent>,\n ): Promise<ProcessBlockResponse> {\n return this.indexerManager.indexBlock(\n block,\n await this.projectService.getDataSources(block.getHeader().blockHeight),\n );\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
3
|
-
import { NodeConfig, StoreService, StoreCacheService, IProjectService, WorkerBlockDispatcher, ConnectionPoolStateManager, IProjectUpgradeService, PoiSyncService, InMemoryCacheService } from '@subql/node-core';
|
|
3
|
+
import { NodeConfig, StoreService, StoreCacheService, IProjectService, WorkerBlockDispatcher, ConnectionPoolStateManager, IProjectUpgradeService, PoiSyncService, InMemoryCacheService, MonitorServiceInterface } from '@subql/node-core';
|
|
4
4
|
import { EthereumBlock } from '@subql/types-ethereum';
|
|
5
5
|
import { EthereumProjectDs, SubqueryProject } from '../../configure/SubqueryProject';
|
|
6
6
|
import { EthereumApiConnection } from '../../ethereum/api.connection';
|
|
@@ -11,7 +11,7 @@ type IndexerWorker = IIndexerWorker & {
|
|
|
11
11
|
terminate: () => Promise<number>;
|
|
12
12
|
};
|
|
13
13
|
export declare class WorkerBlockDispatcherService extends WorkerBlockDispatcher<EthereumProjectDs, IndexerWorker, EthereumBlock> implements OnApplicationShutdown {
|
|
14
|
-
constructor(nodeConfig: NodeConfig, eventEmitter: EventEmitter2, projectService: IProjectService<EthereumProjectDs>, projectUpgadeService: IProjectUpgradeService, cacheService: InMemoryCacheService, storeService: StoreService, storeCacheService: StoreCacheService, poiSyncService: PoiSyncService, project: SubqueryProject, dynamicDsService: DynamicDsService, unfinalizedBlocksSevice: UnfinalizedBlocksService, connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection
|
|
14
|
+
constructor(nodeConfig: NodeConfig, eventEmitter: EventEmitter2, projectService: IProjectService<EthereumProjectDs>, projectUpgadeService: IProjectUpgradeService, cacheService: InMemoryCacheService, storeService: StoreService, storeCacheService: StoreCacheService, poiSyncService: PoiSyncService, project: SubqueryProject, dynamicDsService: DynamicDsService, unfinalizedBlocksSevice: UnfinalizedBlocksService, connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection>, monitorService?: MonitorServiceInterface);
|
|
15
15
|
protected fetchBlock(worker: IndexerWorker, height: number): Promise<void>;
|
|
16
16
|
}
|
|
17
17
|
export {};
|
|
@@ -26,8 +26,8 @@ const SubqueryProject_1 = require("../../configure/SubqueryProject");
|
|
|
26
26
|
const dynamic_ds_service_1 = require("../dynamic-ds.service");
|
|
27
27
|
const unfinalizedBlocks_service_1 = require("../unfinalizedBlocks.service");
|
|
28
28
|
let WorkerBlockDispatcherService = class WorkerBlockDispatcherService extends node_core_1.WorkerBlockDispatcher {
|
|
29
|
-
constructor(nodeConfig, eventEmitter, projectService, projectUpgadeService, cacheService, storeService, storeCacheService, poiSyncService, project, dynamicDsService, unfinalizedBlocksSevice, connectionPoolState) {
|
|
30
|
-
super(nodeConfig, eventEmitter, projectService, projectUpgadeService, storeService, storeCacheService, poiSyncService, project, () => (0, node_core_1.createIndexerWorker)(path_1.default.resolve(__dirname, '../../../dist/indexer/worker/worker.js'), [], storeService.getStore(), cacheService.getCache(), dynamicDsService, unfinalizedBlocksSevice, connectionPoolState, project.root, projectService.startHeight));
|
|
29
|
+
constructor(nodeConfig, eventEmitter, projectService, projectUpgadeService, cacheService, storeService, storeCacheService, poiSyncService, project, dynamicDsService, unfinalizedBlocksSevice, connectionPoolState, monitorService) {
|
|
30
|
+
super(nodeConfig, eventEmitter, projectService, projectUpgadeService, storeService, storeCacheService, poiSyncService, project, () => (0, node_core_1.createIndexerWorker)(path_1.default.resolve(__dirname, '../../../dist/indexer/worker/worker.js'), [], storeService.getStore(), cacheService.getCache(), dynamicDsService, unfinalizedBlocksSevice, connectionPoolState, project.root, projectService.startHeight, monitorService), monitorService);
|
|
31
31
|
}
|
|
32
32
|
async fetchBlock(worker, height) {
|
|
33
33
|
await worker.fetchBlock(height, null);
|
|
@@ -46,7 +46,7 @@ WorkerBlockDispatcherService = __decorate([
|
|
|
46
46
|
SubqueryProject_1.SubqueryProject,
|
|
47
47
|
dynamic_ds_service_1.DynamicDsService,
|
|
48
48
|
unfinalizedBlocks_service_1.UnfinalizedBlocksService,
|
|
49
|
-
node_core_1.ConnectionPoolStateManager])
|
|
49
|
+
node_core_1.ConnectionPoolStateManager, Object])
|
|
50
50
|
], WorkerBlockDispatcherService);
|
|
51
51
|
exports.WorkerBlockDispatcherService = WorkerBlockDispatcherService;
|
|
52
52
|
//# sourceMappingURL=worker-block-dispatcher.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/worker-block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;AAEnC,gDAAwB;AACxB,2CAA2E;AAC3E,yDAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"worker-block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/worker-block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AY;QACP,6BAAiB;QACpB,0BAAc;QACO,iCAAe;QAClC,qCAAgB;QACT,oDAAwB;QAC5B,sCAA0B;GAlBtC,4BAA4B,CA0DxC;AA1DY,oEAA4B","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport path from 'path';\nimport { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n NodeConfig,\n StoreService,\n StoreCacheService,\n IProjectService,\n WorkerBlockDispatcher,\n ConnectionPoolStateManager,\n IProjectUpgradeService,\n PoiSyncService,\n InMemoryCacheService,\n createIndexerWorker,\n MonitorServiceInterface,\n} from '@subql/node-core';\nimport { EthereumBlock } from '@subql/types-ethereum';\nimport {\n EthereumProjectDs,\n SubqueryProject,\n} from '../../configure/SubqueryProject';\nimport { EthereumApiConnection } from '../../ethereum/api.connection';\nimport { DynamicDsService } from '../dynamic-ds.service';\nimport { BlockContent } from '../types';\nimport { UnfinalizedBlocksService } from '../unfinalizedBlocks.service';\nimport { IIndexerWorker } from '../worker/worker';\n\ntype IndexerWorker = IIndexerWorker & {\n terminate: () => Promise<number>;\n};\n\n@Injectable()\nexport class WorkerBlockDispatcherService\n extends WorkerBlockDispatcher<EthereumProjectDs, IndexerWorker, EthereumBlock>\n implements OnApplicationShutdown\n{\n constructor(\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n @Inject('IProjectService')\n projectService: IProjectService<EthereumProjectDs>,\n @Inject('IProjectUpgradeService')\n projectUpgadeService: IProjectUpgradeService,\n cacheService: InMemoryCacheService,\n storeService: StoreService,\n storeCacheService: StoreCacheService,\n poiSyncService: PoiSyncService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksSevice: UnfinalizedBlocksService,\n connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection>,\n monitorService?: MonitorServiceInterface,\n ) {\n super(\n nodeConfig,\n eventEmitter,\n projectService,\n projectUpgadeService,\n storeService,\n storeCacheService,\n poiSyncService,\n project,\n () =>\n createIndexerWorker<\n IIndexerWorker,\n EthereumApiConnection,\n BlockContent,\n EthereumProjectDs\n >(\n path.resolve(__dirname, '../../../dist/indexer/worker/worker.js'),\n [],\n storeService.getStore(),\n cacheService.getCache(),\n dynamicDsService,\n unfinalizedBlocksSevice,\n connectionPoolState,\n project.root,\n projectService.startHeight,\n monitorService,\n ),\n monitorService,\n );\n }\n\n protected async fetchBlock(\n worker: IndexerWorker,\n height: number,\n ): Promise<void> {\n await worker.fetchBlock(height, null);\n }\n}\n"]}
|
|
@@ -25,6 +25,8 @@ const v1_1 = require("./v1");
|
|
|
25
25
|
const v2_1 = require("./v2");
|
|
26
26
|
const logger = (0, node_core_1.getLogger)('dictionary');
|
|
27
27
|
let EthDictionaryService = class EthDictionaryService extends node_core_1.DictionaryService {
|
|
28
|
+
project;
|
|
29
|
+
apiService;
|
|
28
30
|
constructor(project, nodeConfig, eventEmitter, apiService) {
|
|
29
31
|
super(project.network.chainId, nodeConfig, eventEmitter);
|
|
30
32
|
this.project = project;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionary.service.js","sourceRoot":"","sources":["../../../src/indexer/dictionary/ethDictionary.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,0CAA+C;AAC/C,gDAK0B;AAE1B,qEAAkE;AAClE,6CAAoD;AACpD,6BAAuC;AACvC,6BAAuC;AAEvC,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,YAAY,CAAC,CAAC;AAGhC,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,6BAGzC;
|
|
1
|
+
{"version":3,"file":"ethDictionary.service.js","sourceRoot":"","sources":["../../../src/indexer/dictionary/ethDictionary.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;A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AAC,UAAU,EACf,QAAQ,CACT,CAAC;oBACF,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACnC;gBAAC,OAAO,CAAC,EAAE;oBACV,MAAM,CAAC,IAAI,CACT,wBAAwB,QAAQ,6BAA6B,CAC9D,CAAC;iBACH;aACF;SACF;QACD,MAAM,CAAC,KAAK,CACV,4BAA4B,cAAc,CAAC,MAAM,SAAS,cAAc,CAAC,MAAM,EAAE,CAClF,CAAC;QACF,2BAA2B;QAC3B,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IACpD,CAAC;CACF,CAAA;AAxDY,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAG1B,WAAA,IAAA,eAAM,EAAC,sBAAU,CAAC,CAAA;qCAH4B,iCAAe;QAClD,sBAAU;QACR,6BAAa;QACa,6BAAkB;GARjD,oBAAoB,CAwDhC;AAxDY,oDAAoB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { NETWORK_FAMILY } from '@subql/common';\nimport {\n NodeConfig,\n DictionaryService,\n ApiService,\n getLogger,\n} from '@subql/node-core';\nimport { EthereumBlock, SubqlDatasource } from '@subql/types-ethereum';\nimport { SubqueryProject } from '../../configure/SubqueryProject';\nimport { EthereumApiService } from '../../ethereum';\nimport { EthDictionaryV1 } from './v1';\nimport { EthDictionaryV2 } from './v2';\n\nconst logger = getLogger('dictionary');\n\n@Injectable()\nexport class EthDictionaryService extends DictionaryService<\n SubqlDatasource,\n EthereumBlock\n> {\n constructor(\n @Inject('ISubqueryProject') protected project: SubqueryProject,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n @Inject(ApiService) private apiService: EthereumApiService,\n ) {\n super(project.network.chainId, nodeConfig, eventEmitter);\n }\n\n async initDictionaries(): Promise<void> {\n const dictionariesV1: EthDictionaryV1[] = [];\n const dictionariesV2: EthDictionaryV2[] = [];\n\n if (!this.project) {\n throw new Error(`Project in Dictionary service not initialized `);\n }\n\n const dictionaryEndpoints = await this.getDictionaryEndpoints(\n NETWORK_FAMILY.ethereum,\n this.project.network,\n );\n\n for (const endpoint of dictionaryEndpoints) {\n try {\n const dictionaryV2 = await EthDictionaryV2.create(\n endpoint,\n this.nodeConfig,\n this.project,\n this.apiService.api,\n );\n dictionariesV2.push(dictionaryV2);\n } catch (e) {\n try {\n const dictionaryV1 = await EthDictionaryV1.create(\n this.project,\n this.nodeConfig,\n endpoint,\n );\n dictionariesV1.push(dictionaryV1);\n } catch (e) {\n logger.warn(\n `Dictionary endpoint \"${endpoint}\" is not a valid dictionary`,\n );\n }\n }\n }\n logger.debug(\n `Dictionary versions, v1: ${dictionariesV1.length}, v2: ${dictionariesV2.length}`,\n );\n // v2 should be prioritised\n this.init([...dictionariesV2, ...dictionariesV1]);\n }\n}\n"]}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.ethFilterDs = void 0;
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
7
7
|
function isTemplateDs(ds) {
|
|
8
|
-
return !!
|
|
8
|
+
return !!ds?.name;
|
|
9
9
|
}
|
|
10
10
|
function ethFilterDs(dataSources) {
|
|
11
11
|
const [normalDataSources, templateDataSources] = (0, lodash_1.partition)(dataSources, (ds) => !isTemplateDs(ds));
|
|
@@ -16,7 +16,10 @@ function ethFilterDs(dataSources) {
|
|
|
16
16
|
}
|
|
17
17
|
const options = grouped.map((ds) => ds.options);
|
|
18
18
|
const ref = grouped[0];
|
|
19
|
-
return
|
|
19
|
+
return {
|
|
20
|
+
...ref,
|
|
21
|
+
groupedOptions: options,
|
|
22
|
+
};
|
|
20
23
|
});
|
|
21
24
|
return [...normalDataSources, ...groupedDataSources];
|
|
22
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/indexer/dictionary/utils.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,mCAA4C;AAM5C,SAAS,YAAY,CACnB,EAAiD;IAEjD,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/indexer/dictionary/utils.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,mCAA4C;AAM5C,SAAS,YAAY,CACnB,EAAiD;IAEjD,OAAO,CAAC,CAAE,EAAgC,EAAE,IAAI,CAAC;AACnD,CAAC;AAED,SAAgB,WAAW,CACzB,WAA8D;IAE9D,MAAM,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,GAAG,IAAA,kBAAS,EACxD,WAAW,EACX,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAC1B,CAAC;IAEF,cAAc;IACd,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CACtC,IAAA,gBAAO,EACL,mBAAkD,EAClD,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAChB,CACF,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAChB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;SACnB;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAEvB,OAAO;YACL,GAAG,GAAG;YACN,cAAc,EAAE,OAAO;SACxB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,iBAAiB,EAAE,GAAG,kBAAkB,CAAC,CAAC;AACvD,CAAC;AA7BD,kCA6BC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { SubqlDatasource } from '@subql/types-ethereum';\nimport { groupBy, partition } from 'lodash';\nimport {\n EthereumProjectDsTemplate,\n EthereumProjectDs,\n} from '../../configure/SubqueryProject';\n\nfunction isTemplateDs(\n ds: EthereumProjectDs | EthereumProjectDsTemplate,\n): ds is EthereumProjectDsTemplate {\n return !!(ds as EthereumProjectDsTemplate)?.name;\n}\n\nexport function ethFilterDs(\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n): SubqlDatasource[] {\n const [normalDataSources, templateDataSources] = partition(\n dataSources,\n (ds) => !isTemplateDs(ds),\n );\n\n // Group templ\n const groupedDataSources = Object.values(\n groupBy(\n templateDataSources as EthereumProjectDsTemplate[],\n (ds) => ds.name,\n ),\n ).map((grouped) => {\n if (grouped.length === 1) {\n return grouped[0];\n }\n\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 return [...normalDataSources, ...groupedDataSources];\n}\n"]}
|
|
@@ -64,9 +64,9 @@ describe('Dictionary utils', () => {
|
|
|
64
64
|
},
|
|
65
65
|
};
|
|
66
66
|
const duplicateDataSources = [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
{ ...mockTempDs[0], options: { address: 'address1' } },
|
|
68
|
+
{ ...mockTempDs[0], options: { address: 'address2' } },
|
|
69
|
+
{ ...mockTempDs[1], options: { address: 'address3' } },
|
|
70
70
|
];
|
|
71
71
|
const dataSources = [ds, ...duplicateDataSources];
|
|
72
72
|
// Runtime + ERC721 + ERC721 + ERC1155
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.spec.js","sourceRoot":"","sources":["../../../src/indexer/dictionary/utils.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;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6BAC9D;yBACF;qBACF;iBACF;aACF;SACF,CAAC;QAEF,MAAM,oBAAoB,GAAG;YAC3B,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE;YACtD,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE;YACtD,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE;SACvD,CAAC;QAEF,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,GAAG,oBAAoB,CAAC,CAAC;QAClD,sCAAsC;QACtC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAEnC,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,WAAW,CAAC,CAAC;QAC5C,8CAA8C;QAC9C,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClC,MAAM,CAAE,UAAU,CAAC,CAAC,CAAS,CAAC,cAAc,CAAC,CAAC,aAAa,CAAC;YAC1D,EAAE,OAAO,EAAE,UAAU,EAAE;YACvB,EAAE,OAAO,EAAE,UAAU,EAAE;SACxB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { EthereumProjectDsTemplate } from '../../configure/SubqueryProject';\nimport { ethFilterDs } from './utils';\n\ndescribe('Dictionary utils', () => {\n it('can filter eth ds with multiple dynamic ds/templates', () => {\n const mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n ];\n\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n // Runtime + ERC721 + ERC721 + ERC1155\n expect(dataSources.length).toBe(4);\n\n const filteredDs = ethFilterDs(dataSources);\n // Runtime + ERC721 (groupedOptions) + ERC1155\n expect(filteredDs.length).toBe(3);\n expect((filteredDs[1] as any).groupedOptions).toStrictEqual([\n { address: 'address1' },\n { address: 'address2' },\n ]);\n });\n});\n"]}
|
|
@@ -32,7 +32,7 @@ function appendDsOptions(dsOptions, conditions) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
if (dsOptions
|
|
35
|
+
if (dsOptions?.address) {
|
|
36
36
|
conditions.push({
|
|
37
37
|
field: 'address',
|
|
38
38
|
value: dsOptions.address.toLowerCase(),
|
|
@@ -128,7 +128,6 @@ function callFilterToQueryEntry(filter, dsOptions) {
|
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
function buildDictionaryV1QueryEntries(dataSources) {
|
|
131
|
-
var _a;
|
|
132
131
|
const queryEntries = [];
|
|
133
132
|
for (const ds of dataSources) {
|
|
134
133
|
for (const handler of ds.mapping.handlers) {
|
|
@@ -158,7 +157,7 @@ function buildDictionaryV1QueryEntries(dataSources) {
|
|
|
158
157
|
if (ds.groupedOptions) {
|
|
159
158
|
queryEntries.push(eventFilterToQueryEntry(filter, ds.groupedOptions));
|
|
160
159
|
}
|
|
161
|
-
else if (
|
|
160
|
+
else if (ds.options?.address || filter.topics) {
|
|
162
161
|
queryEntries.push(eventFilterToQueryEntry(filter, ds.options));
|
|
163
162
|
}
|
|
164
163
|
else {
|
|
@@ -175,7 +174,7 @@ function buildDictionaryV1QueryEntries(dataSources) {
|
|
|
175
174
|
exports.buildDictionaryV1QueryEntries = buildDictionaryV1QueryEntries;
|
|
176
175
|
class EthDictionaryV1 extends node_core_1.DictionaryV1 {
|
|
177
176
|
constructor(project, nodeConfig, dictionaryUrl, chainId) {
|
|
178
|
-
super(dictionaryUrl, chainId
|
|
177
|
+
super(dictionaryUrl, chainId ?? project.network.chainId, nodeConfig);
|
|
179
178
|
}
|
|
180
179
|
static async create(project, nodeConfig, dictionaryUrl) {
|
|
181
180
|
/*Some dictionarys for EVM are built with other SDKs as they are chains with an EVM runtime
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionaryV1.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,gDAAuE;AAKvE,0DAO+B;AAC/B,kDAA0B;AAC1B,mCAAwC;AACxC,4DAA+B;AAM/B,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAEvC,MAAM,iBAAiB,GACrB,8EAA8E,CAAC;AAEjF,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,S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{ NodeConfig, DictionaryV1, getLogger } from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry as DictionaryV1QueryEntry,\n} from '@subql/types-core';\nimport {\n EthereumBlockFilter,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport JSON5 from 'json5';\nimport { sortBy, uniqBy } from 'lodash';\nimport fetch from 'node-fetch';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\nconst logger = getLogger('dictionary-v1');\n\nexport function appendDsOptions(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n conditions: DictionaryQueryCondition[],\n): void {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\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}\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\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\n if (topic === '!null') {\n conditions.push({\n field,\n value: false as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n } else {\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n\n for (const condition of conditions) {\n if (condition.field === 'address') {\n condition.field = 'to';\n }\n }\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n const optionsAddresses = conditions.find((c) => c.field === 'to');\n if (!optionsAddresses) {\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 } else if (optionsAddresses && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n\n if (filter.function === null || filter.function === '0x') {\n conditions.push({\n field: 'func',\n value: true,\n matcher: 'isNull',\n });\n } else 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\nexport type GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\n\nexport function buildDictionaryV1QueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryV1QueryEntry[] {\n const queryEntries: DictionaryV1QueryEntry[] = [];\n\n for (const ds of dataSources) {\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 if (handler.filter.modulo === undefined) {\n return [];\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n queryEntries.push(callFilterToQueryEntry(filter, ds.options));\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\nexport class EthDictionaryV1 extends DictionaryV1<GroupedEthereumProjectDs> {\n private constructor(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl: string,\n chainId?: string,\n ) {\n super(dictionaryUrl, chainId ?? project.network.chainId, nodeConfig);\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl?: string,\n ): Promise<EthDictionaryV1> {\n /*Some dictionarys for EVM are built with other SDKs as they are chains with an EVM runtime\n * we maintain a list of aliases so we can map the evmChainId to the genesis hash of the other SDKs\n * e.g moonbeam is built with Substrate SDK but can be used as an EVM dictionary\n */\n const chainAliases = await this.getEvmChainId();\n const chainAlias = chainAliases[project.network.chainId];\n\n const dictionary = new EthDictionaryV1(\n project,\n nodeConfig,\n dictionaryUrl,\n chainAlias,\n );\n await dictionary.init();\n return dictionary;\n }\n\n private static async getEvmChainId(): Promise<Record<string, string>> {\n const response = await fetch(CHAIN_ALIASES_URL);\n\n const raw = await response.text();\n // We use JSON5 here because the file has comments in it\n return JSON5.parse(raw);\n }\n\n buildDictionaryQueryEntries(\n // Add name to datasource as templates have this set\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): DictionaryV1QueryEntry[] {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV1QueryEntries(filteredDs);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV1.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,gDAAuE;AAKvE,0DAO+B;AAC/B,kDAA0B;AAC1B,mCAAwC;AACxC,4DAA+B;AAM/B,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAEvC,MAAM,iBAAiB,GACrB,8EAA8E,CAAC;AAEjF,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,SAAgB,eAAe,CAC7B,SAA0E,EAC1E,UAAsC;IAEtC,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnE,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,GAAG,iBAAiB,EAAE;YACxC,MAAM,CAAC,KAAK,CACV,qBAAqB,SAAS,CAAC,MAAM,wBAAwB,iBAAiB,wEAAwE,CACvJ,CAAC;SACH;QAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,IAAI,iBAAiB,EAAE;YACnE,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,SAAS;gBAChB,OAAO,EAAE,IAAI;aACd,CAA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AEO,MAAM,CAAC,KAAK,CAAC,aAAa;QAChC,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,iBAAiB,CAAC,CAAC;QAEhD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClC,wDAAwD;QACxD,OAAO,eAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,2BAA2B;IACzB,oDAAoD;IACpD,WAA8D;QAE9D,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,WAAW,CAAC,CAAC;QAC5C,OAAO,6BAA6B,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;CACF;AA/CD,0CA+CC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig, DictionaryV1, getLogger } from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry as DictionaryV1QueryEntry,\n} from '@subql/types-core';\nimport {\n EthereumBlockFilter,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport JSON5 from 'json5';\nimport { sortBy, uniqBy } from 'lodash';\nimport fetch from 'node-fetch';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\nconst logger = getLogger('dictionary-v1');\n\nexport function appendDsOptions(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n conditions: DictionaryQueryCondition[],\n): void {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\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}\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\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\n if (topic === '!null') {\n conditions.push({\n field,\n value: false as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n } else {\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n\n for (const condition of conditions) {\n if (condition.field === 'address') {\n condition.field = 'to';\n }\n }\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n const optionsAddresses = conditions.find((c) => c.field === 'to');\n if (!optionsAddresses) {\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 } else if (optionsAddresses && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n\n if (filter.function === null || filter.function === '0x') {\n conditions.push({\n field: 'func',\n value: true,\n matcher: 'isNull',\n });\n } else 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\nexport type GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\n\nexport function buildDictionaryV1QueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryV1QueryEntry[] {\n const queryEntries: DictionaryV1QueryEntry[] = [];\n\n for (const ds of dataSources) {\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 if (handler.filter.modulo === undefined) {\n return [];\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n queryEntries.push(callFilterToQueryEntry(filter, ds.options));\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\nexport class EthDictionaryV1 extends DictionaryV1<GroupedEthereumProjectDs> {\n private constructor(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl: string,\n chainId?: string,\n ) {\n super(dictionaryUrl, chainId ?? project.network.chainId, nodeConfig);\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl?: string,\n ): Promise<EthDictionaryV1> {\n /*Some dictionarys for EVM are built with other SDKs as they are chains with an EVM runtime\n * we maintain a list of aliases so we can map the evmChainId to the genesis hash of the other SDKs\n * e.g moonbeam is built with Substrate SDK but can be used as an EVM dictionary\n */\n const chainAliases = await this.getEvmChainId();\n const chainAlias = chainAliases[project.network.chainId];\n\n const dictionary = new EthDictionaryV1(\n project,\n nodeConfig,\n dictionaryUrl,\n chainAlias,\n );\n await dictionary.init();\n return dictionary;\n }\n\n private static async getEvmChainId(): Promise<Record<string, string>> {\n const response = await fetch(CHAIN_ALIASES_URL);\n\n const raw = await response.text();\n // We use JSON5 here because the file has comments in it\n return JSON5.parse(raw);\n }\n\n buildDictionaryQueryEntries(\n // Add name to datasource as templates have this set\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): DictionaryV1QueryEntry[] {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV1QueryEntries(filteredDs);\n }\n}\n"]}
|
|
@@ -400,9 +400,9 @@ describe('buildDictionaryV1QueryEntries', () => {
|
|
|
400
400
|
},
|
|
401
401
|
};
|
|
402
402
|
const duplicateDataSources = [
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
403
|
+
{ ...mockTempDs[0], options: { address: 'address1' } },
|
|
404
|
+
{ ...mockTempDs[0], options: { address: 'address2' } },
|
|
405
|
+
{ ...mockTempDs[1], options: { address: 'address3' } },
|
|
406
406
|
];
|
|
407
407
|
const dataSources = [ds, ...duplicateDataSources];
|
|
408
408
|
const queryEntry = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)(dataSources);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionaryV1.spec.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.spec.ts"],"names":[],"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AAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,UAAU,EAAE;wBACV;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,UAAU,EAAE;wBACV;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig } from '@subql/node-core';\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { GraphQLSchema } from 'graphql';\nimport {\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport {\n buildDictionaryV1QueryEntries,\n EthDictionaryV1,\n} from './ethDictionaryV1';\n\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n];\nfunction testSubqueryProject(\n endpoint: string,\n ds: any,\n mockTempDs,\n): SubqueryProject {\n return {\n network: {\n endpoint,\n chainId: '1',\n },\n dataSources: ds as any,\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: mockTempDs as any,\n } as any;\n}\n\ndescribe('Eth Dictionary V1', () => {\n it('Can resovle chain aliases', async () => {\n (EthDictionaryV1.prototype as any).init = jest.fn();\n const dictionary = await EthDictionaryV1.create(\n {\n network: { chainId: '336', dictionary: 'https://foo.bar' } as any,\n } as any,\n new NodeConfig({} as any, true),\n null,\n );\n\n expect((dictionary as any).chainId).toBe(\n '0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108',\n );\n\n jest.clearAllMocks();\n });\n});\n\ndescribe('buildDictionaryV1QueryEntries', () => {\n describe('Log filters', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n {\n field: 'topics3',\n value: false,\n matcher: 'isNull',\n },\n ],\n },\n ]);\n });\n });\n\n describe('Transaction filters', () => {\n it('Build a filter for contract creation transactions', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [{ field: 'to', matcher: 'isNull', value: true }],\n },\n ]);\n });\n\n it('Build a filter with include ds option and contract address', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option and filter both provide contract address, it should use ds options one', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option provide contract address, it should use ds options \"address\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If filter provide contract address, it should use filter \"to\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('builds a filter when theres a block handler with modulo filter', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n {\n handler: 'handleBlock',\n kind: EthereumHandlerKind.Block,\n filter: {\n modulo: 200,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n });\n\n describe('Correct dictionary query with dynamic ds', () => {\n it('Build correct erc1155 transfer single query', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n\n it('Builds a groupded query for multiple dynamic ds', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n\n const queryEntry = buildDictionaryV1QueryEntries(dataSources);\n\n expect(queryEntry).toEqual([\n {\n conditions: [\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address1',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address2',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address3',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n ]);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV1.spec.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,gDAA8C;AAC9C,0DAI+B;AAC/B,qCAAwC;AAKxC,uDAG2B;AAE3B,gEAAgE;AACh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;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,UAAU,EAAE;wBACV;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,UAAU,EAAE;wBACV;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig } from '@subql/node-core';\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { GraphQLSchema } from 'graphql';\nimport {\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport {\n buildDictionaryV1QueryEntries,\n EthDictionaryV1,\n} from './ethDictionaryV1';\n\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n];\nfunction testSubqueryProject(\n endpoint: string,\n ds: any,\n mockTempDs,\n): SubqueryProject {\n return {\n network: {\n endpoint,\n chainId: '1',\n },\n dataSources: ds as any,\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: mockTempDs as any,\n } as any;\n}\n\ndescribe('Eth Dictionary V1', () => {\n it('Can resovle chain aliases', async () => {\n (EthDictionaryV1.prototype as any).init = jest.fn();\n const dictionary = await EthDictionaryV1.create(\n {\n network: { chainId: '336', dictionary: 'https://foo.bar' } as any,\n } as any,\n new NodeConfig({} as any, true),\n null,\n );\n\n expect((dictionary as any).chainId).toBe(\n '0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108',\n );\n\n jest.clearAllMocks();\n });\n});\n\ndescribe('buildDictionaryV1QueryEntries', () => {\n describe('Log filters', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n {\n field: 'topics3',\n value: false,\n matcher: 'isNull',\n },\n ],\n },\n ]);\n });\n });\n\n describe('Transaction filters', () => {\n it('Build a filter for contract creation transactions', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [{ field: 'to', matcher: 'isNull', value: true }],\n },\n ]);\n });\n\n it('Build a filter with include ds option and contract address', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option and filter both provide contract address, it should use ds options one', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option provide contract address, it should use ds options \"address\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If filter provide contract address, it should use filter \"to\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('builds a filter when theres a block handler with modulo filter', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n {\n handler: 'handleBlock',\n kind: EthereumHandlerKind.Block,\n filter: {\n modulo: 200,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n });\n\n describe('Correct dictionary query with dynamic ds', () => {\n it('Build correct erc1155 transfer single query', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n\n it('Builds a groupded query for multiple dynamic ds', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n\n const queryEntry = buildDictionaryV1QueryEntries(dataSources);\n\n expect(queryEntry).toEqual([\n {\n conditions: [\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address1',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address2',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address3',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n ]);\n });\n });\n});\n"]}
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
8
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _EthDictionaryV2_skipTransactions;
|
|
16
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
5
|
exports.EthDictionaryV2 = exports.buildDictionaryV2QueryEntry = void 0;
|
|
18
6
|
const node_core_1 = require("@subql/node-core");
|
|
@@ -38,7 +26,7 @@ function extractOptionAddresses(dsOptions) {
|
|
|
38
26
|
}
|
|
39
27
|
}
|
|
40
28
|
else {
|
|
41
|
-
if (dsOptions
|
|
29
|
+
if (dsOptions?.address) {
|
|
42
30
|
addressArray.push(dsOptions.address.toLowerCase());
|
|
43
31
|
}
|
|
44
32
|
}
|
|
@@ -124,7 +112,6 @@ function sanitiseDictionaryConditions(dictionaryConditions) {
|
|
|
124
112
|
return dictionaryConditions;
|
|
125
113
|
}
|
|
126
114
|
function buildDictionaryV2QueryEntry(dataSources) {
|
|
127
|
-
var _a;
|
|
128
115
|
const dictionaryConditions = {
|
|
129
116
|
logs: [],
|
|
130
117
|
transactions: [],
|
|
@@ -157,7 +144,7 @@ function buildDictionaryV2QueryEntry(dataSources) {
|
|
|
157
144
|
if (ds.groupedOptions) {
|
|
158
145
|
dictionaryConditions.logs.push(eventFilterToDictionaryCondition(filter, ds.groupedOptions));
|
|
159
146
|
}
|
|
160
|
-
else if (
|
|
147
|
+
else if (ds.options?.address || filter.topics) {
|
|
161
148
|
dictionaryConditions.logs.push(eventFilterToDictionaryCondition(filter, ds.options));
|
|
162
149
|
}
|
|
163
150
|
else {
|
|
@@ -173,12 +160,13 @@ function buildDictionaryV2QueryEntry(dataSources) {
|
|
|
173
160
|
}
|
|
174
161
|
exports.buildDictionaryV2QueryEntry = buildDictionaryV2QueryEntry;
|
|
175
162
|
class EthDictionaryV2 extends node_core_1.DictionaryV2 {
|
|
163
|
+
api;
|
|
164
|
+
#skipTransactions;
|
|
176
165
|
constructor(endpoint, nodeConfig, project, api) {
|
|
177
166
|
super(endpoint, project.network.chainId, nodeConfig);
|
|
178
167
|
this.api = api;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
.skipTransactions, "f");
|
|
168
|
+
this.#skipTransactions = !!new NodeConfig_1.EthereumNodeConfig(nodeConfig)
|
|
169
|
+
.skipTransactions;
|
|
182
170
|
}
|
|
183
171
|
static async create(endpoint, nodeConfig, project, api) {
|
|
184
172
|
const dictionary = new EthDictionaryV2(endpoint, nodeConfig, project, api);
|
|
@@ -193,7 +181,7 @@ class EthDictionaryV2 extends node_core_1.DictionaryV2 {
|
|
|
193
181
|
async getData(startBlock, endBlock, limit = MIN_FETCH_LIMIT) {
|
|
194
182
|
return super.getData(startBlock, endBlock, limit, {
|
|
195
183
|
blockHeader: true,
|
|
196
|
-
logs: { transaction: !
|
|
184
|
+
logs: { transaction: !this.#skipTransactions },
|
|
197
185
|
transactions: { log: true },
|
|
198
186
|
});
|
|
199
187
|
}
|
|
@@ -214,5 +202,4 @@ class EthDictionaryV2 extends node_core_1.DictionaryV2 {
|
|
|
214
202
|
}
|
|
215
203
|
}
|
|
216
204
|
exports.EthDictionaryV2 = EthDictionaryV2;
|
|
217
|
-
_EthDictionaryV2_skipTransactions = new WeakMap();
|
|
218
205
|
//# sourceMappingURL=ethDictionaryV2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDict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BAAW,EAAC,WAAW,CAAC,CAAC;QAC5C,OAAO,2BAA2B,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO,CACX,UAAkB,EAClB,QAAgB,EAChB,QAAgB,eAAe;QAE/B,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE;YAChD,WAAW,EAAE,IAAI;YACjB,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,uBAAA,IAAI,yCAAkB,EAAE;YAC9C,YAAY,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,qBAAqB,CACnB,IAAoC;QAEpC,IAAI;YACF,MAAM,MAAM,GAA4B,CACrC,IAAI,CAAC,MAAwB,IAAI,EAAE,CACrC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,0BAAkB,EAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9C,OAAO;gBACL,WAAW,EAAE,MAAM;gBACnB,kBAAkB,EAAE,MAAM,CAAC,MAAM;oBAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;oBACxC,CAAC,CAAC,SAAS;aACd,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,kCAAkC,CAAC,CAAC;YACpD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;CACF;AAnED,0CAmEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n NodeConfig,\n DictionaryV2,\n RawDictionaryResponseData,\n DictionaryResponse,\n getLogger,\n IBlock,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport { uniqBy } from 'lodash';\nimport { EthereumNodeConfig } from '../../../configure/NodeConfig';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { EthereumApi } from '../../../ethereum';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\nimport { GroupedEthereumProjectDs } from '../v1';\nimport {\n RawEthBlock,\n EthDictionaryV2QueryEntry,\n EthDictionaryTxConditions,\n EthDictionaryLogConditions,\n} from './types';\nimport { rawBlockToEthBlock } from './utils';\n\nconst MIN_FETCH_LIMIT = 200;\n\nconst logger = getLogger('dictionary-v2');\n\nfunction extractOptionAddresses(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): string[] {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n const addressArray: string[] = [];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n addressArray.push(...addresses);\n }\n } else {\n if (dsOptions?.address) {\n addressArray.push(dsOptions.address.toLowerCase());\n }\n }\n return addressArray;\n}\n\nfunction callFilterToDictionaryCondition(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions,\n): EthDictionaryTxConditions {\n const txConditions: EthDictionaryTxConditions = {};\n const toArray = [];\n const fromArray = [];\n const funcArray = [];\n\n if (filter.from) {\n fromArray.push(filter.from.toLowerCase());\n }\n\n const assignTo = (value: string | null | undefined) => {\n if (value === null) {\n toArray.push(null);\n } else if (value !== undefined) {\n toArray.push(value.toLowerCase());\n }\n };\n\n const optionsAddresses = extractOptionAddresses(dsOptions);\n if (!optionsAddresses.length) {\n assignTo(filter.to);\n } else {\n if (filter.to || filter.to === null) {\n logger.warn(\n `TransactionFilter 'to' conflicts with 'address' in data source options, using data source option`,\n );\n }\n optionsAddresses.forEach(assignTo);\n }\n\n if (filter.function) {\n funcArray.push(functionToSighash(filter.function));\n }\n\n if (toArray.length !== 0) {\n txConditions.to = toArray;\n }\n if (fromArray.length !== 0) {\n txConditions.from = fromArray;\n }\n\n if (funcArray.length !== 0) {\n txConditions.data = funcArray;\n }\n\n return txConditions;\n}\n\nfunction eventFilterToDictionaryCondition(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): EthDictionaryLogConditions {\n const logConditions: EthDictionaryLogConditions = {};\n logConditions.address = extractOptionAddresses(dsOptions);\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 // Initialized\n if (!logConditions[field]) {\n logConditions[field] = [];\n }\n if (topic === '!null') {\n logConditions[field] = []; // TODO, check if !null\n } else {\n logConditions[field].push(eventToTopic(topic));\n }\n }\n }\n return logConditions;\n}\n\nfunction sanitiseDictionaryConditions(\n dictionaryConditions: EthDictionaryV2QueryEntry,\n): EthDictionaryV2QueryEntry {\n if (!dictionaryConditions.logs.length) {\n delete dictionaryConditions.logs;\n } else {\n dictionaryConditions.logs = uniqBy(dictionaryConditions.logs, (log) =>\n JSON.stringify(log),\n );\n }\n\n if (!dictionaryConditions.transactions.length) {\n delete dictionaryConditions.transactions;\n } else {\n dictionaryConditions.transactions = uniqBy(\n dictionaryConditions.transactions,\n (tx) => JSON.stringify(tx),\n );\n }\n\n return dictionaryConditions;\n}\n\nexport function buildDictionaryV2QueryEntry(\n dataSources: GroupedEthereumProjectDs[],\n): EthDictionaryV2QueryEntry {\n const dictionaryConditions: EthDictionaryV2QueryEntry = {\n logs: [],\n transactions: [],\n };\n\n for (const ds of dataSources) {\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 if (handler.filter.modulo === undefined) {\n return {};\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n dictionaryConditions.transactions.push(\n callFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n default:\n }\n }\n }\n\n return sanitiseDictionaryConditions(dictionaryConditions);\n}\n\nexport class EthDictionaryV2 extends DictionaryV2<\n EthereumBlock,\n SubqlDatasource,\n EthDictionaryV2QueryEntry\n> {\n #skipTransactions: boolean;\n\n constructor(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n private api: EthereumApi,\n ) {\n super(endpoint, project.network.chainId, nodeConfig);\n this.#skipTransactions = !!new EthereumNodeConfig(nodeConfig)\n .skipTransactions;\n }\n\n static async create(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n api: EthereumApi,\n ): Promise<EthDictionaryV2> {\n const dictionary = new EthDictionaryV2(endpoint, nodeConfig, project, api);\n await dictionary.init();\n return dictionary;\n }\n\n buildDictionaryQueryEntries(\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): EthDictionaryV2QueryEntry {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV2QueryEntry(filteredDs);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async getData(\n startBlock: number,\n endBlock: number,\n limit: number = MIN_FETCH_LIMIT,\n ): Promise<DictionaryResponse<IBlock<EthereumBlock> | number> | undefined> {\n return super.getData(startBlock, endBlock, limit, {\n blockHeader: true,\n logs: { transaction: !this.#skipTransactions },\n transactions: { log: true },\n });\n }\n\n convertResponseBlocks<RFB = RawEthBlock>(\n data: RawDictionaryResponseData<RFB>,\n ): DictionaryResponse<IBlock<EthereumBlock>> | undefined {\n try {\n const blocks: IBlock<EthereumBlock>[] = (\n (data.blocks as RawEthBlock[]) || []\n ).map((b) => rawBlockToEthBlock(b, this.api));\n return {\n batchBlocks: blocks,\n lastBufferedHeight: blocks.length\n ? blocks[blocks.length - 1].block.number\n : undefined,\n };\n } catch (e) {\n logger.error(e, `Failed to handle block response}`);\n throw e;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV2.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/ethDictionaryV2.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAO0B;AAC1B,0DAO+B;AAC/B,mCAAgC;AAChC,8DAAmE;AAOnE,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAQvC,mCAA6C;AAE7C,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,SAAS,sBAAsB,CAC7B,SAA0E;IAE1E,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnE,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,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,MAA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,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;oBACxC,CAAC,CAAC,SAAS;aACd,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,kCAAkC,CAAC,CAAC;YACpD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;CACF;AAnED,0CAmEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n NodeConfig,\n DictionaryV2,\n RawDictionaryResponseData,\n DictionaryResponse,\n getLogger,\n IBlock,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport { uniqBy } from 'lodash';\nimport { EthereumNodeConfig } from '../../../configure/NodeConfig';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { EthereumApi } from '../../../ethereum';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\nimport { GroupedEthereumProjectDs } from '../v1';\nimport {\n RawEthBlock,\n EthDictionaryV2QueryEntry,\n EthDictionaryTxConditions,\n EthDictionaryLogConditions,\n} from './types';\nimport { rawBlockToEthBlock } from './utils';\n\nconst MIN_FETCH_LIMIT = 200;\n\nconst logger = getLogger('dictionary-v2');\n\nfunction extractOptionAddresses(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): string[] {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n const addressArray: string[] = [];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n addressArray.push(...addresses);\n }\n } else {\n if (dsOptions?.address) {\n addressArray.push(dsOptions.address.toLowerCase());\n }\n }\n return addressArray;\n}\n\nfunction callFilterToDictionaryCondition(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions,\n): EthDictionaryTxConditions {\n const txConditions: EthDictionaryTxConditions = {};\n const toArray = [];\n const fromArray = [];\n const funcArray = [];\n\n if (filter.from) {\n fromArray.push(filter.from.toLowerCase());\n }\n\n const assignTo = (value: string | null | undefined) => {\n if (value === null) {\n toArray.push(null);\n } else if (value !== undefined) {\n toArray.push(value.toLowerCase());\n }\n };\n\n const optionsAddresses = extractOptionAddresses(dsOptions);\n if (!optionsAddresses.length) {\n assignTo(filter.to);\n } else {\n if (filter.to || filter.to === null) {\n logger.warn(\n `TransactionFilter 'to' conflicts with 'address' in data source options, using data source option`,\n );\n }\n optionsAddresses.forEach(assignTo);\n }\n\n if (filter.function) {\n funcArray.push(functionToSighash(filter.function));\n }\n\n if (toArray.length !== 0) {\n txConditions.to = toArray;\n }\n if (fromArray.length !== 0) {\n txConditions.from = fromArray;\n }\n\n if (funcArray.length !== 0) {\n txConditions.data = funcArray;\n }\n\n return txConditions;\n}\n\nfunction eventFilterToDictionaryCondition(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): EthDictionaryLogConditions {\n const logConditions: EthDictionaryLogConditions = {};\n logConditions.address = extractOptionAddresses(dsOptions);\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 // Initialized\n if (!logConditions[field]) {\n logConditions[field] = [];\n }\n if (topic === '!null') {\n logConditions[field] = []; // TODO, check if !null\n } else {\n logConditions[field].push(eventToTopic(topic));\n }\n }\n }\n return logConditions;\n}\n\nfunction sanitiseDictionaryConditions(\n dictionaryConditions: EthDictionaryV2QueryEntry,\n): EthDictionaryV2QueryEntry {\n if (!dictionaryConditions.logs.length) {\n delete dictionaryConditions.logs;\n } else {\n dictionaryConditions.logs = uniqBy(dictionaryConditions.logs, (log) =>\n JSON.stringify(log),\n );\n }\n\n if (!dictionaryConditions.transactions.length) {\n delete dictionaryConditions.transactions;\n } else {\n dictionaryConditions.transactions = uniqBy(\n dictionaryConditions.transactions,\n (tx) => JSON.stringify(tx),\n );\n }\n\n return dictionaryConditions;\n}\n\nexport function buildDictionaryV2QueryEntry(\n dataSources: GroupedEthereumProjectDs[],\n): EthDictionaryV2QueryEntry {\n const dictionaryConditions: EthDictionaryV2QueryEntry = {\n logs: [],\n transactions: [],\n };\n\n for (const ds of dataSources) {\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 if (handler.filter.modulo === undefined) {\n return {};\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n dictionaryConditions.transactions.push(\n callFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n default:\n }\n }\n }\n\n return sanitiseDictionaryConditions(dictionaryConditions);\n}\n\nexport class EthDictionaryV2 extends DictionaryV2<\n EthereumBlock,\n SubqlDatasource,\n EthDictionaryV2QueryEntry\n> {\n #skipTransactions: boolean;\n\n constructor(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n private api: EthereumApi,\n ) {\n super(endpoint, project.network.chainId, nodeConfig);\n this.#skipTransactions = !!new EthereumNodeConfig(nodeConfig)\n .skipTransactions;\n }\n\n static async create(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n api: EthereumApi,\n ): Promise<EthDictionaryV2> {\n const dictionary = new EthDictionaryV2(endpoint, nodeConfig, project, api);\n await dictionary.init();\n return dictionary;\n }\n\n buildDictionaryQueryEntries(\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): EthDictionaryV2QueryEntry {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV2QueryEntry(filteredDs);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async getData(\n startBlock: number,\n endBlock: number,\n limit: number = MIN_FETCH_LIMIT,\n ): Promise<DictionaryResponse<IBlock<EthereumBlock> | number> | undefined> {\n return super.getData(startBlock, endBlock, limit, {\n blockHeader: true,\n logs: { transaction: !this.#skipTransactions },\n transactions: { log: true },\n });\n }\n\n convertResponseBlocks<RFB = RawEthBlock>(\n data: RawDictionaryResponseData<RFB>,\n ): DictionaryResponse<IBlock<EthereumBlock>> | undefined {\n try {\n const blocks: IBlock<EthereumBlock>[] = (\n (data.blocks as RawEthBlock[]) || []\n ).map((b) => rawBlockToEthBlock(b, this.api));\n return {\n batchBlocks: blocks,\n lastBufferedHeight: blocks.length\n ? blocks[blocks.length - 1].block.number\n : undefined,\n };\n } catch (e) {\n logger.error(e, `Failed to handle block response}`);\n throw e;\n }\n }\n}\n"]}
|