mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Added extension support for auth rpc module (#6060)
Co-authored-by: root <root@Arindam>
This commit is contained in:
@ -242,7 +242,7 @@ impl RpcServerArgs {
|
||||
let module_config = self.transport_rpc_module_config();
|
||||
debug!(target: "reth::cli", http=?module_config.http(), ws=?module_config.ws(), "Using RPC module config");
|
||||
|
||||
let (mut modules, auth_module, mut registry) = RpcModuleBuilder::default()
|
||||
let (mut modules, mut auth_module, mut registry) = RpcModuleBuilder::default()
|
||||
.with_provider(components.provider())
|
||||
.with_pool(components.pool())
|
||||
.with_network(components.network())
|
||||
@ -250,7 +250,11 @@ impl RpcServerArgs {
|
||||
.with_executor(components.task_executor())
|
||||
.build_with_auth_server(module_config, engine_api);
|
||||
|
||||
let rpc_components = RethRpcComponents { registry: &mut registry, modules: &mut modules };
|
||||
let rpc_components = RethRpcComponents {
|
||||
registry: &mut registry,
|
||||
modules: &mut modules,
|
||||
auth_module: &mut auth_module,
|
||||
};
|
||||
// apply configured customization
|
||||
conf.extend_rpc_modules(self, components, rpc_components)?;
|
||||
|
||||
@ -268,7 +272,7 @@ impl RpcServerArgs {
|
||||
handle
|
||||
});
|
||||
|
||||
let launch_auth = auth_module.start_server(auth_config).map_ok(|handle| {
|
||||
let launch_auth = auth_module.clone().start_server(auth_config).map_ok(|handle| {
|
||||
let addr = handle.local_addr();
|
||||
info!(target: "reth::cli", url=%addr, "RPC auth server started");
|
||||
handle
|
||||
@ -279,7 +283,11 @@ impl RpcServerArgs {
|
||||
let handles = RethRpcServerHandles { rpc, auth };
|
||||
|
||||
// call hook
|
||||
let rpc_components = RethRpcComponents { registry: &mut registry, modules: &mut modules };
|
||||
let rpc_components = RethRpcComponents {
|
||||
registry: &mut registry,
|
||||
modules: &mut modules,
|
||||
auth_module: &mut auth_module,
|
||||
};
|
||||
conf.on_rpc_server_started(self, components, rpc_components, handles.clone())?;
|
||||
|
||||
Ok(handles)
|
||||
|
||||
@ -8,7 +8,8 @@ use reth_provider::{
|
||||
EvmEnvProvider, StateProviderFactory,
|
||||
};
|
||||
use reth_rpc_builder::{
|
||||
auth::AuthServerHandle, RethModuleRegistry, RpcServerHandle, TransportRpcModules,
|
||||
auth::{AuthRpcModule, AuthServerHandle},
|
||||
RethModuleRegistry, RpcServerHandle, TransportRpcModules,
|
||||
};
|
||||
use reth_tasks::TaskSpawner;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
@ -75,11 +76,11 @@ pub trait RethNodeComponents: Clone + Send + Sync + 'static {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper container to encapsulate [RethModuleRegistry] and [TransportRpcModules].
|
||||
/// Helper container to encapsulate [RethModuleRegistry],[TransportRpcModules] and [AuthRpcModule].
|
||||
///
|
||||
/// This can be used to access installed modules, or create commonly used handlers like
|
||||
/// [reth_rpc::EthApi], and ultimately merge additional rpc handler into the configured transport
|
||||
/// modules [TransportRpcModules].
|
||||
/// modules [TransportRpcModules] as well as configured authenticated methods [AuthRpcModule].
|
||||
#[derive(Debug)]
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub struct RethRpcComponents<'a, Reth: RethNodeComponents> {
|
||||
@ -98,6 +99,10 @@ pub struct RethRpcComponents<'a, Reth: RethNodeComponents> {
|
||||
/// This can be used to merge additional modules into the configured transports (http, ipc,
|
||||
/// ws). See [TransportRpcModules::merge_configured]
|
||||
pub modules: &'a mut TransportRpcModules,
|
||||
/// Holds jwt authenticated rpc module.
|
||||
///
|
||||
/// This can be used to merge additional modules into the configured authenticated methods
|
||||
pub auth_module: &'a mut AuthRpcModule,
|
||||
}
|
||||
|
||||
/// A Generic implementation of the RethNodeComponents trait.
|
||||
|
||||
@ -9,6 +9,7 @@ pub use jsonrpsee::server::ServerBuilder;
|
||||
use jsonrpsee::{
|
||||
http_client::HeaderMap,
|
||||
server::{RpcModule, ServerHandle},
|
||||
Methods,
|
||||
};
|
||||
use reth_network_api::{NetworkInfo, Peers};
|
||||
use reth_node_api::EngineTypes;
|
||||
@ -247,12 +248,12 @@ impl AuthServerConfigBuilder {
|
||||
}
|
||||
|
||||
/// Holds installed modules for the auth server.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AuthRpcModule {
|
||||
pub(crate) inner: RpcModule<()>,
|
||||
}
|
||||
|
||||
// === impl TransportRpcModules ===
|
||||
// === impl AuthRpcModule ===
|
||||
|
||||
impl AuthRpcModule {
|
||||
/// Create a new `AuthRpcModule` with the given `engine_api`.
|
||||
@ -271,6 +272,16 @@ impl AuthRpcModule {
|
||||
&mut self.inner
|
||||
}
|
||||
|
||||
/// Merge the given [Methods] in the configured authenticated methods.
|
||||
///
|
||||
/// Fails if any of the methods in other is present already.
|
||||
pub fn merge_auth_methods(
|
||||
&mut self,
|
||||
other: impl Into<Methods>,
|
||||
) -> Result<bool, jsonrpsee::core::error::Error> {
|
||||
self.module_mut().merge(other.into()).map(|_| true)
|
||||
}
|
||||
|
||||
/// Convenience function for starting a server
|
||||
pub async fn start_server(
|
||||
self,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
//! cargo run -p additional-rpc-namespace-in-cli -- node --http --ws --enable-ext
|
||||
//! ```
|
||||
//!
|
||||
//! This installs an additional RPC method `txpoolExt_transactionCount` that can queried via [cast](https://github.com/foundry-rs/foundry)
|
||||
//! This installs an additional RPC method `txpoolExt_transactionCount` that can be queried via [cast](https://github.com/foundry-rs/foundry)
|
||||
//!
|
||||
//! ```sh
|
||||
//! cast rpc txpoolExt_transactionCount
|
||||
|
||||
Reference in New Issue
Block a user