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<Tasks>(config: EthConfig, executor: Tasks, eth_api: EthApi) -> Self
25    where
26        Tasks: TaskSpawner + Clone + 'static,
27    {
28        let filter =
29            EthFilter::new(eth_api.clone(), config.filter_config(), Box::new(executor.clone()));
30
31        let pubsub = EthPubSub::with_spawner(eth_api.clone(), Box::new(executor));
32
33        Self { api: eth_api, filter, pubsub }
34    }
35}