From 0573393e8da93c2a43197cb07c9609cf59ee4388 Mon Sep 17 00:00:00 2001 From: Anynomouss Date: Wed, 5 Feb 2025 20:54:33 +0100 Subject: [PATCH] More debugging, next trace the overwrite of the config --- config/src/config.rs | 92 ++++++++++++++++++++++++++++++++---------- src/bin/grin-wallet.rs | 8 +--- 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index 327f16b..01af83c 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -43,28 +43,28 @@ pub const API_SECRET_FILE_NAME: &str = ".foreign_api_secret"; /// Owner API secret pub const OWNER_API_SECRET_FILE_NAME: &str = ".owner_api_secret"; -fn get_grin_wallet_path( +fn get_grin_path( chain_type: &global::ChainTypes, create_path: bool, ) -> Result { // Check if grin dir exists - let mut grin_wallet_path = match dirs::home_dir() { + let mut grin_path = match dirs::home_dir() { Some(p) => p, None => PathBuf::new(), }; - grin_wallet_path.push(GRIN_HOME); - grin_wallet_path.push(chain_type.shortname()); + grin_path.push(GRIN_HOME); + grin_path.push(chain_type.shortname()); // Create if the default path doesn't exist - if !grin_wallet_path.exists() && create_path { - fs::create_dir_all(grin_wallet_path.clone())?; + if !grin_path.exists() && create_path { + fs::create_dir_all(grin_path.clone())?; } - if !grin_wallet_path.exists() { + if !grin_path.exists() { Err(ConfigError::PathNotFoundError(String::from( - grin_wallet_path.to_str().unwrap(), + grin_path.to_str().unwrap(), ))) } else { - Ok(grin_wallet_path) + Ok(grin_path) } } @@ -120,11 +120,11 @@ fn check_api_secret_file( data_path: Option, file_name: &str, ) -> Result<(), ConfigError> { - let grin_wallet_path = match data_path { + let grin_path = match data_path { Some(p) => p, - None => get_grin_wallet_path(chain_type, false)?, + None => get_grin_path(chain_type, false)?, }; - let mut api_secret_path = grin_wallet_path; + let mut api_secret_path = grin_path; api_secret_path.push(file_name); if !api_secret_path.exists() { init_api_secret(&api_secret_path) @@ -144,21 +144,23 @@ pub fn initial_setup_wallet( fs::create_dir_all(p)?; } } - // Use config file if current directory if it exists, .grin home otherwise + // Use config file in current directory if it exists, .grin home otherwise let (path, config) = if let Some(p) = check_config_current_dir(WALLET_CONFIG_FILE_NAME) { let mut path = p.clone(); path.pop(); + dbg!("This means the config file already exists!"); (path, GlobalWalletConfig::new(p.to_str().unwrap())?) } else { // Check if grin dir exists - let node_path = get_grin_wallet_path(chain_type, create_path)?; - let grin_wallet_path = match data_path { + let node_path = get_grin_path(chain_type, false)?; + dbg!("in init function 1", &node_path); + let grin_path = match data_path { Some(p) => p, None => node_path.clone(), }; // Get path to default config file - let mut config_path = grin_wallet_path.clone(); + let mut config_path = grin_path.clone(); config_path.push(WALLET_CONFIG_FILE_NAME); // Return defaults if file doesn't exist @@ -167,8 +169,30 @@ pub fn initial_setup_wallet( let mut default_config = GlobalWalletConfig::for_chain(chain_type); default_config.config_file_path = Some(config_path); // update paths relative to current dir, assumes node secret is in user home - default_config.update_paths(&grin_wallet_path, &node_path); - // Write config file, otherwise default will writen + dbg!( + "This is the node_path before asking update_paths {}", + &node_path + ); + default_config.update_paths(&grin_path, &node_path); + dbg!( + "This path, after this line write to config file before default will do so: {}", + &default_config + .members + .as_mut() + .unwrap() + .wallet + .node_api_secret_path + ); + // Write config file, otherwise defaults will be writen + dbg!( + "This path, after this line write to config file before default will do so: {}", + &default_config + .members + .as_mut() + .unwrap() + .wallet + .node_api_secret_path + ); default_config.write_to_file( &default_config .config_file_path @@ -180,11 +204,29 @@ pub fn initial_setup_wallet( None, None, ); - (grin_wallet_path, default_config) + + // After writing the updated config, load it as strig + let mut path = default_config.config_file_path.clone(); + path.pop(); + dbg!( + "Here we load from the cofig we just wrote {}", + &config_path.clone().exists() + ); + ( + path.unwrap(), + GlobalWalletConfig::new(config_path.to_str().unwrap())?, + ) + + // Before it would retuur + // (grin_path, default_config) } true => { let mut path = config_path.clone(); path.pop(); + dbg!( + "This means the file exists already.... arm on in match in connfig init {}", + &config_path.clone().exists() + ); ( path, GlobalWalletConfig::new(config_path.to_str().unwrap())?, @@ -194,7 +236,10 @@ pub fn initial_setup_wallet( }; check_api_secret_file(chain_type, Some(path.clone()), OWNER_API_SECRET_FILE_NAME)?; check_api_secret_file(chain_type, Some(path), API_SECRET_FILE_NAME)?; - // println!("{:#?}",&config.members.clone().unwrap().wallet.node_api_secret_path); + println!( + "{:#?}", + &config.members.clone().unwrap().wallet.node_api_secret_path + ); // println!("CONFIG APPEARS TO BE OK"); Ok(config) } @@ -293,10 +338,13 @@ impl GlobalWalletConfig { Some(secret_path.to_str().unwrap().to_owned()); let mut node_secret_path = node_home.clone(); node_secret_path.push(API_SECRET_FILE_NAME); - dbg!(&node_secret_path); + dbg!("Voor update, path to node to set to:{}", &node_secret_path); self.members.as_mut().unwrap().wallet.node_api_secret_path = Some(node_secret_path.to_str().unwrap().to_owned()); - dbg!(&self.members.as_mut().unwrap().wallet.node_api_secret_path); + dbg!( + "Na update, path to node:{}", + &self.members.as_mut().unwrap().wallet.node_api_secret_path + ); let mut log_path = wallet_home.clone(); log_path.push(WALLET_LOG_FILE_NAME); self.members diff --git a/src/bin/grin-wallet.rs b/src/bin/grin-wallet.rs index 50e7455..0974407 100644 --- a/src/bin/grin-wallet.rs +++ b/src/bin/grin-wallet.rs @@ -110,7 +110,6 @@ fn real_main() -> i32 { // Load relevant config, try and load a wallet config file // Use defaults for configuration if config file not found anywhere - dbg!(¤t_dir, &create_path); let mut config = match config::initial_setup_wallet(&chain_type, current_dir, create_path) { Ok(c) => c, Err(e) => match e { @@ -142,6 +141,7 @@ fn real_main() -> i32 { println!("here3"); log_build_info(); + dbg!(&config.members.as_mut().unwrap().wallet.node_api_secret_path); global::init_global_chain_type( config .members @@ -153,14 +153,10 @@ fn real_main() -> i32 { .unwrap() .clone(), ); - println!("here4"); global::init_global_accept_fee_base(config.members.as_ref().unwrap().wallet.accept_fee_base()); let wallet_config = config.clone().members.unwrap().wallet; - println!("here5"); + dbg!(&config.members.as_mut().unwrap().wallet.node_api_secret_path); let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None).unwrap(); - println!("here6"); - //dbg!(&config.check_node_api_http_addr, None).unwrap(); - println!("here7"); cmd::wallet_command(&args, config, node_client) }