Skip to content

Commit 675410d

Browse files
authored
add replace and remove methods (paradigmxyz#13059)
Co-authored-by: dkathiriya <lakshya-sky@users.noreply.github.com>
1 parent aacf5d1 commit 675410d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

crates/rpc/rpc-builder/src/auth.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,30 @@ impl AuthRpcModule {
221221
self.module_mut().merge(other.into()).map(|_| true)
222222
}
223223

224+
/// Removes the method with the given name from the configured authenticated methods.
225+
///
226+
/// Returns `true` if the method was found and removed, `false` otherwise.
227+
pub fn remove_auth_method(&mut self, method_name: &'static str) -> bool {
228+
self.module_mut().remove_method(method_name).is_some()
229+
}
230+
231+
/// Removes the given methods from the configured authenticated methods.
232+
pub fn remove_auth_methods(&mut self, methods: impl IntoIterator<Item = &'static str>) {
233+
for name in methods {
234+
self.remove_auth_method(name);
235+
}
236+
}
237+
238+
/// Replace the given [Methods] in the configured authenticated methods.
239+
pub fn replace_auth_methods(
240+
&mut self,
241+
other: impl Into<Methods>,
242+
) -> Result<bool, RegisterMethodError> {
243+
let other = other.into();
244+
self.remove_auth_methods(other.method_names());
245+
self.merge_auth_methods(other)
246+
}
247+
224248
/// Convenience function for starting a server
225249
pub async fn start_server(
226250
self,

0 commit comments

Comments
 (0)