@subql/node-ethereum 0.3.1-0 → 0.3.1-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +0 -2
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/configure/SubqueryProject.js +15 -5
  4. package/dist/configure/SubqueryProject.js.map +1 -1
  5. package/dist/configure/configure.module.js +2 -2
  6. package/dist/configure/configure.module.js.map +1 -1
  7. package/dist/ethereum/api.ethereum.d.ts +1 -0
  8. package/dist/ethereum/api.ethereum.js +28 -0
  9. package/dist/ethereum/api.ethereum.js.map +1 -1
  10. package/dist/ethereum/api.service.ethereum.d.ts +4 -0
  11. package/dist/ethereum/api.service.ethereum.js +16 -1
  12. package/dist/ethereum/api.service.ethereum.js.map +1 -1
  13. package/dist/indexer/blockDispatcher/base-block-dispatcher.d.ts +1 -1
  14. package/dist/indexer/blockDispatcher/base-block-dispatcher.js +3 -1
  15. package/dist/indexer/blockDispatcher/base-block-dispatcher.js.map +1 -1
  16. package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +1 -1
  17. package/dist/indexer/blockDispatcher/block-dispatcher.service.js +10 -5
  18. package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
  19. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +1 -1
  20. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +3 -3
  21. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
  22. package/dist/indexer/dictionary.service.js +7 -2
  23. package/dist/indexer/dictionary.service.js.map +1 -1
  24. package/dist/indexer/ds-processor.service.d.ts +1 -1
  25. package/dist/indexer/ds-processor.service.js +4 -0
  26. package/dist/indexer/ds-processor.service.js.map +1 -1
  27. package/dist/indexer/dynamic-ds.service.js +4 -0
  28. package/dist/indexer/dynamic-ds.service.js.map +1 -1
  29. package/dist/indexer/fetch.module.js +12 -5
  30. package/dist/indexer/fetch.module.js.map +1 -1
  31. package/dist/indexer/fetch.service.d.ts +5 -1
  32. package/dist/indexer/fetch.service.js +71 -22
  33. package/dist/indexer/fetch.service.js.map +1 -1
  34. package/dist/indexer/indexer.manager.d.ts +1 -1
  35. package/dist/indexer/indexer.manager.js +4 -0
  36. package/dist/indexer/indexer.manager.js.map +1 -1
  37. package/dist/indexer/indexer.module.js +4 -6
  38. package/dist/indexer/indexer.module.js.map +1 -1
  39. package/dist/indexer/project.service.d.ts +1 -1
  40. package/dist/indexer/project.service.js +22 -6
  41. package/dist/indexer/project.service.js.map +1 -1
  42. package/dist/indexer/sandbox.service.js +4 -0
  43. package/dist/indexer/sandbox.service.js.map +1 -1
  44. package/dist/indexer/worker/worker.js +1 -1
  45. package/dist/indexer/worker/worker.js.map +1 -1
  46. package/dist/subcommands/forceClean.service.d.ts +3 -1
  47. package/dist/subcommands/forceClean.service.js +26 -6
  48. package/dist/subcommands/forceClean.service.js.map +1 -1
  49. package/dist/subcommands/reindex.module.js.map +1 -1
  50. package/dist/subcommands/reindex.service.js +6 -1
  51. package/dist/subcommands/reindex.service.js.map +1 -1
  52. package/dist/utils/project.d.ts +1 -0
  53. package/dist/utils/project.js +5 -1
  54. package/dist/utils/project.js.map +1 -1
  55. package/dist/yargs.d.ts +1 -7
  56. package/dist/yargs.js +1 -6
  57. package/dist/yargs.js.map +1 -1
  58. package/package.json +7 -7
@@ -1,12 +1,19 @@
1
1
  "use strict";
2
2
  // Copyright 2020-2022 OnFinality Limited authors & contributors
3
3
  // SPDX-License-Identifier: Apache-2.0
4
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ };
4
10
  var __importDefault = (this && this.__importDefault) || function (mod) {
5
11
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
12
  };
7
13
  Object.defineProperty(exports, "__esModule", { value: true });
8
14
  exports.generateTimestampReferenceForBlockFilters = exports.SubqueryProject = void 0;
9
- const common_1 = require("@subql/common");
15
+ const common_1 = require("@nestjs/common");
16
+ const common_2 = require("@subql/common");
10
17
  const common_ethereum_1 = require("@subql/common-ethereum");
11
18
  const utils_1 = require("@subql/utils");
12
19
  const cron_converter_1 = __importDefault(require("cron-converter"));
@@ -14,11 +21,11 @@ const project_1 = require("../utils/project");
14
21
  const NOT_SUPPORT = (name) => {
15
22
  throw new Error(`Manifest specVersion ${name}() is not supported`);
16
23
  };
17
- class SubqueryProject {
24
+ let SubqueryProject = class SubqueryProject {
18
25
  static async create(path, networkOverrides, readerOptions) {
19
26
  // We have to use reader here, because path can be remote or local
20
27
  // and the `loadProjectManifest(projectPath)` only support local mode
21
- const reader = await common_1.ReaderFactory.create(path, readerOptions);
28
+ const reader = await common_2.ReaderFactory.create(path, readerOptions);
22
29
  const projectSchema = await reader.getProjectSchema();
23
30
  if (projectSchema === undefined) {
24
31
  throw new Error(`Get manifest from project path ${path} failed`);
@@ -31,7 +38,10 @@ class SubqueryProject {
31
38
  NOT_SUPPORT(manifest.specVersion);
32
39
  }
33
40
  }
34
- }
41
+ };
42
+ SubqueryProject = __decorate([
43
+ (0, common_1.Injectable)()
44
+ ], SubqueryProject);
35
45
  exports.SubqueryProject = SubqueryProject;
36
46
  function processChainId(network) {
37
47
  if (network.chainId && network.genesisHash) {
@@ -76,7 +86,7 @@ const { name: packageName, version: packageVersion, } = require('../../package.j
76
86
  async function loadProjectFromManifest1_0_0(projectManifest, reader, path, networkOverrides) {
77
87
  const project = await loadProjectFromManifestBase(projectManifest, reader, path, networkOverrides);
78
88
  project.runner = projectManifest.runner;
79
- if (!(0, common_1.validateSemver)(packageVersion, project.runner.node.version)) {
89
+ if (!(0, common_2.validateSemver)(packageVersion, project.runner.node.version)) {
80
90
  throw new Error(`Runner require node version ${project.runner.node.version}, current node ${packageVersion}`);
81
91
  }
82
92
  return project;
@@ -1 +1 @@
1
- {"version":3,"file":"SubqueryProject.js","sourceRoot":"","sources":["../../src/configure/SubqueryProject.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAItC,0CAMuB;AACvB,4DASgC;AAChC,wCAAqD;AACrD,oEAAkC;AAGlC,8CAI0B;AAkB1B,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;IACnC,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,qBAAqB,CAAC,CAAC;AACrE,CAAC,CAAC;AAEF,MAAa,eAAe;IAU1B,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,IAAY,EACZ,gBAAwD,EACxD,aAA6B;QAE7B,kEAAkE;QAClE,qEAAqE;QACrE,MAAM,MAAM,GAAG,MAAM,sBAAa,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC/D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,gBAAgB,EAAE,CAAC;QACtD,IAAI,aAAa,KAAK,SAAS,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,SAAS,CAAC,CAAC;SAClE;QACD,MAAM,QAAQ,GAAG,IAAA,8CAA4B,EAAC,aAAa,CAAC,CAAC;QAE7D,IAAI,QAAQ,CAAC,QAAQ,EAAE;YACrB,OAAO,4BAA4B,CACjC,QAAQ,CAAC,QAAQ,EACjB,MAAM,EACN,IAAI,EACJ,gBAAgB,CACjB,CAAC;SACH;aAAM;YACL,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;SACnC;IACH,CAAC;CACF;AAnCD,0CAmCC;AASD,SAAS,cAAc,CAAC,OAAY;IAClC,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,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C;wBAClD,OAAO,CAAC,MAAkC,CAAC,YAAY,GAAG;4BACzD,QAAQ,EAAE,QAAQ;4BAClB,IAAI,IAAI;gCACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;4BACnD,CAAC;yBACF,CAAC;qBACH;iBACF;gBACD,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC,CACH,CAAC;SACH;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC;AA/CD,8FA+CC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Block } from '@ethersproject/abstract-provider';\nimport { RegisteredTypes } from '@polkadot/types/types';\nimport {\n ReaderFactory,\n ReaderOptions,\n Reader,\n RunnerSpecs,\n validateSemver,\n} from '@subql/common';\nimport {\n EthereumProjectNetworkConfig,\n parseEthereumProjectManifest,\n SubqlEthereumDataSource,\n EthereumBlockFilter,\n FileType,\n ProjectManifestV1_0_0Impl,\n isRuntimeDs,\n EthereumHandlerKind,\n} from '@subql/common-ethereum';\nimport { buildSchemaFromString } from '@subql/utils';\nimport Cron from 'cron-converter';\nimport { GraphQLSchema } from 'graphql';\nimport { EthereumApi } from '../ethereum/api.ethereum';\nimport {\n getChainTypes,\n getProjectRoot,\n updateDataSourcesV0_2_0,\n} from '../utils/project';\n// import { getBlockByHeight, getTimestamp } from '../utils/substrate';\n\nexport type SubqlProjectDs = SubqlEthereumDataSource & {\n mapping: SubqlEthereumDataSource['mapping'] & { entryScript: string };\n};\n\nexport type SubqlProjectBlockFilter = EthereumBlockFilter & {\n cronSchedule?: {\n schedule: Cron.Seeker;\n next: number;\n };\n};\n\nexport type SubqlProjectDsTemplate = Omit<SubqlProjectDs, 'startBlock'> & {\n name: string;\n};\n\nconst NOT_SUPPORT = (name: string) => {\n throw new Error(`Manifest specVersion ${name}() is not supported`);\n};\n\nexport class SubqueryProject {\n id: string;\n root: string;\n network: Partial<EthereumProjectNetworkConfig>;\n dataSources: SubqlProjectDs[];\n schema: GraphQLSchema;\n templates: SubqlProjectDsTemplate[];\n chainTypes?: RegisteredTypes;\n runner?: RunnerSpecs;\n\n static async create(\n path: string,\n networkOverrides?: Partial<EthereumProjectNetworkConfig>,\n readerOptions?: ReaderOptions,\n ): Promise<SubqueryProject> {\n // We have to use reader here, because path can be remote or local\n // and the `loadProjectManifest(projectPath)` only support local mode\n const reader = await ReaderFactory.create(path, readerOptions);\n const projectSchema = await reader.getProjectSchema();\n if (projectSchema === undefined) {\n throw new Error(`Get manifest from project path ${path} failed`);\n }\n const manifest = parseEthereumProjectManifest(projectSchema);\n\n if (manifest.isV1_0_0) {\n return loadProjectFromManifest1_0_0(\n manifest.asV1_0_0,\n reader,\n path,\n networkOverrides,\n );\n } else {\n NOT_SUPPORT(manifest.specVersion);\n }\n }\n}\n\nexport interface SubqueryProjectNetwork {\n chainId: string;\n endpoint?: string;\n dictionary?: string;\n chaintypes?: FileType;\n}\n\nfunction processChainId(network: any): SubqueryProjectNetwork {\n if (network.chainId && network.genesisHash) {\n throw new Error('Please only provide one of chainId and genesisHash');\n } else if (network.genesisHash && !network.chainId) {\n network.chainId = network.genesisHash;\n }\n delete network.genesisHash;\n return network;\n}\n\ntype SUPPORT_MANIFEST = ProjectManifestV1_0_0Impl;\n\nasync function loadProjectFromManifestBase(\n projectManifest: SUPPORT_MANIFEST,\n reader: Reader,\n path: string,\n networkOverrides?: Partial<EthereumProjectNetworkConfig>,\n): Promise<SubqueryProject> {\n const root = await getProjectRoot(reader);\n\n const network = processChainId({\n ...projectManifest.network,\n ...networkOverrides,\n });\n\n if (!network.endpoint) {\n throw new Error(\n `Network endpoint must be provided for network. chainId=\"${network.chainId}\"`,\n );\n }\n\n let schemaString: string;\n try {\n schemaString = await reader.getFile(projectManifest.schema.file);\n } catch (e) {\n throw new Error(\n `unable to fetch the schema from ${projectManifest.schema.file}`,\n );\n }\n const schema = buildSchemaFromString(schemaString);\n\n const chainTypes = projectManifest.network.chaintypes\n ? await getChainTypes(reader, root, projectManifest.network.chaintypes.file)\n : undefined;\n\n const dataSources = await updateDataSourcesV0_2_0(\n projectManifest.dataSources,\n reader,\n root,\n );\n\n const templates = await loadProjectTemplates(projectManifest, root, reader);\n\n return {\n id: reader.root ? reader.root : path, //TODO, need to method to get project_id\n root,\n network,\n dataSources,\n schema,\n chainTypes,\n templates,\n };\n}\n\nconst {\n name: packageName,\n version: packageVersion,\n} = require('../../package.json');\n\nasync function loadProjectFromManifest1_0_0(\n projectManifest: ProjectManifestV1_0_0Impl,\n reader: Reader,\n path: string,\n networkOverrides?: Partial<EthereumProjectNetworkConfig>,\n): Promise<SubqueryProject> {\n const project = await loadProjectFromManifestBase(\n projectManifest,\n reader,\n path,\n networkOverrides,\n );\n project.runner = projectManifest.runner;\n if (!validateSemver(packageVersion, project.runner.node.version)) {\n throw new Error(\n `Runner require node version ${project.runner.node.version}, current node ${packageVersion}`,\n );\n }\n return project;\n}\n\nasync function loadProjectTemplates(\n projectManifest: ProjectManifestV1_0_0Impl,\n root: string,\n reader: Reader,\n): Promise<SubqlProjectDsTemplate[]> {\n if (projectManifest.templates && projectManifest.templates.length !== 0) {\n const dsTemplates = await updateDataSourcesV0_2_0(\n projectManifest.templates,\n reader,\n root,\n );\n return dsTemplates.map((ds, index) => ({\n ...ds,\n name: projectManifest.templates[index].name,\n }));\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function generateTimestampReferenceForBlockFilters(\n dataSources: SubqlProjectDs[],\n api: EthereumApi,\n): Promise<SubqlProjectDs[]> {\n const cron = new Cron();\n\n dataSources = await Promise.all(\n dataSources.map(async (ds) => {\n if (isRuntimeDs(ds)) {\n const startBlock = ds.startBlock ?? 1;\n let block: Block;\n let timestampReference: Date;\n\n ds.mapping.handlers = await Promise.all(\n ds.mapping.handlers.map(async (handler) => {\n if (handler.kind === EthereumHandlerKind.Block) {\n if (handler.filter?.timestamp) {\n if (!block) {\n block = await api.getBlockByHeightOrHash(startBlock);\n timestampReference = new Date(block.timestamp * 1000); // Add millis\n }\n try {\n cron.fromString(handler.filter.timestamp);\n } catch (e) {\n throw new Error(\n `Invalid Cron string: ${handler.filter.timestamp}`,\n );\n }\n\n const schedule = cron.schedule(timestampReference);\n (handler.filter as SubqlProjectBlockFilter).cronSchedule = {\n schedule: schedule,\n get next() {\n return Date.parse(this.schedule.next().format());\n },\n };\n }\n }\n return handler;\n }),\n );\n }\n return ds;\n }),\n );\n\n return dataSources;\n}\n"]}
1
+ {"version":3,"file":"SubqueryProject.js","sourceRoot":"","sources":["../../src/configure/SubqueryProject.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;AAGtC,2CAA4C;AAE5C,0CAMuB;AACvB,4DASgC;AAChC,wCAAqD;AACrD,oEAAkC;AAGlC,8CAI0B;AAkB1B,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;IACnC,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,qBAAqB,CAAC,CAAC;AACrE,CAAC,CAAC;AAGK,IAAM,eAAe,GAArB,MAAM,eAAe;IAU1B,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,IAAY,EACZ,gBAAwD,EACxD,aAA6B;QAE7B,kEAAkE;QAClE,qEAAqE;QACrE,MAAM,MAAM,GAAG,MAAM,sBAAa,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC/D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,gBAAgB,EAAE,CAAC;QACtD,IAAI,aAAa,KAAK,SAAS,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,SAAS,CAAC,CAAC;SAClE;QACD,MAAM,QAAQ,GAAG,IAAA,8CAA4B,EAAC,aAAa,CAAC,CAAC;QAE7D,IAAI,QAAQ,CAAC,QAAQ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AAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,aAAa;yBACrE;wBACD,IAAI;4BACF,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;yBAC3C;wBAAC,OAAO,CAAC,EAAE;4BACV,MAAM,IAAI,KAAK,CACb,wBAAwB,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,CACnD,CAAC;yBACH;wBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;wBAClD,OAAO,CAAC,MAAkC,CAAC,YAAY,GAAG;4BACzD,QAAQ,EAAE,QAAQ;4BAClB,IAAI,IAAI;gCACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;4BACnD,CAAC;yBACF,CAAC;qBACH;iBACF;gBACD,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC,CACH,CAAC;SACH;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC;AA/CD,8FA+CC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Block } from '@ethersproject/abstract-provider';\nimport { Injectable } from '@nestjs/common';\nimport { RegisteredTypes } from '@polkadot/types/types';\nimport {\n ReaderFactory,\n ReaderOptions,\n Reader,\n RunnerSpecs,\n validateSemver,\n} from '@subql/common';\nimport {\n EthereumProjectNetworkConfig,\n parseEthereumProjectManifest,\n SubqlEthereumDataSource,\n EthereumBlockFilter,\n FileType,\n ProjectManifestV1_0_0Impl,\n isRuntimeDs,\n EthereumHandlerKind,\n} from '@subql/common-ethereum';\nimport { buildSchemaFromString } from '@subql/utils';\nimport Cron from 'cron-converter';\nimport { GraphQLSchema } from 'graphql';\nimport { EthereumApi } from '../ethereum/api.ethereum';\nimport {\n getChainTypes,\n getProjectRoot,\n updateDataSourcesV0_2_0,\n} from '../utils/project';\n// import { getBlockByHeight, getTimestamp } from '../utils/substrate';\n\nexport type SubqlProjectDs = SubqlEthereumDataSource & {\n mapping: SubqlEthereumDataSource['mapping'] & { entryScript: string };\n};\n\nexport type SubqlProjectBlockFilter = EthereumBlockFilter & {\n cronSchedule?: {\n schedule: Cron.Seeker;\n next: number;\n };\n};\n\nexport type SubqlProjectDsTemplate = Omit<SubqlProjectDs, 'startBlock'> & {\n name: string;\n};\n\nconst NOT_SUPPORT = (name: string) => {\n throw new Error(`Manifest specVersion ${name}() is not supported`);\n};\n\n@Injectable()\nexport class SubqueryProject {\n id: string;\n root: string;\n network: Partial<EthereumProjectNetworkConfig>;\n dataSources: SubqlProjectDs[];\n schema: GraphQLSchema;\n templates: SubqlProjectDsTemplate[];\n chainTypes?: RegisteredTypes;\n runner?: RunnerSpecs;\n\n static async create(\n path: string,\n networkOverrides?: Partial<EthereumProjectNetworkConfig>,\n readerOptions?: ReaderOptions,\n ): Promise<SubqueryProject> {\n // We have to use reader here, because path can be remote or local\n // and the `loadProjectManifest(projectPath)` only support local mode\n const reader = await ReaderFactory.create(path, readerOptions);\n const projectSchema = await reader.getProjectSchema();\n if (projectSchema === undefined) {\n throw new Error(`Get manifest from project path ${path} failed`);\n }\n const manifest = parseEthereumProjectManifest(projectSchema);\n\n if (manifest.isV1_0_0) {\n return loadProjectFromManifest1_0_0(\n manifest.asV1_0_0,\n reader,\n path,\n networkOverrides,\n );\n } else {\n NOT_SUPPORT(manifest.specVersion);\n }\n }\n}\n\nexport interface SubqueryProjectNetwork {\n chainId: string;\n endpoint?: string;\n dictionary?: string;\n chaintypes?: FileType;\n}\n\nfunction processChainId(network: any): SubqueryProjectNetwork {\n if (network.chainId && network.genesisHash) {\n throw new Error('Please only provide one of chainId and genesisHash');\n } else if (network.genesisHash && !network.chainId) {\n network.chainId = network.genesisHash;\n }\n delete network.genesisHash;\n return network;\n}\n\ntype SUPPORT_MANIFEST = ProjectManifestV1_0_0Impl;\n\nasync function loadProjectFromManifestBase(\n projectManifest: SUPPORT_MANIFEST,\n reader: Reader,\n path: string,\n networkOverrides?: Partial<EthereumProjectNetworkConfig>,\n): Promise<SubqueryProject> {\n const root = await getProjectRoot(reader);\n\n const network = processChainId({\n ...projectManifest.network,\n ...networkOverrides,\n });\n\n if (!network.endpoint) {\n throw new Error(\n `Network endpoint must be provided for network. chainId=\"${network.chainId}\"`,\n );\n }\n\n let schemaString: string;\n try {\n schemaString = await reader.getFile(projectManifest.schema.file);\n } catch (e) {\n throw new Error(\n `unable to fetch the schema from ${projectManifest.schema.file}`,\n );\n }\n const schema = buildSchemaFromString(schemaString);\n\n const chainTypes = projectManifest.network.chaintypes\n ? await getChainTypes(reader, root, projectManifest.network.chaintypes.file)\n : undefined;\n\n const dataSources = await updateDataSourcesV0_2_0(\n projectManifest.dataSources,\n reader,\n root,\n );\n\n const templates = await loadProjectTemplates(projectManifest, root, reader);\n\n return {\n id: reader.root ? reader.root : path, //TODO, need to method to get project_id\n root,\n network,\n dataSources,\n schema,\n chainTypes,\n templates,\n };\n}\n\nconst {\n name: packageName,\n version: packageVersion,\n} = require('../../package.json');\n\nasync function loadProjectFromManifest1_0_0(\n projectManifest: ProjectManifestV1_0_0Impl,\n reader: Reader,\n path: string,\n networkOverrides?: Partial<EthereumProjectNetworkConfig>,\n): Promise<SubqueryProject> {\n const project = await loadProjectFromManifestBase(\n projectManifest,\n reader,\n path,\n networkOverrides,\n );\n project.runner = projectManifest.runner;\n if (!validateSemver(packageVersion, project.runner.node.version)) {\n throw new Error(\n `Runner require node version ${project.runner.node.version}, current node ${packageVersion}`,\n );\n }\n return project;\n}\n\nasync function loadProjectTemplates(\n projectManifest: ProjectManifestV1_0_0Impl,\n root: string,\n reader: Reader,\n): Promise<SubqlProjectDsTemplate[]> {\n if (projectManifest.templates && projectManifest.templates.length !== 0) {\n const dsTemplates = await updateDataSourcesV0_2_0(\n projectManifest.templates,\n reader,\n root,\n );\n return dsTemplates.map((ds, index) => ({\n ...ds,\n name: projectManifest.templates[index].name,\n }));\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function generateTimestampReferenceForBlockFilters(\n dataSources: SubqlProjectDs[],\n api: EthereumApi,\n): Promise<SubqlProjectDs[]> {\n const cron = new Cron();\n\n dataSources = await Promise.all(\n dataSources.map(async (ds) => {\n if (isRuntimeDs(ds)) {\n const startBlock = ds.startBlock ?? 1;\n let block: Block;\n let timestampReference: Date;\n\n ds.mapping.handlers = await Promise.all(\n ds.mapping.handlers.map(async (handler) => {\n if (handler.kind === EthereumHandlerKind.Block) {\n if (handler.filter?.timestamp) {\n if (!block) {\n block = await api.getBlockByHeightOrHash(startBlock);\n timestampReference = new Date(block.timestamp * 1000); // Add millis\n }\n try {\n cron.fromString(handler.filter.timestamp);\n } catch (e) {\n throw new Error(\n `Invalid Cron string: ${handler.filter.timestamp}`,\n );\n }\n\n const schedule = cron.schedule(timestampReference);\n (handler.filter as SubqlProjectBlockFilter).cronSchedule = {\n schedule: schedule,\n get next() {\n return Date.parse(this.schedule.next().format());\n },\n };\n }\n }\n return handler;\n }),\n );\n }\n return ds;\n }),\n );\n\n return dataSources;\n}\n"]}
@@ -156,11 +156,11 @@ let ConfigureModule = ConfigureModule_1 = class ConfigureModule {
156
156
  useValue: config,
157
157
  },
158
158
  {
159
- provide: SubqueryProject_1.SubqueryProject,
159
+ provide: 'ISubqueryProject',
160
160
  useFactory: project,
161
161
  },
162
162
  ],
163
- exports: [node_core_1.NodeConfig, SubqueryProject_1.SubqueryProject],
163
+ exports: [node_core_1.NodeConfig, 'ISubqueryProject'],
164
164
  };
165
165
  }
166
166
  };
@@ -1 +1 @@
1
- {"version":3,"file":"configure.module.js","sourceRoot":"","sources":["../../src/configure/configure.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;AAEtC,oDAA4B;AAC5B,gDAAwB;AACxB,2CAA+D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AAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CA2G3B;AA3GY,0CAAe","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport path from 'path';\nimport { DynamicModule, Global, Module } from '@nestjs/common';\nimport { getProjectRootAndManifest, IPFS_REGEX } from '@subql/common';\nimport { EthereumProjectNetworkConfig } from '@subql/common-ethereum';\nimport {\n IConfig,\n MinConfig,\n NodeConfig,\n getLogger,\n setLevel,\n} from '@subql/node-core';\nimport { camelCase, last, omitBy, isNil } from 'lodash';\nimport { yargsOptions } from '../yargs';\nimport { SubqueryProject } from './SubqueryProject';\n\nconst logger = getLogger('configure');\n\nconst YargsNameMapping: Record<string, string> = {\n local: 'localMode',\n};\n\ntype Args = typeof yargsOptions.argv['argv'];\n\nfunction yargsToIConfig(yargs: Args): Partial<IConfig> {\n return Object.entries(yargs).reduce((acc, [key, value]) => {\n if (['_', '$0'].includes(key)) return acc;\n\n if (key === 'network-registry') {\n try {\n value = JSON.parse(value as string);\n } catch (e) {\n throw new Error('Argument `network-registry` is not valid JSON');\n }\n }\n acc[YargsNameMapping[key] ?? camelCase(key)] = value;\n return acc;\n }, {} as any);\n}\n\nfunction defaultSubqueryName(config: Partial<IConfig>): MinConfig {\n const ipfsMatch = config.subquery.match(IPFS_REGEX);\n return {\n ...config,\n subqueryName:\n config.subqueryName ??\n (ipfsMatch\n ? config.subquery.replace(IPFS_REGEX, '')\n : last(\n getProjectRootAndManifest(config.subquery).root.split(path.sep),\n )),\n } as MinConfig;\n}\n\n// Check if a subquery name is a valid schema name\nexport function validDbSchemaName(name: string): boolean {\n if (name.length === 0) {\n return false;\n } else {\n name = name.toLowerCase();\n const regexp = new RegExp('^[a-zA-Z_][a-zA-Z0-9_\\\\-\\\\/]{0,62}$');\n const flag0 = !name.startsWith('pg_'); // Reserved identifier\n const flag1 = regexp.test(name); // <= Valid characters, less than 63 bytes\n if (!flag0) {\n logger.error(\n `Invalid schema name '${name}', schema name must not be prefixed with 'pg_'`,\n );\n }\n if (!flag1) {\n logger.error(\n `Invalid schema name '${name}', schema name must start with a letter or underscore, \n be less than 63 bytes and must contain only valid alphanumeric characters (can include characters '_-/')`,\n );\n }\n return flag0 && flag1;\n }\n}\n\nfunction warnDeprecations() {\n const { argv } = yargsOptions;\n if (argv['subquery-name']) {\n logger.warn(\n 'Note that argument --subquery-name has been deprecated in favour of --db-schema',\n );\n }\n if (argv.local) {\n logger.warn('Note that argument --local has been deprecated');\n }\n}\n\n@Global()\n@Module({})\nexport class ConfigureModule {\n static registerWithConfig(config: NodeConfig): DynamicModule {\n if (!validDbSchemaName(config.dbSchema)) {\n process.exit(1);\n }\n\n if (config.debug) {\n setLevel('debug');\n }\n\n const project = async () => {\n const p = await SubqueryProject.create(\n config.subquery,\n omitBy<EthereumProjectNetworkConfig>(\n {\n endpoint: config.networkEndpoint,\n dictionary: config.networkDictionary,\n },\n isNil,\n ),\n {\n ipfs: config.ipfs,\n },\n ).catch((err) => {\n logger.error(err, 'Create Subquery project from given path failed!');\n process.exit(1);\n });\n return p;\n };\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: config,\n },\n {\n provide: SubqueryProject,\n useFactory: project,\n },\n ],\n exports: [NodeConfig, SubqueryProject],\n };\n }\n static register(): DynamicModule {\n const { argv } = yargsOptions;\n let config: NodeConfig;\n if (argv.config) {\n config = NodeConfig.fromFile(argv.config, yargsToIConfig(argv));\n } else {\n if (!argv.subquery) {\n logger.error(\n 'Subquery path is missing neither in cli options nor in config file',\n );\n yargsOptions.showHelp();\n process.exit(1);\n }\n\n warnDeprecations();\n assert(argv.subquery, 'subquery path is missing');\n config = new NodeConfig(defaultSubqueryName(yargsToIConfig(argv)));\n }\n\n if (!validDbSchemaName(config.dbSchema)) {\n process.exit(1);\n }\n\n if (config.debug) {\n setLevel('debug');\n }\n\n const project = async () => {\n const p = await SubqueryProject.create(\n argv.subquery,\n omitBy<Partial<EthereumProjectNetworkConfig>>(\n {\n endpoint: config.networkEndpoint,\n dictionary: config.networkDictionary,\n },\n isNil,\n ),\n {\n ipfs: config.ipfs,\n },\n ).catch((err) => {\n logger.error(err, 'Create Subquery project from given path failed!');\n process.exit(1);\n });\n return p;\n };\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: config,\n },\n {\n provide: SubqueryProject,\n useFactory: project,\n },\n ],\n exports: [NodeConfig, SubqueryProject],\n };\n }\n}\n"]}
1
+ {"version":3,"file":"configure.module.js","sourceRoot":"","sources":["../../src/configure/configure.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;AAEtC,oDAA4B;AAC5B,gDAAwB;AACxB,2CAA+D;AAC/D,0CAAsE;AAEtE,gDAM0B;AAC1B,mCAAwD;AACxD,oCAAwC;AACxC,uDAAoD;AAEpD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAC;AAEtC,MAAM,gBAAgB,GAA2B;IAC/C,KAAK,EAAE,WAAW;CACnB,CAAC;AAIF,SAAS,cAAc,CAAC,KAAW;IACjC,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;;QACxD,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC;QAE1C,IAAI,GAAG,KAAK,kBAAkB,EAAE;YAC9B,IAAI;gBACF,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAe,CAAC,CAAC;aACrC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;aAClE;SACF;QACD,GAAG,CAAC,MAAA,gBAAgB,CAAC,GAAG,CAAC,mCAAI,IAAA,kBA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,CAAC,GAAG,EAAE,EAAE;gBACd,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,iDAAiD,CAAC,CAAC;gBACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,CAAC;QACX,CAAC,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,sBAAU;oBACnB,QAAQ,EAAE,MAAM;iBACjB;gBACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,UAAU,EAAE,OAAO;iBACpB;aACF;YACD,OAAO,EAAE,CAAC,sBAAU,EAAE,kBAAkB,CAAC;SAC1C,CAAC;IACJ,CAAC;CACF,CAAA;AA3GY,eAAe;IAF3B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CA2G3B;AA3GY,0CAAe","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport path from 'path';\nimport { DynamicModule, Global, Module } from '@nestjs/common';\nimport { getProjectRootAndManifest, IPFS_REGEX } from '@subql/common';\nimport { EthereumProjectNetworkConfig } from '@subql/common-ethereum';\nimport {\n IConfig,\n MinConfig,\n NodeConfig,\n getLogger,\n setLevel,\n} from '@subql/node-core';\nimport { camelCase, last, omitBy, isNil } from 'lodash';\nimport { yargsOptions } from '../yargs';\nimport { SubqueryProject } from './SubqueryProject';\n\nconst logger = getLogger('configure');\n\nconst YargsNameMapping: Record<string, string> = {\n local: 'localMode',\n};\n\ntype Args = typeof yargsOptions.argv['argv'];\n\nfunction yargsToIConfig(yargs: Args): Partial<IConfig> {\n return Object.entries(yargs).reduce((acc, [key, value]) => {\n if (['_', '$0'].includes(key)) return acc;\n\n if (key === 'network-registry') {\n try {\n value = JSON.parse(value as string);\n } catch (e) {\n throw new Error('Argument `network-registry` is not valid JSON');\n }\n }\n acc[YargsNameMapping[key] ?? camelCase(key)] = value;\n return acc;\n }, {} as any);\n}\n\nfunction defaultSubqueryName(config: Partial<IConfig>): MinConfig {\n const ipfsMatch = config.subquery.match(IPFS_REGEX);\n return {\n ...config,\n subqueryName:\n config.subqueryName ??\n (ipfsMatch\n ? config.subquery.replace(IPFS_REGEX, '')\n : last(\n getProjectRootAndManifest(config.subquery).root.split(path.sep),\n )),\n } as MinConfig;\n}\n\n// Check if a subquery name is a valid schema name\nexport function validDbSchemaName(name: string): boolean {\n if (name.length === 0) {\n return false;\n } else {\n name = name.toLowerCase();\n const regexp = new RegExp('^[a-zA-Z_][a-zA-Z0-9_\\\\-\\\\/]{0,62}$');\n const flag0 = !name.startsWith('pg_'); // Reserved identifier\n const flag1 = regexp.test(name); // <= Valid characters, less than 63 bytes\n if (!flag0) {\n logger.error(\n `Invalid schema name '${name}', schema name must not be prefixed with 'pg_'`,\n );\n }\n if (!flag1) {\n logger.error(\n `Invalid schema name '${name}', schema name must start with a letter or underscore, \n be less than 63 bytes and must contain only valid alphanumeric characters (can include characters '_-/')`,\n );\n }\n return flag0 && flag1;\n }\n}\n\nfunction warnDeprecations() {\n const { argv } = yargsOptions;\n if (argv['subquery-name']) {\n logger.warn(\n 'Note that argument --subquery-name has been deprecated in favour of --db-schema',\n );\n }\n if (argv.local) {\n logger.warn('Note that argument --local has been deprecated');\n }\n}\n\n@Global()\n@Module({})\nexport class ConfigureModule {\n static registerWithConfig(config: NodeConfig): DynamicModule {\n if (!validDbSchemaName(config.dbSchema)) {\n process.exit(1);\n }\n\n if (config.debug) {\n setLevel('debug');\n }\n\n const project = async () => {\n const p = await SubqueryProject.create(\n config.subquery,\n omitBy<EthereumProjectNetworkConfig>(\n {\n endpoint: config.networkEndpoint,\n dictionary: config.networkDictionary,\n },\n isNil,\n ),\n {\n ipfs: config.ipfs,\n },\n ).catch((err) => {\n logger.error(err, 'Create Subquery project from given path failed!');\n process.exit(1);\n });\n return p;\n };\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: config,\n },\n {\n provide: SubqueryProject,\n useFactory: project,\n },\n ],\n exports: [NodeConfig, SubqueryProject],\n };\n }\n static register(): DynamicModule {\n const { argv } = yargsOptions;\n let config: NodeConfig;\n if (argv.config) {\n config = NodeConfig.fromFile(argv.config, yargsToIConfig(argv));\n } else {\n if (!argv.subquery) {\n logger.error(\n 'Subquery path is missing neither in cli options nor in config file',\n );\n yargsOptions.showHelp();\n process.exit(1);\n }\n\n warnDeprecations();\n assert(argv.subquery, 'subquery path is missing');\n config = new NodeConfig(defaultSubqueryName(yargsToIConfig(argv)));\n }\n\n if (!validDbSchemaName(config.dbSchema)) {\n process.exit(1);\n }\n\n if (config.debug) {\n setLevel('debug');\n }\n\n const project = async () => {\n const p = await SubqueryProject.create(\n argv.subquery,\n omitBy<Partial<EthereumProjectNetworkConfig>>(\n {\n endpoint: config.networkEndpoint,\n dictionary: config.networkDictionary,\n },\n isNil,\n ),\n {\n ipfs: config.ipfs,\n },\n ).catch((err) => {\n logger.error(err, 'Create Subquery project from given path failed!');\n process.exit(1);\n });\n return p;\n };\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: config,\n },\n {\n provide: 'ISubqueryProject',\n useFactory: project,\n },\n ],\n exports: [NodeConfig, 'ISubqueryProject'],\n };\n }\n}\n"]}
@@ -7,6 +7,7 @@ export declare class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {
7
7
  private genesisBlock;
8
8
  private contractInterfaces;
9
9
  private chainId;
10
+ private endpointSupportsGetBlockReceipts;
10
11
  constructor(endpoint: string);
11
12
  init(): Promise<void>;
12
13
  getFinalizedBlockHeight(): Promise<number>;
@@ -6,8 +6,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.EthereumApi = void 0;
9
+ const assert_1 = __importDefault(require("assert"));
9
10
  const fs_1 = __importDefault(require("fs"));
10
11
  const abi_1 = require("@ethersproject/abi");
12
+ const bignumber_1 = require("@ethersproject/bignumber");
11
13
  const providers_1 = require("@ethersproject/providers");
12
14
  const node_core_1 = require("@subql/node-core");
13
15
  const utils_1 = require("ethers/lib/utils");
@@ -36,6 +38,7 @@ class EthereumApi {
36
38
  constructor(endpoint) {
37
39
  this.endpoint = endpoint;
38
40
  this.contractInterfaces = {};
41
+ this.endpointSupportsGetBlockReceipts = true;
39
42
  const { hostname, pathname, port, protocol, searchParams } = new URL(endpoint);
40
43
  const protocolStr = protocol.replace(':', '');
41
44
  logger.info(this.endpoint.split('?')[0]);
@@ -93,6 +96,31 @@ class EthereumApi {
93
96
  const block_promise = await this.getBlockPromise(num);
94
97
  const block = (0, utils_ethereum_1.formatBlock)(block_promise);
95
98
  block.stateRoot = this.client.formatter.hash(block.stateRoot);
99
+ if (this.endpointSupportsGetBlockReceipts) {
100
+ try {
101
+ const rawReceipts = await this.client.send('eth_getBlockReceipts', [(0, utils_1.hexValue)(block.number)]);
102
+ const receipts = rawReceipts.map((receipt) => (0, utils_ethereum_1.formatReceipt)(receipt, block));
103
+ const txs = block.transactions.map((tx) => {
104
+ const transaction = (0, utils_ethereum_1.formatTransaction)(tx);
105
+ transaction.receipt =
106
+ receipts[bignumber_1.BigNumber.from(transaction.transactionIndex).toNumber()];
107
+ (0, assert_1.default)(transaction.hash === transaction.receipt.transactionHash, 'Failed to match receipt to transaction');
108
+ return transaction;
109
+ });
110
+ return new block_ethereum_1.EthereumBlockWrapped(block, txs);
111
+ }
112
+ catch (e) {
113
+ // Method not avaialble https://eips.ethereum.org/EIPS/eip-1474
114
+ if (e.error.code === -32601) {
115
+ logger.warn(`The endpoint doesn't support 'eth_getBlockReceipts', individual receipts will be fetched instead, this will greatly impact performance.`);
116
+ this.endpointSupportsGetBlockReceipts = false;
117
+ // Should continue and use old method here
118
+ }
119
+ else {
120
+ throw e;
121
+ }
122
+ }
123
+ }
96
124
  const transactions = await Promise.all(block.transactions.map(async (tx) => {
97
125
  const transaction = (0, utils_ethereum_1.formatTransaction)(tx);
98
126
  const receipt = await this.getTransactionReceipt(tx.hash);
@@ -1 +1 @@
1
- {"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAEtC,4CAAoB;AAGpB,4CAA+C;AAE/C,wDAA8E;AAE9E,gDAA6C;AAS7C,4CAA0E;AAC1E,8CAAkD;AAClD,qDAAwD;AACxD,qDAI0B;AAE1B,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,cAAc,CAAC,CAAC;AAEzC,KAAK,UAAU,UAAU,CACvB,EAA2B;IAE3B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE;QACd,OAAO,EAAE,CAAC;KACX;IACD,MAAM,GAAG,GAA2B,EAAE,CAAC;IAEvC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;QACxD,IAAI;YACF,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;SACpE;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAC;SAC5D;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAa,WAAW;IAMtB,YAAoB,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;QAH5B,uBAAkB,GAA8B,EAAE,CAAC;QAIzD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,YA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C,CAAC,OAAO,EAAE,CAAC,CAAC;YACtD,OAAO,GAAG,CAAC;SACZ;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,WAAgC,EAChC,EAA2B;;QAE3B,IAAI;YACF,IAAI,CAAC,CAAA,MAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,OAAO,0CAAE,GAAG,CAAA,EAAE;gBACrB,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;gBAC9C,OAAO,WAAW,CAAC;aACpB;YACD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,EAAE,CAAC,CAAC;YACpC,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,IAAA,oBAAY,EAAC,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACtE,MAAM,IAAI,GAAG,KAAK,CAAC,kBAAkB,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAM,CAAC;YACpE,uCACK,WAAW,KACd,IAAI,IACJ;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;CACF;AA9LD,kCA8LC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport { Block, TransactionReceipt } from '@ethersproject/abstract-provider';\nimport { JsonRpcProvider, WebSocketProvider } from '@ethersproject/providers';\nimport { RuntimeDataSourceV0_2_0 } from '@subql/common-ethereum';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n BlockWrapper,\n EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n} from '@subql/types-ethereum';\nimport { ConnectionInfo, hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport {\n formatBlock,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: RuntimeDataSourceV0_2_0,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nexport class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {\n private client: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n\n constructor(private endpoint: string) {\n const { hostname, pathname, port, protocol, searchParams } = new URL(\n endpoint,\n );\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(this.endpoint.split('?')[0]);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.genesisBlock = await this.client.getBlock(0);\n\n this.chainId = (await this.client.getNetwork()).chainId;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.client.getBlock('finalized')).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.client.getBlock('safe')).number;\n }\n\n getRuntimeChain(): string {\n return 'ethereum';\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n return this.client.getBlock(heightOrHash);\n }\n\n async getBlockPromise(num: number): Promise<any> {\n return retryOnFailEth(() =>\n this.client.send('eth_getBlockByNumber', [hexValue(num), true]),\n );\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n async fetchBlock(num: number): Promise<EthereumBlockWrapper> {\n const block_promise = await this.getBlockPromise(num);\n\n const block = formatBlock(block_promise);\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n const transactions = await Promise.all(\n block.transactions.map(async (tx) => {\n const transaction = formatTransaction(tx);\n const receipt = await this.getTransactionReceipt(tx.hash);\n transaction.receipt = formatReceipt(receipt, block);\n return transaction;\n }),\n );\n return new EthereumBlockWrapped(block, transactions);\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => {\n try {\n // Fetch Block\n return await this.fetchBlock(num);\n } catch (e) {\n // Wrap error from an axios error to fix issue with error being undefined\n const error = new Error(e.message);\n logger.error(error, `Failed to fetch block at height ${num}`);\n throw error;\n }\n }),\n );\n }\n\n freezeApi(processor: any, blockContent: BlockWrapper): void {\n processor.freeze(this.client, 'api');\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAEtC,oDAA4B;AAC5B,4CAAoB;AAGpB,4CAA+C;AAE/C,wDAAqD;AACrD,wDAA8E;AAE9E,gDAA6C;AAS7C,4CAA0E;AAC1E,8CAAk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C,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,IAAA,oBAAY,EAAC,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACtE,MAAM,IAAI,GAAG,KAAK,CAAC,kBAAkB,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAM,CAAC;YACpE,uCACK,WAAW,KACd,IAAI,IACJ;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;CACF;AAxOD,kCAwOC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport { Block, TransactionReceipt } from '@ethersproject/abstract-provider';\nimport { BigNumber } from '@ethersproject/bignumber';\nimport { JsonRpcProvider, WebSocketProvider } from '@ethersproject/providers';\nimport { RuntimeDataSourceV0_2_0 } from '@subql/common-ethereum';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n BlockWrapper,\n EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n} from '@subql/types-ethereum';\nimport { ConnectionInfo, hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport {\n formatBlock,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: RuntimeDataSourceV0_2_0,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nexport class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {\n private client: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n\n private endpointSupportsGetBlockReceipts = true;\n\n constructor(private endpoint: string) {\n const { hostname, pathname, port, protocol, searchParams } = new URL(\n endpoint,\n );\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(this.endpoint.split('?')[0]);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.genesisBlock = await this.client.getBlock(0);\n\n this.chainId = (await this.client.getNetwork()).chainId;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.client.getBlock('finalized')).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.client.getBlock('safe')).number;\n }\n\n getRuntimeChain(): string {\n return 'ethereum';\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n return this.client.getBlock(heightOrHash);\n }\n\n async getBlockPromise(num: number): Promise<any> {\n return retryOnFailEth(() =>\n this.client.send('eth_getBlockByNumber', [hexValue(num), true]),\n );\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n async fetchBlock(num: number): Promise<EthereumBlockWrapper> {\n const block_promise = await this.getBlockPromise(num);\n\n const block = formatBlock(block_promise);\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n if (this.endpointSupportsGetBlockReceipts) {\n try {\n const rawReceipts: any[] = await this.client.send(\n 'eth_getBlockReceipts',\n [hexValue(block.number)],\n );\n\n const receipts = rawReceipts.map((receipt) =>\n formatReceipt(receipt, block),\n );\n\n const txs = block.transactions.map((tx) => {\n const transaction = formatTransaction(tx);\n transaction.receipt =\n receipts[BigNumber.from(transaction.transactionIndex).toNumber()];\n\n assert(\n transaction.hash === transaction.receipt.transactionHash,\n 'Failed to match receipt to transaction',\n );\n\n return transaction;\n });\n\n return new EthereumBlockWrapped(block, txs);\n } catch (e) {\n // Method not avaialble https://eips.ethereum.org/EIPS/eip-1474\n if (e.error.code === -32601) {\n logger.warn(\n `The endpoint doesn't support 'eth_getBlockReceipts', individual receipts will be fetched instead, this will greatly impact performance.`,\n );\n this.endpointSupportsGetBlockReceipts = false;\n\n // Should continue and use old method here\n } else {\n throw e;\n }\n }\n }\n\n const transactions = await Promise.all(\n block.transactions.map(async (tx) => {\n const transaction = formatTransaction(tx);\n const receipt = await this.getTransactionReceipt(tx.hash);\n transaction.receipt = formatReceipt(receipt, block);\n return transaction;\n }),\n );\n return new EthereumBlockWrapped(block, transactions);\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => {\n try {\n // Fetch Block\n return await this.fetchBlock(num);\n } catch (e) {\n // Wrap error from an axios error to fix issue with error being undefined\n const error = new Error(e.message);\n logger.error(error, `Failed to fetch block at height ${num}`);\n throw error;\n }\n }),\n );\n }\n\n freezeApi(processor: any, blockContent: BlockWrapper): void {\n processor.freeze(this.client, 'api');\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n}\n"]}
@@ -1,6 +1,10 @@
1
+ import { EventEmitter2 } from '@nestjs/event-emitter';
1
2
  import { ApiService } from '@subql/node-core';
3
+ import { SubqueryProject } from '../configure/SubqueryProject';
2
4
  import { EthereumApi } from './api.ethereum';
3
5
  export declare class EthereumApiService extends ApiService {
6
+ private eventEmitter;
7
+ constructor(project: SubqueryProject, eventEmitter: EventEmitter2);
4
8
  private _api;
5
9
  init(): Promise<EthereumApiService>;
6
10
  get api(): EthereumApi;
@@ -7,13 +7,25 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
8
  return c > 3 && r && Object.defineProperty(target, key, r), r;
9
9
  };
10
+ var __metadata = (this && this.__metadata) || function (k, v) {
11
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12
+ };
13
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
+ return function (target, key) { decorator(target, key, paramIndex); }
15
+ };
10
16
  Object.defineProperty(exports, "__esModule", { value: true });
11
17
  exports.EthereumApiService = void 0;
12
18
  const common_1 = require("@nestjs/common");
19
+ const event_emitter_1 = require("@nestjs/event-emitter");
13
20
  const node_core_1 = require("@subql/node-core");
21
+ const SubqueryProject_1 = require("../configure/SubqueryProject");
14
22
  const api_ethereum_1 = require("./api.ethereum");
15
23
  const logger = (0, node_core_1.getLogger)('api');
16
24
  let EthereumApiService = class EthereumApiService extends node_core_1.ApiService {
25
+ constructor(project, eventEmitter) {
26
+ super(project);
27
+ this.eventEmitter = eventEmitter;
28
+ }
17
29
  async init() {
18
30
  try {
19
31
  let network;
@@ -51,7 +63,10 @@ let EthereumApiService = class EthereumApiService extends node_core_1.ApiService
51
63
  }
52
64
  };
53
65
  EthereumApiService = __decorate([
54
- (0, common_1.Injectable)()
66
+ (0, common_1.Injectable)(),
67
+ __param(0, (0, common_1.Inject)('ISubqueryProject')),
68
+ __metadata("design:paramtypes", [SubqueryProject_1.SubqueryProject,
69
+ event_emitter_1.EventEmitter2])
55
70
  ], EthereumApiService);
56
71
  exports.EthereumApiService = EthereumApiService;
57
72
  //# sourceMappingURL=api.service.ethereum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;AAEtC,2CAA4C;AAE5C,gDAAyD;AACzD,iDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,sBAAU;IAGhD,KAAK,CAAC,IAAI;QACR,IAAI;YACF,IAAI,OAA6B,CAAC;YAClC,IAAI;gBACF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;aAChC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,IAAI,CAAC,GAAG,GAAG,IAAI,0BAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAE7C,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,GAAG;gBACjB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE;gBACjC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;gBAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE;aACvC,CAAC;YAEF,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACxD,MAAM,GAAG,GAAG,IAAI,KAAK,CACnB,6DACE,OAAO,CAAC,OACV,aAAa,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,CACrC,CAAC;gBACF,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC/B,MAAM,GAAG,CAAC;aACX;YAED,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,4BAA4B,CAAC,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAY,GAAG,CAAC,KAAkB;QAChC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;CACF,CAAA;AA9CY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CA8C9B;AA9CY,gDAAkB","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Injectable } from '@nestjs/common';\nimport { ProjectNetworkV1_0_0 } from '@subql/common-ethereum';\nimport { ApiService, getLogger } from '@subql/node-core';\nimport { EthereumApi } from './api.ethereum';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class EthereumApiService extends ApiService {\n private _api: EthereumApi;\n\n async init(): Promise<EthereumApiService> {\n try {\n let network: ProjectNetworkV1_0_0;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n this.api = new EthereumApi(network.endpoint);\n\n await this.api.init();\n this.networkMeta = {\n chain: this.api.getRuntimeChain(),\n specName: this.api.getSpecName(),\n genesisHash: this.api.getGenesisHash(),\n };\n\n if (network.chainId !== this.api.getChainId().toString()) {\n const err = new Error(\n `Network chainId doesn't match expected chainId. expected=\"${\n network.chainId\n }\" actual=\"${this.api.getChainId()}`,\n );\n logger.error(err, err.message);\n throw err;\n }\n\n return this;\n } catch (e) {\n logger.error(e, 'Failed to init api service');\n process.exit(1);\n }\n }\n\n get api(): EthereumApi {\n return this._api;\n }\n\n private set api(value: EthereumApi) {\n this._api = value;\n }\n}\n"]}
1
+ {"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;AAEtC,2CAAoD;AACpD,yDAAsD;AAEtD,gDAAyD;AACzD,kEAA+D;AAC/D,iDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,sBAAU;IAChD,YAC8B,OAAwB,EAC5C,YAA2B;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFP,iBAAY,GAAZ,YAAY,CAAe;IAGrC,CAAC;IAGD,KAAK,CAAC,IAAI;QACR,IAAI;YACF,IAAI,OAA6B,CAAC;YAClC,IAAI;gBACF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;aAChC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,IAAI,CAAC,GAAG,GAAG,IAAI,0BAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAE7C,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,GAAG;gBACjB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE;gBACjC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;gBAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE;aACvC,CAAC;YAEF,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACxD,MAAM,GAAG,GAAG,IAAI,KAAK,CACnB,6DACE,OAAO,CAAC,OACV,aAAa,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,CACrC,CAAC;gBACF,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC/B,MAAM,GAAG,CAAC;aACX;YAED,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,4BAA4B,CAAC,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAY,GAAG,CAAC,KAAkB;QAChC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;CACF,CAAA;AApDY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAAU,iCAAe;QAC9B,6BAAa;GAH1B,kBAAkB,CAoD9B;AApDY,gDAAkB","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { ProjectNetworkV1_0_0 } from '@subql/common-ethereum';\nimport { ApiService, getLogger } from '@subql/node-core';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApi } from './api.ethereum';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class EthereumApiService extends ApiService {\n constructor(\n @Inject('ISubqueryProject') project: SubqueryProject,\n private eventEmitter: EventEmitter2,\n ) {\n super(project);\n }\n private _api: EthereumApi;\n\n async init(): Promise<EthereumApiService> {\n try {\n let network: ProjectNetworkV1_0_0;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n this.api = new EthereumApi(network.endpoint);\n\n await this.api.init();\n this.networkMeta = {\n chain: this.api.getRuntimeChain(),\n specName: this.api.getSpecName(),\n genesisHash: this.api.getGenesisHash(),\n };\n\n if (network.chainId !== this.api.getChainId().toString()) {\n const err = new Error(\n `Network chainId doesn't match expected chainId. expected=\"${\n network.chainId\n }\" actual=\"${this.api.getChainId()}`,\n );\n logger.error(err, err.message);\n throw err;\n }\n\n return this;\n } catch (e) {\n logger.error(e, 'Failed to init api service');\n process.exit(1);\n }\n }\n\n get api(): EthereumApi {\n return this._api;\n }\n\n private set api(value: EthereumApi) {\n this._api = value;\n }\n}\n"]}
@@ -8,7 +8,7 @@ export declare type ProcessBlockResponse = {
8
8
  };
9
9
  export interface IBlockDispatcher {
10
10
  init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void>;
11
- enqueueBlocks(heights: number[]): void;
11
+ enqueueBlocks(heights: number[], latestBufferHeight?: number): void;
12
12
  queueSize: number;
13
13
  freeSize: number;
14
14
  latestBufferedHeight: number | undefined;
@@ -77,10 +77,12 @@ class BaseBlockDispatcher {
77
77
  }
78
78
  else {
79
79
  if (this.nodeConfig.proofOfIndex && !isNullMerkelRoot(operationHash)) {
80
- if (!this.projectService.blockOffset) {
80
+ // We only check if it is undefined, need to be caution here when blockOffset is 0
81
+ if (this.projectService.blockOffset === undefined) {
81
82
  // Which means during project init, it has not found offset and set value
82
83
  await this.projectService.upsertMetadataBlockOffset(height - 1);
83
84
  }
85
+ // this will return if project service blockOffset already exist
84
86
  void this.projectService.setBlockOffset(height - 1);
85
87
  }
86
88
  if (dynamicDsCreated) {
@@ -1 +1 @@
1
- {"version":3,"file":"base-block-dispatcher.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/base-block-dispatcher.ts"],"names":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AI,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE;gBACpE,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE;oBACpC,yEAAyE;oBACzE,MAAM,IAAI,CAAC,cAAc,CAAC,yBAAyB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;iBACjE;gBACD,KAAK,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aACrD;YACD,IAAI,gBAAgB,EAAE;gBACpB,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;aACvC;YACD,IAAA,gBAAM,EACJ,CAAC,IAAI,CAAC,qBAAqB,IAAI,MAAM,GAAG,IAAI,CAAC,qBAAqB,EAClE,yCAAyC,MAAM,aAAa,IAAI,CAAC,qBAAqB,EAAE,CACzF,CAAC;YACF,8FAA8F;YAC9F,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC,CAAC;YAC3D,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;SACrC;IACH,CAAC;CACF;AA5GD,kDA4GC","sourcesContent":["// Copyright 2020-2021 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { hexToU8a, u8aEq } from '@polkadot/util';\nimport { getLogger, IndexerEvent, IQueue, NodeConfig } from '@subql/node-core';\nimport { ProjectService } from '../project.service';\n\nconst logger = getLogger('BaseBlockDispatcherService');\n\nexport type ProcessBlockResponse = {\n dynamicDsCreated: boolean;\n operationHash: Uint8Array;\n reindexBlockHeight: number;\n};\n\nexport interface IBlockDispatcher {\n init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void>;\n\n enqueueBlocks(heights: number[]): void;\n\n queueSize: number;\n freeSize: number;\n latestBufferedHeight: number | undefined;\n\n // Remove all enqueued blocks, used when a dynamic ds is created\n flushQueue(height: number): void;\n rewind(height: number): Promise<void>;\n}\n\nconst NULL_MERKEL_ROOT = hexToU8a('0x00');\n\nfunction isNullMerkelRoot(operationHash: Uint8Array): boolean {\n return u8aEq(operationHash, NULL_MERKEL_ROOT);\n}\n\nexport abstract class BaseBlockDispatcher<Q extends IQueue>\n implements IBlockDispatcher\n{\n protected _latestBufferedHeight: number;\n protected _processedBlockCount: number;\n protected latestProcessedHeight: number;\n protected currentProcessingHeight: number;\n protected onDynamicDsCreated: (height: number) => Promise<void>;\n\n constructor(\n protected nodeConfig: NodeConfig,\n protected eventEmitter: EventEmitter2,\n protected projectService: ProjectService,\n protected queue: Q,\n ) {}\n\n abstract enqueueBlocks(heights: number[]): void;\n abstract init(\n onDynamicDsCreated: (height: number) => Promise<void>,\n ): Promise<void>;\n\n get queueSize(): number {\n return this.queue.size;\n }\n\n get freeSize(): number {\n return this.queue.freeSpace;\n }\n\n get latestBufferedHeight(): number {\n return this._latestBufferedHeight;\n }\n\n set latestBufferedHeight(height: number) {\n this.eventEmitter.emit(IndexerEvent.BlocknumberQueueSize, {\n value: this.queueSize,\n });\n this._latestBufferedHeight = height;\n }\n\n protected setProcessedBlockCount(processedBlockCount: number): void {\n this._processedBlockCount = processedBlockCount;\n this.eventEmitter.emit(IndexerEvent.BlockProcessedCount, {\n processedBlockCount,\n timestamp: Date.now(),\n });\n }\n\n // Compare it with current indexing number, if last corrected is already indexed\n // rewind, also flush queued blocks, drop current indexing transaction, set last processed to correct block too\n // if rollback is greater than current index flush queue only\n async rewind(lastCorrectHeight: number): Promise<void> {\n if (lastCorrectHeight <= this.currentProcessingHeight) {\n logger.info(\n `Found last verified block at height ${lastCorrectHeight}, rewinding...`,\n );\n await this.projectService.reindex(lastCorrectHeight);\n this.latestProcessedHeight = lastCorrectHeight;\n logger.info(`Successful rewind to block ${lastCorrectHeight}!`);\n }\n this.flushQueue(lastCorrectHeight);\n logger.info(`Queued blocks flushed!`); //Also last buffered height reset, next fetching should start after lastCorrectHeight\n }\n\n flushQueue(height: number): void {\n this.latestBufferedHeight = height;\n this.queue.flush();\n }\n\n // Is called directly before a block is processed\n protected preProcessBlock(height: number): void {\n this.currentProcessingHeight = height;\n this.eventEmitter.emit(IndexerEvent.BlockProcessing, {\n height,\n timestamp: Date.now(),\n });\n }\n\n // Is called directly after a block is processed\n protected async postProcessBlock(\n height: number,\n processBlockResponse: ProcessBlockResponse,\n ): Promise<void> {\n const { dynamicDsCreated, operationHash, reindexBlockHeight } =\n processBlockResponse;\n if (reindexBlockHeight !== null && reindexBlockHeight !== undefined) {\n await this.rewind(reindexBlockHeight);\n this.latestProcessedHeight = reindexBlockHeight;\n } else {\n if (this.nodeConfig.proofOfIndex && !isNullMerkelRoot(operationHash)) {\n if (!this.projectService.blockOffset) {\n // Which means during project init, it has not found offset and set value\n await this.projectService.upsertMetadataBlockOffset(height - 1);\n }\n void this.projectService.setBlockOffset(height - 1);\n }\n if (dynamicDsCreated) {\n await this.onDynamicDsCreated(height);\n }\n assert(\n !this.latestProcessedHeight || height > this.latestProcessedHeight,\n `Block processed out of order. Height: ${height}. Latest: ${this.latestProcessedHeight}`,\n );\n // In memory _processedBlockCount increase, db metadata increase BlockCount in indexer.manager\n this.setProcessedBlockCount(this._processedBlockCount + 1);\n this.latestProcessedHeight = height;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"base-block-dispatcher.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/base-block-dispatcher.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAEtC,oDAA4B;AAE5B,yCAAiD;AACjD,gDAA+E;AAG/E,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,4BAA4B,CAAC,CAAC;AAsBvD,MAAM,gBAAgB,GAAG,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC;AAE1C,SAAS,gBAAgB,CAAC,aAAyB;IACjD,OAAO,IAAA,YAAK,EAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAChD,CAAC;AAED,MAAsB,mBAA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;gBACpB,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;aACvC;YACD,IAAA,gBAAM,EACJ,CAAC,IAAI,CAAC,qBAAqB,IAAI,MAAM,GAAG,IAAI,CAAC,qBAAqB,EAClE,yCAAyC,MAAM,aAAa,IAAI,CAAC,qBAAqB,EAAE,CACzF,CAAC;YACF,8FAA8F;YAC9F,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC,CAAC;YAC3D,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;SACrC;IACH,CAAC;CACF;AA9GD,kDA8GC","sourcesContent":["// Copyright 2020-2021 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { hexToU8a, u8aEq } from '@polkadot/util';\nimport { getLogger, IndexerEvent, IQueue, NodeConfig } from '@subql/node-core';\nimport { ProjectService } from '../project.service';\n\nconst logger = getLogger('BaseBlockDispatcherService');\n\nexport type ProcessBlockResponse = {\n dynamicDsCreated: boolean;\n operationHash: Uint8Array;\n reindexBlockHeight: number;\n};\n\nexport interface IBlockDispatcher {\n init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void>;\n\n enqueueBlocks(heights: number[], latestBufferHeight?: number): void;\n\n queueSize: number;\n freeSize: number;\n latestBufferedHeight: number | undefined;\n\n // Remove all enqueued blocks, used when a dynamic ds is created\n flushQueue(height: number): void;\n rewind(height: number): Promise<void>;\n}\n\nconst NULL_MERKEL_ROOT = hexToU8a('0x00');\n\nfunction isNullMerkelRoot(operationHash: Uint8Array): boolean {\n return u8aEq(operationHash, NULL_MERKEL_ROOT);\n}\n\nexport abstract class BaseBlockDispatcher<Q extends IQueue>\n implements IBlockDispatcher\n{\n protected _latestBufferedHeight: number;\n protected _processedBlockCount: number;\n protected latestProcessedHeight: number;\n protected currentProcessingHeight: number;\n protected onDynamicDsCreated: (height: number) => Promise<void>;\n\n constructor(\n protected nodeConfig: NodeConfig,\n protected eventEmitter: EventEmitter2,\n protected projectService: ProjectService,\n protected queue: Q,\n ) {}\n\n abstract enqueueBlocks(heights: number[]): void;\n abstract init(\n onDynamicDsCreated: (height: number) => Promise<void>,\n ): Promise<void>;\n\n get queueSize(): number {\n return this.queue.size;\n }\n\n get freeSize(): number {\n return this.queue.freeSpace;\n }\n\n get latestBufferedHeight(): number {\n return this._latestBufferedHeight;\n }\n\n set latestBufferedHeight(height: number) {\n this.eventEmitter.emit(IndexerEvent.BlocknumberQueueSize, {\n value: this.queueSize,\n });\n this._latestBufferedHeight = height;\n }\n\n protected setProcessedBlockCount(processedBlockCount: number): void {\n this._processedBlockCount = processedBlockCount;\n this.eventEmitter.emit(IndexerEvent.BlockProcessedCount, {\n processedBlockCount,\n timestamp: Date.now(),\n });\n }\n\n // Compare it with current indexing number, if last corrected is already indexed\n // rewind, also flush queued blocks, drop current indexing transaction, set last processed to correct block too\n // if rollback is greater than current index flush queue only\n async rewind(lastCorrectHeight: number): Promise<void> {\n if (lastCorrectHeight <= this.currentProcessingHeight) {\n logger.info(\n `Found last verified block at height ${lastCorrectHeight}, rewinding...`,\n );\n await this.projectService.reindex(lastCorrectHeight);\n this.latestProcessedHeight = lastCorrectHeight;\n logger.info(`Successful rewind to block ${lastCorrectHeight}!`);\n }\n this.flushQueue(lastCorrectHeight);\n logger.info(`Queued blocks flushed!`); //Also last buffered height reset, next fetching should start after lastCorrectHeight\n }\n\n flushQueue(height: number): void {\n this.latestBufferedHeight = height;\n this.queue.flush();\n }\n\n // Is called directly before a block is processed\n protected preProcessBlock(height: number): void {\n this.currentProcessingHeight = height;\n this.eventEmitter.emit(IndexerEvent.BlockProcessing, {\n height,\n timestamp: Date.now(),\n });\n }\n\n // Is called directly after a block is processed\n protected async postProcessBlock(\n height: number,\n processBlockResponse: ProcessBlockResponse,\n ): Promise<void> {\n const { dynamicDsCreated, operationHash, reindexBlockHeight } =\n processBlockResponse;\n if (reindexBlockHeight !== null && reindexBlockHeight !== undefined) {\n await this.rewind(reindexBlockHeight);\n this.latestProcessedHeight = reindexBlockHeight;\n } else {\n if (this.nodeConfig.proofOfIndex && !isNullMerkelRoot(operationHash)) {\n // We only check if it is undefined, need to be caution here when blockOffset is 0\n if (this.projectService.blockOffset === undefined) {\n // Which means during project init, it has not found offset and set value\n await this.projectService.upsertMetadataBlockOffset(height - 1);\n }\n // this will return if project service blockOffset already exist\n void this.projectService.setBlockOffset(height - 1);\n }\n if (dynamicDsCreated) {\n await this.onDynamicDsCreated(height);\n }\n assert(\n !this.latestProcessedHeight || height > this.latestProcessedHeight,\n `Block processed out of order. Height: ${height}. Latest: ${this.latestProcessedHeight}`,\n );\n // In memory _processedBlockCount increase, db metadata increase BlockCount in indexer.manager\n this.setProcessedBlockCount(this._processedBlockCount + 1);\n this.latestProcessedHeight = height;\n }\n }\n}\n"]}
@@ -17,7 +17,7 @@ export declare class BlockDispatcherService extends BaseBlockDispatcher<Queue<nu
17
17
  constructor(apiService: ApiService, nodeConfig: NodeConfig, indexerManager: IndexerManager, eventEmitter: EventEmitter2, projectService: ProjectService);
18
18
  init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void>;
19
19
  onApplicationShutdown(): void;
20
- enqueueBlocks(heights: number[]): void;
20
+ enqueueBlocks(cleanedBlocks: number[], latestBufferHeight?: number): void;
21
21
  flushQueue(height: number): void;
22
22
  private fetchBlocksFromQueue;
23
23
  }
@@ -49,12 +49,17 @@ let BlockDispatcherService = class BlockDispatcherService extends base_block_dis
49
49
  this.isShutdown = true;
50
50
  this.processQueue.abort();
51
51
  }
52
- enqueueBlocks(heights) {
53
- if (!heights.length)
52
+ enqueueBlocks(cleanedBlocks, latestBufferHeight) {
53
+ // // In the case where factors of batchSize is equal to bypassBlock or when cleanedBatchBlocks is []
54
+ // // to ensure block is bypassed, latestBufferHeight needs to be manually set
55
+ // If cleanedBlocks = []
56
+ if (!!latestBufferHeight && !cleanedBlocks.length) {
57
+ this.latestBufferedHeight = latestBufferHeight;
54
58
  return;
55
- logger.info(`Enqueing blocks ${heights[0]}...${(0, lodash_1.last)(heights)}, total ${heights.length} blocks`);
56
- this.queue.putMany(heights);
57
- this.latestBufferedHeight = (0, lodash_1.last)(heights);
59
+ }
60
+ logger.info(`Enqueueing blocks ${cleanedBlocks[0]}...${(0, lodash_1.last)(cleanedBlocks)}, total ${cleanedBlocks.length} blocks`);
61
+ this.queue.putMany(cleanedBlocks);
62
+ this.latestBufferedHeight = latestBufferHeight !== null && latestBufferHeight !== void 0 ? latestBufferHeight : (0, lodash_1.last)(cleanedBlocks);
58
63
  void this.fetchBlocksFromQueue().catch((e) => {
59
64
  logger.error(e, 'Failed to fetch blocks from queue');
60
65
  if (!this.isShutdown) {
@@ -1 +1 @@
1
- {"version":3,"file":"block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;AAEtC,2CAAmE;AACnE,yDAAsD;AACtD,gDAS0B;AAC1B,mCAA8B;AAE9B,wDAAoD;AACpD,wDAAoD;AACpD,mEAA8D;AAE9D,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,wBAAwB,CAAC,CAAC;AAEnD;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBACX,SAAQ,2CAAkC;IAS1C,YACU,UAAsB,EAC9B,UAAsB,EACd,cAA8B,EACtC,YAA2B,EAC3B,cAA8B;QAE9B,KAAK,CACH,UAAU,EACV,YAAY,EACZ,cAAc,EACd,IAAI,iBAAK,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC,CACpC,CAAC;QAXM,eAAU,GAAV,UAAU,CAAY;QAEtB,mBAAc,GAAd,cAAc,CAAgB;QAPhC,aAAQ,GAAG,KAAK,CAAC;QACjB,eAAU,GAAG,KAAK,CAAC;QAgBzB,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAS,CA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AAU;QACE,gCAAc;QACxB,6BAAa;QACX,gCAAc;GAfrB,sBAAsB,CAwJlC;AAxJY,wDAAsB","sourcesContent":["// Copyright 2020-2021 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n getLogger,\n NodeConfig,\n IndexerEvent,\n delay,\n profilerWrap,\n AutoQueue,\n Queue,\n} from '@subql/node-core';\nimport { last } from 'lodash';\nimport { EthereumApiService } from '../../ethereum';\nimport { IndexerManager } from '../indexer.manager';\nimport { ProjectService } from '../project.service';\nimport { BaseBlockDispatcher } from './base-block-dispatcher';\n\nconst logger = getLogger('BlockDispatcherService');\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 BaseBlockDispatcher<Queue<number>>\n implements OnApplicationShutdown\n{\n private processQueue: AutoQueue<void>;\n\n private fetching = false;\n private isShutdown = false;\n private fetchBlocksBatches: EthereumApiService['api']['fetchBlocks'];\n\n constructor(\n private apiService: ApiService,\n nodeConfig: NodeConfig,\n private indexerManager: IndexerManager,\n eventEmitter: EventEmitter2,\n projectService: ProjectService,\n ) {\n super(\n nodeConfig,\n eventEmitter,\n projectService,\n new Queue(nodeConfig.batchSize * 3),\n );\n this.processQueue = new AutoQueue(nodeConfig.batchSize * 3);\n\n const fetchBlocks = this.apiService.api.fetchBlocks.bind(\n this.apiService.api,\n );\n if (this.nodeConfig.profiler) {\n this.fetchBlocksBatches = profilerWrap(\n fetchBlocks,\n 'EthereumUtil',\n 'fetchBlocksBatches',\n );\n } else {\n this.fetchBlocksBatches = fetchBlocks;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async init(\n onDynamicDsCreated: (height: number) => Promise<void>,\n ): Promise<void> {\n this.onDynamicDsCreated = onDynamicDsCreated;\n const blockAmount = await this.projectService.getProcessedBlockCount();\n this.setProcessedBlockCount(blockAmount ?? 0);\n }\n\n onApplicationShutdown(): void {\n this.isShutdown = true;\n this.processQueue.abort();\n }\n\n enqueueBlocks(heights: number[]): void {\n if (!heights.length) return;\n\n logger.info(\n `Enqueing blocks ${heights[0]}...${last(heights)}, total ${\n heights.length\n } blocks`,\n );\n\n this.queue.putMany(heights);\n this.latestBufferedHeight = last(heights);\n\n void this.fetchBlocksFromQueue().catch((e) => {\n logger.error(e, 'Failed to fetch blocks from queue');\n if (!this.isShutdown) {\n process.exit(1);\n }\n });\n }\n\n flushQueue(height: number): void {\n super.flushQueue(height);\n this.processQueue.flush();\n }\n\n private async fetchBlocksFromQueue(): Promise<void> {\n if (this.fetching || this.isShutdown) return;\n // Process queue is full, no point in fetching more blocks\n // if (this.processQueue.freeSpace < this.nodeConfig.batchSize) return;\n\n this.fetching = true;\n\n try {\n while (!this.isShutdown) {\n const blockNums = this.queue.takeMany(\n Math.min(this.nodeConfig.batchSize, this.processQueue.freeSpace),\n );\n // Used to compare before and after as a way to check if queue was flushed\n const bufferedHeight = this._latestBufferedHeight;\n\n // Queue is empty\n if (!blockNums.length) {\n // The process queue might be full so no block nums were taken, wait and try again\n if (this.queue.size) {\n await delay(1);\n continue;\n }\n break;\n }\n\n logger.info(\n `fetch block [${blockNums[0]},${\n blockNums[blockNums.length - 1]\n }], total ${blockNums.length} blocks`,\n );\n\n const blocks = await this.fetchBlocksBatches(blockNums);\n\n if (bufferedHeight > this._latestBufferedHeight) {\n logger.debug(`Queue was reset for new DS, discarding fetched blocks`);\n continue;\n }\n const blockTasks = blocks.map((block) => async () => {\n const height = block.blockHeight;\n try {\n this.preProcessBlock(height);\n\n const processBlockResponse = await this.indexerManager.indexBlock(\n block,\n );\n\n await this.postProcessBlock(height, processBlockResponse);\n } catch (e) {\n if (this.isShutdown) {\n return;\n }\n logger.error(\n e,\n `failed to index block at height ${height} ${\n e.handler ? `${e.handler}(${e.stack ?? ''})` : ''\n }`,\n );\n throw e;\n }\n });\n\n // There can be enough of a delay after fetching blocks that shutdown could now be true\n if (this.isShutdown) break;\n\n this.processQueue.putMany(blockTasks);\n\n this.eventEmitter.emit(IndexerEvent.BlockQueueSize, {\n value: this.processQueue.size,\n });\n }\n } finally {\n this.fetching = false;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;AAEtC,2CAAmE;AACnE,yDAAsD;AACtD,gDAS0B;AAC1B,mCAA8B;AAE9B,wDAAoD;AACpD,wDAAoD;AACpD,mEAA8D;AAE9D,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,wBAAwB,CAAC,CAAC;AAEnD;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBACX,SAAQ,2CAAkC;IAS1C,YACU,UAAsB,EAC9B,UAAsB,EACd,cAA8B,EACtC,YAA2B,EAC3B,cAA8B;QAE9B,KAAK,CACH,UAAU,EACV,YAAY,EACZ,cAAc,EACd,IAAI,iBAAK,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC,CACpC,CAAC;QAXM,eAAU,GAAV,UAAU,CAAY;QAEtB,mBAAc,GAAd,cAAc,CAAgB;QAPhC,aAAQ,GAAG,KAAK,CAAC;QACjB,eAAU,GAAG,KAAK,CAAC;QAgBzB,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAS,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;QAE5D,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CACtD,IAAI,CAAC,UAAU,CAAC,GAAG,CACpB,CAAC;QACF,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE;YAC5B,IAAI,CAAC,kBAAkB,GAAG,IAAA,wBAAY,EACpC,WAAW,EACX,cAAc,EACd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inality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n getLogger,\n NodeConfig,\n IndexerEvent,\n delay,\n profilerWrap,\n AutoQueue,\n Queue,\n} from '@subql/node-core';\nimport { last } from 'lodash';\nimport { EthereumApiService } from '../../ethereum';\nimport { IndexerManager } from '../indexer.manager';\nimport { ProjectService } from '../project.service';\nimport { BaseBlockDispatcher } from './base-block-dispatcher';\n\nconst logger = getLogger('BlockDispatcherService');\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 BaseBlockDispatcher<Queue<number>>\n implements OnApplicationShutdown\n{\n private processQueue: AutoQueue<void>;\n\n private fetching = false;\n private isShutdown = false;\n private fetchBlocksBatches: EthereumApiService['api']['fetchBlocks'];\n\n constructor(\n private apiService: ApiService,\n nodeConfig: NodeConfig,\n private indexerManager: IndexerManager,\n eventEmitter: EventEmitter2,\n projectService: ProjectService,\n ) {\n super(\n nodeConfig,\n eventEmitter,\n projectService,\n new Queue(nodeConfig.batchSize * 3),\n );\n this.processQueue = new AutoQueue(nodeConfig.batchSize * 3);\n\n const fetchBlocks = this.apiService.api.fetchBlocks.bind(\n this.apiService.api,\n );\n if (this.nodeConfig.profiler) {\n this.fetchBlocksBatches = profilerWrap(\n fetchBlocks,\n 'EthereumUtil',\n 'fetchBlocksBatches',\n );\n } else {\n this.fetchBlocksBatches = fetchBlocks;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async init(\n onDynamicDsCreated: (height: number) => Promise<void>,\n ): Promise<void> {\n this.onDynamicDsCreated = onDynamicDsCreated;\n const blockAmount = await this.projectService.getProcessedBlockCount();\n this.setProcessedBlockCount(blockAmount ?? 0);\n }\n\n onApplicationShutdown(): void {\n this.isShutdown = true;\n this.processQueue.abort();\n }\n\n enqueueBlocks(cleanedBlocks: number[], latestBufferHeight?: number): void {\n // // In the case where factors of batchSize is equal to bypassBlock or when cleanedBatchBlocks is []\n // // to ensure block is bypassed, latestBufferHeight needs to be manually set\n // If cleanedBlocks = []\n if (!!latestBufferHeight && !cleanedBlocks.length) {\n this.latestBufferedHeight = latestBufferHeight;\n return;\n }\n\n logger.info(\n `Enqueueing blocks ${cleanedBlocks[0]}...${last(cleanedBlocks)}, total ${\n cleanedBlocks.length\n } blocks`,\n );\n\n this.queue.putMany(cleanedBlocks);\n\n this.latestBufferedHeight = latestBufferHeight ?? last(cleanedBlocks);\n void this.fetchBlocksFromQueue().catch((e) => {\n logger.error(e, 'Failed to fetch blocks from queue');\n if (!this.isShutdown) {\n process.exit(1);\n }\n });\n }\n\n flushQueue(height: number): void {\n super.flushQueue(height);\n this.processQueue.flush();\n }\n\n private async fetchBlocksFromQueue(): Promise<void> {\n if (this.fetching || this.isShutdown) return;\n // Process queue is full, no point in fetching more blocks\n // if (this.processQueue.freeSpace < this.nodeConfig.batchSize) return;\n\n this.fetching = true;\n\n try {\n while (!this.isShutdown) {\n const blockNums = this.queue.takeMany(\n Math.min(this.nodeConfig.batchSize, this.processQueue.freeSpace),\n );\n // Used to compare before and after as a way to check if queue was flushed\n const bufferedHeight = this._latestBufferedHeight;\n\n // Queue is empty\n if (!blockNums.length) {\n // The process queue might be full so no block nums were taken, wait and try again\n if (this.queue.size) {\n await delay(1);\n continue;\n }\n break;\n }\n\n logger.info(\n `fetch block [${blockNums[0]},${\n blockNums[blockNums.length - 1]\n }], total ${blockNums.length} blocks`,\n );\n\n const blocks = await this.fetchBlocksBatches(blockNums);\n\n if (bufferedHeight > this._latestBufferedHeight) {\n logger.debug(`Queue was reset for new DS, discarding fetched blocks`);\n continue;\n }\n const blockTasks = blocks.map((block) => async () => {\n const height = block.blockHeight;\n try {\n this.preProcessBlock(height);\n\n const processBlockResponse = await this.indexerManager.indexBlock(\n block,\n );\n\n await this.postProcessBlock(height, processBlockResponse);\n } catch (e) {\n if (this.isShutdown) {\n return;\n }\n logger.error(\n e,\n `failed to index block at height ${height} ${\n e.handler ? `${e.handler}(${e.stack ?? ''})` : ''\n }`,\n );\n throw e;\n }\n });\n\n // There can be enough of a delay after fetching blocks that shutdown could now be true\n if (this.isShutdown) break;\n\n this.processQueue.putMany(blockTasks);\n\n this.eventEmitter.emit(IndexerEvent.BlockQueueSize, {\n value: this.processQueue.size,\n });\n }\n } finally {\n this.fetching = false;\n }\n }\n}\n"]}
@@ -11,7 +11,7 @@ export declare class WorkerBlockDispatcherService extends BaseBlockDispatcher<Au
11
11
  constructor(nodeConfig: NodeConfig, eventEmitter: EventEmitter2, projectService: ProjectService);
12
12
  init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void>;
13
13
  onApplicationShutdown(): Promise<void>;
14
- enqueueBlocks(heights: number[]): void;
14
+ enqueueBlocks(heights: number[], latestBufferHeight?: number): void;
15
15
  private enqueueBlock;
16
16
  sampleWorkerStatus(): Promise<void>;
17
17
  get latestBufferedHeight(): number;
@@ -64,7 +64,7 @@ let WorkerBlockDispatcherService = class WorkerBlockDispatcherService extends ba
64
64
  await Promise.all(this.workers.map((w) => w.terminate()));
65
65
  }
66
66
  }
67
- enqueueBlocks(heights) {
67
+ enqueueBlocks(heights, latestBufferHeight) {
68
68
  if (!heights.length)
69
69
  return;
70
70
  logger.info(`Enqueing blocks [${heights[0]}...${(0, lodash_1.last)(heights)}], total ${heights.length} blocks`);
@@ -86,7 +86,7 @@ let WorkerBlockDispatcherService = class WorkerBlockDispatcherService extends ba
86
86
  */
87
87
  heights.map((height) => this.enqueueBlock(height, this.getNextWorkerIndex()));
88
88
  }
89
- this.latestBufferedHeight = (0, lodash_1.last)(heights);
89
+ this.latestBufferedHeight = latestBufferHeight !== null && latestBufferHeight !== void 0 ? latestBufferHeight : (0, lodash_1.last)(heights);
90
90
  }
91
91
  enqueueBlock(height, workerIdx) {
92
92
  if (this.isShutdown)
@@ -126,7 +126,7 @@ let WorkerBlockDispatcherService = class WorkerBlockDispatcherService extends ba
126
126
  }
127
127
  catch (e) {
128
128
  logger.error(e, `failed to index block at height ${height} ${e.handler ? `${e.handler}(${(_a = e.stack) !== null && _a !== void 0 ? _a : ''})` : ''}`);
129
- throw e;
129
+ process.exit(1);
130
130
  }
131
131
  };
132
132
  void this.queue.put(processBlock);