From 43ced3d1721ceac4c6b38582345d2065d45b8150 Mon Sep 17 00:00:00 2001 From: ltitanb Date: Thu, 1 Aug 2024 18:04:29 +0100 Subject: [PATCH] comments --- crates/common/src/config/module.rs | 72 +++++++++++++++--------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/crates/common/src/config/module.rs b/crates/common/src/config/module.rs index 953d098..508c6b5 100644 --- a/crates/common/src/config/module.rs +++ b/crates/common/src/config/module.rs @@ -1,4 +1,4 @@ -use eyre::{eyre, ContextCompat, Result}; +use eyre::{ContextCompat, Result}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use toml::Table; @@ -85,26 +85,27 @@ pub fn load_commit_module_config() -> Result> = cb_config .modules .into_iter() - .filter_map(|m| if let ThisModule::Target(config) = m { Some(config) } else { None }) + .filter_map(|m| match m { + ThisModule::Target(config) => Some(config), + _ => None, + }) .collect(); - if matches.is_empty() { - Err(eyre!("Failed to find matching config type")) - } else { - let module_config = matches - .into_iter() - .find(|m| m.static_config.id == module_id) - .wrap_err(format!("failed to find module for {module_id}"))?; - - let signer_client = SignerClient::new(signer_server_address, &module_jwt)?; - - Ok(StartCommitModuleConfig { - id: module_config.static_config.id, - chain: cb_config.chain, - signer_client, - extra: module_config.extra, - }) - } + eyre::ensure!(!matches.is_empty(), "Failed to find matching config type"); + + let module_config = matches + .into_iter() + .find(|m| m.static_config.id == module_id) + .wrap_err(format!("failed to find module for {module_id}"))?; + + let signer_client = SignerClient::new(signer_server_address, &module_jwt)?; + + Ok(StartCommitModuleConfig { + id: module_config.static_config.id, + chain: cb_config.chain, + signer_client, + extra: module_config.extra, + }) } #[derive(Debug)] @@ -153,22 +154,23 @@ pub fn load_builder_module_config() -> eyre::Result> = cb_config .modules .into_iter() - .filter_map(|m| if let ThisModule::Target(config) = m { Some(config) } else { None }) + .filter_map(|m| match m { + ThisModule::Target(config) => Some(config), + _ => None, + }) .collect(); - if matches.is_empty() { - Err(eyre!("Failed to find matching config type")) - } else { - let module_config = matches - .into_iter() - .find(|m| m.static_config.id == module_id) - .wrap_err(format!("failed to find module for {module_id}"))?; - - Ok(StartBuilderModuleConfig { - id: module_config.static_config.id, - chain: cb_config.chain, - server_port: builder_events_port, - extra: module_config.extra, - }) - } + eyre::ensure!(!matches.is_empty(), "Failed to find matching config type"); + + let module_config = matches + .into_iter() + .find(|m| m.static_config.id == module_id) + .wrap_err(format!("failed to find module for {module_id}"))?; + + Ok(StartBuilderModuleConfig { + id: module_config.static_config.id, + chain: cb_config.chain, + server_port: builder_events_port, + extra: module_config.extra, + }) }