mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 12:26:19 +00:00
Filter blocks without contract events when eth_getLogs filter is unset
This commit is contained in:
parent
e1abd5f684
commit
6810130ef4
@ -469,10 +469,27 @@ export class Indexer {
|
|||||||
topics
|
topics
|
||||||
});
|
});
|
||||||
|
|
||||||
const blockLogsMap = this._reduceLogsToBlockLogsMap(logs);
|
let blockLogsMap = this._reduceLogsToBlockLogsMap(logs);
|
||||||
// Create unique list of tx required
|
|
||||||
|
// Filter blocks which have no events from watched contracts
|
||||||
|
blockLogsMap = Array.from(blockLogsMap.entries())
|
||||||
|
.filter(([, logs]) => {
|
||||||
|
return logs.some(log => {
|
||||||
|
const contractAddress = ethers.utils.getAddress(log.account.address);
|
||||||
|
return this.isContractAddressWatched(contractAddress)?.length;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.reduce((acc, [blockHash, logs]) => {
|
||||||
|
acc.set(blockHash, logs);
|
||||||
|
return acc;
|
||||||
|
}, new Map());
|
||||||
|
|
||||||
|
// Create unique list of txs required
|
||||||
const txHashes = Array.from([
|
const txHashes = Array.from([
|
||||||
...new Set<string>(logs.map((log: any) => log.transaction.hash))
|
...new Set<string>(
|
||||||
|
Array.from(blockLogsMap.values())
|
||||||
|
.flat()
|
||||||
|
.map((log: any) => log.transaction.hash))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Fetch blocks with transactions for the logs returned
|
// Fetch blocks with transactions for the logs returned
|
||||||
@ -543,7 +560,7 @@ export class Indexer {
|
|||||||
return blocksWithDbEvents;
|
return blocksWithDbEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
_reduceLogsToBlockLogsMap (logs: any[]): Map<string, any> {
|
_reduceLogsToBlockLogsMap (logs: any[]): Map<string, any[]> {
|
||||||
return logs.reduce((acc: Map<string, any>, log: any) => {
|
return logs.reduce((acc: Map<string, any>, log: any) => {
|
||||||
const { blockHash: logBlockHash } = log;
|
const { blockHash: logBlockHash } = log;
|
||||||
assert(typeof logBlockHash === 'string');
|
assert(typeof logBlockHash === 'string');
|
||||||
|
@ -728,9 +728,9 @@ export class JobRunner {
|
|||||||
|
|
||||||
this._blockAndEventsMap.delete(block.blockHash);
|
this._blockAndEventsMap.delete(block.blockHash);
|
||||||
|
|
||||||
// Check if new contract was added and filterLogsByAddresses is set to true
|
// Check if new contract was added
|
||||||
if (isNewContractWatched && this._indexer.upstreamConfig.ethServer.filterLogsByAddresses) {
|
if (isNewContractWatched) {
|
||||||
// Check if historical processing is running and that current block is being processed was trigerred by historical processing
|
// Check if historical processing is running and that current block being processed was trigerred by historical processing
|
||||||
if (this._historicalProcessingCompletedUpto && this._historicalProcessingCompletedUpto > block.blockNumber) {
|
if (this._historicalProcessingCompletedUpto && this._historicalProcessingCompletedUpto > block.blockNumber) {
|
||||||
const nextBlockNumberToProcess = block.blockNumber + 1;
|
const nextBlockNumberToProcess = block.blockNumber + 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user