chore: rm redundant builder types (#11129)

This commit is contained in:
Matthias Seitz
2024-09-23 17:37:45 +02:00
committed by GitHub
parent cf294ce397
commit f81c7d075c
2 changed files with 22 additions and 95 deletions

View File

@ -30,11 +30,17 @@ pub struct EthHandlers<Provider, Pool, Network, Events, EthApi: EthApiTypes> {
impl<Provider, Pool, Network, Events, EthApi> EthHandlers<Provider, Pool, Network, Events, EthApi>
where
EthApi: EthApiTypes,
Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static,
Pool: Send + Sync + Clone + 'static,
Network: Clone + 'static,
Events: CanonStateSubscriptions + Clone + 'static,
EthApi: EthApiTypes + 'static,
{
/// Returns a new [`EthHandlers`] builder.
/// Returns a new instance with handlers for `eth` namespace.
///
/// This will spawn all necessary tasks for the handlers.
#[allow(clippy::too_many_arguments)]
pub fn builder<EvmConfig, Tasks>(
pub fn bootstrap<EvmConfig, Tasks>(
provider: Provider,
pool: Pool,
network: Network,
@ -51,49 +57,11 @@ where
Events,
EthApi,
>,
) -> EthHandlersBuilder<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi> {
EthHandlersBuilder {
provider,
pool,
network,
evm_config,
config,
executor,
events,
eth_api_builder,
}
}
}
/// Builds [`EthHandlers`] for core, filter, and pubsub `eth_` apis.
#[allow(missing_debug_implementations)]
pub struct EthHandlersBuilder<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi> {
provider: Provider,
pool: Pool,
network: Network,
evm_config: EvmConfig,
config: EthConfig,
executor: Tasks,
events: Events,
eth_api_builder: DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi>,
}
impl<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi>
EthHandlersBuilder<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi>
where
Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static,
Pool: Send + Sync + Clone + 'static,
EvmConfig: ConfigureEvm<Header = Header>,
Network: Clone + 'static,
Tasks: TaskSpawner + Clone + 'static,
Events: CanonStateSubscriptions + Clone + 'static,
EthApi: EthApiTypes + 'static,
{
/// Returns a new instance with handlers for `eth` namespace.
pub fn build(self) -> EthHandlers<Provider, Pool, Network, Events, EthApi> {
let Self { provider, pool, network, evm_config, config, executor, events, eth_api_builder } =
self;
) -> Self
where
EvmConfig: ConfigureEvm<Header = Header>,
Tasks: TaskSpawner + Clone + 'static,
{
let cache = EthStateCache::spawn_with(
provider.clone(),
config.cache,
@ -124,62 +92,22 @@ where
let api = eth_api_builder(&ctx);
let filter = EthFilterApiBuilder::build(&ctx);
let pubsub = EthPubSubApiBuilder::build(&ctx);
EthHandlers { api, cache: ctx.cache, filter, pubsub }
}
}
/// Builds the `eth_` namespace API [`EthFilterApiServer`](reth_rpc_eth_api::EthFilterApiServer).
#[derive(Debug)]
pub struct EthFilterApiBuilder;
impl EthFilterApiBuilder {
/// Builds the [`EthFilterApiServer`](reth_rpc_eth_api::EthFilterApiServer), for given context.
pub fn build<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>(
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>,
) -> EthFilter<Provider, Pool, Eth>
where
Provider: Send + Sync + Clone + 'static,
Pool: Send + Sync + Clone + 'static,
Tasks: TaskSpawner + Clone + 'static,
Eth: EthApiTypes + 'static,
{
EthFilter::new(
let filter = EthFilter::new(
ctx.provider.clone(),
ctx.pool.clone(),
ctx.cache.clone(),
ctx.config.filter_config(),
Box::new(ctx.executor.clone()),
)
}
}
);
/// Builds the `eth_` namespace API [`EthPubSubApiServer`](reth_rpc_eth_api::EthFilterApiServer).
#[derive(Debug)]
pub struct EthPubSubApiBuilder;
impl EthPubSubApiBuilder {
/// Builds the [`EthPubSubApiServer`](reth_rpc_eth_api::EthPubSubApiServer), for given context.
pub fn build<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>(
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>,
) -> EthPubSub<Provider, Pool, Events, Network, Eth>
where
Provider: Clone,
Pool: Clone,
Events: Clone,
Network: Clone,
Tasks: TaskSpawner + Clone + 'static,
Eth: EthApiTypes + 'static,
{
EthPubSub::with_spawner(
let pubsub = EthPubSub::with_spawner(
ctx.provider.clone(),
ctx.pool.clone(),
ctx.events.clone(),
ctx.network.clone(),
Box::new(ctx.executor.clone()),
)
);
Self { api, cache: ctx.cache, filter, pubsub }
}
}

View File

@ -661,7 +661,7 @@ where
{
let blocking_pool_guard = BlockingTaskGuard::new(config.eth.max_tracing_requests);
let eth = EthHandlers::builder(
let eth = EthHandlers::bootstrap(
provider.clone(),
pool.clone(),
network.clone(),
@ -670,8 +670,7 @@ where
executor.clone(),
events.clone(),
eth_api_builder,
)
.build();
);
Self {
provider,