reth_rpc_builder/
eth.rs

1use reth_rpc::{EthFilter, EthPubSub};
2use reth_rpc_eth_api::EthApiTypes;
3use reth_rpc_eth_types::EthConfig;
4use reth_tasks::TaskSpawner;
5
6/// Handlers for core, filter and pubsub `eth` namespace APIs.
7#[derive(Debug, Clone)]
8pub struct EthHandlers<EthApi: EthApiTypes> {
9    /// Main `eth_` request handler
10    pub api: EthApi,
11    /// Polling based filter handler available on all transports
12    pub filter: EthFilter<EthApi>,
13    /// Handler for subscriptions only available for transports that support it (ws, ipc)
14    pub pubsub: EthPubSub<EthApi>,
15}
16
17impl<EthApi> EthHandlers<EthApi>
18where
19    EthApi: EthApiTypes + 'static,
20{
21    /// Returns a new instance with the additional handlers for the `eth` namespace.
22    ///
23    /// This will spawn all necessary tasks for the additional handlers.
24    pub fn bootstrap(
25        config: EthConfig,
26        executor: Box<dyn TaskSpawner + 'static>,
27        eth_api: EthApi,
28    ) -> Self {
29        let filter = EthFilter::new(eth_api.clone(), config.filter_config(), executor.clone());
30
31        let pubsub = EthPubSub::with_spawner(eth_api.clone(), executor);
32
33        Self { api: eth_api, filter, pubsub }
34    }
35}