feat: add contains fns to transport rpc modules (#12593)

This commit is contained in:
Matthias Seitz
2024-11-16 05:19:40 +01:00
committed by GitHub
parent b31b1ea288
commit 02237bfa71
2 changed files with 29 additions and 0 deletions

View File

@ -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> {

View File

@ -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 {