Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ltitanb committed Aug 1, 2024
1 parent 3aa8dc8 commit 43ced3d
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions crates/common/src/config/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eyre::{eyre, ContextCompat, Result};
use eyre::{ContextCompat, Result};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use toml::Table;

Expand Down Expand Up @@ -85,26 +85,27 @@ pub fn load_commit_module_config<T: DeserializeOwned>() -> Result<StartCommitMod
let matches: Vec<ThisModuleConfig<T>> = 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)]
Expand Down Expand Up @@ -153,22 +154,23 @@ pub fn load_builder_module_config<T: DeserializeOwned>() -> eyre::Result<StartBu
let matches: Vec<ThisModuleConfig<T>> = 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,
})
}

0 comments on commit 43ced3d

Please sign in to comment.