Skip to content

Commit

Permalink
Get it to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Jul 7, 2023
1 parent 308e747 commit ae696d1
Showing 1 changed file with 57 additions and 61 deletions.
118 changes: 57 additions & 61 deletions crates/relayer-cli/src/commands/config/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,92 +83,88 @@ impl Runnable for AutoCmd {
.cloned()
.collect::<Vec<_>>();

let sorted_names_set = HashSet::from_iter(sorted_names.iter().cloned());
let sorted_names_set: HashSet<String> = HashSet::from_iter(sorted_names.iter().cloned());

let commit = self.commit.clone();

// Extract keys and sort chains by name
// Fetch chain configs from the chain registry
info!("Fetching configuration for chains: {sorted_names:?}");

let Ok(config_results) = runtime.block_on(get_configs(&sorted_names, commit)) else {
let config_results = runtime.block_on(get_configs(&sorted_names, commit));

if let Err(e) = config_results {
let config = Config::default();

match store(&config, &self.path) {
Ok(_) => Output::error(format!(
"An error occurred while generating the chain config file.
"An error occurred while generating the chain config file: {}
A default config file has been written at '{}'",
e,
self.path.display(),
))
.exit(),
Err(e) => Output::error(e).exit(),
Err(e) => Output::error(format!("An error occurred while attempting to write the config file: {}", e)).exit(),
}
};

let fetched_configs: Vec<ChainConfig> = config_results
let mut chain_configs: Vec<ChainConfig> = config_results
.unwrap()
.into_iter()
.filter_map(|r| r.ok())
.collect();

match fetched_configs {
Ok(mut chain_configs) => {
let configs_and_keys = chain_configs
.iter_mut()
.zip(names_and_keys.iter().map(|n| &n.1).cloned());

for (chain_config, key_option) in configs_and_keys {
// If a key is provided, use it
if let Some(key_name) = key_option {
info!("{}: uses key \"{}\"", &chain_config.id, &key_name);
chain_config.key_name = key_name;
} else {
// Otherwise, find the key in the keystore
let chain_id = &chain_config.id;
let key = find_key(chain_config);
if let Some(key) = key {
info!("{}: uses key '{}'", &chain_id, &key);
chain_config.key_name = key;
} else {
// If no key is found, warn the user and continue
warn!("No key found for chain: {}", chain_id);
}
}
}

let config = Config {
chains: chain_configs,
..Config::default()
};

match store(&config, &self.path) {
Ok(_) => Output::success_msg(format!(
"Config file written successfully at '{}'",
self.path.display()
))
.exit(),
Err(e) => Output::error(e).exit(),
}
}
Err(e) => {
// In the case that we get a RegistryError, construct a Config with
// the chain configs that were successfully generated. Print out the names
// of the chains whose configs were not successfully generated.
let sorted_names_set = HashSet::from_iter(sorted_names);
let missing_chain_configs: Vec<String> = Vec::new();
let config = Config::default();

match store(&config, &self.path) {
Ok(_) => Output::error(format!(
"An error occurred while generating the chain config file.
A default config file has been written at '{}'
Configurations for the following chains were unable to be generated: {:?}",
// Determine which chains were not fetched
let fetched_chains_set = HashSet::from_iter(chain_configs.iter().map(|c| c.id.id.clone()));
let missing_chains_set: HashSet<_> = sorted_names_set.difference(&fetched_chains_set).collect();

let configs_and_keys = chain_configs
.iter_mut()
.zip(names_and_keys.iter().map(|n| &n.1).cloned());

for (chain_config, key_option) in configs_and_keys {
// If a key is provided, use it
if let Some(key_name) = key_option {
info!("{}: uses key \"{}\"", &chain_config.id, &key_name);
chain_config.key_name = key_name;
} else {
// Otherwise, find the key in the keystore
let chain_id = &chain_config.id;
let key = find_key(chain_config);
if let Some(key) = key {
info!("{}: uses key '{}'", &chain_id, &key);
chain_config.key_name = key;
} else {
// If no key is found, warn the user and continue
warn!("No key found for chain: {}", chain_id);
}
}
}

let config = Config {
chains: chain_configs,
..Config::default()
};

match store(&config, &self.path) {
Ok(_) => {
if missing_chains_set.is_empty() {
Output::success_msg(format!(
"Config file written successfully at '{}'",
self.path.display()
))
.exit()
} else {
Output::success_msg(format!(
"Config file written successfully at '{}'.
However, configurations for the following chains were not able to be generated: {:?}",
self.path.display(),
missing_chain_configs,
missing_chains_set,
))
.exit(),
Err(e) => Output::error(e).exit(),
.exit()
}
}
}
Err(e) => Output::error(format!("An error occurred while attempting to write the config file: {}", e)).exit(),
}
}
}
Expand Down

0 comments on commit ae696d1

Please sign in to comment.