alloy_provider/layers/
chain.rsuse alloy_chains::NamedChain;
use alloy_network::Ethereum;
use alloy_transport::Transport;
use std::time::Duration;
use crate::{Provider, ProviderLayer};
#[derive(Debug, Clone, Copy)]
pub struct ChainLayer(NamedChain);
impl ChainLayer {
pub const fn average_blocktime_hint(&self) -> Option<Duration> {
self.0.average_blocktime_hint()
}
}
impl From<NamedChain> for ChainLayer {
fn from(chain: NamedChain) -> Self {
Self(chain)
}
}
impl<P, T> ProviderLayer<P, T, Ethereum> for ChainLayer
where
P: Provider<T>,
T: Transport + Clone,
{
type Provider = P;
fn layer(&self, inner: P) -> Self::Provider {
if !inner.client().is_local() {
if let Some(avg_block_time) = self.average_blocktime_hint() {
let poll_interval = avg_block_time.mul_f32(0.6);
inner.client().set_poll_interval(poll_interval);
}
}
inner
}
}