Skip to content

Commit

Permalink
feat: add contains fns to transport rpc modules (#12593)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 16, 2024
1 parent b31b1ea commit 02237bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,26 @@ impl TransportRpcModuleConfig {
self.config.as_ref()
}

/// Returns true if the given module is configured for any transport.
pub fn contains_any(&self, module: &RethRpcModule) -> bool {
self.contains_http(module) || self.contains_ws(module) || self.contains_ipc(module)
}

/// Returns true if the given module is configured for the http transport.
pub fn contains_http(&self, module: &RethRpcModule) -> bool {
self.http.as_ref().map_or(false, |http| http.contains(module))
}

/// Returns true if the given module is configured for the ws transport.
pub fn contains_ws(&self, module: &RethRpcModule) -> bool {
self.ws.as_ref().map_or(false, |ws| ws.contains(module))
}

/// Returns true if the given module is configured for the ipc transport.
pub fn contains_ipc(&self, module: &RethRpcModule) -> bool {
self.ipc.as_ref().map_or(false, |ipc| ipc.contains(module))
}

/// Ensures that both http and ws are configured and that they are configured to use the same
/// port.
fn ensure_ws_http_identical(&self) -> Result<(), WsHttpSamePortError> {
Expand Down
9 changes: 9 additions & 0 deletions crates/rpc/rpc-server-types/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ impl RpcModuleSelection {
(None, None) => true,
}
}

/// Returns true if the selection contains the given module.
pub fn contains(&self, module: &RethRpcModule) -> bool {
match self {
Self::All => true,
Self::Standard => Self::STANDARD_MODULES.contains(module),
Self::Selection(s) => s.contains(module),
}
}
}

impl From<&HashSet<RethRpcModule>> for RpcModuleSelection {
Expand Down

0 comments on commit 02237bf

Please sign in to comment.