Skip to content

Commit

Permalink
Fix option address field (#146)
Browse files Browse the repository at this point in the history
* Convert option address to 'to'

* typo
  • Loading branch information
jiqiang90 authored Aug 22, 2023
1 parent e2ff6a0 commit 3f39786
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
42 changes: 41 additions & 1 deletion packages/node/src/indexer/fetch.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,47 @@ describe('Dictionary queries', () => {
entity: 'evmTransactions',
conditions: [
{
field: 'address',
field: 'to',
matcher: 'equalTo',
value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
},
{ field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },
],
},
]);
});

it('If ds option and filter both provide contract address, it should use ds options one ', () => {
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: {
to: '0xabcde',
function: 'approve(address spender, uint256 rawAmount)',
},
},
],
},
};

const result = buildDictionaryQueryEntries([ds], 1);
expect(result).toEqual([
{
entity: 'evmTransactions',
conditions: [
{
field: 'to',
matcher: 'equalTo',
value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
},
Expand Down
38 changes: 26 additions & 12 deletions packages/node/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,40 @@ function callFilterToQueryEntry(
): DictionaryQueryEntry {
const conditions: DictionaryQueryCondition[] = [];
appendDsOptions(dsOptions, conditions);

for (const condition of conditions) {
if (condition.field === 'address') {
condition.field = 'to';
}
}
if (filter.from) {
conditions.push({
field: 'from',
value: filter.from.toLowerCase(),
matcher: 'equalTo',
});
}
if (filter.to) {
conditions.push({
field: 'to',
value: filter.to.toLowerCase(),
matcher: 'equalTo',
});
} else if (filter.to === null) {
conditions.push({
field: 'to',
value: true as any, // TODO update types to allow boolean
matcher: 'isNull',
});
const optionsAddresses = conditions.find((c) => c.field === 'to');
if (!optionsAddresses) {
if (filter.to) {
conditions.push({
field: 'to',
value: filter.to.toLowerCase(),
matcher: 'equalTo',
});
} else if (filter.to === null) {
conditions.push({
field: 'to',
value: true as any, // TODO update types to allow boolean
matcher: 'isNull',
});
}
} else {
logger.warn(
`TransactionFilter 'to' conflict with 'address' in data source options`,
);
}

if (filter.function) {
conditions.push({
field: 'func',
Expand Down

0 comments on commit 3f39786

Please sign in to comment.