Skip to content

Commit

Permalink
Fix custom wallet startup logic
Browse files Browse the repository at this point in the history
Added a logic so that the wallet will not ask to connect to a detected base node if
a custom base node has already been set in the database.
  • Loading branch information
hansieodendaal committed May 31, 2023
1 parent 9d0d8b5 commit 2a8dfd9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
12 changes: 10 additions & 2 deletions applications/tari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,23 @@ pub async fn get_base_node_peer_config(
wallet: &mut WalletSqlite,
non_interactive_mode: bool,
) -> Result<PeerConfig, ExitError> {
let mut use_custom_base_node_peer = false;
let mut selected_base_node = match config.wallet.custom_base_node {
Some(ref custom) => SeedPeer::from_str(custom)
.map(|node| Some(Peer::from(node)))
.map_err(|err| ExitError::new(ExitCode::ConfigError, format!("Malformed custom base node: {}", err)))?,
None => get_custom_base_node_peer_from_db(wallet),
None => {
if let Some(custom_base_node_peer) = get_custom_base_node_peer_from_db(wallet) {
use_custom_base_node_peer = true;
Some(custom_base_node_peer)
} else {
None
}
},
};

// If the user has not explicitly set a base node in the config, we try detect one
if !non_interactive_mode && config.wallet.custom_base_node.is_none() {
if !non_interactive_mode && config.wallet.custom_base_node.is_none() && !use_custom_base_node_peer {
if let Some(detected_node) = detect_local_base_node(config.wallet.network).await {
match selected_base_node {
Some(ref base_node) if base_node.public_key == detected_node.public_key => {
Expand Down
5 changes: 1 addition & 4 deletions common/src/configuration/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ pub trait ConfigLoader: ConfigPath + Sized {
/// config.set("my_node.goodbye_message", "see you later");
/// let my_config = MyNodeConfig::load_from(&config).unwrap();
/// assert_eq!(my_config.goodbye_message, "see you later".to_string());
/// assert_eq!(
/// my_config.welcome_message,
/// MyNodeConfig::default().welcome_message
/// );
/// assert_eq!(my_config.welcome_message, MyNodeConfig::default().welcome_message);
/// ```
pub trait DefaultConfigLoader: ConfigPath + Sized {
/// Try to load configuration from supplied Config by `main_key_prefix()`
Expand Down
4 changes: 1 addition & 3 deletions comms/dht/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ use crate::{
///
/// ```rust
/// # use tari_comms_dht::{DbConnectionUrl, Dht};
/// let builder = Dht::builder()
/// .mainnet()
/// .with_database_url(DbConnectionUrl::Memory);
/// let builder = Dht::builder().mainnet().with_database_url(DbConnectionUrl::Memory);
/// // let dht = builder.build(...).unwrap();
/// ```
#[derive(Debug, Clone, Default)]
Expand Down

0 comments on commit 2a8dfd9

Please sign in to comment.