starknet.js
starknet.js copied to clipboard
Add polling for getBlock and emit `block` event whenever a new block is added on Starknet
To be implemented on Provider
this sounds like a very heavy method.. I don't like polling very much. If implemented with polling then it should be lazy.
private async waitTillBlock(blockNumber: number) {
let latestBlockNumber;
while (latestBlockNumber !== blockNumber) {
try {
latestBlockNumber = await this.provider.getBlockNumber();
this.log.info(`waiting till block`, { waitingFor: blockNumber, latest: latestBlockNumber });
} catch (e) {
this.log.warn('failed to get block number, retrying', {
err: e
});
}
await Promise.delay(10000);
}
}
I don't know if are there use cases for this but as a method, we can have it in both providers, I see no reason for this not to be implemented. Ideally, this would be implemented true WebSocket for RPC but until we get to Nodes with it we can provide this? @rzmahmood Can you create PR for this? Or if not we can close the Issue until someone ask for it?
Closing in favour of https://github.com/0xs34n/starknet.js/issues/112 ...since support for WebSockets should become a reality soon on Pathfinder