From 39bfdf854d298c4f0237e108985f12bb9667e21f Mon Sep 17 00:00:00 2001 From: Jay Ji Date: Mon, 21 Aug 2023 14:59:10 +1200 Subject: [PATCH] Fix missing ds option in event query entries (#145) * Fix missing ds option in event query entries * changelog --- packages/node/CHANGELOG.md | 3 ++ .../node/src/indexer/fetch.service.spec.ts | 48 +++++++++++++++++++ packages/node/src/indexer/fetch.service.ts | 21 +++++--- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/packages/node/CHANGELOG.md b/packages/node/CHANGELOG.md index 6de8139447..a3efe07e5c 100644 --- a/packages/node/CHANGELOG.md +++ b/packages/node/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fix missing ds option for event in dictionary query entries (#145) + ## [2.11.1] - 2023-08-14 ### Changed - Synced with main sdk: diff --git a/packages/node/src/indexer/fetch.service.spec.ts b/packages/node/src/indexer/fetch.service.spec.ts index 29921b505b..61e83f0841 100644 --- a/packages/node/src/indexer/fetch.service.spec.ts +++ b/packages/node/src/indexer/fetch.service.spec.ts @@ -82,6 +82,10 @@ describe('Dictionary queries', () => { const ds: SubqlRuntimeDatasource = { kind: EthereumDatasourceKind.Runtime, assets: new Map(), + options: { + abi: 'erc20', + address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', + }, startBlock: 1, mapping: { file: '', @@ -107,6 +111,11 @@ describe('Dictionary queries', () => { { entity: 'evmLogs', conditions: [ + { + field: 'address', + matcher: 'equalTo', + value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + }, { field: 'topics0', value: @@ -153,6 +162,45 @@ describe('Dictionary queries', () => { }, ]); }); + + it('Build a filter with include ds option and contract address', () => { + const ds: SubqlRuntimeDatasource = { + kind: EthereumDatasourceKind.Runtime, + assets: new Map(), + options: { + abi: 'erc20', + address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', + }, + startBlock: 1, + mapping: { + file: '', + handlers: [ + { + handler: 'handleTransfer', + kind: EthereumHandlerKind.Call, + filter: { + function: 'approve(address spender, uint256 rawAmount)', + }, + }, + ], + }, + }; + + const result = buildDictionaryQueryEntries([ds], 1); + expect(result).toEqual([ + { + entity: 'evmTransactions', + conditions: [ + { + field: 'address', + matcher: 'equalTo', + value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + }, + { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' }, + ], + }, + ]); + }); }); describe('Correct dictionary query with dynamic ds', () => { it('Build correct erc1155 transfer single query', () => { diff --git a/packages/node/src/indexer/fetch.service.ts b/packages/node/src/indexer/fetch.service.ts index 26c03bb62e..60e0046e21 100644 --- a/packages/node/src/indexer/fetch.service.ts +++ b/packages/node/src/indexer/fetch.service.ts @@ -43,14 +43,11 @@ const BLOCK_TIME_VARIANCE = 5000; const INTERVAL_PERCENT = 0.9; -function eventFilterToQueryEntry( - filter: EthereumLogFilter, +function appendDsOptions( dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[], -): DictionaryQueryEntry { + conditions: DictionaryQueryCondition[], +): void { const queryAddressLimit = yargsOptions.argv['query-address-limit']; - - const conditions: DictionaryQueryCondition[] = []; - if (Array.isArray(dsOptions)) { const addresses = dsOptions.map((option) => option.address).filter(Boolean); @@ -76,6 +73,14 @@ function eventFilterToQueryEntry( }); } } +} + +function eventFilterToQueryEntry( + filter: EthereumLogFilter, + dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[], +): DictionaryQueryEntry { + const conditions: DictionaryQueryCondition[] = []; + appendDsOptions(dsOptions, conditions); if (filter.topics) { for (let i = 0; i < Math.min(filter.topics.length, 4); i++) { const topic = filter.topics[i]; @@ -107,8 +112,10 @@ function eventFilterToQueryEntry( function callFilterToQueryEntry( filter: EthereumTransactionFilter, + dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[], ): DictionaryQueryEntry { const conditions: DictionaryQueryCondition[] = []; + appendDsOptions(dsOptions, conditions); if (filter.from) { conditions.push({ field: 'from', @@ -172,7 +179,7 @@ export function buildDictionaryQueryEntries( filter.to !== undefined || filter.function ) { - queryEntries.push(callFilterToQueryEntry(filter)); + queryEntries.push(callFilterToQueryEntry(filter, ds.options)); } else { return []; }