@subql/node-ethereum 3.7.1-1 → 3.7.1

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.
@@ -24,9 +24,9 @@ const event_emitter_1 = require("@nestjs/event-emitter");
24
24
  const common_2 = require("@subql/common");
25
25
  const node_core_1 = require("@subql/node-core");
26
26
  const json5_1 = __importDefault(require("json5"));
27
- const node_fetch_1 = __importDefault(require("node-fetch"));
28
27
  const SubqueryProject_1 = require("../configure/SubqueryProject");
29
28
  const CHAIN_ALIASES_URL = 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';
29
+ const logger = (0, node_core_1.getLogger)('dictionary');
30
30
  let DictionaryService = DictionaryService_1 = class DictionaryService extends node_core_1.DictionaryService {
31
31
  constructor(project, nodeConfig, eventEmitter, chainId, dictionaryUrl) {
32
32
  super(dictionaryUrl !== null && dictionaryUrl !== void 0 ? dictionaryUrl : project.network.dictionary, chainId !== null && chainId !== void 0 ? chainId : project.network.chainId, nodeConfig, eventEmitter);
@@ -48,10 +48,17 @@ let DictionaryService = DictionaryService_1 = class DictionaryService extends no
48
48
  return this.apiGenesisHash === metaData.genesisHash;
49
49
  }
50
50
  static async getEvmChainId() {
51
- const response = await (0, node_fetch_1.default)(CHAIN_ALIASES_URL);
52
- const raw = await response.text();
53
- // We use JSON5 here because the file has comments in it
54
- return json5_1.default.parse(raw);
51
+ try {
52
+ // Use fetch added in nodejs 18, it is missing from @types/node though so we need the cast
53
+ const response = await global.fetch(CHAIN_ALIASES_URL);
54
+ const raw = await response.text();
55
+ // We use JSON5 here because the file has comments in it
56
+ return json5_1.default.parse(raw);
57
+ }
58
+ catch (e) {
59
+ logger.warn(e, `Unable to get chain aliases. If you're using a Substrate based network with EVM then the dictionary may not work`);
60
+ return {};
61
+ }
55
62
  }
56
63
  };
57
64
  DictionaryService = DictionaryService_1 = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"dictionary.service.js","sourceRoot":"","sources":["../../src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C;IACtD,CAAC;IAEO,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;CACF,CAAA;AAzDY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAAoB,iCAAe;QAClD,sBAAU;QACR,6BAAa;GAJlB,iBAAiB,CAyD7B;AAzDY,8CAAiB","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 as CoreDictionaryService,\n} from '@subql/node-core';\nimport { MetaData } from '@subql/utils';\nimport JSON5 from 'json5';\nimport fetch from 'node-fetch';\nimport { SubqueryProject } from '../configure/SubqueryProject';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\n@Injectable()\nexport class DictionaryService extends CoreDictionaryService {\n private constructor(\n @Inject('ISubqueryProject') protected project: SubqueryProject,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n chainId?: string,\n dictionaryUrl?: string,\n ) {\n super(\n dictionaryUrl ?? project.network.dictionary,\n chainId ?? project.network.chainId,\n nodeConfig,\n eventEmitter,\n );\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n ): Promise<DictionaryService> {\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 url =\n project.network.dictionary ??\n (await CoreDictionaryService.resolveDictionary(\n NETWORK_FAMILY.ethereum,\n chainAlias,\n nodeConfig.dictionaryRegistry,\n ));\n\n return new DictionaryService(\n project,\n nodeConfig,\n eventEmitter,\n chainAlias,\n url,\n );\n }\n\n protected validateChainMeta(metaData: MetaData): boolean {\n // Due to dictionary metadata doesn't include chainId, in here we only validate endpoint genesisHash with metadata\n return this.apiGenesisHash === metaData.genesisHash;\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"]}
1
+ {"version":3,"file":"dictionary.service.js","sourceRoot":"","sources":["../../src/indexer/dictionary.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,0CAA+C;AAC/C,gDAI0B;AAE1B,kDAA0B;AAC1B,kEAA+D;AAE/D,MAAM,iBAAiB,GACrB,8EAA8E,CAAC;AAEjF,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,YAAY,CAAC,CAAC;AAGhC,IAAM,iBAAiB,yBAAvB,MAAM,iBAAkB,SAAQ,6BAAqB;IAC1D,YACwC,OAAwB,EAC9D,UAAsB,EACtB,YAA2B,EAC3B,OAAgB,EAChB,aAAsB;QAEtB,KAAK,CACH,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,OAAO,CAAC,OAAO,CAAC,UAAU,EAC3C,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,OAAO,CAAC,OAAO,CAAC,OAAO,EAClC,UAAU,EACV,YAAY,CACb,CAAC;QAXoC,YAAO,GAAP,OAAO,CAAiB;IAYhE,CAAC;IAED,M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020-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 as CoreDictionaryService,\n getLogger,\n} from '@subql/node-core';\nimport { MetaData } from '@subql/utils';\nimport JSON5 from 'json5';\nimport { SubqueryProject } from '../configure/SubqueryProject';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\nconst logger = getLogger('dictionary');\n\n@Injectable()\nexport class DictionaryService extends CoreDictionaryService {\n private constructor(\n @Inject('ISubqueryProject') protected project: SubqueryProject,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n chainId?: string,\n dictionaryUrl?: string,\n ) {\n super(\n dictionaryUrl ?? project.network.dictionary,\n chainId ?? project.network.chainId,\n nodeConfig,\n eventEmitter,\n );\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n ): Promise<DictionaryService> {\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 url =\n project.network.dictionary ??\n (await CoreDictionaryService.resolveDictionary(\n NETWORK_FAMILY.ethereum,\n chainAlias,\n nodeConfig.dictionaryRegistry,\n ));\n\n return new DictionaryService(\n project,\n nodeConfig,\n eventEmitter,\n chainAlias,\n url,\n );\n }\n\n protected validateChainMeta(metaData: MetaData): boolean {\n // Due to dictionary metadata doesn't include chainId, in here we only validate endpoint genesisHash with metadata\n return this.apiGenesisHash === metaData.genesisHash;\n }\n\n private static async getEvmChainId(): Promise<Record<string, string>> {\n try {\n // Use fetch added in nodejs 18, it is missing from @types/node though so we need the cast\n const response = await (global as any).fetch(CHAIN_ALIASES_URL);\n const raw = await response.text();\n\n // We use JSON5 here because the file has comments in it\n return JSON5.parse(raw);\n } catch (e) {\n logger.warn(\n e,\n `Unable to get chain aliases. If you're using a Substrate based network with EVM then the dictionary may not work`,\n );\n return {};\n }\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
+ // SPDX-License-Identifier: GPL-3.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const node_core_1 = require("@subql/node-core");
6
+ const dictionary_service_1 = require("./dictionary.service");
7
+ describe('Dictionary service', () => {
8
+ it('Can resovle chain aliases', async () => {
9
+ const dictionary = await dictionary_service_1.DictionaryService.create({
10
+ network: { chainId: '336', dictionary: 'https://foo.bar' },
11
+ }, new node_core_1.NodeConfig({}, true), null);
12
+ expect(dictionary.chainId).toBe('0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108');
13
+ });
14
+ });
15
+ //# sourceMappingURL=dictionary.service.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionary.service.spec.js","sourceRoot":"","sources":["../../src/indexer/dictionary.service.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,gDAA8C;AAC9C,6DAAyD;AAEzD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QACzC,MAAM,UAAU,GAAG,MAAM,sCAAiB,CAAC,MAAM,CAC/C;YACE,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAS;SAC3D,EACR,IAAI,sBAAU,CAAC,EAAS,EAAE,IAAI,CAAC,EAC/B,IAAI,CACL,CAAC;QAEF,MAAM,CAAE,UAAkB,CAAC,OAAO,CAAC,CAAC,IAAI,CACtC,oEAAoE,CACrE,CAAC;IACJ,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 { DictionaryService } from './dictionary.service';\n\ndescribe('Dictionary service', () => {\n it('Can resovle chain aliases', async () => {\n const dictionary = await DictionaryService.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});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subql/node-ethereum",
3
- "version": "3.7.1-1",
3
+ "version": "3.7.1",
4
4
  "description": "",
5
5
  "author": "Ian He",
6
6
  "license": "GPL-3.0",
@@ -25,11 +25,11 @@
25
25
  "@nestjs/event-emitter": "^2.0.0",
26
26
  "@nestjs/platform-express": "^9.4.0",
27
27
  "@nestjs/schedule": "^3.0.1",
28
- "@subql/common": "^3.3.1",
29
- "@subql/common-ethereum": "3.3.1-0",
30
- "@subql/node-core": "^7.2.0",
28
+ "@subql/common": "^3.4.0",
29
+ "@subql/common-ethereum": "3.4.0",
30
+ "@subql/node-core": "^7.2.1",
31
31
  "@subql/testing": "^2.1.0",
32
- "@subql/types-ethereum": "3.3.1-0",
32
+ "@subql/types-ethereum": "3.3.1",
33
33
  "cacheable-lookup": "6",
34
34
  "cron-converter": "^1.0.2",
35
35
  "ethers": "^5.7.0",
@@ -65,6 +65,5 @@
65
65
  "files": [
66
66
  "/dist",
67
67
  "/bin"
68
- ],
69
- "stableVersion": "3.7.1-0"
68
+ ]
70
69
  }