@subql/node-ethereum 3.11.0 → 3.11.1-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/ethereum/api.connection.d.ts +4 -4
  3. package/dist/ethereum/api.connection.js.map +1 -1
  4. package/dist/ethereum/api.ethereum.d.ts +4 -3
  5. package/dist/ethereum/api.ethereum.js +6 -3
  6. package/dist/ethereum/api.ethereum.js.map +1 -1
  7. package/dist/ethereum/api.ethereum.test.js +13 -1
  8. package/dist/ethereum/api.ethereum.test.js.map +1 -1
  9. package/dist/ethereum/api.service.ethereum.d.ts +2 -2
  10. package/dist/ethereum/api.service.ethereum.js.map +1 -1
  11. package/dist/ethereum/block.ethereum.js +6 -2
  12. package/dist/ethereum/block.ethereum.js.map +1 -1
  13. package/dist/ethereum/utils.ethereum.d.ts +8 -1
  14. package/dist/ethereum/utils.ethereum.js +17 -1
  15. package/dist/ethereum/utils.ethereum.js.map +1 -1
  16. package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +2 -3
  17. package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -4
  18. package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
  19. package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.d.ts +2 -1
  20. package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.js.map +1 -1
  21. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +2 -1
  22. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +0 -12
  23. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
  24. package/dist/indexer/dictionary/ethDictionary.service.d.ts +9 -0
  25. package/dist/indexer/dictionary/ethDictionary.service.js +59 -0
  26. package/dist/indexer/dictionary/ethDictionary.service.js.map +1 -0
  27. package/dist/indexer/dictionary/utils.d.ts +3 -0
  28. package/dist/indexer/dictionary/utils.js +24 -0
  29. package/dist/indexer/dictionary/utils.js.map +1 -0
  30. package/dist/indexer/dictionary/utils.spec.js +83 -0
  31. package/dist/indexer/dictionary/utils.spec.js.map +1 -0
  32. package/dist/indexer/dictionary/v1/ethDictionaryV1.d.ts +16 -0
  33. package/dist/indexer/dictionary/v1/ethDictionaryV1.js +202 -0
  34. package/dist/indexer/dictionary/v1/ethDictionaryV1.js.map +1 -0
  35. package/dist/indexer/{fetch.service.spec.js → dictionary/v1/ethDictionaryV1.spec.js} +45 -23
  36. package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js.map +1 -0
  37. package/dist/indexer/dictionary/v1/index.d.ts +1 -0
  38. package/dist/indexer/dictionary/v1/index.js +20 -0
  39. package/dist/indexer/dictionary/v1/index.js.map +1 -0
  40. package/dist/indexer/dictionary/v2/ethDictionaryV2.d.ts +14 -0
  41. package/dist/indexer/dictionary/v2/ethDictionaryV2.js +188 -0
  42. package/dist/indexer/dictionary/v2/ethDictionaryV2.js.map +1 -0
  43. package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.d.ts +1 -0
  44. package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js +232 -0
  45. package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js.map +1 -0
  46. package/dist/indexer/dictionary/v2/index.d.ts +2 -0
  47. package/dist/indexer/dictionary/v2/index.js +21 -0
  48. package/dist/indexer/dictionary/v2/index.js.map +1 -0
  49. package/dist/indexer/dictionary/v2/types.d.ts +75 -0
  50. package/dist/indexer/dictionary/v2/types.js +5 -0
  51. package/dist/indexer/dictionary/v2/types.js.map +1 -0
  52. package/dist/indexer/dictionary/v2/utils.d.ts +4 -0
  53. package/dist/indexer/dictionary/v2/utils.js +22 -0
  54. package/dist/indexer/dictionary/v2/utils.js.map +1 -0
  55. package/dist/indexer/dictionary/v2/utils.spec.d.ts +1 -0
  56. package/dist/indexer/dictionary/v2/utils.spec.js +98 -0
  57. package/dist/indexer/dictionary/v2/utils.spec.js.map +1 -0
  58. package/dist/indexer/fetch.module.js +4 -3
  59. package/dist/indexer/fetch.module.js.map +1 -1
  60. package/dist/indexer/fetch.service.d.ts +4 -14
  61. package/dist/indexer/fetch.service.js +4 -177
  62. package/dist/indexer/fetch.service.js.map +1 -1
  63. package/dist/indexer/indexer.manager.d.ts +5 -5
  64. package/dist/indexer/indexer.manager.js +3 -3
  65. package/dist/indexer/indexer.manager.js.map +1 -1
  66. package/dist/indexer/unfinalizedBlocks.service.d.ts +1 -5
  67. package/dist/indexer/unfinalizedBlocks.service.js +5 -21
  68. package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
  69. package/dist/indexer/worker/worker.service.d.ts +4 -4
  70. package/dist/indexer/worker/worker.service.js +1 -1
  71. package/dist/indexer/worker/worker.service.js.map +1 -1
  72. package/dist/indexer/worker/worker.unfinalizedBlocks.service.d.ts +2 -2
  73. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +2 -6
  74. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -1
  75. package/dist/subcommands/testing.service.d.ts +2 -2
  76. package/dist/subcommands/testing.service.js.map +1 -1
  77. package/package.json +8 -7
  78. package/dist/indexer/dictionary.service.d.ts +0 -11
  79. package/dist/indexer/dictionary.service.js +0 -72
  80. package/dist/indexer/dictionary.service.js.map +0 -1
  81. package/dist/indexer/dictionary.service.spec.js +0 -15
  82. package/dist/indexer/dictionary.service.spec.js.map +0 -1
  83. package/dist/indexer/fetch.service.spec.js.map +0 -1
  84. /package/dist/indexer/{dictionary.service.spec.d.ts → dictionary/utils.spec.d.ts} +0 -0
  85. /package/dist/indexer/{fetch.service.spec.d.ts → dictionary/v1/ethDictionaryV1.spec.d.ts} +0 -0
@@ -2,9 +2,10 @@
2
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
+ const node_core_1 = require("@subql/node-core");
5
6
  const types_ethereum_1 = require("@subql/types-ethereum");
6
7
  const graphql_1 = require("graphql");
7
- const fetch_service_1 = require("./fetch.service");
8
+ const ethDictionaryV1_1 = require("./ethDictionaryV1");
8
9
  // const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
9
10
  const HTTP_ENDPOINT = 'https://eth.llamarpc.com';
10
11
  const mockTempDs = [
@@ -58,7 +59,17 @@ function testSubqueryProject(endpoint, ds, mockTempDs) {
58
59
  templates: mockTempDs,
59
60
  };
60
61
  }
61
- describe('Dictionary queries', () => {
62
+ describe('Eth Dictionary V1', () => {
63
+ it('Can resovle chain aliases', async () => {
64
+ ethDictionaryV1_1.EthDictionaryV1.prototype.init = jest.fn();
65
+ const dictionary = await ethDictionaryV1_1.EthDictionaryV1.create({
66
+ network: { chainId: '336', dictionary: 'https://foo.bar' },
67
+ }, new node_core_1.NodeConfig({}, true), null);
68
+ expect(dictionary.chainId).toBe('0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108');
69
+ jest.clearAllMocks();
70
+ });
71
+ });
72
+ describe('buildDictionaryV1QueryEntries', () => {
62
73
  describe('Log filters', () => {
63
74
  it('Build filter for !null', () => {
64
75
  const ds = {
@@ -87,7 +98,7 @@ describe('Dictionary queries', () => {
87
98
  ],
88
99
  },
89
100
  };
90
- const result = (0, fetch_service_1.buildDictionaryQueryEntries)([ds]);
101
+ const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
91
102
  expect(result).toEqual([
92
103
  {
93
104
  entity: 'evmLogs',
@@ -131,7 +142,7 @@ describe('Dictionary queries', () => {
131
142
  ],
132
143
  },
133
144
  };
134
- const result = (0, fetch_service_1.buildDictionaryQueryEntries)([ds]);
145
+ const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
135
146
  expect(result).toEqual([
136
147
  {
137
148
  entity: 'evmTransactions',
@@ -161,7 +172,7 @@ describe('Dictionary queries', () => {
161
172
  ],
162
173
  },
163
174
  };
164
- const result = (0, fetch_service_1.buildDictionaryQueryEntries)([ds]);
175
+ const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
165
176
  expect(result).toEqual([
166
177
  {
167
178
  entity: 'evmTransactions',
@@ -199,7 +210,7 @@ describe('Dictionary queries', () => {
199
210
  ],
200
211
  },
201
212
  };
202
- const result = (0, fetch_service_1.buildDictionaryQueryEntries)([ds]);
213
+ const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
203
214
  expect(result).toEqual([
204
215
  {
205
216
  entity: 'evmTransactions',
@@ -236,7 +247,7 @@ describe('Dictionary queries', () => {
236
247
  ],
237
248
  },
238
249
  };
239
- const result = (0, fetch_service_1.buildDictionaryQueryEntries)([ds]);
250
+ const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
240
251
  expect(result).toEqual([
241
252
  {
242
253
  entity: 'evmTransactions',
@@ -273,7 +284,7 @@ describe('Dictionary queries', () => {
273
284
  ],
274
285
  },
275
286
  };
276
- const result = (0, fetch_service_1.buildDictionaryQueryEntries)([ds]);
287
+ const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
277
288
  expect(result).toEqual([
278
289
  {
279
290
  entity: 'evmTransactions',
@@ -310,7 +321,7 @@ describe('Dictionary queries', () => {
310
321
  ],
311
322
  },
312
323
  };
313
- const result = (0, fetch_service_1.buildDictionaryQueryEntries)([ds]);
324
+ const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
314
325
  expect(result).toEqual([
315
326
  {
316
327
  entity: 'evmLogs',
@@ -350,54 +361,65 @@ describe('Dictionary queries', () => {
350
361
  Object.assign(Object.assign({}, mockTempDs[1]), { options: { address: 'address3' } }),
351
362
  ];
352
363
  const dataSources = [ds, ...duplicateDataSources];
353
- const project = testSubqueryProject(HTTP_ENDPOINT, dataSources, mockTempDs);
354
- const fetchService = new fetch_service_1.FetchService(null, null, null, project, null, null, null, null, null, null);
355
- const queryEntry = fetchService.buildDictionaryQueryEntries(dataSources);
364
+ const queryEntry = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)(dataSources);
356
365
  expect(queryEntry).toEqual([
357
366
  {
358
- entity: 'evmLogs',
359
367
  conditions: [
360
368
  {
361
369
  field: 'topics0',
362
- value: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
363
370
  matcher: 'equalTo',
371
+ value: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
364
372
  },
365
373
  ],
374
+ entity: 'evmLogs',
366
375
  },
367
376
  {
368
- entity: 'evmLogs',
369
377
  conditions: [
370
378
  {
371
379
  field: 'address',
372
- // This is what we're looking to happen with multiple instances of template
373
- value: ['address1', 'address2'],
374
- matcher: 'in',
380
+ matcher: 'equalTo',
381
+ value: 'address1',
375
382
  },
376
383
  {
377
384
  field: 'topics0',
378
- value: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
379
385
  matcher: 'equalTo',
386
+ value: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
380
387
  },
381
388
  ],
389
+ entity: 'evmLogs',
382
390
  },
383
391
  {
392
+ conditions: [
393
+ {
394
+ field: 'address',
395
+ matcher: 'equalTo',
396
+ value: 'address2',
397
+ },
398
+ {
399
+ field: 'topics0',
400
+ matcher: 'equalTo',
401
+ value: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
402
+ },
403
+ ],
384
404
  entity: 'evmLogs',
405
+ },
406
+ {
385
407
  conditions: [
386
- // This condition should not be grouped because there is a single instance of the tamplate
387
408
  {
388
409
  field: 'address',
389
- value: 'address3',
390
410
  matcher: 'equalTo',
411
+ value: 'address3',
391
412
  },
392
413
  {
393
414
  field: 'topics0',
394
- value: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
395
415
  matcher: 'equalTo',
416
+ value: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
396
417
  },
397
418
  ],
419
+ entity: 'evmLogs',
398
420
  },
399
421
  ]);
400
422
  });
401
423
  });
402
424
  });
403
- //# sourceMappingURL=fetch.service.spec.js.map
425
+ //# sourceMappingURL=ethDictionaryV1.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ethDictionaryV1.spec.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,gDAA8C;AAC9C,0DAI+B;AAC/B,qCAAwC;AAKxC,uDAG2B;AAE3B,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,UAAU,GAAgC;IAC9C;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,OAAO,EAAE;YACP,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,cAAc;oBACvB,IAAI,EAAE,oCAAmB,CAAC,KAAK;oBAC/B,MAAM,EAAE;wBACN,MAAM,EAAE,CAAC,qCAAqC,CAAC;qBAChD;iBACF;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,OAAO,EAAE;YACP,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,eAAe;oBACxB,IAAI,EAAE,oCAAmB,CAAC,KAAK;oBAC/B,MAAM,EAAE;wBACN,MAAM,EAAE;4BACN,6DAA6D;yBAC9D;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC;AACF,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,EAAO,EACP,UAAU;IAEV,OAAO;QACL,OAAO,EAAE;YACP,QAAQ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CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig } from '@subql/node-core';\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { GraphQLSchema } from 'graphql';\nimport {\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport {\n buildDictionaryV1QueryEntries,\n EthDictionaryV1,\n} from './ethDictionaryV1';\n\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n];\nfunction testSubqueryProject(\n endpoint: string,\n ds: any,\n mockTempDs,\n): SubqueryProject {\n return {\n network: {\n endpoint,\n chainId: '1',\n },\n dataSources: ds as any,\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: mockTempDs as any,\n } as any;\n}\n\ndescribe('Eth Dictionary V1', () => {\n it('Can resovle chain aliases', async () => {\n (EthDictionaryV1.prototype as any).init = jest.fn();\n const dictionary = await EthDictionaryV1.create(\n {\n network: { chainId: '336', dictionary: 'https://foo.bar' } as any,\n } as any,\n new NodeConfig({} as any, true),\n null,\n );\n\n expect((dictionary as any).chainId).toBe(\n '0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108',\n );\n\n jest.clearAllMocks();\n });\n});\n\ndescribe('buildDictionaryV1QueryEntries', () => {\n describe('Log filters', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n {\n field: 'topics3',\n value: false,\n matcher: 'isNull',\n },\n ],\n },\n ]);\n });\n });\n\n describe('Transaction filters', () => {\n it('Build a filter for contract creation transactions', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [{ field: 'to', matcher: 'isNull', value: true }],\n },\n ]);\n });\n\n it('Build a filter with include ds option and contract address', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option and filter both provide contract address, it should use ds options one', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option provide contract address, it should use ds options \"address\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If filter provide contract address, it should use filter \"to\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n });\n describe('Correct dictionary query with dynamic ds', () => {\n it('Build correct erc1155 transfer single query', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n\n it('Builds a groupded query for multiple dynamic ds', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n\n const queryEntry = buildDictionaryV1QueryEntries(dataSources);\n\n expect(queryEntry).toEqual([\n {\n conditions: [\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address1',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address2',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address3',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n ]);\n });\n });\n});\n"]}
@@ -0,0 +1 @@
1
+ export * from './ethDictionaryV1';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
+ // SPDX-License-Identifier: GPL-3.0
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ __exportStar(require("./ethDictionaryV1"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/index.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;AAEnC,oDAAkC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nexport * from './ethDictionaryV1';\n"]}
@@ -0,0 +1,14 @@
1
+ import { EventEmitter2 } from '@nestjs/event-emitter';
2
+ import { NodeConfig, DictionaryV2, RawDictionaryResponseData, DictionaryResponse, IBlock } from '@subql/node-core';
3
+ import { EthereumBlock, SubqlDatasource } from '@subql/types-ethereum';
4
+ import { EthereumProjectDs, EthereumProjectDsTemplate, SubqueryProject } from '../../../configure/SubqueryProject';
5
+ import { GroupedEthereumProjectDs } from '../v1';
6
+ import { RawEthBlock, EthDictionaryV2QueryEntry } from './types';
7
+ export declare function buildDictionaryV2QueryEntry(dataSources: GroupedEthereumProjectDs[]): EthDictionaryV2QueryEntry;
8
+ export declare class EthDictionaryV2 extends DictionaryV2<EthereumBlock, SubqlDatasource, EthDictionaryV2QueryEntry> {
9
+ constructor(endpoint: string, nodeConfig: NodeConfig, eventEmitter: EventEmitter2, project: SubqueryProject, chainId?: string);
10
+ static create(endpoint: string, nodeConfig: NodeConfig, eventEmitter: EventEmitter2, project: SubqueryProject, chainId?: string): Promise<EthDictionaryV2>;
11
+ buildDictionaryQueryEntries(dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[]): EthDictionaryV2QueryEntry;
12
+ getData(startBlock: number, endBlock: number, limit?: number): Promise<DictionaryResponse<IBlock<EthereumBlock> | number> | undefined>;
13
+ convertResponseBlocks<RFB = RawEthBlock>(data: RawDictionaryResponseData<RFB>): DictionaryResponse<IBlock<EthereumBlock>> | undefined;
14
+ }
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
+ // SPDX-License-Identifier: GPL-3.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.EthDictionaryV2 = exports.buildDictionaryV2QueryEntry = void 0;
6
+ const node_core_1 = require("@subql/node-core");
7
+ const types_ethereum_1 = require("@subql/types-ethereum");
8
+ const lodash_1 = require("lodash");
9
+ const string_1 = require("../../../utils/string");
10
+ const yargs_1 = require("../../../yargs");
11
+ const utils_1 = require("../utils");
12
+ const utils_2 = require("./utils");
13
+ const MIN_FETCH_LIMIT = 200;
14
+ const logger = (0, node_core_1.getLogger)('eth-dictionary-v2');
15
+ function extractOptionAddresses(dsOptions) {
16
+ const queryAddressLimit = yargs_1.yargsOptions.argv['query-address-limit'];
17
+ const addressArray = [];
18
+ if (Array.isArray(dsOptions)) {
19
+ const addresses = dsOptions.map((option) => option.address).filter(Boolean);
20
+ if (addresses.length > queryAddressLimit) {
21
+ logger.debug(`Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `);
22
+ }
23
+ if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {
24
+ addressArray.push(...addresses);
25
+ }
26
+ }
27
+ else {
28
+ if (dsOptions === null || dsOptions === void 0 ? void 0 : dsOptions.address) {
29
+ addressArray.push(dsOptions.address.toLowerCase());
30
+ }
31
+ }
32
+ return addressArray;
33
+ }
34
+ function callFilterToDictionaryCondition(filter, dsOptions) {
35
+ const txConditions = {};
36
+ const toArray = [];
37
+ const fromArray = [];
38
+ const funcArray = [];
39
+ if (filter.from) {
40
+ fromArray.push(filter.from.toLowerCase());
41
+ }
42
+ const optionsAddresses = extractOptionAddresses(dsOptions);
43
+ if (!optionsAddresses.length) {
44
+ if (filter.to) {
45
+ toArray.push(filter.to.toLowerCase());
46
+ }
47
+ else if (filter.to === null) {
48
+ toArray.push(null); //TODO, is this correct?
49
+ }
50
+ }
51
+ else if (!!optionsAddresses.length && (filter.to || filter.to === null)) {
52
+ logger.warn(`TransactionFilter 'to' conflict with 'address' in data source options`);
53
+ }
54
+ if (filter.function) {
55
+ funcArray.push((0, string_1.functionToSighash)(filter.function));
56
+ }
57
+ if (toArray.length !== 0) {
58
+ txConditions.to = toArray;
59
+ }
60
+ if (fromArray.length !== 0) {
61
+ txConditions.from = fromArray;
62
+ }
63
+ if (funcArray.length !== 0) {
64
+ txConditions.function = funcArray;
65
+ }
66
+ return txConditions;
67
+ }
68
+ function eventFilterToDictionaryCondition(filter, dsOptions) {
69
+ const logConditions = {};
70
+ logConditions.address = extractOptionAddresses(dsOptions);
71
+ if (filter.topics) {
72
+ for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {
73
+ const topic = filter.topics[i];
74
+ if (!topic) {
75
+ continue;
76
+ }
77
+ const field = `topics${i}`;
78
+ // Initialized
79
+ if (!logConditions[field]) {
80
+ logConditions[field] = [];
81
+ }
82
+ if (topic === '!null') {
83
+ logConditions[field] = []; // TODO, check if !null
84
+ }
85
+ else {
86
+ logConditions[field].push((0, string_1.eventToTopic)(topic));
87
+ }
88
+ }
89
+ }
90
+ return logConditions;
91
+ }
92
+ function buildDictionaryV2QueryEntry(dataSources) {
93
+ var _a;
94
+ const dictionaryConditions = {
95
+ logs: [],
96
+ transactions: [],
97
+ };
98
+ for (const ds of dataSources) {
99
+ for (const handler of ds.mapping.handlers) {
100
+ // No filters, cant use dictionary
101
+ if (!handler.filter)
102
+ return dictionaryConditions;
103
+ switch (handler.kind) {
104
+ case types_ethereum_1.EthereumHandlerKind.Block:
105
+ return dictionaryConditions;
106
+ case types_ethereum_1.EthereumHandlerKind.Call: {
107
+ const filter = handler.filter;
108
+ if (filter.from !== undefined ||
109
+ filter.to !== undefined ||
110
+ filter.function !== undefined) {
111
+ dictionaryConditions.transactions.push(callFilterToDictionaryCondition(filter, ds.options));
112
+ }
113
+ else {
114
+ // do nothing;
115
+ }
116
+ break;
117
+ }
118
+ case types_ethereum_1.EthereumHandlerKind.Event: {
119
+ const filter = handler.filter;
120
+ if (ds.groupedOptions) {
121
+ dictionaryConditions.logs.push(eventFilterToDictionaryCondition(filter, ds.groupedOptions));
122
+ }
123
+ else if (((_a = ds.options) === null || _a === void 0 ? void 0 : _a.address) || filter.topics) {
124
+ dictionaryConditions.logs.push(eventFilterToDictionaryCondition(filter, ds.options));
125
+ }
126
+ else {
127
+ // do nothing;
128
+ }
129
+ break;
130
+ }
131
+ default:
132
+ }
133
+ }
134
+ }
135
+ if (!dictionaryConditions.logs.length) {
136
+ delete dictionaryConditions.logs;
137
+ }
138
+ else {
139
+ dictionaryConditions.logs = (0, lodash_1.uniqBy)(dictionaryConditions.logs, lodash_1.isEqual);
140
+ }
141
+ if (!dictionaryConditions.transactions.length) {
142
+ delete dictionaryConditions.transactions;
143
+ }
144
+ else {
145
+ dictionaryConditions.transactions = (0, lodash_1.uniqBy)(dictionaryConditions.transactions, lodash_1.isEqual);
146
+ }
147
+ return dictionaryConditions;
148
+ }
149
+ exports.buildDictionaryV2QueryEntry = buildDictionaryV2QueryEntry;
150
+ class EthDictionaryV2 extends node_core_1.DictionaryV2 {
151
+ constructor(endpoint, nodeConfig, eventEmitter, project, chainId) {
152
+ super(endpoint, chainId !== null && chainId !== void 0 ? chainId : project.network.chainId, nodeConfig, eventEmitter);
153
+ }
154
+ static async create(endpoint, nodeConfig, eventEmitter, project, chainId) {
155
+ const dictionary = new EthDictionaryV2(endpoint, nodeConfig, eventEmitter, project, chainId);
156
+ await dictionary.init();
157
+ return dictionary;
158
+ }
159
+ buildDictionaryQueryEntries(dataSources) {
160
+ const filteredDs = (0, utils_1.ethFilterDs)(dataSources);
161
+ return buildDictionaryV2QueryEntry(filteredDs);
162
+ }
163
+ // eslint-disable-next-line @typescript-eslint/require-await
164
+ async getData(startBlock, endBlock, limit = MIN_FETCH_LIMIT) {
165
+ return super.getData(startBlock, endBlock, limit, {
166
+ blockHeader: true,
167
+ logs: { transaction: true },
168
+ transactions: { log: true },
169
+ });
170
+ }
171
+ convertResponseBlocks(data) {
172
+ try {
173
+ const blocks = (data.blocks || []).map(utils_2.rawBlockToEthBlock);
174
+ return {
175
+ batchBlocks: blocks,
176
+ lastBufferedHeight: blocks.length
177
+ ? blocks[blocks.length - 1].block.number
178
+ : undefined,
179
+ };
180
+ }
181
+ catch (e) {
182
+ logger.error(e, `Failed to handle block response}`);
183
+ throw e;
184
+ }
185
+ }
186
+ }
187
+ exports.EthDictionaryV2 = EthDictionaryV2;
188
+ //# sourceMappingURL=ethDictionaryV2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ethDictionaryV2.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/ethDictionaryV2.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAO0B;AAC1B,0DAO+B;AAC/B,mCAAyC;AAMzC,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAQvC,mCAA6C;AAE7C,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,mBAAmB,CAAC,CAAC;AAE9C,SAAS,sBAAsB,CAC7B,SAA0E;IAE1E,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnE,MAAM,YAAY,GAAa,E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Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n NodeConfig,\n DictionaryV2,\n RawDictionaryResponseData,\n DictionaryResponse,\n getLogger,\n IBlock,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport { isEqual, uniqBy } from 'lodash';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\nimport { GroupedEthereumProjectDs } from '../v1';\nimport {\n RawEthBlock,\n EthDictionaryV2QueryEntry,\n EthDictionaryTxConditions,\n EthDictionaryLogConditions,\n} from './types';\nimport { rawBlockToEthBlock } from './utils';\n\nconst MIN_FETCH_LIMIT = 200;\n\nconst logger = getLogger('eth-dictionary-v2');\n\nfunction extractOptionAddresses(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): string[] {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n const addressArray: string[] = [];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n addressArray.push(...addresses);\n }\n } else {\n if (dsOptions?.address) {\n addressArray.push(dsOptions.address.toLowerCase());\n }\n }\n return addressArray;\n}\n\nfunction callFilterToDictionaryCondition(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions,\n): EthDictionaryTxConditions {\n const txConditions: EthDictionaryTxConditions = {};\n const toArray = [];\n const fromArray = [];\n const funcArray = [];\n\n if (filter.from) {\n fromArray.push(filter.from.toLowerCase());\n }\n const optionsAddresses = extractOptionAddresses(dsOptions);\n if (!optionsAddresses.length) {\n if (filter.to) {\n toArray.push(filter.to.toLowerCase());\n } else if (filter.to === null) {\n toArray.push(null); //TODO, is this correct?\n }\n } else if (!!optionsAddresses.length && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n if (filter.function) {\n funcArray.push(functionToSighash(filter.function));\n }\n\n if (toArray.length !== 0) {\n txConditions.to = toArray;\n }\n if (fromArray.length !== 0) {\n txConditions.from = fromArray;\n }\n\n if (funcArray.length !== 0) {\n txConditions.function = funcArray;\n }\n\n return txConditions;\n}\n\nfunction eventFilterToDictionaryCondition(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): EthDictionaryLogConditions {\n const logConditions: EthDictionaryLogConditions = {};\n logConditions.address = extractOptionAddresses(dsOptions);\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n // Initialized\n if (!logConditions[field]) {\n logConditions[field] = [];\n }\n if (topic === '!null') {\n logConditions[field] = []; // TODO, check if !null\n } else {\n logConditions[field].push(eventToTopic(topic));\n }\n }\n }\n return logConditions;\n}\n\nexport function buildDictionaryV2QueryEntry(\n dataSources: GroupedEthereumProjectDs[],\n): EthDictionaryV2QueryEntry {\n const dictionaryConditions: EthDictionaryV2QueryEntry = {\n logs: [],\n transactions: [],\n };\n\n for (const ds of dataSources) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return dictionaryConditions;\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n return dictionaryConditions;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n dictionaryConditions.transactions.push(\n callFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n default:\n }\n }\n }\n\n if (!dictionaryConditions.logs.length) {\n delete dictionaryConditions.logs;\n } else {\n dictionaryConditions.logs = uniqBy(dictionaryConditions.logs, isEqual);\n }\n\n if (!dictionaryConditions.transactions.length) {\n delete dictionaryConditions.transactions;\n } else {\n dictionaryConditions.transactions = uniqBy(\n dictionaryConditions.transactions,\n isEqual,\n );\n }\n return dictionaryConditions;\n}\n\nexport class EthDictionaryV2 extends DictionaryV2<\n EthereumBlock,\n SubqlDatasource,\n EthDictionaryV2QueryEntry\n> {\n constructor(\n endpoint: string,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n project: SubqueryProject,\n chainId?: string,\n ) {\n super(\n endpoint,\n chainId ?? project.network.chainId,\n nodeConfig,\n eventEmitter,\n );\n }\n\n static async create(\n endpoint: string,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n project: SubqueryProject,\n chainId?: string,\n ): Promise<EthDictionaryV2> {\n const dictionary = new EthDictionaryV2(\n endpoint,\n nodeConfig,\n eventEmitter,\n project,\n chainId,\n );\n await dictionary.init();\n return dictionary;\n }\n\n buildDictionaryQueryEntries(\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): EthDictionaryV2QueryEntry {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV2QueryEntry(filteredDs);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async getData(\n startBlock: number,\n endBlock: number,\n limit: number = MIN_FETCH_LIMIT,\n ): Promise<DictionaryResponse<IBlock<EthereumBlock> | number> | undefined> {\n return super.getData(startBlock, endBlock, limit, {\n blockHeader: true,\n logs: { transaction: true },\n transactions: { log: true },\n });\n }\n\n convertResponseBlocks<RFB = RawEthBlock>(\n data: RawDictionaryResponseData<RFB>,\n ): DictionaryResponse<IBlock<EthereumBlock>> | undefined {\n try {\n const blocks: IBlock<EthereumBlock>[] = (\n (data.blocks as RawEthBlock[]) || []\n ).map(rawBlockToEthBlock);\n return {\n batchBlocks: blocks,\n lastBufferedHeight: blocks.length\n ? blocks[blocks.length - 1].block.number\n : undefined,\n };\n } catch (e) {\n logger.error(e, `Failed to handle block response}`);\n throw e;\n }\n }\n}\n"]}