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) => { web3.eth.subscribe('newBlockHeaders', (error, blockHeader) => {
if (error) console.error(error); if (error) console.error(error);
// Set status every 10 blocks const shouldLogWei = blockHeader.number % 10 === 0;
const shouldSetStatus = blockHeader.number % 10 === 0;
// Get the gas price for this block // Get the gas price for this block
web3.eth.getGasPrice((error, gasPrice) => { web3.eth.getGasPrice((error, gasPrice) => {
if (error) console.error(error); 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))) redisClient.set('gas-price', Math.round(Number(gasPrice)))
}); });
if (shouldSetStatus) setDiscordStatus() // Set status every block
setDiscordStatus()
}); });
} }

View File

@ -13,7 +13,7 @@ const handleGasCommand = async (interaction: ChatInputCommandInteraction): Promi
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setColor('#0099ff') .setColor('#0099ff')
.setTitle('Current Gas Prices') .setTitle('Current Gas Prices')
.setDescription(`${gasPrices.fast} ⦚⦚ 🚶${gasPrices.average} ⦚⦚ 🐢${gasPrices.slow}`) .setDescription(` ${gasPrices.fast} ⦚⦚ 🚶 ${gasPrices.average} ⦚⦚ 🐢 ${gasPrices.slow}`)
await interaction.reply({ embeds: [embed] }); await interaction.reply({ embeds: [embed] });
}; };