@subql/node-ethereum 3.7.0 → 3.7.1-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/app.module.js +1 -1
  4. package/dist/app.module.js.map +1 -1
  5. package/dist/configure/NodeConfig.js +1 -1
  6. package/dist/configure/NodeConfig.js.map +1 -1
  7. package/dist/configure/SubqueryProject.js +1 -1
  8. package/dist/configure/SubqueryProject.js.map +1 -1
  9. package/dist/configure/configure.module.js +1 -1
  10. package/dist/configure/configure.module.js.map +1 -1
  11. package/dist/ethereum/api.connection.js +1 -1
  12. package/dist/ethereum/api.connection.js.map +1 -1
  13. package/dist/ethereum/api.ethereum.js +4 -2
  14. package/dist/ethereum/api.ethereum.js.map +1 -1
  15. package/dist/ethereum/api.ethereum.test.js +22 -1
  16. package/dist/ethereum/api.ethereum.test.js.map +1 -1
  17. package/dist/ethereum/api.service.ethereum.js +1 -1
  18. package/dist/ethereum/api.service.ethereum.js.map +1 -1
  19. package/dist/ethereum/api.service.ethereum.test.js +1 -1
  20. package/dist/ethereum/api.service.ethereum.test.js.map +1 -1
  21. package/dist/ethereum/block.ethereum.js +7 -2
  22. package/dist/ethereum/block.ethereum.js.map +1 -1
  23. package/dist/ethereum/ethers/celo/celo-json-rpc-batch-provider.js +1 -1
  24. package/dist/ethereum/ethers/celo/celo-json-rpc-batch-provider.js.map +1 -1
  25. package/dist/ethereum/ethers/celo/celo-json-rpc-batch-provider.spec.js +1 -1
  26. package/dist/ethereum/ethers/celo/celo-json-rpc-batch-provider.spec.js.map +1 -1
  27. package/dist/ethereum/ethers/celo/celo-json-rpc-provider.js +1 -1
  28. package/dist/ethereum/ethers/celo/celo-json-rpc-provider.js.map +1 -1
  29. package/dist/ethereum/ethers/celo/celo-json-rpc-provider.spec.js +1 -1
  30. package/dist/ethereum/ethers/celo/celo-json-rpc-provider.spec.js.map +1 -1
  31. package/dist/ethereum/ethers/celo/celo-ws-provider.js +1 -1
  32. package/dist/ethereum/ethers/celo/celo-ws-provider.js.map +1 -1
  33. package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js +1 -1
  34. package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js.map +1 -1
  35. package/dist/ethereum/index.js +1 -1
  36. package/dist/ethereum/index.js.map +1 -1
  37. package/dist/ethereum/safe-api.js +1 -1
  38. package/dist/ethereum/safe-api.js.map +1 -1
  39. package/dist/ethereum/utils.ethereum.js +1 -1
  40. package/dist/ethereum/utils.ethereum.js.map +1 -1
  41. package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -1
  42. package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
  43. package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.js +1 -1
  44. package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.js.map +1 -1
  45. package/dist/indexer/blockDispatcher/index.js +1 -1
  46. package/dist/indexer/blockDispatcher/index.js.map +1 -1
  47. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +1 -1
  48. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
  49. package/dist/indexer/dictionary.service.js +1 -1
  50. package/dist/indexer/dictionary.service.js.map +1 -1
  51. package/dist/indexer/ds-processor.service.js +1 -1
  52. package/dist/indexer/ds-processor.service.js.map +1 -1
  53. package/dist/indexer/dynamic-ds.service.js +1 -1
  54. package/dist/indexer/dynamic-ds.service.js.map +1 -1
  55. package/dist/indexer/fetch.module.js +1 -1
  56. package/dist/indexer/fetch.module.js.map +1 -1
  57. package/dist/indexer/fetch.service.js +10 -3
  58. package/dist/indexer/fetch.service.js.map +1 -1
  59. package/dist/indexer/fetch.service.spec.js +1 -1
  60. package/dist/indexer/fetch.service.spec.js.map +1 -1
  61. package/dist/indexer/indexer.manager.js +1 -1
  62. package/dist/indexer/indexer.manager.js.map +1 -1
  63. package/dist/indexer/project.service.js +1 -1
  64. package/dist/indexer/project.service.js.map +1 -1
  65. package/dist/indexer/project.service.test.js +1 -1
  66. package/dist/indexer/project.service.test.js.map +1 -1
  67. package/dist/indexer/sandbox.service.js +1 -1
  68. package/dist/indexer/sandbox.service.js.map +1 -1
  69. package/dist/indexer/types.js +1 -1
  70. package/dist/indexer/types.js.map +1 -1
  71. package/dist/indexer/unfinalizedBlocks.service.js +1 -1
  72. package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
  73. package/dist/indexer/unfinalizedBlocks.service.spec.js +1 -1
  74. package/dist/indexer/unfinalizedBlocks.service.spec.js.map +1 -1
  75. package/dist/indexer/worker/worker.js +1 -1
  76. package/dist/indexer/worker/worker.js.map +1 -1
  77. package/dist/indexer/worker/worker.module.js +1 -1
  78. package/dist/indexer/worker/worker.module.js.map +1 -1
  79. package/dist/indexer/worker/worker.service.js +1 -1
  80. package/dist/indexer/worker/worker.service.js.map +1 -1
  81. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +1 -1
  82. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -1
  83. package/dist/indexer/worker-fetch.module.js +1 -1
  84. package/dist/indexer/worker-fetch.module.js.map +1 -1
  85. package/dist/init.js +1 -1
  86. package/dist/init.js.map +1 -1
  87. package/dist/main.js +1 -1
  88. package/dist/main.js.map +1 -1
  89. package/dist/meta/meta.controller.js +1 -1
  90. package/dist/meta/meta.controller.js.map +1 -1
  91. package/dist/meta/meta.module.js +1 -1
  92. package/dist/meta/meta.module.js.map +1 -1
  93. package/dist/meta/meta.service.js +1 -1
  94. package/dist/meta/meta.service.js.map +1 -1
  95. package/dist/subcommands/forceClean.init.js +1 -1
  96. package/dist/subcommands/forceClean.init.js.map +1 -1
  97. package/dist/subcommands/forceClean.module.js +1 -1
  98. package/dist/subcommands/forceClean.module.js.map +1 -1
  99. package/dist/subcommands/reindex.init.js +1 -1
  100. package/dist/subcommands/reindex.init.js.map +1 -1
  101. package/dist/subcommands/reindex.module.js +1 -1
  102. package/dist/subcommands/reindex.module.js.map +1 -1
  103. package/dist/subcommands/testing.init.js +1 -1
  104. package/dist/subcommands/testing.init.js.map +1 -1
  105. package/dist/subcommands/testing.module.js +1 -1
  106. package/dist/subcommands/testing.module.js.map +1 -1
  107. package/dist/subcommands/testing.service.js +1 -1
  108. package/dist/subcommands/testing.service.js.map +1 -1
  109. package/dist/utils/project.js +1 -1
  110. package/dist/utils/project.js.map +1 -1
  111. package/dist/utils/string.js +1 -1
  112. package/dist/utils/string.js.map +1 -1
  113. package/dist/yargs.js +1 -1
  114. package/dist/yargs.js.map +1 -1
  115. package/package.json +5 -4
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
5
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1 +1 @@
1
- {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA2D;AAC3D,+CAAkD;AAClD,gDAA4C;AAC5C,mEAA+D;AAC/D,yDAAqD;AACrD,oDAAgD;AAazC,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,SAAS;IAXrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAkB,CAAC,OAAO,EAAE;YAC5B,kCAAe,CAAC,QAAQ,EAAE;YAC1B,yBAAc,CAAC,OAAO,EAAE;YACxB,0BAAW;YACX,wBAAU;SACX;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { ScheduleModule } from '@nestjs/schedule';\nimport { DbModule } from '@subql/node-core';\nimport { ConfigureModule } from './configure/configure.module';\nimport { FetchModule } from './indexer/fetch.module';\nimport { MetaModule } from './meta/meta.module';\n\n@Module({\n imports: [\n DbModule.forRoot(),\n EventEmitterModule.forRoot(),\n ConfigureModule.register(),\n ScheduleModule.forRoot(),\n FetchModule,\n MetaModule,\n ],\n controllers: [],\n})\nexport class AppModule {}\n"]}
1
+ {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA2D;AAC3D,+CAAkD;AAClD,gDAA4C;AAC5C,mEAA+D;AAC/D,yDAAqD;AACrD,oDAAgD;AAazC,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,SAAS;IAXrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAkB,CAAC,OAAO,EAAE;YAC5B,kCAAe,CAAC,QAAQ,EAAE;YAC1B,yBAAc,CAAC,OAAO,EAAE;YACxB,0BAAW;YACX,wBAAU;SACX;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { ScheduleModule } from '@nestjs/schedule';\nimport { DbModule } from '@subql/node-core';\nimport { ConfigureModule } from './configure/configure.module';\nimport { FetchModule } from './indexer/fetch.module';\nimport { MetaModule } from './meta/meta.module';\n\n@Module({\n imports: [\n DbModule.forRoot(),\n EventEmitterModule.forRoot(),\n ConfigureModule.register(),\n ScheduleModule.forRoot(),\n FetchModule,\n MetaModule,\n ],\n controllers: [],\n})\nexport class AppModule {}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.EthereumNodeConfig = void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"NodeConfig.js","sourceRoot":"","sources":["../../src/configure/NodeConfig.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAAuD;AAQvD,MAAa,kBAAmB,SAAQ,sBAA2B;IACjE;;;;;;;;;;SAUK;IACL,YAAY,MAAkB;QAC5B,+BAA+B;QAC/B,KAAK,CAAE,MAAc,CAAC,OAAO,EAAG,MAAc,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACzC,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;IACzC,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACvC,CAAC;CACF;AA5BD,gDA4BC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { IConfig, NodeConfig } from '@subql/node-core';\n\nexport interface IEthereumConfig extends IConfig {\n skipTransactions: boolean;\n blockConfirmations: number;\n blockForkReindex: number;\n}\n\nexport class EthereumNodeConfig extends NodeConfig<IEthereumConfig> {\n /**\n * This is a wrapper around the core NodeConfig to get additional properties that are provided through args or node runner options\n * NOTE: This isn't injected anywhere so you need to wrap the injected node config\n *\n * @example\n * constructor(\n * nodeConfig: NodeConfig,\n * ) {\n * this.nodeConfig = new EthereumNodeConfig(nodeConfig);\n * }\n * */\n constructor(config: NodeConfig) {\n // Rebuild with internal config\n super((config as any)._config, (config as any)._isTest);\n }\n\n get skipTransactions(): boolean {\n return !!this._config.skipTransactions;\n }\n\n get blockConfirmations(): number {\n return this._config.blockConfirmations;\n }\n\n get blockForkReindex(): number {\n return this._config.blockForkReindex;\n }\n}\n"]}
1
+ {"version":3,"file":"NodeConfig.js","sourceRoot":"","sources":["../../src/configure/NodeConfig.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAAuD;AAQvD,MAAa,kBAAmB,SAAQ,sBAA2B;IACjE;;;;;;;;;;SAUK;IACL,YAAY,MAAkB;QAC5B,+BAA+B;QAC/B,KAAK,CAAE,MAAc,CAAC,OAAO,EAAG,MAAc,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACzC,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;IACzC,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACvC,CAAC;CACF;AA5BD,gDA4BC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { IConfig, NodeConfig } from '@subql/node-core';\n\nexport interface IEthereumConfig extends IConfig {\n skipTransactions: boolean;\n blockConfirmations: number;\n blockForkReindex: number;\n}\n\nexport class EthereumNodeConfig extends NodeConfig<IEthereumConfig> {\n /**\n * This is a wrapper around the core NodeConfig to get additional properties that are provided through args or node runner options\n * NOTE: This isn't injected anywhere so you need to wrap the injected node config\n *\n * @example\n * constructor(\n * nodeConfig: NodeConfig,\n * ) {\n * this.nodeConfig = new EthereumNodeConfig(nodeConfig);\n * }\n * */\n constructor(config: NodeConfig) {\n // Rebuild with internal config\n super((config as any)._config, (config as any)._isTest);\n }\n\n get skipTransactions(): boolean {\n return !!this._config.skipTransactions;\n }\n\n get blockConfirmations(): number {\n return this._config.blockConfirmations;\n }\n\n get blockForkReindex(): number {\n return this._config.blockForkReindex;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
5
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1 +1 @@
1
- {"version":3,"file":"SubqueryProject.js","sourceRoot":"","sources":["../../src/configure/SubqueryProject.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnC,oDAA4B;AAC5B,2CAA4C;AAC5C,0CAA+C;AAC/C,4DAOgC;AAChC,gDAK0B;AAQ1B,wCAAqD;AAErD,qCAAwC;AACxC,8CAA0D;AAE1D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAelE,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;IACnC,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,mBAAmB,CAAC,CAAC;AACnE,CAAC,CAAC;AAMK,IAAM,eAAe,GAArB,MAAM,eAAe;IAG1B,YACW,EAAU,EACV,IAAY,EACZ,OAAsB,EAC/B,WAAgC,EACvB,MAAqB,EACrB,SAAsC,EACtC,MAAoB,EACpB,MAAsB;QAPtB,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OA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ACN,4BAAU,CACX,CAAC;IACF,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IACtC,IAAA,gBAAM,EACJ,IAAA,uBAAc,EAAC,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EACnD,IAAI,KAAK,CACP,+BAA+B,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,cAAc,EAAE,CACrF,CACF,CAAC;IAEF,OAAO,IAAI,eAAe,CACxB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,wCAAwC;IAC1E,IAAI,EACJ,OAAO,EACP,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,eAAe,CAAC,MAAM,CACvB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Injectable } from '@nestjs/common';\nimport { validateSemver } from '@subql/common';\nimport {\n parseEthereumProjectManifest,\n SubqlEthereumDataSource,\n ProjectManifestV1_0_0Impl,\n isRuntimeDs,\n EthereumHandlerKind,\n isCustomDs,\n} from '@subql/common-ethereum';\nimport {\n insertBlockFiltersCronSchedules,\n ISubqueryProject,\n loadProjectTemplates,\n SubqlProjectDs,\n} from '@subql/node-core';\nimport { ParentProject, Reader, RunnerSpecs } from '@subql/types-core';\nimport {\n EthereumNetworkConfig,\n RuntimeDatasourceTemplate,\n CustomDatasourceTemplate,\n EthereumBlockFilter,\n} from '@subql/types-ethereum';\nimport { buildSchemaFromString } from '@subql/utils';\nimport Cron from 'cron-converter';\nimport { GraphQLSchema } from 'graphql';\nimport { updateDatasourcesFlare } from '../utils/project';\n\nconst { version: packageVersion } = require('../../package.json');\n\nexport type EthereumProjectDs = SubqlProjectDs<SubqlEthereumDataSource>;\n\nexport type EthereumProjectDsTemplate =\n | SubqlProjectDs<RuntimeDatasourceTemplate>\n | SubqlProjectDs<CustomDatasourceTemplate>;\n\nexport type SubqlProjectBlockFilter = EthereumBlockFilter & {\n cronSchedule?: {\n schedule: Cron.Seeker;\n next: number;\n };\n};\n\nconst NOT_SUPPORT = (name: string) => {\n throw new Error(`Manifest specVersion ${name} is not supported`);\n};\n\n// This is the runtime type after we have mapped genesisHash to chainId and endpoint/dict have been provided when dealing with deployments\ntype NetworkConfig = EthereumNetworkConfig & { chainId: string };\n\n@Injectable()\nexport class SubqueryProject implements ISubqueryProject {\n #dataSources: EthereumProjectDs[];\n\n constructor(\n readonly id: string,\n readonly root: string,\n readonly network: NetworkConfig,\n dataSources: EthereumProjectDs[],\n readonly schema: GraphQLSchema,\n readonly templates: EthereumProjectDsTemplate[],\n readonly runner?: RunnerSpecs,\n readonly parent?: ParentProject,\n ) {\n this.#dataSources = dataSources;\n }\n\n get dataSources(): EthereumProjectDs[] {\n return this.#dataSources;\n }\n\n async applyCronTimestamps(\n getTimestamp: (height: number) => Promise<Date>,\n ): Promise<void> {\n this.#dataSources = await insertBlockFiltersCronSchedules(\n this.dataSources,\n getTimestamp,\n isRuntimeDs,\n EthereumHandlerKind.Block,\n );\n }\n\n static async create(\n path: string,\n rawManifest: unknown,\n reader: Reader,\n root: string, // If project local then directory otherwise temp directory\n networkOverrides?: Partial<EthereumNetworkConfig>,\n ): Promise<SubqueryProject> {\n // rawManifest and reader can be reused here.\n // It has been pre-fetched and used for rebase manifest runner options with args\n // in order to generate correct configs.\n\n // But we still need reader here, because path can be remote or local\n // and the `loadProjectManifest(projectPath)` only support local mode\n if (rawManifest === undefined) {\n throw new Error(`Get manifest from project path ${path} failed`);\n }\n const manifest = parseEthereumProjectManifest(rawManifest);\n\n if (manifest.isV1_0_0) {\n return loadProjectFromManifestBase(\n manifest.asV1_0_0,\n reader,\n path,\n root,\n networkOverrides,\n );\n } else {\n NOT_SUPPORT(manifest.specVersion);\n }\n }\n}\n\nfunction processChainId(network: any): NetworkConfig {\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 root: string,\n networkOverrides?: Partial<EthereumNetworkConfig>,\n): Promise<SubqueryProject> {\n if (typeof projectManifest.network.endpoint === 'string') {\n projectManifest.network.endpoint = [projectManifest.network.endpoint];\n }\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 dataSources = await updateDatasourcesFlare(\n projectManifest.dataSources,\n reader,\n root,\n );\n\n const templates = await loadProjectTemplates(\n projectManifest.templates,\n root,\n reader,\n isCustomDs,\n );\n const runner = projectManifest.runner;\n assert(\n validateSemver(packageVersion, runner.node.version),\n new Error(\n `Runner require node version ${runner.node.version}, current node ${packageVersion}`,\n ),\n );\n\n return new SubqueryProject(\n reader.root ? reader.root : path, //TODO, need to method to get project_id\n root,\n network,\n dataSources,\n schema,\n templates,\n runner,\n projectManifest.parent,\n );\n}\n"]}
1
+ {"version":3,"file":"SubqueryProject.js","sourceRoot":"","sources":["../../src/configure/SubqueryProject.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnC,oDAA4B;AAC5B,2CAA4C;AAC5C,0CAA+C;AAC/C,4DAOgC;AAChC,gDAK0B;AAQ1B,wCAAqD;AAErD,qCAAwC;AACxC,8CAA0D;AAE1D,MAAM,EAAE,OAAO,EAAE,cAAc,E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AAC,IAAI,CAAC,CAAC;KAClE;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CACb,mCAAmC,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,CACjE,CAAC;KACH;IACD,MAAM,MAAM,GAAG,IAAA,6BAAqB,EAAC,YAAY,CAAC,CAAC;IAEnD,MAAM,WAAW,GAAG,MAAM,IAAA,gCAAsB,EAC9C,eAAe,CAAC,WAAW,EAC3B,MAAM,EACN,IAAI,CACL,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,IAAA,gCAAoB,EAC1C,eAAe,CAAC,SAAS,EACzB,IAAI,EACJ,MAAM,EACN,4BAAU,CACX,CAAC;IACF,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IACtC,IAAA,gBAAM,EACJ,IAAA,uBAAc,EAAC,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EACnD,IAAI,KAAK,CACP,+BAA+B,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,cAAc,EAAE,CACrF,CACF,CAAC;IAEF,OAAO,IAAI,eAAe,CACxB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,wCAAwC;IAC1E,IAAI,EACJ,OAAO,EACP,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,eAAe,CAAC,MAAM,CACvB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Injectable } from '@nestjs/common';\nimport { validateSemver } from '@subql/common';\nimport {\n parseEthereumProjectManifest,\n SubqlEthereumDataSource,\n ProjectManifestV1_0_0Impl,\n isRuntimeDs,\n EthereumHandlerKind,\n isCustomDs,\n} from '@subql/common-ethereum';\nimport {\n insertBlockFiltersCronSchedules,\n ISubqueryProject,\n loadProjectTemplates,\n SubqlProjectDs,\n} from '@subql/node-core';\nimport { ParentProject, Reader, RunnerSpecs } from '@subql/types-core';\nimport {\n EthereumNetworkConfig,\n RuntimeDatasourceTemplate,\n CustomDatasourceTemplate,\n EthereumBlockFilter,\n} from '@subql/types-ethereum';\nimport { buildSchemaFromString } from '@subql/utils';\nimport Cron from 'cron-converter';\nimport { GraphQLSchema } from 'graphql';\nimport { updateDatasourcesFlare } from '../utils/project';\n\nconst { version: packageVersion } = require('../../package.json');\n\nexport type EthereumProjectDs = SubqlProjectDs<SubqlEthereumDataSource>;\n\nexport type EthereumProjectDsTemplate =\n | SubqlProjectDs<RuntimeDatasourceTemplate>\n | SubqlProjectDs<CustomDatasourceTemplate>;\n\nexport type SubqlProjectBlockFilter = EthereumBlockFilter & {\n cronSchedule?: {\n schedule: Cron.Seeker;\n next: number;\n };\n};\n\nconst NOT_SUPPORT = (name: string) => {\n throw new Error(`Manifest specVersion ${name} is not supported`);\n};\n\n// This is the runtime type after we have mapped genesisHash to chainId and endpoint/dict have been provided when dealing with deployments\ntype NetworkConfig = EthereumNetworkConfig & { chainId: string };\n\n@Injectable()\nexport class SubqueryProject implements ISubqueryProject {\n #dataSources: EthereumProjectDs[];\n\n constructor(\n readonly id: string,\n readonly root: string,\n readonly network: NetworkConfig,\n dataSources: EthereumProjectDs[],\n readonly schema: GraphQLSchema,\n readonly templates: EthereumProjectDsTemplate[],\n readonly runner?: RunnerSpecs,\n readonly parent?: ParentProject,\n ) {\n this.#dataSources = dataSources;\n }\n\n get dataSources(): EthereumProjectDs[] {\n return this.#dataSources;\n }\n\n async applyCronTimestamps(\n getTimestamp: (height: number) => Promise<Date>,\n ): Promise<void> {\n this.#dataSources = await insertBlockFiltersCronSchedules(\n this.dataSources,\n getTimestamp,\n isRuntimeDs,\n EthereumHandlerKind.Block,\n );\n }\n\n static async create(\n path: string,\n rawManifest: unknown,\n reader: Reader,\n root: string, // If project local then directory otherwise temp directory\n networkOverrides?: Partial<EthereumNetworkConfig>,\n ): Promise<SubqueryProject> {\n // rawManifest and reader can be reused here.\n // It has been pre-fetched and used for rebase manifest runner options with args\n // in order to generate correct configs.\n\n // But we still need reader here, because path can be remote or local\n // and the `loadProjectManifest(projectPath)` only support local mode\n if (rawManifest === undefined) {\n throw new Error(`Get manifest from project path ${path} failed`);\n }\n const manifest = parseEthereumProjectManifest(rawManifest);\n\n if (manifest.isV1_0_0) {\n return loadProjectFromManifestBase(\n manifest.asV1_0_0,\n reader,\n path,\n root,\n networkOverrides,\n );\n } else {\n NOT_SUPPORT(manifest.specVersion);\n }\n }\n}\n\nfunction processChainId(network: any): NetworkConfig {\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 root: string,\n networkOverrides?: Partial<EthereumNetworkConfig>,\n): Promise<SubqueryProject> {\n if (typeof projectManifest.network.endpoint === 'string') {\n projectManifest.network.endpoint = [projectManifest.network.endpoint];\n }\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 dataSources = await updateDatasourcesFlare(\n projectManifest.dataSources,\n reader,\n root,\n );\n\n const templates = await loadProjectTemplates(\n projectManifest.templates,\n root,\n reader,\n isCustomDs,\n );\n const runner = projectManifest.runner;\n assert(\n validateSemver(packageVersion, runner.node.version),\n new Error(\n `Runner require node version ${runner.node.version}, current node ${packageVersion}`,\n ),\n );\n\n return new SubqueryProject(\n reader.root ? reader.root : path, //TODO, need to method to get project_id\n root,\n network,\n dataSources,\n schema,\n templates,\n runner,\n projectManifest.parent,\n );\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
5
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1 +1 @@
1
- {"version":3,"file":"configure.module.js","sourceRoot":"","sources":["../../src/configure/configure.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;AAEnC,2CAA+D;AAC/D,gDAA2D;AAC3D,oCAAwC;AACxC,uDAAoD;AAEpD,MAAM,KAAK,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAIrC,IAAM,eAAe,uBAArB,MAAM,eAAe;IAC1B,MAAM,CAAC,KAAK,CAAC,WAAW;QAItB,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAY,CAAC;QAC9B,OAAO,IAAA,uBAAW,EAChB,IAAI,EACJ,iCAAe,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAe,CAAC,EAC5C,oBAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,oBAAY,CAAC,EACxC,KAAK,CACN,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,QAAQ;QACnB,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,iBAAe,CAAC,WAAW,EAAE,CAAC;QAEpE,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,sBAAU;oBACnB,QAAQ,EAAE,UAAU;iBACrB;gBACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,wBAAwB;oBACjC,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,MAAM;oBACf,QAAQ,EAAE,IAAI;iBACf;aACF;YACD,OAAO,EAAE;gBACP,sBAAU;gBACV,kBAAkB;gBAClB,wBAAwB;gBACxB,MAAM;aACP;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA5CY,eAAe;IAF3B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CA4C3B;AA5CY,0CAAe","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { DynamicModule, Global, Module } from '@nestjs/common';\nimport { NodeConfig, registerApp } from '@subql/node-core';\nimport { yargsOptions } from '../yargs';\nimport { SubqueryProject } from './SubqueryProject';\n\nconst pjson = require('../../package.json');\n\n@Global()\n@Module({})\nexport class ConfigureModule {\n static async getInstance(): Promise<{\n nodeConfig: NodeConfig;\n project: SubqueryProject;\n }> {\n const { argv } = yargsOptions;\n return registerApp<SubqueryProject>(\n argv,\n SubqueryProject.create.bind(SubqueryProject),\n yargsOptions.showHelp.bind(yargsOptions),\n pjson,\n );\n }\n static async register(): Promise<DynamicModule> {\n const { nodeConfig, project } = await ConfigureModule.getInstance();\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: nodeConfig,\n },\n {\n provide: 'ISubqueryProject',\n useValue: project,\n },\n {\n provide: 'IProjectUpgradeService',\n useValue: project,\n },\n {\n provide: 'Null',\n useValue: null,\n },\n ],\n exports: [\n NodeConfig,\n 'ISubqueryProject',\n 'IProjectUpgradeService',\n 'Null',\n ],\n };\n }\n}\n"]}
1
+ {"version":3,"file":"configure.module.js","sourceRoot":"","sources":["../../src/configure/configure.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;AAEnC,2CAA+D;AAC/D,gDAA2D;AAC3D,oCAAwC;AACxC,uDAAoD;AAEpD,MAAM,KAAK,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAIrC,IAAM,eAAe,uBAArB,MAAM,eAAe;IAC1B,MAAM,CAAC,KAAK,CAAC,WAAW;QAItB,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAY,CAAC;QAC9B,OAAO,IAAA,uBAAW,EAChB,IAAI,EACJ,iCAAe,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAe,CAAC,EAC5C,oBAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,oBAAY,CAAC,EACxC,KAAK,CACN,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,QAAQ;QACnB,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,iBAAe,CAAC,WAAW,EAAE,CAAC;QAEpE,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,sBAAU;oBACnB,QAAQ,EAAE,UAAU;iBACrB;gBACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,wBAAwB;oBACjC,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,MAAM;oBACf,QAAQ,EAAE,IAAI;iBACf;aACF;YACD,OAAO,EAAE;gBACP,sBAAU;gBACV,kBAAkB;gBAClB,wBAAwB;gBACxB,MAAM;aACP;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA5CY,eAAe;IAF3B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CA4C3B;AA5CY,0CAAe","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { DynamicModule, Global, Module } from '@nestjs/common';\nimport { NodeConfig, registerApp } from '@subql/node-core';\nimport { yargsOptions } from '../yargs';\nimport { SubqueryProject } from './SubqueryProject';\n\nconst pjson = require('../../package.json');\n\n@Global()\n@Module({})\nexport class ConfigureModule {\n static async getInstance(): Promise<{\n nodeConfig: NodeConfig;\n project: SubqueryProject;\n }> {\n const { argv } = yargsOptions;\n return registerApp<SubqueryProject>(\n argv,\n SubqueryProject.create.bind(SubqueryProject),\n yargsOptions.showHelp.bind(yargsOptions),\n pjson,\n );\n }\n static async register(): Promise<DynamicModule> {\n const { nodeConfig, project } = await ConfigureModule.getInstance();\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: nodeConfig,\n },\n {\n provide: 'ISubqueryProject',\n useValue: project,\n },\n {\n provide: 'IProjectUpgradeService',\n useValue: project,\n },\n {\n provide: 'Null',\n useValue: null,\n },\n ],\n exports: [\n NodeConfig,\n 'ISubqueryProject',\n 'IProjectUpgradeService',\n 'Null',\n ],\n };\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.EthereumApiConnection = void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/ethereum/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAS0B;AAE1B,iDAA6C;AAU7C,MAAa,qBAAqB;IAUhC,YACS,SAAsB,EACrB,kBAAgC;QADjC,cAAS,GAAT,SAAS,CAAa;QACrB,uBAAkB,GAAlB,kBAAkB,CAAc;QA+C1C,gBAAW,GAAG,qBAAqB,CAAC,WAAW,CAAC;QA7C9C,IAAI,CAAC,WAAW,GAAG;YACjB,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE;YACxC,QAAQ,EAAE,SAAS,CAAC,WAAW,E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E;YAC3D,eAAe,GAAG,IAAI,0BAAc,CAAC,CAAC,CAAC,CAAC;SACzC;aAAM,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE;YACtD,eAAe,GAAG,IAAI,8BAAkB,CAAC,CAAC,CAAC,CAAC;SAC7C;aAAM;YACL,eAAe,GAAG,IAAI,8BAAkB,CACtC,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;SACH;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AAhFD,sDAgFC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n NetworkMetadataPayload,\n RateLimitError,\n TimeoutError,\n IApiConnectionSpecific,\n} from '@subql/node-core';\nimport { EthereumBlock, LightEthereumBlock } from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nexport type FetchFunc =\n | ((api: EthereumApi, batch: number[]) => Promise<EthereumBlock[]>)\n | ((api: EthereumApi, batch: number[]) => Promise<LightEthereumBlock[]>);\n\n// We use a function to get the fetch function because it can change depending on the skipBlocks feature\nexport type GetFetchFunc = () => FetchFunc;\n\nexport class EthereumApiConnection\n implements\n IApiConnectionSpecific<\n EthereumApi,\n SafeEthProvider,\n EthereumBlock[] | LightEthereumBlock[]\n >\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n constructor(\n public unsafeApi: EthereumApi,\n private fetchBlocksBatches: GetFetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.getChainId().toString(),\n specName: unsafeApi.getSpecName(),\n genesisHash: unsafeApi.getGenesisHash(),\n };\n }\n\n static async create(\n endpoint: string,\n blockConfirmations: number,\n fetchBlocksBatches: GetFetchFunc,\n eventEmitter: EventEmitter2,\n unfinalizedBlocks: boolean,\n ): Promise<EthereumApiConnection> {\n const api = new EthereumApi(\n endpoint,\n blockConfirmations,\n eventEmitter,\n unfinalizedBlocks,\n );\n\n await api.init();\n\n return new EthereumApiConnection(api, fetchBlocksBatches);\n }\n\n safeApi(height: number): SafeEthProvider {\n throw new Error(`Not Implemented`);\n }\n\n async apiConnect(): Promise<void> {\n await this.unsafeApi.connect();\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async fetchBlocks(\n heights: number[],\n ): Promise<EthereumBlock[] | LightEthereumBlock[]> {\n const blocks = await this.fetchBlocksBatches()(this.unsafeApi, heights);\n return blocks;\n }\n\n handleError = EthereumApiConnection.handleError;\n\n static handleError(e: Error): ApiConnectionError {\n let formatted_error: ApiConnectionError;\n if (e.message.startsWith(`No response received from RPC endpoint in`)) {\n formatted_error = new TimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = new DisconnectionError(e);\n } else if (e.message.startsWith(`Rate Limited at endpoint`)) {\n formatted_error = new RateLimitError(e);\n } else if (e.message.includes(`Exceeded max limit of`)) {\n formatted_error = new LargeResponseError(e);\n } else {\n formatted_error = new ApiConnectionError(\n e.name,\n e.message,\n ApiErrorType.Default,\n );\n }\n return formatted_error;\n }\n}\n"]}
1
+ {"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/ethereum/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAS0B;AAE1B,iDAA6C;AAU7C,MAAa,qBAAqB;IAUhC,YACS,SAAsB,EACrB,kBAAgC;QADjC,cAAS,GAAT,SAAS,CAAa;QACrB,uBAAkB,GAAlB,kBAAkB,CAAc;QA+C1C,gBAAW,GAAG,qBAAqB,CAAC,WAAW,CAAC;QA7C9C,IAAI,CAAC,WAAW,GAAG;YACjB,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE;Y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,CAAC,UAAU,CAAC,0BAA0B,CAAC,EAAE;YAC3D,eAAe,GAAG,IAAI,0BAAc,CAAC,CAAC,CAAC,CAAC;SACzC;aAAM,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE;YACtD,eAAe,GAAG,IAAI,8BAAkB,CAAC,CAAC,CAAC,CAAC;SAC7C;aAAM;YACL,eAAe,GAAG,IAAI,8BAAkB,CACtC,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;SACH;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AAhFD,sDAgFC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n NetworkMetadataPayload,\n RateLimitError,\n TimeoutError,\n IApiConnectionSpecific,\n} from '@subql/node-core';\nimport { EthereumBlock, LightEthereumBlock } from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nexport type FetchFunc =\n | ((api: EthereumApi, batch: number[]) => Promise<EthereumBlock[]>)\n | ((api: EthereumApi, batch: number[]) => Promise<LightEthereumBlock[]>);\n\n// We use a function to get the fetch function because it can change depending on the skipBlocks feature\nexport type GetFetchFunc = () => FetchFunc;\n\nexport class EthereumApiConnection\n implements\n IApiConnectionSpecific<\n EthereumApi,\n SafeEthProvider,\n EthereumBlock[] | LightEthereumBlock[]\n >\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n constructor(\n public unsafeApi: EthereumApi,\n private fetchBlocksBatches: GetFetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.getChainId().toString(),\n specName: unsafeApi.getSpecName(),\n genesisHash: unsafeApi.getGenesisHash(),\n };\n }\n\n static async create(\n endpoint: string,\n blockConfirmations: number,\n fetchBlocksBatches: GetFetchFunc,\n eventEmitter: EventEmitter2,\n unfinalizedBlocks: boolean,\n ): Promise<EthereumApiConnection> {\n const api = new EthereumApi(\n endpoint,\n blockConfirmations,\n eventEmitter,\n unfinalizedBlocks,\n );\n\n await api.init();\n\n return new EthereumApiConnection(api, fetchBlocksBatches);\n }\n\n safeApi(height: number): SafeEthProvider {\n throw new Error(`Not Implemented`);\n }\n\n async apiConnect(): Promise<void> {\n await this.unsafeApi.connect();\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async fetchBlocks(\n heights: number[],\n ): Promise<EthereumBlock[] | LightEthereumBlock[]> {\n const blocks = await this.fetchBlocksBatches()(this.unsafeApi, heights);\n return blocks;\n }\n\n handleError = EthereumApiConnection.handleError;\n\n static handleError(e: Error): ApiConnectionError {\n let formatted_error: ApiConnectionError;\n if (e.message.startsWith(`No response received from RPC endpoint in`)) {\n formatted_error = new TimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = new DisconnectionError(e);\n } else if (e.message.startsWith(`Rate Limited at endpoint`)) {\n formatted_error = new RateLimitError(e);\n } else if (e.message.includes(`Exceeded max limit of`)) {\n formatted_error = new LargeResponseError(e);\n } else {\n formatted_error = new ApiConnectionError(\n e.name,\n e.message,\n ApiErrorType.Default,\n );\n }\n return formatted_error;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -305,7 +305,9 @@ class EthereumApi {
305
305
  var _a;
306
306
  try {
307
307
  if (!((_a = ds === null || ds === void 0 ? void 0 : ds.options) === null || _a === void 0 ? void 0 : _a.abi)) {
308
- logger.warn('No ABI provided for datasource');
308
+ if (transaction.input !== '0x') {
309
+ logger.warn('No ABI provided for datasource');
310
+ }
309
311
  return transaction;
310
312
  }
311
313
  const assets = await loadAssets(ds);
@@ -1 +1 @@
1
- {"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,4CAA+C;AAO/C,wDAA6D;AAE7D,gDAAsD;AAWtD,wEAA+C;AAC/C,4CAA0D;AAC1D,8CAAkD;AAClD,6FAAsF;AACtF,iFAA2E;AAC3E,qEAAgE;AAChE,8EAAwE;AACxE,kEAA6D;AAE7D,0DAAyC;AACzC,qDAK0B;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,EAA0B;IAE1B,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,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE;QAClD,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,SAAS,aAAa;IACpB,8CAA8C;IAC9C,uDAAuD;IACvD,M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AC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,MAAM,YAAY,6BAAiB,EAAE;YAC5C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SACnD;IACH,CAAC;IAED,WAAW,CAAC,CAAQ;QAClB,IAAI,CAAC,CAAS,aAAT,CAAC,uBAAD,CAAC,CAAU,MAAM,MAAK,GAAG,EAAE;YAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;SAC3D;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA3XD,kCA2XC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { CeloJsonRpcBatchProvider } from './ethers/celo/celo-json-rpc-batch-provider';\nimport { CeloJsonRpcProvider } from './ethers/celo/celo-json-rpc-provider';\nimport { CeloWsProvider } from './ethers/celo/celo-ws-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\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: SubqlRuntimeDatasource,\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 ds.assets.entries()) {\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\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private _supportsFinalization = true;\n\n get supportsFinalization(): boolean {\n return this._supportsFinalization;\n }\n\n /**\n * @param {string} endpoint - The endpoint of the RPC provider\n * @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.\n * @param {object} eventEmitter - Used to monitor the number of RPC requests\n */\n constructor(\n private endpoint: string,\n private blockConfirmations: number,\n private eventEmitter: EventEmitter2,\n private unfinalizedBlocks = false,\n ) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\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 allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = 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.injectClient();\n\n const network = await this.client.getNetwork();\n\n //celo\n if (network.chainId === 42220) {\n if (this.client instanceof WebSocketProvider) {\n this.client = new CeloWsProvider(this.client.connection.url);\n } else {\n this.client = new CeloJsonRpcBatchProvider(this.client.connection);\n this.nonBatchClient = new CeloJsonRpcProvider(this.client.connection);\n }\n }\n\n try {\n const [genesisBlock, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.getGenesisBlock(network.chainId),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this.genesisBlock = genesisBlock;\n this._supportsFinalization = supportsFinalization && supportsSafe;\n this.chainId = network.chainId;\n this.name = network.name;\n } catch (e) {\n if ((e as Error).message.startsWith('Invalid response')) {\n this.client = this.nonBatchClient;\n\n logger.warn(\n `The RPC Node at ${this.endpoint} cannot process batch requests. ` +\n `Switching to non-batch mode for subsequent requests. Please consider checking if batch processing is supported on the RPC node.`,\n );\n\n return this.init();\n }\n\n throw e;\n }\n }\n\n private async getSupportsTag(tag: BlockTag): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n const result = await timeout(this.client.getBlock(tag), 2);\n\n return true;\n } catch (e) {\n logger.info(`Chain doesnt support ${tag} tag`);\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n private async getGenesisBlock(chainId: number): Promise<Block> {\n const tag = () => {\n switch (chainId) {\n // BEVM Canary\n case 1501:\n return 4157986;\n default:\n return 'earliest';\n }\n };\n\n return this.client.getBlock(tag());\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n\n const block = await this.client.getBlock(height);\n // The finalized block could sometimes fail to fetch,\n // due to some nodes on the network falling behind the synced node.\n if (!block) {\n throw new Error(`get finalized block \"${height}\" failed `);\n }\n return block;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n // Cronos \"safe\" tag doesn't currently work as indended\n const tag =\n !this.unfinalizedBlocks &&\n this.supportsFinalization &&\n this.chainId !== 25\n ? 'safe'\n : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\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 if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\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\n async fetchBlock(blockNumber: number): Promise<EthereumBlock> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({ blockHash: block.hash });\n\n block.logs = logsRaw.map((l) => formatLog(l, block));\n block.transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n logs: block.logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n this.eventEmitter.emit('fetchBlock');\n return block;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<LightEthereumBlock> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n return {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlock[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<LightEthereumBlock[]> {\n console.log('FETCH BLOCKS LIGHT');\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\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 | LightEthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<\n EthereumLog | LightEthereumLog | EthereumLog<T> | LightEthereumLog<T>\n > {\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\n log.args = iface?.parseLog(log).args as T;\n\n return log;\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: SubqlRuntimeDatasource,\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\n transaction.logs =\n transaction.logs &&\n ((await Promise.all(\n transaction.logs.map(async (log) => this.parseLog(log, ds)),\n )) as Array<EthereumLog | EthereumLog<T>>);\n\n transaction.args = args;\n\n return transaction;\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\n"]}
1
+ {"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,4CAA+C;AAO/C,wDAA6D;AAE7D,gDAAsD;AAWtD,wEAA+C;AAC/C,4CAA0D;AAC1D,8CAAkD;AAClD,6FAAsF;AACtF,iFAA2E;AAC3E,qEAAgE;AAChE,8EAAwE;AACxE,kEAA6D;AAE7D,0DAAyC;AACzC,qDAK0B;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,EAA0B;IAE1B,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,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE;Q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n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { CeloJsonRpcBatchProvider } from './ethers/celo/celo-json-rpc-batch-provider';\nimport { CeloJsonRpcProvider } from './ethers/celo/celo-json-rpc-provider';\nimport { CeloWsProvider } from './ethers/celo/celo-ws-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\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: SubqlRuntimeDatasource,\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 ds.assets.entries()) {\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\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private _supportsFinalization = true;\n\n get supportsFinalization(): boolean {\n return this._supportsFinalization;\n }\n\n /**\n * @param {string} endpoint - The endpoint of the RPC provider\n * @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.\n * @param {object} eventEmitter - Used to monitor the number of RPC requests\n */\n constructor(\n private endpoint: string,\n private blockConfirmations: number,\n private eventEmitter: EventEmitter2,\n private unfinalizedBlocks = false,\n ) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\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 allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = 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.injectClient();\n\n const network = await this.client.getNetwork();\n\n //celo\n if (network.chainId === 42220) {\n if (this.client instanceof WebSocketProvider) {\n this.client = new CeloWsProvider(this.client.connection.url);\n } else {\n this.client = new CeloJsonRpcBatchProvider(this.client.connection);\n this.nonBatchClient = new CeloJsonRpcProvider(this.client.connection);\n }\n }\n\n try {\n const [genesisBlock, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.getGenesisBlock(network.chainId),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this.genesisBlock = genesisBlock;\n this._supportsFinalization = supportsFinalization && supportsSafe;\n this.chainId = network.chainId;\n this.name = network.name;\n } catch (e) {\n if ((e as Error).message.startsWith('Invalid response')) {\n this.client = this.nonBatchClient;\n\n logger.warn(\n `The RPC Node at ${this.endpoint} cannot process batch requests. ` +\n `Switching to non-batch mode for subsequent requests. Please consider checking if batch processing is supported on the RPC node.`,\n );\n\n return this.init();\n }\n\n throw e;\n }\n }\n\n private async getSupportsTag(tag: BlockTag): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n const result = await timeout(this.client.getBlock(tag), 2);\n\n return true;\n } catch (e) {\n logger.info(`Chain doesnt support ${tag} tag`);\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n private async getGenesisBlock(chainId: number): Promise<Block> {\n const tag = () => {\n switch (chainId) {\n // BEVM Canary\n case 1501:\n return 4157986;\n default:\n return 'earliest';\n }\n };\n\n return this.client.getBlock(tag());\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n\n const block = await this.client.getBlock(height);\n // The finalized block could sometimes fail to fetch,\n // due to some nodes on the network falling behind the synced node.\n if (!block) {\n throw new Error(`get finalized block \"${height}\" failed `);\n }\n return block;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n // Cronos \"safe\" tag doesn't currently work as indended\n const tag =\n !this.unfinalizedBlocks &&\n this.supportsFinalization &&\n this.chainId !== 25\n ? 'safe'\n : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\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 if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\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\n async fetchBlock(blockNumber: number): Promise<EthereumBlock> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({ blockHash: block.hash });\n\n block.logs = logsRaw.map((l) => formatLog(l, block));\n block.transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n logs: block.logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n this.eventEmitter.emit('fetchBlock');\n return block;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<LightEthereumBlock> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n return {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlock[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<LightEthereumBlock[]> {\n console.log('FETCH BLOCKS LIGHT');\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\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 | LightEthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<\n EthereumLog | LightEthereumLog | EthereumLog<T> | LightEthereumLog<T>\n > {\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\n log.args = iface?.parseLog(log).args as T;\n\n return log;\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: SubqlRuntimeDatasource,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n if (transaction.input !== '0x') {\n logger.warn('No ABI provided for datasource');\n }\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\n transaction.logs =\n transaction.logs &&\n ((await Promise.all(\n transaction.logs.map(async (log) => this.parseLog(log, ds)),\n )) as Array<EthereumLog | EthereumLog<T>>);\n\n transaction.args = args;\n\n return transaction;\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -126,6 +126,27 @@ describe('Api.ethereum', () => {
126
126
  expect(erc20Transfers.length).toBe(7);
127
127
  expect(erc721Transfers.length).toBe(2);
128
128
  });
129
+ it('Null and 0x (empty) filter support for transaction data', async () => {
130
+ const beamEndpoint = 'https://mainnet.base.org/';
131
+ ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
132
+ await ethApi.init();
133
+ blockData = await fetchBlock(1104962);
134
+ // blockData.transactions[0].to = undefined;
135
+ const result = blockData.transactions.filter((tx) => {
136
+ if ((0, block_ethereum_1.filterTransactionsProcessor)(tx, { function: null })) {
137
+ return tx.hash;
138
+ }
139
+ });
140
+ expect(result.length).toBe(1);
141
+ expect(result[0].hash).toBe('0x182c5381f8fa3332a7bd676b1c819a15119972db52bd5210afead88f18fff642');
142
+ const result2 = blockData.transactions.filter((tx) => {
143
+ if ((0, block_ethereum_1.filterTransactionsProcessor)(tx, { function: '0x' })) {
144
+ return tx.hash;
145
+ }
146
+ });
147
+ expect(result2.length).toBe(1);
148
+ expect(result2[0].hash).toBe('0x182c5381f8fa3332a7bd676b1c819a15119972db52bd5210afead88f18fff642');
149
+ });
129
150
  it('Null filter support, for undefined transaction.to', async () => {
130
151
  const beamEndpoint = 'https://rpc.api.moonbeam.network';
131
152
  ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
@@ -1 +1 @@
1
- {"version":3,"file":"api.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;AAEnC,gDAAwB;AACxB,yDAAsD;AACtD,0DAM+B;AAC/B,iDAA6C;AAC7C,qDAG0B;AAE1B,sBAAsB;AACtB,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,EAAE,GAA2B;IACjC,OAAO,EAAE;QACP,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE;YACR;gBACE,OAAO,EAAE,MAAM;gBACf,IAAI,EAAE,oCAAmB,CAAC,IAAI;gBAC9B,MAAM,EAAE,E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,IAAI,0BAAW,CACtB,kCAAkC,EAClC,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU,EAAE,CAAC;QAE1D,MAAM;QACN,MAAM,GAAG,IAAI,0BAAW,CACtB,kCAAkC,EAClC,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,CAAC;QAEtD,UAAU;QACV,MAAM,GAAG,IAAI,0BAAW,CACtB,8BAA8B,EAC9B,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport path from 'path';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n EthereumBlock,\n EthereumDatasourceKind,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport {\n filterLogsProcessor,\n filterTransactionsProcessor,\n} from './block.ethereum';\n\n// Add api key to work\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst BLOCK_CONFIRMATIONS = 20;\n\nconst ds: SubqlRuntimeDatasource = {\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'test',\n kind: EthereumHandlerKind.Call,\n filter: { function: '0x23b872dd' },\n },\n ],\n },\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 16258633,\n options: { abi: 'erc721' },\n assets: new Map([\n ['erc721', { file: path.join(__dirname, '../../test/erc721.json') }],\n ]),\n};\n\njest.setTimeout(90000);\ndescribe('Api.ethereum', () => {\n let ethApi: EthereumApi;\n const eventEmitter = new EventEmitter2();\n let blockData: EthereumBlock;\n\n const fetchBlock = async (height: number) => {\n const block = await ethApi.fetchBlock(height);\n\n return block as EthereumBlock;\n };\n\n beforeEach(async () => {\n ethApi = new EthereumApi(HTTP_ENDPOINT, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(16258633);\n });\n\n it('Should format transaction in logs, and the transaction gas should be bigInt type', () => {\n expect(typeof blockData.logs[0].transaction.gas).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.blockNumber).toBe('number');\n expect(typeof blockData.logs[0].transaction.gasPrice).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.maxPriorityFeePerGas).toBe(\n 'bigint',\n );\n expect(typeof blockData.logs[0].transaction.transactionIndex).toBe(\n 'bigint',\n );\n });\n\n it('should have the ability to get receipts via transactions from all types', () => {\n expect(typeof blockData.transactions[0].receipt).toEqual('function');\n expect(typeof blockData.logs[0].transaction.receipt).toEqual('function');\n expect(typeof blockData.logs[0].transaction.from).toEqual('string');\n expect(typeof blockData.transactions[81].logs[0].transaction.from).toEqual(\n 'string',\n );\n expect(\n typeof blockData.transactions[81].logs[0].transaction.receipt,\n ).toEqual('function');\n });\n\n it('Decode nested logs in transactions', async () => {\n // Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n );\n const parsedTx = await ethApi.parseTransaction(tx, ds);\n expect(parsedTx.logs[0].args).toBeTruthy();\n });\n\n it('Should decode transaction data and not clone object', async () => {\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n );\n const parsedTx = await ethApi.parseTransaction(tx, ds);\n\n expect(parsedTx).toBe(tx);\n });\n\n it('Should return raw logs, if decode fails', async () => {\n // not Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0xed62f7a7720fe6ae05dec45ad9dd4f53034a0aae2c140d229b1151504ee9a6c9',\n );\n const parsedLog = await ethApi.parseLog(tx.logs[0], ds);\n expect(parsedLog).not.toHaveProperty('args');\n expect(parsedLog).toBeTruthy();\n });\n\n // This test is here to ensure getters aren't removed\n it('Should not clone logs when parsing args', async () => {\n const log = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n ).logs[1];\n\n const parsedLog = await ethApi.parseLog(log, ds);\n expect(parsedLog).toBe(log);\n });\n\n it('Null filter support', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('!null filter support for logs, expect to filter out', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n const filter_1: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n undefined,\n undefined,\n '!null',\n ],\n };\n\n const filter_2: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n };\n\n blockData = await fetchBlock(4015990);\n const transaction = blockData.transactions.find(\n (tx) =>\n tx.hash ===\n '0xeb2e443f2d4e784193fa13bbbae2b85e6ee459e7b7b53f8ca098ffae9b25b059',\n );\n\n const erc20Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_2),\n );\n const erc721Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_1),\n );\n\n expect(erc20Transfers.length).toBe(7);\n expect(erc721Transfers.length).toBe(2);\n });\n\n it('Null filter support, for undefined transaction.to', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n blockData.transactions[1].to = undefined;\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('Should return all tx if filter.to is not defined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n undefined,\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('filter.to Should support only null not undefined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: undefined },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(0);\n });\n\n it('If transaction is undefined, with null filter, should be supported', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n tx.to = undefined;\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('Resolves the correct tags for finalization', async () => {\n // Ethereum\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // Moonbeam\n ethApi = new EthereumApi(\n 'https://rpc.api.moonbeam.network',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // BSC\n ethApi = new EthereumApi(\n 'https://bsc-dataseed.binance.org',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n\n // Polygon\n ethApi = new EthereumApi(\n 'https://polygon.llamarpc.com',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n });\n});\n"]}
1
+ {"version":3,"file":"api.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;AAEnC,gDAAwB;AACxB,yDAAsD;AACtD,0DAM+B;AAC/B,iDAA6C;AAC7C,qDAG0B;AAE1B,sBAAsB;AACtB,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,EAAE,GAA2B;IACjC,OAA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AAU,EAAE,CAAC;QAE1D,WAAW;QACX,MAAM,GAAG,IAAI,0BAAW,CACtB,kCAAkC,EAClC,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU,EAAE,CAAC;QAE1D,MAAM;QACN,MAAM,GAAG,IAAI,0BAAW,CACtB,kCAAkC,EAClC,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,CAAC;QAEtD,UAAU;QACV,MAAM,GAAG,IAAI,0BAAW,CACtB,8BAA8B,EAC9B,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport path from 'path';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n EthereumBlock,\n EthereumDatasourceKind,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport {\n filterLogsProcessor,\n filterTransactionsProcessor,\n} from './block.ethereum';\n\n// Add api key to work\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst BLOCK_CONFIRMATIONS = 20;\n\nconst ds: SubqlRuntimeDatasource = {\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'test',\n kind: EthereumHandlerKind.Call,\n filter: { function: '0x23b872dd' },\n },\n ],\n },\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 16258633,\n options: { abi: 'erc721' },\n assets: new Map([\n ['erc721', { file: path.join(__dirname, '../../test/erc721.json') }],\n ]),\n};\n\njest.setTimeout(90000);\ndescribe('Api.ethereum', () => {\n let ethApi: EthereumApi;\n const eventEmitter = new EventEmitter2();\n let blockData: EthereumBlock;\n\n const fetchBlock = async (height: number) => {\n const block = await ethApi.fetchBlock(height);\n\n return block as EthereumBlock;\n };\n\n beforeEach(async () => {\n ethApi = new EthereumApi(HTTP_ENDPOINT, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(16258633);\n });\n\n it('Should format transaction in logs, and the transaction gas should be bigInt type', () => {\n expect(typeof blockData.logs[0].transaction.gas).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.blockNumber).toBe('number');\n expect(typeof blockData.logs[0].transaction.gasPrice).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.maxPriorityFeePerGas).toBe(\n 'bigint',\n );\n expect(typeof blockData.logs[0].transaction.transactionIndex).toBe(\n 'bigint',\n );\n });\n\n it('should have the ability to get receipts via transactions from all types', () => {\n expect(typeof blockData.transactions[0].receipt).toEqual('function');\n expect(typeof blockData.logs[0].transaction.receipt).toEqual('function');\n expect(typeof blockData.logs[0].transaction.from).toEqual('string');\n expect(typeof blockData.transactions[81].logs[0].transaction.from).toEqual(\n 'string',\n );\n expect(\n typeof blockData.transactions[81].logs[0].transaction.receipt,\n ).toEqual('function');\n });\n\n it('Decode nested logs in transactions', async () => {\n // Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n );\n const parsedTx = await ethApi.parseTransaction(tx, ds);\n expect(parsedTx.logs[0].args).toBeTruthy();\n });\n\n it('Should decode transaction data and not clone object', async () => {\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n );\n const parsedTx = await ethApi.parseTransaction(tx, ds);\n\n expect(parsedTx).toBe(tx);\n });\n\n it('Should return raw logs, if decode fails', async () => {\n // not Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0xed62f7a7720fe6ae05dec45ad9dd4f53034a0aae2c140d229b1151504ee9a6c9',\n );\n const parsedLog = await ethApi.parseLog(tx.logs[0], ds);\n expect(parsedLog).not.toHaveProperty('args');\n expect(parsedLog).toBeTruthy();\n });\n\n // This test is here to ensure getters aren't removed\n it('Should not clone logs when parsing args', async () => {\n const log = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n ).logs[1];\n\n const parsedLog = await ethApi.parseLog(log, ds);\n expect(parsedLog).toBe(log);\n });\n\n it('Null filter support', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('!null filter support for logs, expect to filter out', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n const filter_1: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n undefined,\n undefined,\n '!null',\n ],\n };\n\n const filter_2: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n };\n\n blockData = await fetchBlock(4015990);\n const transaction = blockData.transactions.find(\n (tx) =>\n tx.hash ===\n '0xeb2e443f2d4e784193fa13bbbae2b85e6ee459e7b7b53f8ca098ffae9b25b059',\n );\n\n const erc20Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_2),\n );\n const erc721Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_1),\n );\n\n expect(erc20Transfers.length).toBe(7);\n expect(erc721Transfers.length).toBe(2);\n });\n\n it('Null and 0x (empty) filter support for transaction data', async () => {\n const beamEndpoint = 'https://mainnet.base.org/';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(1104962);\n // blockData.transactions[0].to = undefined;\n const result = blockData.transactions.filter((tx) => {\n if (filterTransactionsProcessor(tx, { function: null })) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(1);\n expect(result[0].hash).toBe(\n '0x182c5381f8fa3332a7bd676b1c819a15119972db52bd5210afead88f18fff642',\n );\n\n const result2 = blockData.transactions.filter((tx) => {\n if (filterTransactionsProcessor(tx, { function: '0x' })) {\n return tx.hash;\n }\n });\n expect(result2.length).toBe(1);\n expect(result2[0].hash).toBe(\n '0x182c5381f8fa3332a7bd676b1c819a15119972db52bd5210afead88f18fff642',\n );\n });\n\n it('Null filter support, for undefined transaction.to', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n blockData.transactions[1].to = undefined;\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('Should return all tx if filter.to is not defined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n undefined,\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('filter.to Should support only null not undefined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: undefined },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(0);\n });\n\n it('If transaction is undefined, with null filter, should be supported', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n tx.to = undefined;\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('Resolves the correct tags for finalization', async () => {\n // Ethereum\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // Moonbeam\n ethApi = new EthereumApi(\n 'https://rpc.api.moonbeam.network',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // BSC\n ethApi = new EthereumApi(\n 'https://bsc-dataseed.binance.org',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n\n // Polygon\n ethApi = new EthereumApi(\n 'https://polygon.llamarpc.com',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n });\n});\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
5
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1 +1 @@
1
- {"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,gDAM0B;AAM1B,wDAA6D;AAC7D,kEAA+D;AAC/D,8CAAuD;AACvD,qDAI0B;AAI1B,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,sBAIvC;IAKC,YACsC,OAAwB,EAC5D,qBAAmE,EACnE,YAA2B,EAC3B,UAAsB;QAEtB,KAAK,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;QALP,YAAO,GAAP,OAAO,CAAiB;QAJtD,uBAAkB,GAAiB,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC;QAUxE,IAAI,CAAC,UAAU,GAAG,IAAI,+BAAkB,CAAC,UAAU,CAAC,CAAC;QAErD,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,IAAI;QACR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ACT,eAAe,EACf,oBAAoB,CACrB,CAAC;SACH;aAAM;YACL,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;CACF,CAAA;AApLY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAAkB,iCAAe;QACrC,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GAbb,kBAAkB,CAoL9B;AApLY,gDAAkB","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n NodeConfig,\n profilerWrap,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumNetworkConfig,\n LightEthereumBlock,\n} from '@subql/types-ethereum';\nimport { EthereumNodeConfig } from '../configure/NodeConfig';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { isOnlyEventHandlers } from '../utils/project';\nimport {\n EthereumApiConnection,\n FetchFunc,\n GetFetchFunc,\n} from './api.connection';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class EthereumApiService extends ApiService<\n EthereumApi,\n SafeEthProvider,\n EthereumBlock[] | LightEthereumBlock[]\n> {\n private fetchBlocksFunction: FetchFunc;\n private fetchBlocksBatches: GetFetchFunc = () => this.fetchBlocksFunction;\n private nodeConfig: EthereumNodeConfig;\n\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) {\n super(connectionPoolService, eventEmitter);\n this.nodeConfig = new EthereumNodeConfig(nodeConfig);\n\n this.updateBlockFetching();\n }\n\n async init(): Promise<EthereumApiService> {\n let network: EthereumNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const endpoints = Array.isArray(network.endpoint)\n ? network.endpoint\n : [network.endpoint];\n\n if (this.nodeConfig.primaryNetworkEndpoint) {\n endpoints.push(this.nodeConfig.primaryNetworkEndpoint);\n }\n\n await this.createConnections(\n network,\n (endpoint) =>\n EthereumApiConnection.create(\n endpoint,\n this.nodeConfig.blockConfirmations,\n this.fetchBlocksBatches,\n this.eventEmitter,\n this.nodeConfig.unfinalizedBlocks,\n ),\n //eslint-disable-next-line @typescript-eslint/require-await\n async (connection: EthereumApiConnection) => {\n const api = connection.unsafeApi;\n return api.getChainId().toString();\n },\n );\n\n return this;\n }\n\n protected metadataMismatchError(\n metadata: string,\n expected: string,\n actual: string,\n ): Error {\n return Error(\n `Value of ${metadata} does not match across all endpoints. Please check that your endpoints are for the same network.\\n\n Expected: ${expected}\n Actual: ${actual}`,\n );\n }\n\n get api(): EthereumApi {\n return this.unsafeApi;\n }\n\n safeApi(height: number): SafeEthProvider {\n const maxRetries = 5;\n\n const retryErrorCodes = [\n 'UNKNOWN_ERROR',\n 'NOT_IMPLEMENTED',\n 'NETWORK_ERROR',\n 'SERVER_ERROR',\n 'TIMEOUT',\n 'BAD_DATA',\n 'CANCELLED',\n ];\n\n const handler: ProxyHandler<SafeEthProvider> = {\n get: (target, prop, receiver) => {\n const originalMethod = target[prop as keyof SafeEthProvider];\n if (typeof originalMethod === 'function') {\n return async (...args: any[]) => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error: any) {\n // other than retryErrorCodes, other errors does not have anything to do with network request, retrying would not change its outcome\n if (!retryErrorCodes.includes(error?.code)) {\n throw error;\n }\n\n logger.warn(\n `Request failed with api at height ${height} (retry ${retries}): ${error.message}`,\n );\n throwingError = error;\n currentApi = this.unsafeApi.getSafeApi(height);\n retries++;\n }\n }\n\n logger.error(\n `Maximum retries (${maxRetries}) exceeded for api at height ${height}`,\n );\n throw throwingError;\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n };\n\n return new Proxy(this.unsafeApi.getSafeApi(height), handler);\n }\n\n private async fetchFullBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<EthereumBlock[]> {\n return api.fetchBlocks(batch);\n }\n\n private async fetchLightBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<LightEthereumBlock[]> {\n return api.fetchBlocksLight(batch);\n }\n\n updateBlockFetching(): void {\n const onlyEventHandlers = isOnlyEventHandlers(this.project);\n const skipTransactions =\n this.nodeConfig.skipTransactions && onlyEventHandlers;\n\n if (this.nodeConfig.skipTransactions) {\n if (onlyEventHandlers) {\n logger.info(\n 'skipTransactions is enabled, only events and block headers will be fetched.',\n );\n } else {\n logger.info(\n `skipTransactions is disabled, the project contains handlers that aren't event handlers.`,\n );\n }\n } else {\n if (onlyEventHandlers) {\n logger.warn(\n 'skipTransactions is disabled, the project contains only event handlers, it could be enabled to improve indexing performance.',\n );\n } else {\n logger.info(`skipTransactions is disabled.`);\n }\n }\n\n const fetchFunc = skipTransactions\n ? this.fetchLightBlocksBatch.bind(this)\n : this.fetchFullBlocksBatch.bind(this);\n\n if (this.nodeConfig?.profiler) {\n this.fetchBlocksFunction = profilerWrap(\n fetchFunc,\n 'SubstrateUtil',\n 'fetchBlocksBatches',\n );\n } else {\n this.fetchBlocksFunction = fetchFunc;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,gDAM0B;AAM1B,wDAA6D;AAC7D,kEAA+D;AAC/D,8CAAuD;AACvD,qDAI0B;AAI1B,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;A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BACrB,MAAM,CAAC,IAAI,CACT,8HAA8H,CAC/H,CAAC;aACH;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;aAC9C;SACF;QAED,MAAM,SAAS,GAAG,gBAAgB;YAChC,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;YACvC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,QAAQ,EAAE;YAC7B,IAAI,CAAC,mBAAmB,GAAG,IAAA,wBAAY,EACrC,SAAS,EACT,eAAe,EACf,oBAAoB,CACrB,CAAC;SACH;aAAM;YACL,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;CACF,CAAA;AApLY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAAkB,iCAAe;QACrC,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GAbb,kBAAkB,CAoL9B;AApLY,gDAAkB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n NodeConfig,\n profilerWrap,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumNetworkConfig,\n LightEthereumBlock,\n} from '@subql/types-ethereum';\nimport { EthereumNodeConfig } from '../configure/NodeConfig';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { isOnlyEventHandlers } from '../utils/project';\nimport {\n EthereumApiConnection,\n FetchFunc,\n GetFetchFunc,\n} from './api.connection';\nimport { EthereumApi } from './api.ethereum';\nimport SafeEthProvider from './safe-api';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class EthereumApiService extends ApiService<\n EthereumApi,\n SafeEthProvider,\n EthereumBlock[] | LightEthereumBlock[]\n> {\n private fetchBlocksFunction: FetchFunc;\n private fetchBlocksBatches: GetFetchFunc = () => this.fetchBlocksFunction;\n private nodeConfig: EthereumNodeConfig;\n\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) {\n super(connectionPoolService, eventEmitter);\n this.nodeConfig = new EthereumNodeConfig(nodeConfig);\n\n this.updateBlockFetching();\n }\n\n async init(): Promise<EthereumApiService> {\n let network: EthereumNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const endpoints = Array.isArray(network.endpoint)\n ? network.endpoint\n : [network.endpoint];\n\n if (this.nodeConfig.primaryNetworkEndpoint) {\n endpoints.push(this.nodeConfig.primaryNetworkEndpoint);\n }\n\n await this.createConnections(\n network,\n (endpoint) =>\n EthereumApiConnection.create(\n endpoint,\n this.nodeConfig.blockConfirmations,\n this.fetchBlocksBatches,\n this.eventEmitter,\n this.nodeConfig.unfinalizedBlocks,\n ),\n //eslint-disable-next-line @typescript-eslint/require-await\n async (connection: EthereumApiConnection) => {\n const api = connection.unsafeApi;\n return api.getChainId().toString();\n },\n );\n\n return this;\n }\n\n protected metadataMismatchError(\n metadata: string,\n expected: string,\n actual: string,\n ): Error {\n return Error(\n `Value of ${metadata} does not match across all endpoints. Please check that your endpoints are for the same network.\\n\n Expected: ${expected}\n Actual: ${actual}`,\n );\n }\n\n get api(): EthereumApi {\n return this.unsafeApi;\n }\n\n safeApi(height: number): SafeEthProvider {\n const maxRetries = 5;\n\n const retryErrorCodes = [\n 'UNKNOWN_ERROR',\n 'NOT_IMPLEMENTED',\n 'NETWORK_ERROR',\n 'SERVER_ERROR',\n 'TIMEOUT',\n 'BAD_DATA',\n 'CANCELLED',\n ];\n\n const handler: ProxyHandler<SafeEthProvider> = {\n get: (target, prop, receiver) => {\n const originalMethod = target[prop as keyof SafeEthProvider];\n if (typeof originalMethod === 'function') {\n return async (...args: any[]) => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error: any) {\n // other than retryErrorCodes, other errors does not have anything to do with network request, retrying would not change its outcome\n if (!retryErrorCodes.includes(error?.code)) {\n throw error;\n }\n\n logger.warn(\n `Request failed with api at height ${height} (retry ${retries}): ${error.message}`,\n );\n throwingError = error;\n currentApi = this.unsafeApi.getSafeApi(height);\n retries++;\n }\n }\n\n logger.error(\n `Maximum retries (${maxRetries}) exceeded for api at height ${height}`,\n );\n throw throwingError;\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n };\n\n return new Proxy(this.unsafeApi.getSafeApi(height), handler);\n }\n\n private async fetchFullBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<EthereumBlock[]> {\n return api.fetchBlocks(batch);\n }\n\n private async fetchLightBlocksBatch(\n api: EthereumApi,\n batch: number[],\n ): Promise<LightEthereumBlock[]> {\n return api.fetchBlocksLight(batch);\n }\n\n updateBlockFetching(): void {\n const onlyEventHandlers = isOnlyEventHandlers(this.project);\n const skipTransactions =\n this.nodeConfig.skipTransactions && onlyEventHandlers;\n\n if (this.nodeConfig.skipTransactions) {\n if (onlyEventHandlers) {\n logger.info(\n 'skipTransactions is enabled, only events and block headers will be fetched.',\n );\n } else {\n logger.info(\n `skipTransactions is disabled, the project contains handlers that aren't event handlers.`,\n );\n }\n } else {\n if (onlyEventHandlers) {\n logger.warn(\n 'skipTransactions is disabled, the project contains only event handlers, it could be enabled to improve indexing performance.',\n );\n } else {\n logger.info(`skipTransactions is disabled.`);\n }\n }\n\n const fetchFunc = skipTransactions\n ? this.fetchLightBlocksBatch.bind(this)\n : this.fetchFullBlocksBatch.bind(this);\n\n if (this.nodeConfig?.profiler) {\n this.fetchBlocksFunction = profilerWrap(\n fetchFunc,\n 'SubstrateUtil',\n 'fetchBlocksBatches',\n );\n } else {\n this.fetchBlocksFunction = fetchFunc;\n }\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  const event_emitter_1 = require("@nestjs/event-emitter");
@@ -1 +1 @@
1
- {"version":3,"file":"api.service.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAI0B;AAC1B,qCAAwC;AACxC,mCAA+B;AAE/B,iEAA4D;AAE5D,sBAAsB;AACtB,MAAM,WAAW,GAAG,wCAAwC,CAAC;AAC7D,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,QAAQ,CAAC;YACpB,OAAO,EAAE,GAAG;SACb;QACD,WAAW,EAAE,EAAE;QACf,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI,uBAAa,CAAC,EAAE,CAAC;QAC7B,SAAS,EAAE,EAAE;KACP,CAAC;AACX,CAAC;AAED,MAAM,iBAAiB,GAAG,KAAK,EAC7B,WAAmB,aAAa,EACiB,EAAE;IACnD,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;QAC5C,SAAS,EAAE;YACT,iCAAqB;YACrB,sCAA0B;YAC1B;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBAC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AAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC;QAE9D,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,QAAU,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,MAAM,CACV,UAAU;aACP,OAAO,CAAC,QAAQ,CAAC;aACjB,OAAO,CAAC,2CAA2C,CAAC,CACxD,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACpE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAC/D,MAAM,MAAM,CACV,UAAU;aACP,OAAO,CAAC,QAAQ,CAAC;aACjB,OAAO,CAAC,2CAA2C,CAAC,CACxD,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;QAErD,MAAM,CAAC,OAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { INestApplication } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { Test } from '@nestjs/testing';\nimport {\n ConnectionPoolService,\n ConnectionPoolStateManager,\n NodeConfig,\n} from '@subql/node-core';\nimport { GraphQLSchema } from 'graphql';\nimport { range } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiService } from './api.service.ethereum';\n\n// Add api key to work\nconst WS_ENDPOINT = 'wss://eth.api.onfinality.io/ws?apikey=';\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\n\nfunction testSubqueryProject(endpoint: string): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n chainId: '1',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as any;\n}\n\nconst prepareApiService = async (\n endpoint: string = HTTP_ENDPOINT,\n): Promise<[EthereumApiService, INestApplication]> => {\n const module = await Test.createTestingModule({\n providers: [\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: NodeConfig,\n useFactory: () => ({}),\n },\n {\n provide: 'ISubqueryProject',\n useFactory: () => testSubqueryProject(endpoint),\n },\n EthereumApiService,\n ],\n imports: [EventEmitterModule.forRoot()],\n }).compile();\n\n const app = module.createNestApplication();\n await app.init();\n const apiService = app.get(EthereumApiService);\n await apiService.init();\n return [apiService, app];\n};\n\njest.setTimeout(90000);\ndescribe('ApiService', () => {\n let apiService: EthereumApiService;\n let app: INestApplication;\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService();\n });\n\n afterEach(async () => {\n return app?.close();\n });\n\n it('can instantiate api', () => {\n expect(apiService.api.getChainId()).toEqual(1);\n });\n\n it('can fetch blocks', async () => {\n await expect(\n apiService.api.fetchBlocks(range(12369621, 12369625)),\n ).resolves.toHaveLength(4);\n });\n\n it('can get the finalized height', async () => {\n const height = await apiService.api.getFinalizedBlockHeight();\n\n console.log('Finalized height', height);\n expect(height).toBeGreaterThan(16_000_000);\n });\n\n it('ensure api errorCode is exposed when throwing', async () => {\n await expect(\n apiService\n .safeApi(17520376)\n .getCode('0x75F0398549C9fDEa03BbDde388361827cb376D5'),\n ).rejects.toHaveProperty('code', 'INVALID_ARGUMENT');\n });\n it('should not retry on any errors not in the retry list', async () => {\n const callSpy = jest.spyOn(apiService.unsafeApi, 'getSafeApi');\n await expect(\n apiService\n .safeApi(17520376)\n .getCode('0x75F0398549C9fDEa03BbDde388361827cb376D5'),\n ).rejects.toHaveProperty('code', 'INVALID_ARGUMENT');\n\n expect(callSpy).toHaveBeenCalledTimes(1);\n });\n});\n"]}
1
+ {"version":3,"file":"api.service.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAI0B;AAC1B,qCAAwC;AACxC,mCAA+B;AAE/B,iEAA4D;AAE5D,sBAAsB;AACtB,MAAM,WAAW,GAAG,wCAAwC,CAAC;AAC7D,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,QAAQ,CAAC;YACpB,OAAO,EAAE,GAAG;SACb;QACD,WAAW,EAAE,EAAE;QACf,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI,uBAAa,CAAC,EAAE,CAAC;QAC7B,SAAS,EAAE,EAAE;KACP,CAAC;AACX,CAAC;AAED,MAAM,iBAAiB,GAAG,KAAK,EAC7B,WAAmB,aAAa,EACiB,EAAE;IACnD,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;QAC5C,SAAS,EAAE;YACT,iCAAqB;YACrB,sCAA0B;YAC1B;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,UAAU,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,QAAQ,CAAC;aAChD;YAC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,IAAI,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC;QAE9D,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,QAAU,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,MAAM,CACV,UAAU;aACP,OAAO,CAAC,QAAQ,CAAC;aACjB,OAAO,CAAC,2CAA2C,CAAC,CACxD,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACpE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAC/D,MAAM,MAAM,CACV,UAAU;aACP,OAAO,CAAC,QAAQ,CAAC;aACjB,OAAO,CAAC,2CAA2C,CAAC,CACxD,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;QAErD,MAAM,CAAC,OAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { INestApplication } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { Test } from '@nestjs/testing';\nimport {\n ConnectionPoolService,\n ConnectionPoolStateManager,\n NodeConfig,\n} from '@subql/node-core';\nimport { GraphQLSchema } from 'graphql';\nimport { range } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiService } from './api.service.ethereum';\n\n// Add api key to work\nconst WS_ENDPOINT = 'wss://eth.api.onfinality.io/ws?apikey=';\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\n\nfunction testSubqueryProject(endpoint: string): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n chainId: '1',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as any;\n}\n\nconst prepareApiService = async (\n endpoint: string = HTTP_ENDPOINT,\n): Promise<[EthereumApiService, INestApplication]> => {\n const module = await Test.createTestingModule({\n providers: [\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: NodeConfig,\n useFactory: () => ({}),\n },\n {\n provide: 'ISubqueryProject',\n useFactory: () => testSubqueryProject(endpoint),\n },\n EthereumApiService,\n ],\n imports: [EventEmitterModule.forRoot()],\n }).compile();\n\n const app = module.createNestApplication();\n await app.init();\n const apiService = app.get(EthereumApiService);\n await apiService.init();\n return [apiService, app];\n};\n\njest.setTimeout(90000);\ndescribe('ApiService', () => {\n let apiService: EthereumApiService;\n let app: INestApplication;\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService();\n });\n\n afterEach(async () => {\n return app?.close();\n });\n\n it('can instantiate api', () => {\n expect(apiService.api.getChainId()).toEqual(1);\n });\n\n it('can fetch blocks', async () => {\n await expect(\n apiService.api.fetchBlocks(range(12369621, 12369625)),\n ).resolves.toHaveLength(4);\n });\n\n it('can get the finalized height', async () => {\n const height = await apiService.api.getFinalizedBlockHeight();\n\n console.log('Finalized height', height);\n expect(height).toBeGreaterThan(16_000_000);\n });\n\n it('ensure api errorCode is exposed when throwing', async () => {\n await expect(\n apiService\n .safeApi(17520376)\n .getCode('0x75F0398549C9fDEa03BbDde388361827cb376D5'),\n ).rejects.toHaveProperty('code', 'INVALID_ARGUMENT');\n });\n it('should not retry on any errors not in the retry list', async () => {\n const callSpy = jest.spyOn(apiService.unsafeApi, 'getSafeApi');\n await expect(\n apiService\n .safeApi(17520376)\n .getCode('0x75F0398549C9fDEa03BbDde388361827cb376D5'),\n ).rejects.toHaveProperty('code', 'INVALID_ARGUMENT');\n\n expect(callSpy).toHaveBeenCalledTimes(1);\n });\n});\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.isFullBlock = exports.filterLogsProcessor = exports.filterTransactionsProcessor = exports.filterBlockTimestamp = exports.filterBlocksProcessor = void 0;
@@ -48,7 +48,12 @@ function filterTransactionsProcessor(transaction, filter, address) {
48
48
  !(0, string_1.stringNormalizedEq)(address, transaction.to)) {
49
49
  return false;
50
50
  }
51
- if (filter.function &&
51
+ if (filter.function === null || filter.function === '0x') {
52
+ if (transaction.input !== '0x') {
53
+ return false;
54
+ }
55
+ }
56
+ else if (filter.function !== undefined &&
52
57
  transaction.input.indexOf((0, string_1.functionToSighash)(filter.function)) !== 0) {
53
58
  return false;
54
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"block.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/block.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAA6C;AAY7C,4CAKyB;AAEzB,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,gBAAgB,CAAC,CAAC;AAE3C,SAAgB,qBAAqB,CACnC,KAAoB,EACpB,MAA2B,EAC3B,OAAgB;IAEhB,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACxD,OAAO,KAAK,CAAC;KACd;IACD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAE;QACrB,OAA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CAAC,CAAC,CAAC,CAAC,EAAE;gBACpD,OAAO,KAAK,CAAC;aACd;SACF;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAhCD,kDAgCC;AAED,SAAgB,WAAW,CAAC,KAAmB;IAC7C,4IAA4I;IAC5I,OAAO,OAAQ,KAAuB,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;AACtE,CAAC;AAHD,kCAGC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { getLogger } from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumTransactionFilter,\n EthereumLog,\n EthereumLogFilter,\n EthereumBlockFilter,\n EthereumTransaction,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport { SubqlProjectBlockFilter } from '../configure/SubqueryProject';\nimport { BlockContent } from '../indexer/types';\nimport {\n eventToTopic,\n functionToSighash,\n hexStringEq,\n stringNormalizedEq,\n} from '../utils/string';\n\nconst logger = getLogger('block.ethereum');\n\nexport function filterBlocksProcessor(\n block: EthereumBlock,\n filter: EthereumBlockFilter,\n address?: string,\n): boolean {\n if (filter?.modulo && block.number % filter.modulo !== 0) {\n return false;\n }\n if (filter?.timestamp) {\n return filterBlockTimestamp(block, filter as SubqlProjectBlockFilter);\n }\n return true;\n}\n\nexport function filterBlockTimestamp(\n block: EthereumBlock,\n filter: SubqlProjectBlockFilter,\n): boolean {\n const unixTimestamp = Number(block.timestamp) * 1000; // Multiply to add MS\n if (unixTimestamp > filter.cronSchedule.next) {\n logger.info(\n `Block with timestamp ${new Date(\n unixTimestamp,\n ).toString()} is about to be indexed`,\n );\n logger.info(\n `Next block will be indexed at ${new Date(\n filter.cronSchedule.next,\n ).toString()}`,\n );\n filter.cronSchedule.schedule.prev();\n return true;\n } else {\n filter.cronSchedule.schedule.prev();\n return false;\n }\n}\n\nexport function filterTransactionsProcessor(\n transaction: EthereumTransaction,\n filter: EthereumTransactionFilter,\n address?: string,\n): boolean {\n if (!filter) return true;\n\n if (\n filter.to === null &&\n !(transaction.to === null || transaction.to === undefined)\n ) {\n return false;\n }\n\n if (filter.to && !stringNormalizedEq(filter.to, transaction.to)) {\n return false;\n }\n if (filter.from && !stringNormalizedEq(filter.from, transaction.from)) {\n return false;\n }\n if (\n address &&\n filter.to === undefined &&\n !stringNormalizedEq(address, transaction.to)\n ) {\n return false;\n }\n if (\n filter.function &&\n transaction.input.indexOf(functionToSighash(filter.function)) !== 0\n ) {\n return false;\n }\n return true;\n}\n\nexport function filterLogsProcessor(\n log: EthereumLog | LightEthereumLog,\n filter: EthereumLogFilter,\n address?: string,\n): boolean {\n if (address && !stringNormalizedEq(address, log.address)) {\n return false;\n }\n\n if (!filter) return true;\n\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n\n if (!log.topics[i]) {\n return false;\n }\n\n if (topic === '!null') {\n return true;\n }\n\n if (!hexStringEq(eventToTopic(topic), log.topics[i])) {\n return false;\n }\n }\n }\n return true;\n}\n\nexport function isFullBlock(block: BlockContent): block is EthereumBlock {\n // Light etherum block just contains transaction hashes for transactions. If the block has no transactions then both types would be the same\n return typeof (block as EthereumBlock).transactions[0] !== 'string';\n}\n"]}
1
+ {"version":3,"file":"block.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/block.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAA6C;AAY7C,4CAKyB;AAEzB,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,gBAAgB,CAAC,CAAC;AAE3C,SAAgB,qBAAqB,CACnC,KAAoB,EACpB,MAA2B,EAC3B,OAAgB;IAEhB,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACxD,OAAO,KAAK,CAAC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ACV,SAAS;aACV;YAED,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;gBAClB,OAAO,KAAK,CAAC;aACd;YAED,IAAI,KAAK,KAAK,OAAO,EAAE;gBACrB,OAAO,IAAI,CAAC;aACb;YAED,IAAI,CAAC,IAAA,oBAAW,EAAC,IAAA,qBAAY,EAAC,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;gBACpD,OAAO,KAAK,CAAC;aACd;SACF;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAhCD,kDAgCC;AAED,SAAgB,WAAW,CAAC,KAAmB;IAC7C,4IAA4I;IAC5I,OAAO,OAAQ,KAAuB,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;AACtE,CAAC;AAHD,kCAGC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { getLogger } from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumTransactionFilter,\n EthereumLog,\n EthereumLogFilter,\n EthereumBlockFilter,\n EthereumTransaction,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport { SubqlProjectBlockFilter } from '../configure/SubqueryProject';\nimport { BlockContent } from '../indexer/types';\nimport {\n eventToTopic,\n functionToSighash,\n hexStringEq,\n stringNormalizedEq,\n} from '../utils/string';\n\nconst logger = getLogger('block.ethereum');\n\nexport function filterBlocksProcessor(\n block: EthereumBlock,\n filter: EthereumBlockFilter,\n address?: string,\n): boolean {\n if (filter?.modulo && block.number % filter.modulo !== 0) {\n return false;\n }\n if (filter?.timestamp) {\n return filterBlockTimestamp(block, filter as SubqlProjectBlockFilter);\n }\n return true;\n}\n\nexport function filterBlockTimestamp(\n block: EthereumBlock,\n filter: SubqlProjectBlockFilter,\n): boolean {\n const unixTimestamp = Number(block.timestamp) * 1000; // Multiply to add MS\n if (unixTimestamp > filter.cronSchedule.next) {\n logger.info(\n `Block with timestamp ${new Date(\n unixTimestamp,\n ).toString()} is about to be indexed`,\n );\n logger.info(\n `Next block will be indexed at ${new Date(\n filter.cronSchedule.next,\n ).toString()}`,\n );\n filter.cronSchedule.schedule.prev();\n return true;\n } else {\n filter.cronSchedule.schedule.prev();\n return false;\n }\n}\n\nexport function filterTransactionsProcessor(\n transaction: EthereumTransaction,\n filter: EthereumTransactionFilter,\n address?: string,\n): boolean {\n if (!filter) return true;\n\n if (\n filter.to === null &&\n !(transaction.to === null || transaction.to === undefined)\n ) {\n return false;\n }\n\n if (filter.to && !stringNormalizedEq(filter.to, transaction.to)) {\n return false;\n }\n if (filter.from && !stringNormalizedEq(filter.from, transaction.from)) {\n return false;\n }\n if (\n address &&\n filter.to === undefined &&\n !stringNormalizedEq(address, transaction.to)\n ) {\n return false;\n }\n if (filter.function === null || filter.function === '0x') {\n if (transaction.input !== '0x') {\n return false;\n }\n } else if (\n filter.function !== undefined &&\n transaction.input.indexOf(functionToSighash(filter.function)) !== 0\n ) {\n return false;\n }\n\n return true;\n}\n\nexport function filterLogsProcessor(\n log: EthereumLog | LightEthereumLog,\n filter: EthereumLogFilter,\n address?: string,\n): boolean {\n if (address && !stringNormalizedEq(address, log.address)) {\n return false;\n }\n\n if (!filter) return true;\n\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n\n if (!log.topics[i]) {\n return false;\n }\n\n if (topic === '!null') {\n return true;\n }\n\n if (!hexStringEq(eventToTopic(topic), log.topics[i])) {\n return false;\n }\n }\n }\n return true;\n}\n\nexport function isFullBlock(block: BlockContent): block is EthereumBlock {\n // Light etherum block just contains transaction hashes for transactions. If the block has no transactions then both types would be the same\n return typeof (block as EthereumBlock).transactions[0] !== 'string';\n}\n"]}