mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-09 04:48:05 +00:00
Remove check for blocks count in eventsInRange
query and check sync status instead (#482)
* Add check for from and to block in eventsInRange query * Update sync status query for more fields --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
d0aca37a74
commit
4a88ff76e0
@ -587,7 +587,11 @@ export class Schema {
|
|||||||
latestIndexedBlockHash: 'String!',
|
latestIndexedBlockHash: 'String!',
|
||||||
latestIndexedBlockNumber: 'Int!',
|
latestIndexedBlockNumber: 'Int!',
|
||||||
latestCanonicalBlockHash: 'String!',
|
latestCanonicalBlockHash: 'String!',
|
||||||
latestCanonicalBlockNumber: 'Int!'
|
latestCanonicalBlockNumber: 'Int!',
|
||||||
|
initialIndexedBlockHash: 'String!',
|
||||||
|
initialIndexedBlockNumber: 'Int!',
|
||||||
|
latestProcessedBlockHash: 'String!',
|
||||||
|
latestProcessedBlockNumber: 'Int!'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -157,9 +157,14 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
|
|||||||
gqlTotalQueryCount.inc(1);
|
gqlTotalQueryCount.inc(1);
|
||||||
gqlQueryCount.labels('eventsInRange').inc(1);
|
gqlQueryCount.labels('eventsInRange').inc(1);
|
||||||
|
|
||||||
const { expected, actual } = await indexer.getProcessedBlockCountForRange(fromBlockNumber, toBlockNumber);
|
const syncStatus = await indexer.getSyncStatus();
|
||||||
if (expected !== actual) {
|
|
||||||
throw new Error(`Range not available, expected ${expected}, got ${actual} blocks in range`);
|
if (!syncStatus) {
|
||||||
|
throw new Error('No blocks processed yet');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fromBlockNumber < syncStatus.initialIndexedBlockNumber) || (toBlockNumber > syncStatus.latestProcessedBlockNumber)) {
|
||||||
|
throw new Error(`Block range should be between ${syncStatus.initialIndexedBlockNumber} and ${syncStatus.latestProcessedBlockNumber}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = await indexer.getEventsInRange(fromBlockNumber, toBlockNumber);
|
const events = await indexer.getEventsInRange(fromBlockNumber, toBlockNumber);
|
||||||
|
Loading…
Reference in New Issue
Block a user