Skip to content

Commit

Permalink
Fix missing ds option in event query entries (#145)
Browse files Browse the repository at this point in the history
* Fix missing ds option in event query entries

* changelog
  • Loading branch information
jiqiang90 authored Aug 21, 2023
1 parent d259efe commit 39bfdf8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
3 changes: 3 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 48 additions & 0 deletions packages/node/src/indexer/fetch.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -107,6 +111,11 @@ describe('Dictionary queries', () => {
{
entity: 'evmLogs',
conditions: [
{
field: 'address',
matcher: 'equalTo',
value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
},
{
field: 'topics0',
value:
Expand Down Expand Up @@ -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', () => {
Expand Down
21 changes: 14 additions & 7 deletions packages/node/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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];
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -172,7 +179,7 @@ export function buildDictionaryQueryEntries(
filter.to !== undefined ||
filter.function
) {
queryEntries.push(callFilterToQueryEntry(filter));
queryEntries.push(callFilterToQueryEntry(filter, ds.options));
} else {
return [];
}
Expand Down

0 comments on commit 39bfdf8

Please sign in to comment.