Update getLogs API usage (#195)

* Update client query to get logs

* Update calls to get logs for contracts
This commit is contained in:
prathamesh0
2022-10-05 15:15:00 +05:30
committed by GitHub
parent 18861eaf79
commit 978f0bb456
8 changed files with 39 additions and 68 deletions
@@ -760,22 +760,16 @@ export class Indexer implements IPLDIndexerInterface {
console.time('time:indexer#_fetchAndSaveEvents-fetch-logs');
if (this._serverConfig.filterLogs) {
const watchedContracts = this._baseIndexer.getWatchedContracts();
const addresses = watchedContracts.map((watchedContract): string => {
return watchedContract.address;
});
// TODO: Query logs by multiple contracts.
const contractlogsPromises = watchedContracts.map((watchedContract): Promise<any> => this._ethClient.getLogs({
const logsResult = await this._ethClient.getLogs({
blockHash,
contract: watchedContract.address
}));
addresses
});
const contractlogs = await Promise.all(contractlogsPromises);
// Flatten logs by contract and sort by index.
logs = contractlogs.map(data => {
return data.logs;
}).flat()
.sort((a, b) => {
return a.index - b.index;
});
logs = logsResult.logs;
} else {
({ logs } = await this._ethClient.getLogs({ blockHash }));
}