reth_rpc/rpc.rs
1use alloy_primitives::map::HashMap;
2use alloy_rpc_types::RpcModules;
3use jsonrpsee::core::RpcResult;
4use reth_rpc_api::RpcApiServer;
5use std::sync::Arc;
6
7/// `rpc` API implementation.
8///
9/// This type provides the functionality for handling `rpc` requests
10#[derive(Debug, Clone, Default)]
11pub struct RPCApi {
12 /// The implementation of the Arc api
13 rpc_modules: Arc<RpcModules>,
14}
15
16impl RPCApi {
17 /// Return a new `RPCApi` struct, with given `module_map`
18 pub fn new(module_map: HashMap<String, String>) -> Self {
19 Self { rpc_modules: Arc::new(RpcModules::new(module_map)) }
20 }
21}
22
23impl RpcApiServer for RPCApi {
24 fn rpc_modules(&self) -> RpcResult<RpcModules> {
25 Ok(self.rpc_modules.as_ref().clone())
26 }
27}