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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/configure/NodeConfig.d.ts +21 -0
  4. package/dist/configure/NodeConfig.js +31 -0
  5. package/dist/configure/NodeConfig.js.map +1 -0
  6. package/dist/configure/SubqueryProject.d.ts +21 -29
  7. package/dist/configure/SubqueryProject.js +48 -72
  8. package/dist/configure/SubqueryProject.js.map +1 -1
  9. package/dist/configure/configure.module.d.ts +2 -2
  10. package/dist/configure/configure.module.js +19 -89
  11. package/dist/configure/configure.module.js.map +1 -1
  12. package/dist/ethereum/api.connection.d.ts +7 -7
  13. package/dist/ethereum/api.connection.js +4 -4
  14. package/dist/ethereum/api.connection.js.map +1 -1
  15. package/dist/ethereum/api.ethereum.d.ts +14 -8
  16. package/dist/ethereum/api.ethereum.js +24 -13
  17. package/dist/ethereum/api.ethereum.js.map +1 -1
  18. package/dist/ethereum/api.ethereum.test.js +29 -32
  19. package/dist/ethereum/api.ethereum.test.js.map +1 -1
  20. package/dist/ethereum/api.service.ethereum.d.ts +9 -7
  21. package/dist/ethereum/api.service.ethereum.js +56 -64
  22. package/dist/ethereum/api.service.ethereum.js.map +1 -1
  23. package/dist/ethereum/api.service.ethereum.test.js +8 -13
  24. package/dist/ethereum/api.service.ethereum.test.js.map +1 -1
  25. package/dist/ethereum/block.ethereum.d.ts +6 -15
  26. package/dist/ethereum/block.ethereum.js +52 -76
  27. package/dist/ethereum/block.ethereum.js.map +1 -1
  28. package/dist/ethereum/ethers/celo/celo-json-rpc-batch-provider.spec.js +3 -6
  29. package/dist/ethereum/ethers/celo/celo-json-rpc-batch-provider.spec.js.map +1 -1
  30. package/dist/ethereum/ethers/celo/celo-json-rpc-provider.spec.js +3 -6
  31. package/dist/ethereum/ethers/celo/celo-json-rpc-provider.spec.js.map +1 -1
  32. package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js +3 -6
  33. package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js.map +1 -1
  34. package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +7 -7
  35. package/dist/indexer/blockDispatcher/block-dispatcher.service.js +7 -6
  36. package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
  37. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +4 -4
  38. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +9 -18
  39. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
  40. package/dist/indexer/dictionary.service.d.ts +3 -3
  41. package/dist/indexer/dictionary.service.js +7 -5
  42. package/dist/indexer/dictionary.service.js.map +1 -1
  43. package/dist/indexer/dynamic-ds.service.d.ts +3 -3
  44. package/dist/indexer/dynamic-ds.service.js.map +1 -1
  45. package/dist/indexer/fetch.module.js +8 -10
  46. package/dist/indexer/fetch.module.js.map +1 -1
  47. package/dist/indexer/fetch.service.d.ts +10 -10
  48. package/dist/indexer/fetch.service.js +22 -43
  49. package/dist/indexer/fetch.service.js.map +1 -1
  50. package/dist/indexer/fetch.service.spec.js +25 -45
  51. package/dist/indexer/fetch.service.spec.js.map +1 -1
  52. package/dist/indexer/indexer.manager.d.ts +10 -12
  53. package/dist/indexer/indexer.manager.js +20 -30
  54. package/dist/indexer/indexer.manager.js.map +1 -1
  55. package/dist/indexer/project.service.d.ts +8 -6
  56. package/dist/indexer/project.service.js +19 -12
  57. package/dist/indexer/project.service.js.map +1 -1
  58. package/dist/indexer/project.service.test.d.ts +1 -0
  59. package/dist/indexer/project.service.test.js +26 -0
  60. package/dist/indexer/project.service.test.js.map +1 -0
  61. package/dist/indexer/sandbox.service.d.ts +1 -1
  62. package/dist/indexer/sandbox.service.js +1 -0
  63. package/dist/indexer/sandbox.service.js.map +1 -1
  64. package/dist/indexer/types.d.ts +2 -11
  65. package/dist/indexer/types.js +0 -6
  66. package/dist/indexer/types.js.map +1 -1
  67. package/dist/indexer/unfinalizedBlocks.service.d.ts +4 -4
  68. package/dist/indexer/unfinalizedBlocks.service.js +25 -1
  69. package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
  70. package/dist/indexer/worker/worker.d.ts +4 -28
  71. package/dist/indexer/worker/worker.js +8 -71
  72. package/dist/indexer/worker/worker.js.map +1 -1
  73. package/dist/indexer/worker/worker.module.js +2 -2
  74. package/dist/indexer/worker/worker.module.js.map +1 -1
  75. package/dist/indexer/worker/worker.service.d.ts +11 -13
  76. package/dist/indexer/worker/worker.service.js +14 -56
  77. package/dist/indexer/worker/worker.service.js.map +1 -1
  78. package/dist/indexer/worker/worker.unfinalizedBlocks.service.d.ts +4 -8
  79. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +8 -7
  80. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -1
  81. package/dist/indexer/worker-fetch.module.d.ts +2 -0
  82. package/dist/indexer/{indexer.module.js → worker-fetch.module.js} +10 -33
  83. package/dist/indexer/worker-fetch.module.js.map +1 -0
  84. package/dist/init.js +1 -1
  85. package/dist/init.js.map +1 -1
  86. package/dist/main.js +4 -8
  87. package/dist/main.js.map +1 -1
  88. package/dist/subcommands/reindex.init.js +1 -2
  89. package/dist/subcommands/reindex.init.js.map +1 -1
  90. package/dist/subcommands/reindex.module.js +10 -6
  91. package/dist/subcommands/reindex.module.js.map +1 -1
  92. package/dist/subcommands/testing.init.js +2 -4
  93. package/dist/subcommands/testing.init.js.map +1 -1
  94. package/dist/subcommands/testing.module.js +3 -8
  95. package/dist/subcommands/testing.module.js.map +1 -1
  96. package/dist/subcommands/testing.service.d.ts +8 -5
  97. package/dist/subcommands/testing.service.js +3 -8
  98. package/dist/subcommands/testing.service.js.map +1 -1
  99. package/dist/utils/project.d.ts +5 -4
  100. package/dist/utils/project.js +17 -1
  101. package/dist/utils/project.js.map +1 -1
  102. package/dist/yargs.d.ts +7 -90
  103. package/dist/yargs.js +9 -112
  104. package/dist/yargs.js.map +1 -1
  105. package/package.json +8 -8
  106. package/dist/indexer/indexer.module.d.ts +0 -2
  107. package/dist/indexer/indexer.module.js.map +0 -1
  108. package/dist/subcommands/mmrMigrate.init.d.ts +0 -2
  109. package/dist/subcommands/mmrMigrate.init.js +0 -28
  110. package/dist/subcommands/mmrMigrate.init.js.map +0 -1
  111. package/dist/subcommands/mmrMigrate.module.d.ts +0 -2
  112. package/dist/subcommands/mmrMigrate.module.js +0 -28
  113. package/dist/subcommands/mmrMigrate.module.js.map +0 -1
  114. package/dist/subcommands/mmrRegenerate.init.d.ts +0 -1
  115. package/dist/subcommands/mmrRegenerate.init.js +0 -28
  116. package/dist/subcommands/mmrRegenerate.init.js.map +0 -1
  117. package/dist/subcommands/mmrRegenerate.module.d.ts +0 -2
  118. package/dist/subcommands/mmrRegenerate.module.js +0 -30
  119. package/dist/subcommands/mmrRegenerate.module.js.map +0 -1
  120. package/dist/subcommands/reindex.service.d.ts +0 -11
  121. package/dist/subcommands/reindex.service.js +0 -46
  122. package/dist/subcommands/reindex.service.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  import { Provider, Block, TransactionReceipt } from '@ethersproject/abstract-provider';
2
2
  import { EventEmitter2 } from '@nestjs/event-emitter';
3
- import { ApiWrapper, EthereumBlockWrapper, EthereumTransaction, EthereumResult, EthereumLog, SubqlRuntimeDatasource } from '@subql/types-ethereum';
4
- import { EthereumBlockWrapped } from './block.ethereum';
3
+ import { ApiWrapper, EthereumBlock, EthereumTransaction, EthereumResult, EthereumLog, SubqlRuntimeDatasource, LightEthereumBlock, LightEthereumLog } from '@subql/types-ethereum';
5
4
  import SafeEthProvider from './safe-api';
6
- export declare class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {
5
+ export declare class EthereumApi implements ApiWrapper {
7
6
  private endpoint;
7
+ private blockConfirmations;
8
8
  private eventEmitter;
9
9
  private client;
10
10
  private nonBatchClient?;
@@ -13,8 +13,12 @@ export declare class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {
13
13
  private chainId;
14
14
  private name;
15
15
  private supportsFinalization;
16
- private blockConfirmations;
17
- constructor(endpoint: string, eventEmitter: EventEmitter2);
16
+ /**
17
+ * @param {string} endpoint - The endpoint of the RPC provider
18
+ * @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.
19
+ * @param {object} eventEmitter - Used to monitor the number of RPC requests
20
+ */
21
+ constructor(endpoint: string, blockConfirmations: number, eventEmitter: EventEmitter2);
18
22
  init(): Promise<void>;
19
23
  private getSupportsTag;
20
24
  private injectClient;
@@ -28,12 +32,14 @@ export declare class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {
28
32
  getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block>;
29
33
  private getBlockPromise;
30
34
  getTransactionReceipt(transactionHash: string | Promise<string>): Promise<TransactionReceipt>;
31
- fetchBlock(blockNumber: number, includeTx?: boolean): Promise<EthereumBlockWrapped>;
32
- fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]>;
35
+ fetchBlock(blockNumber: number): Promise<EthereumBlock>;
36
+ private fetchLightBlock;
37
+ fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlock[]>;
38
+ fetchBlocksLight(bufferBlocks: number[]): Promise<LightEthereumBlock[]>;
33
39
  get api(): Provider;
34
40
  getSafeApi(blockHeight: number): SafeEthProvider;
35
41
  private buildInterface;
36
- parseLog<T extends EthereumResult = EthereumResult>(log: EthereumLog, ds: SubqlRuntimeDatasource): Promise<EthereumLog<T> | EthereumLog>;
42
+ parseLog<T extends EthereumResult = EthereumResult>(log: EthereumLog | LightEthereumLog, ds: SubqlRuntimeDatasource): Promise<EthereumLog | LightEthereumLog | EthereumLog<T> | LightEthereumLog<T>>;
37
43
  parseTransaction<T extends EthereumResult = EthereumResult>(transaction: EthereumTransaction, ds: SubqlRuntimeDatasource): Promise<EthereumTransaction<T> | EthereumTransaction>;
38
44
  connect(): Promise<void>;
39
45
  disconnect(): Promise<void>;
@@ -15,8 +15,6 @@ const node_core_1 = require("@subql/node-core");
15
15
  const cacheable_lookup_1 = __importDefault(require("cacheable-lookup"));
16
16
  const utils_1 = require("ethers/lib/utils");
17
17
  const project_1 = require("../utils/project");
18
- const yargs_1 = require("../yargs");
19
- const block_ethereum_1 = require("./block.ethereum");
20
18
  const celo_json_rpc_batch_provider_1 = require("./ethers/celo/celo-json-rpc-batch-provider");
21
19
  const celo_json_rpc_provider_1 = require("./ethers/celo/celo-json-rpc-provider");
22
20
  const celo_ws_provider_1 = require("./ethers/celo/celo-ws-provider");
@@ -60,13 +58,18 @@ function getHttpAgents() {
60
58
  };
61
59
  }
62
60
  class EthereumApi {
63
- constructor(endpoint, eventEmitter) {
61
+ /**
62
+ * @param {string} endpoint - The endpoint of the RPC provider
63
+ * @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.
64
+ * @param {object} eventEmitter - Used to monitor the number of RPC requests
65
+ */
66
+ constructor(endpoint, blockConfirmations, eventEmitter) {
64
67
  this.endpoint = endpoint;
68
+ this.blockConfirmations = blockConfirmations;
65
69
  this.eventEmitter = eventEmitter;
66
70
  this.contractInterfaces = {};
67
71
  // Ethereum POS
68
72
  this.supportsFinalization = true;
69
- this.blockConfirmations = yargs_1.yargsOptions.argv['block-confirmations'];
70
73
  const { hostname, protocol, searchParams } = new URL(endpoint);
71
74
  const protocolStr = protocol.replace(':', '');
72
75
  logger.info(`Api host: ${hostname}, method: ${protocolStr}`);
@@ -195,15 +198,14 @@ class EthereumApi {
195
198
  async getTransactionReceipt(transactionHash) {
196
199
  return (0, project_1.retryOnFailEth)(this.client.getTransactionReceipt.bind(this.client, transactionHash));
197
200
  }
198
- async fetchBlock(blockNumber, includeTx) {
201
+ async fetchBlock(blockNumber) {
199
202
  try {
200
- const block = await this.getBlockPromise(blockNumber, includeTx);
201
- const logs = await this.client.getLogs({ blockHash: block.hash });
202
- const ret = new block_ethereum_1.EthereumBlockWrapped(block, includeTx
203
- ? block.transactions.map((tx) => (Object.assign(Object.assign({}, (0, utils_ethereum_1.formatTransaction)(tx, block)), {
204
- // TODO memoise
205
- receipt: () => this.getTransactionReceipt(tx.hash).then((r) => (0, utils_ethereum_1.formatReceipt)(r, block)) })))
206
- : [], logs.map((l) => (0, utils_ethereum_1.formatLog)(l, block)));
203
+ const block = await this.getBlockPromise(blockNumber, true);
204
+ const logsRaw = await this.client.getLogs({ blockHash: block.hash });
205
+ const logs = logsRaw.map((l) => (0, utils_ethereum_1.formatLog)(l, block));
206
+ const transactions = block.transactions.map((tx) => (Object.assign(Object.assign({}, (0, utils_ethereum_1.formatTransaction)(tx, block)), { receipt: () => this.getTransactionReceipt(tx.hash).then((r) => (0, utils_ethereum_1.formatReceipt)(r, block)), logs: logs.filter((l) => l.transactionHash === tx.hash) })));
207
+ const ret = Object.assign(Object.assign({}, block), { transactions,
208
+ logs });
207
209
  this.eventEmitter.emit('fetchBlock');
208
210
  return ret;
209
211
  }
@@ -211,8 +213,17 @@ class EthereumApi {
211
213
  throw this.handleError(e);
212
214
  }
213
215
  }
216
+ async fetchLightBlock(blockNumber) {
217
+ const block = await this.getBlockPromise(blockNumber, false);
218
+ const logs = await this.client.getLogs({ blockHash: block.hash });
219
+ return Object.assign(Object.assign({}, block), { logs: logs.map((l) => (0, utils_ethereum_1.formatLog)(l, block)) });
220
+ }
214
221
  async fetchBlocks(bufferBlocks) {
215
- return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num, true)));
222
+ return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));
223
+ }
224
+ async fetchBlocksLight(bufferBlocks) {
225
+ console.log('FETCH BLOCKS LIGHT');
226
+ return Promise.all(bufferBlocks.map(async (num) => this.fetchLightBlock(num)));
216
227
  }
217
228
  get api() {
218
229
  return this.client;
@@ -1 +1 @@
1
- {"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethere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AAC,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;AAtUD,kCAsUC","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 EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { yargsOptions } from '../yargs';\nimport { EthereumBlockWrapped } from './block.ethereum';\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 Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\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<EthereumBlockWrapper> {\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 private blockConfirmations = yargsOptions.argv['block-confirmations'];\n\n constructor(private endpoint: string, private eventEmitter: EventEmitter2) {\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.client.getBlock('earliest'),\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 async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n return this.client.getBlock(height);\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n const tag = this.supportsFinalization ? 'safe' : '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(\n blockNumber: number,\n includeTx?: boolean,\n ): Promise<EthereumBlockWrapped> {\n try {\n const block = await this.getBlockPromise(blockNumber, includeTx);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n const ret = new EthereumBlockWrapped(\n block,\n includeTx\n ? block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n // TODO memoise\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n }))\n : [],\n logs.map((l) => formatLog(l, block)),\n );\n this.eventEmitter.emit('fetchBlock');\n return ret;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchBlock(num, true)),\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,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: 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 ));\n\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // 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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AC,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;AAlWD,kCAkWC","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 Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\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 /**\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 ) {\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.client.getBlock('earliest'),\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 async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n return this.client.getBlock(height);\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n const tag = this.supportsFinalization ? 'safe' : '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 const logs = logsRaw.map((l) => formatLog(l, block));\n const 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: logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n const ret = {\n ...block,\n transactions,\n logs,\n };\n\n this.eventEmitter.emit('fetchBlock');\n return ret;\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 return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: 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 return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // 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"]}
@@ -12,6 +12,7 @@ const api_ethereum_1 = require("./api.ethereum");
12
12
  const block_ethereum_1 = require("./block.ethereum");
13
13
  // Add api key to work
14
14
  const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
15
+ const BLOCK_CONFIRMATIONS = 20;
15
16
  const ds = {
16
17
  mapping: {
17
18
  file: '',
@@ -35,10 +36,14 @@ describe('Api.ethereum', () => {
35
36
  let ethApi;
36
37
  const eventEmitter = new event_emitter_1.EventEmitter2();
37
38
  let blockData;
39
+ const fetchBlock = async (height) => {
40
+ const block = await ethApi.fetchBlock(height);
41
+ return block;
42
+ };
38
43
  beforeEach(async () => {
39
- ethApi = new api_ethereum_1.EthereumApi(HTTP_ENDPOINT, eventEmitter);
44
+ ethApi = new api_ethereum_1.EthereumApi(HTTP_ENDPOINT, BLOCK_CONFIRMATIONS, eventEmitter);
40
45
  await ethApi.init();
41
- blockData = await ethApi.fetchBlock(16258633, true);
46
+ blockData = await fetchBlock(16258633);
42
47
  });
43
48
  it('Should format transaction in logs, and the transaction gas should be bigInt type', () => {
44
49
  expect(typeof blockData.logs[0].transaction.gas).toBe('bigint');
@@ -64,11 +69,11 @@ describe('Api.ethereum', () => {
64
69
  });
65
70
  it('Null filter support', async () => {
66
71
  const beamEndpoint = 'https://rpc.api.moonbeam.network';
67
- ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, eventEmitter);
72
+ ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
68
73
  await ethApi.init();
69
- blockData = await ethApi.fetchBlock(2847447, true);
74
+ blockData = await fetchBlock(2847447);
70
75
  const result = blockData.transactions.filter((tx) => {
71
- if (block_ethereum_1.EthereumBlockWrapped.filterTransactionsProcessor(tx, { to: null }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
76
+ if ((0, block_ethereum_1.filterTransactionsProcessor)(tx, { to: null }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
72
77
  return tx.hash;
73
78
  }
74
79
  });
@@ -77,7 +82,7 @@ describe('Api.ethereum', () => {
77
82
  });
78
83
  it('!null filter support for logs, expect to filter out', async () => {
79
84
  const beamEndpoint = 'https://rpc.api.moonbeam.network';
80
- ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, eventEmitter);
85
+ ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
81
86
  await ethApi.init();
82
87
  const filter_1 = {
83
88
  topics: [
@@ -92,30 +97,22 @@ describe('Api.ethereum', () => {
92
97
  '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
93
98
  ],
94
99
  };
95
- blockData = await ethApi.fetchBlock(4015990, true);
100
+ blockData = await fetchBlock(4015990);
96
101
  const transaction = blockData.transactions.find((tx) => tx.hash ===
97
102
  '0xeb2e443f2d4e784193fa13bbbae2b85e6ee459e7b7b53f8ca098ffae9b25b059');
98
- const erc20Transfers = transaction.logs.filter((log) => {
99
- if (block_ethereum_1.EthereumBlockWrapped.filterLogsProcessor(log, filter_2)) {
100
- return log;
101
- }
102
- });
103
- const erc721Transfers = transaction.logs.filter((log) => {
104
- if (block_ethereum_1.EthereumBlockWrapped.filterLogsProcessor(log, filter_1)) {
105
- return log;
106
- }
107
- });
103
+ const erc20Transfers = transaction.logs.filter((log) => (0, block_ethereum_1.filterLogsProcessor)(log, filter_2));
104
+ const erc721Transfers = transaction.logs.filter((log) => (0, block_ethereum_1.filterLogsProcessor)(log, filter_1));
108
105
  expect(erc20Transfers.length).toBe(7);
109
106
  expect(erc721Transfers.length).toBe(2);
110
107
  });
111
108
  it('Null filter support, for undefined transaction.to', async () => {
112
109
  const beamEndpoint = 'https://rpc.api.moonbeam.network';
113
- ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, eventEmitter);
110
+ ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
114
111
  await ethApi.init();
115
- blockData = await ethApi.fetchBlock(2847447, true);
112
+ blockData = await fetchBlock(2847447);
116
113
  blockData.transactions[1].to = undefined;
117
114
  const result = blockData.transactions.filter((tx) => {
118
- if (block_ethereum_1.EthereumBlockWrapped.filterTransactionsProcessor(tx, { to: null }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
115
+ if ((0, block_ethereum_1.filterTransactionsProcessor)(tx, { to: null }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
119
116
  return tx.hash;
120
117
  }
121
118
  });
@@ -124,11 +121,11 @@ describe('Api.ethereum', () => {
124
121
  });
125
122
  it('Should return all tx if filter.to is not defined', async () => {
126
123
  const beamEndpoint = 'https://rpc.api.moonbeam.network';
127
- ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, eventEmitter);
124
+ ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
128
125
  await ethApi.init();
129
- blockData = await ethApi.fetchBlock(2847447, true);
126
+ blockData = await fetchBlock(2847447);
130
127
  const result = blockData.transactions.filter((tx) => {
131
- if (block_ethereum_1.EthereumBlockWrapped.filterTransactionsProcessor(tx, undefined, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
128
+ if ((0, block_ethereum_1.filterTransactionsProcessor)(tx, undefined, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
132
129
  return tx.hash;
133
130
  }
134
131
  });
@@ -136,11 +133,11 @@ describe('Api.ethereum', () => {
136
133
  });
137
134
  it('filter.to Should support only null not undefined', async () => {
138
135
  const beamEndpoint = 'https://rpc.api.moonbeam.network';
139
- ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, eventEmitter);
136
+ ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
140
137
  await ethApi.init();
141
- blockData = await ethApi.fetchBlock(2847447, true);
138
+ blockData = await fetchBlock(2847447);
142
139
  const result = blockData.transactions.filter((tx) => {
143
- if (block_ethereum_1.EthereumBlockWrapped.filterTransactionsProcessor(tx, { to: undefined }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
140
+ if ((0, block_ethereum_1.filterTransactionsProcessor)(tx, { to: undefined }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
144
141
  return tx.hash;
145
142
  }
146
143
  });
@@ -148,12 +145,12 @@ describe('Api.ethereum', () => {
148
145
  });
149
146
  it('If transaction is undefined, with null filter, should be supported', async () => {
150
147
  const beamEndpoint = 'https://rpc.api.moonbeam.network';
151
- ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, eventEmitter);
148
+ ethApi = new api_ethereum_1.EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
152
149
  await ethApi.init();
153
- blockData = await ethApi.fetchBlock(2847447, true);
150
+ blockData = await fetchBlock(2847447);
154
151
  const result = blockData.transactions.filter((tx) => {
155
152
  tx.to = undefined;
156
- if (block_ethereum_1.EthereumBlockWrapped.filterTransactionsProcessor(tx, { to: null }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
153
+ if ((0, block_ethereum_1.filterTransactionsProcessor)(tx, { to: null }, '0x72a33394f0652e2bf15d7901f3cd46863d968424')) {
157
154
  return tx.hash;
158
155
  }
159
156
  });
@@ -163,15 +160,15 @@ describe('Api.ethereum', () => {
163
160
  // Ethereum
164
161
  expect(ethApi.supportsFinalization).toBeTruthy();
165
162
  // Moonbeam
166
- ethApi = new api_ethereum_1.EthereumApi('https://rpc.api.moonbeam.network', eventEmitter);
163
+ ethApi = new api_ethereum_1.EthereumApi('https://rpc.api.moonbeam.network', BLOCK_CONFIRMATIONS, eventEmitter);
167
164
  await ethApi.init();
168
165
  expect(ethApi.supportsFinalization).toBeTruthy();
169
166
  // BSC
170
- ethApi = new api_ethereum_1.EthereumApi('https://bsc-dataseed.binance.org', eventEmitter);
167
+ ethApi = new api_ethereum_1.EthereumApi('https://bsc-dataseed.binance.org', BLOCK_CONFIRMATIONS, eventEmitter);
171
168
  await ethApi.init();
172
169
  expect(ethApi.supportsFinalized).toBeFalsy();
173
170
  // Polygon
174
- ethApi = new api_ethereum_1.EthereumApi('https://polygon.api.onfinality.io/public', eventEmitter);
171
+ ethApi = new api_ethereum_1.EthereumApi('https://polygon.api.onfinality.io/public', BLOCK_CONFIRMATIONS, eventEmitter);
175
172
  await ethApi.init();
176
173
  expect(ethApi.supportsFinalized).toBeFalsy();
177
174
  });
@@ -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,0DAK+B;AAC/B,iDAA6C;AAC7C,qDAAwD;AAExD,sBAAsB;AACtB,MAAM,aAAa,GAAG,sCAAsC,CAAC;AAE7D,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,EAAE,QAAQ,EAAE,YAAY,EAAE;aACnC;SACF;KACF;IACD,IAAI,EAAE,uCAAsB,CAAC,OAAO;IACpC,UAAU,EAAE,QAAQ;IACpB,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;IAC1B,MAAM,EAAE;QACN,MAAM,EAAE,EAAE,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,wBAAwB,CAAC,EAAE;KACrB;CAC9C,CAAC;AAEF,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACvB,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,MAAmB,CAAC;IACxB,MAAM,YAAY,GAAG,IAAI,6BAAa,EAAE,CAAC;IACzC,IAAI,SAA+B,CAAC;IACpC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,GAAG,IAAI,0BAAW,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;QACtD,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,SAAS,GAAG,MAAM,M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O,EAAE,CAAC,IAAI,CAAC;aAChB;QACH,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,WAAW;QACX,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU,EAAE,CAAC;QAE1D,WAAW;QACX,MAAM,GAAG,IAAI,0BAAW,CAAC,kCAAkC,EAAE,YAAY,CAAC,CAAC;QAC3E,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU,EAAE,CAAC;QAE1D,MAAM;QACN,MAAM,GAAG,IAAI,0BAAW,CAAC,kCAAkC,EAAE,YAAY,CAAC,CAAC;QAC3E,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,0CAA0C,EAC1C,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 EthereumDatasourceKind,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport { EthereumBlockWrapped } from './block.ethereum';\n\n// Add api key to work\nconst HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\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: {\n erc721: { file: path.join(__dirname, '../../test/erc721.json') },\n } as unknown as Map<string, { file: string }>,\n};\n\njest.setTimeout(90000);\ndescribe('Api.ethereum', () => {\n let ethApi: EthereumApi;\n const eventEmitter = new EventEmitter2();\n let blockData: EthereumBlockWrapped;\n beforeEach(async () => {\n ethApi = new EthereumApi(HTTP_ENDPOINT, eventEmitter);\n await ethApi.init();\n blockData = await ethApi.fetchBlock(16258633, true);\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('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 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 it('Null filter support', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, eventEmitter);\n await ethApi.init();\n blockData = await ethApi.fetchBlock(2847447, true);\n const result = blockData.transactions.filter((tx) => {\n if (\n EthereumBlockWrapped.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, 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 ethApi.fetchBlock(4015990, true);\n const transaction = blockData.transactions.find(\n (tx) =>\n tx.hash ===\n '0xeb2e443f2d4e784193fa13bbbae2b85e6ee459e7b7b53f8ca098ffae9b25b059',\n );\n const erc20Transfers = transaction.logs.filter((log) => {\n if (EthereumBlockWrapped.filterLogsProcessor(log, filter_2)) {\n return log;\n }\n });\n const erc721Transfers = transaction.logs.filter((log) => {\n if (EthereumBlockWrapped.filterLogsProcessor(log, filter_1)) {\n return log;\n }\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, eventEmitter);\n await ethApi.init();\n blockData = await ethApi.fetchBlock(2847447, true);\n blockData.transactions[1].to = undefined;\n const result = blockData.transactions.filter((tx) => {\n if (\n EthereumBlockWrapped.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, eventEmitter);\n await ethApi.init();\n blockData = await ethApi.fetchBlock(2847447, true);\n const result = blockData.transactions.filter((tx) => {\n if (\n EthereumBlockWrapped.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, eventEmitter);\n await ethApi.init();\n blockData = await ethApi.fetchBlock(2847447, true);\n const result = blockData.transactions.filter((tx) => {\n if (\n EthereumBlockWrapped.filterTransactionsProcessor(\n tx,\n { to: undefined },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(0);\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, eventEmitter);\n await ethApi.init();\n blockData = await ethApi.fetchBlock(2847447, true);\n const result = blockData.transactions.filter((tx) => {\n tx.to = undefined;\n if (\n EthereumBlockWrapped.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('https://rpc.api.moonbeam.network', eventEmitter);\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // BSC\n ethApi = new EthereumApi('https://bsc-dataseed.binance.org', eventEmitter);\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n\n // Polygon\n ethApi = new EthereumApi(\n 'https://polygon.api.onfinality.io/public',\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,MAAM,aAAa,GAAG,sCAAsC,CAAC;AAC7D,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,EAAE,QAAQ,EAAE,YAAY,EAAE;aACnC;SACF;KACF;IACD,IAAI,EAAE,uCAAsB,CAAC,OAAO;IACpC,UAAU,EAAE,QAAQ;IACpB,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;IAC1B,MAAM,EAAE;QACN,MAAM,EAAE,EAAE,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,wBAAwB,CAAC,EAAE;KACrB;CAC9C,CAAC;AAEF,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACvB,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,MAAmB,CAAC;IACxB,MAAM,YAAY,GAAG,IAAI,6BAAa,EAAE,CAAC;I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C,EAAE,GAAG,SAAS,CAAC;YAClB,IACE,IAAA,4CAA2B,EACzB,EAAE,EACF,EAAE,EAAE,EAAE,IAAI,EAAE,EACZ,4CAA4C,CAC7C,EACD;gBACA,OAAO,EAAE,CAAC,IAAI,CAAC;aAChB;QACH,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,WAAW;QACX,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU,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,0CAA0C,EAC1C,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\nconst HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\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: {\n erc721: { file: path.join(__dirname, '../../test/erc721.json') },\n } as unknown as Map<string, { file: string }>,\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('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 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 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 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.api.onfinality.io/public',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n });\n});\n"]}
@@ -1,19 +1,21 @@
1
1
  import { EventEmitter2 } from '@nestjs/event-emitter';
2
- import { ApiService, ConnectionPoolService, NetworkMetadataPayload, NodeConfig } from '@subql/node-core';
3
- import { EthereumBlockWrapper } from '@subql/types-ethereum';
2
+ import { ApiService, ConnectionPoolService, NodeConfig } from '@subql/node-core';
3
+ import { EthereumBlock, LightEthereumBlock } from '@subql/types-ethereum';
4
4
  import { SubqueryProject } from '../configure/SubqueryProject';
5
5
  import { EthereumApiConnection } from './api.connection';
6
6
  import { EthereumApi } from './api.ethereum';
7
7
  import SafeEthProvider from './safe-api';
8
- export declare class EthereumApiService extends ApiService<EthereumApi, SafeEthProvider, EthereumBlockWrapper> {
8
+ export declare class EthereumApiService extends ApiService<EthereumApi, SafeEthProvider, EthereumBlock[] | LightEthereumBlock[]> {
9
9
  private project;
10
- private eventEmitter;
10
+ private fetchBlocksFunction;
11
+ private fetchBlocksBatches;
11
12
  private nodeConfig;
12
13
  constructor(project: SubqueryProject, connectionPoolService: ConnectionPoolService<EthereumApiConnection>, eventEmitter: EventEmitter2, nodeConfig: NodeConfig);
13
- networkMeta: NetworkMetadataPayload;
14
14
  init(): Promise<EthereumApiService>;
15
- private metadataMismatchError;
15
+ protected metadataMismatchError(metadata: string, expected: string, actual: string): Error;
16
16
  get api(): EthereumApi;
17
17
  safeApi(height: number): SafeEthProvider;
18
- private fetchBlockBatches;
18
+ private fetchFullBlocksBatch;
19
+ private fetchLightBlocksBatch;
20
+ updateBlockFetching(): void;
19
21
  }