Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add merge_if_module_configured #12608

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,29 @@ impl TransportRpcModules {
&self.config
}

/// Merge the given [`Methods`] in all configured transport modules if the given
/// [`RethRpcModule`] is configured for the transport.
///
/// Fails if any of the methods in other is present already.
pub fn merge_if_module_configured(
&mut self,
module: RethRpcModule,
other: impl Into<Methods>,
) -> Result<(), RegisterMethodError> {
let other = other.into();
if self.module_config().contains_http(&module) {
self.merge_http(other.clone())?;
}
if self.module_config().contains_ws(&module) {
self.merge_ws(other.clone())?;
}
if self.module_config().contains_ipc(&module) {
self.merge_ipc(other)?;
}

Ok(())
}

/// Merge the given [Methods] in the configured http methods.
///
/// Fails if any of the methods in other is present already.
Expand Down
Loading