instantiate Api types in reth module registry (#5031)

This commit is contained in:
Supernovahs.eth
2023-10-15 19:50:06 +05:30
committed by GitHub
parent 7389aea3db
commit 7e088da99a

View File

@ -791,17 +791,27 @@ impl<Provider, Pool, Network, Tasks, Events>
where
Network: NetworkInfo + Peers + Clone + 'static,
{
/// Instantiates AdminApi
pub fn admin_api(&mut self) -> AdminApi<Network> {
AdminApi::new(self.network.clone())
}
/// Instantiates Web3Api
pub fn web3_api(&mut self) -> Web3Api<Network> {
Web3Api::new(self.network.clone())
}
/// Register Admin Namespace
pub fn register_admin(&mut self) -> &mut Self {
self.modules
.insert(RethRpcModule::Admin, AdminApi::new(self.network.clone()).into_rpc().into());
let adminapi = self.admin_api();
self.modules.insert(RethRpcModule::Admin, adminapi.into_rpc().into());
self
}
/// Register Web3 Namespace
pub fn register_web3(&mut self) -> &mut Self {
self.modules
.insert(RethRpcModule::Web3, Web3Api::new(self.network.clone()).into_rpc().into());
let web3api = self.web3_api();
self.modules.insert(RethRpcModule::Web3, web3api.into_rpc().into());
self
}
}
@ -832,37 +842,22 @@ where
/// Register Otterscan Namespace
pub fn register_ots(&mut self) -> &mut Self {
let eth_api = self.eth_api();
self.modules.insert(RethRpcModule::Ots, OtterscanApi::new(eth_api).into_rpc().into());
let otterscan_api = self.otterscan_api();
self.modules.insert(RethRpcModule::Ots, otterscan_api.into_rpc().into());
self
}
/// Register Debug Namespace
pub fn register_debug(&mut self) -> &mut Self {
let eth_api = self.eth_api();
self.modules.insert(
RethRpcModule::Debug,
DebugApi::new(
self.provider.clone(),
eth_api,
Box::new(self.executor.clone()),
self.tracing_call_guard.clone(),
)
.into_rpc()
.into(),
);
let debug_api = self.debug_api();
self.modules.insert(RethRpcModule::Debug, debug_api.into_rpc().into());
self
}
/// Register Trace Namespace
pub fn register_trace(&mut self) -> &mut Self {
let eth = self.eth_handlers();
self.modules.insert(
RethRpcModule::Trace,
TraceApi::new(self.provider.clone(), eth.api, self.tracing_call_guard.clone())
.into_rpc()
.into(),
);
let trace_api = self.trace_api();
self.modules.insert(RethRpcModule::Trace, trace_api.into_rpc().into());
self
}
@ -889,20 +884,15 @@ where
/// Register Net Namespace
pub fn register_net(&mut self) -> &mut Self {
let eth_api = self.eth_api();
self.modules.insert(
RethRpcModule::Net,
NetApi::new(self.network.clone(), eth_api).into_rpc().into(),
);
let netapi = self.net_api();
self.modules.insert(RethRpcModule::Net, netapi.into_rpc().into());
self
}
/// Register Reth namespace
pub fn register_reth(&mut self) -> &mut Self {
self.modules.insert(
RethRpcModule::Reth,
RethApi::new(self.provider.clone(), Box::new(self.executor.clone())).into_rpc().into(),
);
let rethapi = self.reth_api();
self.modules.insert(RethRpcModule::Reth, rethapi.into_rpc().into());
self
}
@ -942,7 +932,6 @@ where
// Create a copy, so we can list out all the methods for rpc_ api
let namespaces: Vec<_> = namespaces.collect();
namespaces
.iter()
.copied()
@ -1079,6 +1068,39 @@ where
pub fn eth_api(&mut self) -> EthApi<Provider, Pool, Network> {
self.with_eth(|handlers| handlers.api.clone())
}
/// Instantiates TraceApi
pub fn trace_api(&mut self) -> TraceApi<Provider, EthApi<Provider, Pool, Network>> {
let eth = self.eth_handlers();
TraceApi::new(self.provider.clone(), eth.api, self.tracing_call_guard.clone())
}
/// Instantiates OtterscanApi
pub fn otterscan_api(&mut self) -> OtterscanApi<EthApi<Provider, Pool, Network>> {
let eth_api = self.eth_api();
OtterscanApi::new(eth_api)
}
/// Instantiates DebugApi
pub fn debug_api(&mut self) -> DebugApi<Provider, EthApi<Provider, Pool, Network>> {
let eth_api = self.eth_api();
DebugApi::new(
self.provider.clone(),
eth_api,
Box::new(self.executor.clone()),
self.tracing_call_guard.clone(),
)
}
/// Instantiates NetApi
pub fn net_api(&mut self) -> NetApi<Network, EthApi<Provider, Pool, Network>> {
let eth_api = self.eth_api();
NetApi::new(self.network.clone(), eth_api)
}
/// Instantiates RethApi
pub fn reth_api(&mut self) -> RethApi<Provider> {
RethApi::new(self.provider.clone(), Box::new(self.executor.clone()))
}
}
/// A builder type for configuring and launching the servers that will handle RPC requests.