reth_rpc_eth_types/builder/
ctx.rsuse reth_chain_state::CanonStateSubscriptions;
use reth_chainspec::ChainSpecProvider;
use reth_primitives::NodePrimitives;
use reth_storage_api::{BlockReader, BlockReaderIdExt};
use reth_tasks::TaskSpawner;
use crate::{
fee_history::fee_history_cache_new_blocks_task, EthConfig, EthStateCache, FeeHistoryCache,
GasPriceOracle,
};
#[derive(Debug, Clone)]
pub struct EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events>
where
Provider: BlockReader,
{
pub provider: Provider,
pub pool: Pool,
pub network: Network,
pub evm_config: EvmConfig,
pub config: EthConfig,
pub executor: Tasks,
pub events: Events,
pub cache: EthStateCache<Provider::Block, Provider::Receipt>,
}
impl<Provider, Pool, EvmConfig, Network, Tasks, Events>
EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events>
where
Provider: BlockReaderIdExt + Clone,
{
pub fn new_fee_history_cache<N>(&self) -> FeeHistoryCache
where
N: NodePrimitives,
Tasks: TaskSpawner,
Events: CanonStateSubscriptions<Primitives = N>,
Provider:
BlockReaderIdExt<Block = N::Block, Receipt = N::Receipt> + ChainSpecProvider + 'static,
{
let fee_history_cache = FeeHistoryCache::new(self.config.fee_history_cache);
let new_canonical_blocks = self.events.canonical_state_stream();
let fhc = fee_history_cache.clone();
let provider = self.provider.clone();
let cache = self.cache.clone();
self.executor.spawn_critical(
"cache canonical blocks for fee history task",
Box::pin(async move {
fee_history_cache_new_blocks_task(fhc, new_canonical_blocks, provider, cache).await;
}),
);
fee_history_cache
}
pub fn new_gas_price_oracle(&self) -> GasPriceOracle<Provider> {
GasPriceOracle::new(self.provider.clone(), self.config.gas_oracle, self.cache.clone())
}
}