Skip to main content

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::Runtime;
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(config: EthConfig, executor: Runtime, eth_api: EthApi) -> Self {
25        let filter = EthFilter::new(eth_api.clone(), config.filter_config(), executor.clone());
26
27        let pubsub = EthPubSub::new(eth_api.clone(), executor);
28
29        Self { api: eth_api, filter, pubsub }
30    }
31}