Skip to content

Commit

Permalink
feat: allow network to be selected at application start (#3247)
Browse files Browse the repository at this point in the history
Description
Network selection for applications

Motivation and Context
Allows network to be selected at application start

How Has This Been Tested?
Manually
  • Loading branch information
StriderDM committed Aug 30, 2021
1 parent edc1a2b commit 8a36fb5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 29 additions & 2 deletions applications/tari_app_utilities/src/initialization.rs
@@ -1,8 +1,13 @@
use crate::{consts, utilities::ExitCodes};
use config::Config;
use std::path::PathBuf;
use std::{path::PathBuf, str::FromStr};
use structopt::StructOpt;
use tari_common::{configuration::bootstrap::ApplicationType, ConfigBootstrap, DatabaseType, GlobalConfig};
use tari_common::{
configuration::{bootstrap::ApplicationType, Network},
ConfigBootstrap,
DatabaseType,
GlobalConfig,
};

pub const LOG_TARGET: &str = "tari::application";

Expand All @@ -27,6 +32,28 @@ pub fn init_configuration(
let mut global_config = GlobalConfig::convert_from(application_type, cfg.clone())
.map_err(|err| ExitCodes::ConfigError(err.to_string()))?;
check_file_paths(&mut global_config, &bootstrap);

if let Some(str) = bootstrap.network.clone() {
log::info!(target: LOG_TARGET, "Network selection requested");
let network = Network::from_str(&str);
match network {
Ok(network) => {
log::info!(
target: LOG_TARGET,
"Network selection successful, current network is: {}",
network
);
global_config.network = network;
},
Err(_) => {
log::warn!(
target: LOG_TARGET,
"Network selection was invalid, continuing with default network."
);
},
}
}

Ok((bootstrap, global_config, cfg))
}

Expand Down
4 changes: 4 additions & 0 deletions common/src/configuration/bootstrap.rs
Expand Up @@ -148,6 +148,9 @@ pub struct ConfigBootstrap {
pub miner_max_diff: Option<u64>,
#[structopt(long, alias = "tracing")]
pub tracing_enabled: bool,
/// Supply a network (overrides existing configuration)
#[structopt(long, alias = "network")]
pub network: Option<String>,
}

fn normalize_path(path: PathBuf) -> PathBuf {
Expand Down Expand Up @@ -183,6 +186,7 @@ impl Default for ConfigBootstrap {
miner_min_diff: None,
miner_max_diff: None,
tracing_enabled: false,
network: None,
}
}
}
Expand Down

0 comments on commit 8a36fb5

Please sign in to comment.