set status every block, discord doesn't rate limit until 50 req/sec

This commit is contained in:
GooeyTuxedo 2023-04-18 21:30:23 -07:00
parent 5c3e1fdd6a
commit 4f5812c2b8
2 changed files with 6 additions and 6 deletions

View File

@ -20,19 +20,19 @@ export const subToBlockHeaders = (setDiscordStatus: () => Promise<void>) => {
web3.eth.subscribe('newBlockHeaders', (error, blockHeader) => {
if (error) console.error(error);
// Set status every 10 blocks
const shouldSetStatus = blockHeader.number % 10 === 0;
const shouldLogWei = blockHeader.number % 10 === 0;
// Get the gas price for this block
web3.eth.getGasPrice((error, gasPrice) => {
if (error) console.error(error);
if (shouldSetStatus) console.log('Gas price in wei:', gasPrice);
if (shouldLogWei) console.log('Gas price in wei:', gasPrice);
redisClient.set('gas-price', Math.round(Number(gasPrice)))
});
if (shouldSetStatus) setDiscordStatus()
// Set status every block
setDiscordStatus()
});
}