From ff5028c4813546385d475e1533955b6d5fca5263 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 7 May 2025 17:56:34 +0200 Subject: [PATCH] feat: add AuthHandle::noop (#16082) --- crates/rpc/rpc-builder/src/auth.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/rpc/rpc-builder/src/auth.rs b/crates/rpc/rpc-builder/src/auth.rs index 0c808a823d..4885ef99df 100644 --- a/crates/rpc/rpc-builder/src/auth.rs +++ b/crates/rpc/rpc-builder/src/auth.rs @@ -78,7 +78,7 @@ impl AuthServerConfig { ipc_handle = Some(res); } - Ok(AuthServerHandle { handle, local_addr, secret, ipc_endpoint, ipc_handle }) + Ok(AuthServerHandle { handle: Some(handle), local_addr, secret, ipc_endpoint, ipc_handle }) } } @@ -250,7 +250,7 @@ impl AuthRpcModule { #[must_use = "Server stops if dropped"] pub struct AuthServerHandle { local_addr: SocketAddr, - handle: jsonrpsee::server::ServerHandle, + handle: Option, secret: JwtSecret, ipc_endpoint: Option, ipc_handle: Option, @@ -259,6 +259,22 @@ pub struct AuthServerHandle { // === impl AuthServerHandle === impl AuthServerHandle { + /// Creates a new handle that isn't connected to any server. + /// + /// This can be used to satisfy types that require an engine API. + pub fn noop() -> Self { + Self { + local_addr: SocketAddr::new( + IpAddr::V4(Ipv4Addr::LOCALHOST), + constants::DEFAULT_AUTH_PORT, + ), + handle: None, + secret: JwtSecret::random(), + ipc_endpoint: None, + ipc_handle: None, + } + } + /// Returns the [`SocketAddr`] of the http server if started. pub const fn local_addr(&self) -> SocketAddr { self.local_addr @@ -266,7 +282,8 @@ impl AuthServerHandle { /// Tell the server to stop without waiting for the server to stop. pub fn stop(self) -> Result<(), AlreadyStoppedError> { - self.handle.stop() + let Some(handle) = self.handle else { return Ok(()) }; + handle.stop() } /// Returns the url to the http server