From 08487397178a574d2ae1ccb8e4150c1da74f966a Mon Sep 17 00:00:00 2001 From: Aliaksei Misiukevich Date: Sat, 7 Jun 2025 16:51:56 +0200 Subject: [PATCH] feat: fn that replaces and merges network module's endpoints (#16619) Signed-off-by: Aliaksei Misiukevich Co-authored-by: Matthias Seitz --- crates/rpc/rpc-builder/src/lib.rs | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 901fb9c6fb..d0623ea4a9 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -1943,6 +1943,54 @@ impl TransportRpcModules { self.replace_ipc(other)?; Ok(true) } + + /// Adds or replaces given [`Methods`] in http module. + /// + /// Returns `true` if the methods were replaced or added, `false` otherwise. + pub fn add_or_replace_http( + &mut self, + other: impl Into, + ) -> Result { + let other = other.into(); + self.remove_http_methods(other.method_names()); + self.merge_http(other) + } + + /// Adds or replaces given [`Methods`] in ws module. + /// + /// Returns `true` if the methods were replaced or added, `false` otherwise. + pub fn add_or_replace_ws( + &mut self, + other: impl Into, + ) -> Result { + let other = other.into(); + self.remove_ws_methods(other.method_names()); + self.merge_ws(other) + } + + /// Adds or replaces given [`Methods`] in ipc module. + /// + /// Returns `true` if the methods were replaced or added, `false` otherwise. + pub fn add_or_replace_ipc( + &mut self, + other: impl Into, + ) -> Result { + let other = other.into(); + self.remove_ipc_methods(other.method_names()); + self.merge_ipc(other) + } + + /// Adds or replaces given [`Methods`] in all configured network modules. + pub fn add_or_replace_configured( + &mut self, + other: impl Into, + ) -> Result<(), RegisterMethodError> { + let other = other.into(); + self.add_or_replace_http(other.clone())?; + self.add_or_replace_ws(other.clone())?; + self.add_or_replace_ipc(other)?; + Ok(()) + } } /// Returns the methods installed in the given module that match the given filter.