Skip to content

Commit

Permalink
feature: Network selection for applications
Browse files Browse the repository at this point in the history
  • Loading branch information
StriderDM committed Aug 25, 2021
1 parent 6b91bb6 commit d3f132a
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pub struct ConfigBootstrap {
pub miner_min_diff: Option<u64>,
#[structopt(long, alias = "max-difficulty")]
pub miner_max_diff: Option<u64>,
/// Supply a network (overrides existing configuration)
#[structopt(long, alias = "network")]
pub network: Option<String>,
}

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

0 comments on commit d3f132a

Please sign in to comment.