reth_rpc/
rpc.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use alloy_primitives::map::HashMap;
use alloy_rpc_types::RpcModules;
use jsonrpsee::core::RpcResult;
use reth_rpc_api::RpcApiServer;
use std::sync::Arc;

/// `rpc` API implementation.
///
/// This type provides the functionality for handling `rpc` requests
#[derive(Debug, Clone, Default)]
pub struct RPCApi {
    /// The implementation of the Arc api
    rpc_modules: Arc<RpcModules>,
}

impl RPCApi {
    /// Return a new `RPCApi` struct, with given `module_map`
    pub fn new(module_map: HashMap<String, String>) -> Self {
        Self { rpc_modules: Arc::new(RpcModules::new(module_map)) }
    }
}

impl RpcApiServer for RPCApi {
    fn rpc_modules(&self) -> RpcResult<RpcModules> {
        Ok(self.rpc_modules.as_ref().clone())
    }
}