diff --git a/Cargo.lock b/Cargo.lock index 9b2c951..bd3c379 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1479,6 +1479,7 @@ dependencies = [ "grin_core", "grin_util", "grin_wallet_util", + "log", "pretty_assertions", "rand 0.6.5", "serde", diff --git a/config/Cargo.toml b/config/Cargo.toml index 9d329c7..e3e6ee7 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -15,6 +15,7 @@ serde = "1" serde_derive = "1" toml = "0.5" dirs = "2.0" +log = "0.4" grin_wallet_util = { path = "../util", version = "5.4.0-alpha.1" } diff --git a/config/src/comments.rs b/config/src/comments.rs index 4ae9f1b..c027042 100644 --- a/config/src/comments.rs +++ b/config/src/comments.rs @@ -333,10 +333,9 @@ pub fn migrate_comments( None } false => { - let comments: String = - vec_old_conf.iter().map(|s| s.chars()).flatten().collect(); + let comments: String = vec_old_conf.iter().flat_map(|s| s.chars()).collect(); let key = get_key(line_nospace); - match !(key == "NOT_FOUND") { + match key != "NOT_FOUND" { true => { vec_old_conf.clear(); hm_key_cmt_old.insert(key.clone(), comments); @@ -356,10 +355,10 @@ pub fn migrate_comments( .filter_map(|line| { let line_nospace = line.trim(); let is_ascii_control = line_nospace.chars().all(|x| x.is_ascii_control()); - match !(line.contains("#") || is_ascii_control) { + match !line.contains("#") && !is_ascii_control { true => { let key = get_key(line_nospace); - match !(key == "NOT_FOUND") { + match key != "NOT_FOUND" { true => Some((key, line_nospace.to_string())), false => None, } diff --git a/config/src/config.rs b/config/src/config.rs index 9166626..716c7d9 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -14,15 +14,6 @@ //! Configuration file management -use rand::distributions::{Alphanumeric, Distribution}; -use rand::thread_rng; -use std::env; -use std::fs::{self, File}; -use std::io::prelude::*; -use std::io::BufReader; -use std::path::PathBuf; -use toml; - use crate::comments::{insert_comments, migrate_comments}; use crate::core::global; use crate::types::{ @@ -30,6 +21,15 @@ use crate::types::{ }; use crate::types::{TorConfig, WalletConfig}; use crate::util::logger::LoggingConfig; +use log::warn; +use rand::distributions::{Alphanumeric, Distribution}; +use rand::thread_rng; +use std::env; +use std::fs::{self, File}; +use std::io::prelude::*; +use std::io::BufReader; +use std::path::{Path, PathBuf}; +use toml; /// Wallet configuration file name pub const WALLET_CONFIG_FILE_NAME: &str = "grin-wallet.toml"; @@ -48,11 +48,12 @@ pub fn get_wallet_path( chain_type: &global::ChainTypes, create_path: bool, ) -> Result { - // 1) A If not new wallet, check if walelt exist in working dir + // 1) A If not a new wallet, check if wallet exist in working dir let mut wallet_path = std::env::current_dir()?; wallet_path.push(GRIN_WALLET_DIR); if create_path == false & wallet_path.exists() { wallet_path.pop(); + println!("Detected 'wallet_data' in your working dir, grin-wallet will select this wallet"); return Ok(wallet_path); }; // 1) B, chose working direcotry Check if grin dir exists @@ -226,10 +227,14 @@ pub fn initial_setup_wallet( let mut path = p.clone(); path.pop(); let mut config = GlobalWalletConfig::new(p.to_str().unwrap())?; - // If loaded an run with 'init', use te config as template, update node and wallet dir + if create_path == false { + warn!("Detected 'wallet.toml' detected in working dir, grin-wallet will load the associated wallet."); + } + // If loaded an run with 'init', use local config as template, update node and wallet dir if create_path == true { config.config_file_path = Some(config_path); config.update_paths(&wallet_path, &node_path); + warn!("Detected 'wallet.toml' in your working dir, grin-wallet will used this config as template for the new wallet config."); } (path, config) } else { @@ -301,7 +306,7 @@ impl GlobalWalletConfig { pub fn for_chain(chain_type: &global::ChainTypes) -> GlobalWalletConfig { let mut defaults_conf = GlobalWalletConfig::default(); let defaults = &mut defaults_conf.members.as_mut().unwrap().wallet; - defaults.chain_type = Some(chain_type.clone()); + defaults.chain_type = Some(*chain_type); match *chain_type { global::ChainTypes::Mainnet => {} @@ -358,12 +363,12 @@ impl GlobalWalletConfig { } /// Update paths - pub fn update_paths(&mut self, wallet_home: &PathBuf, node_home: &PathBuf) { - let mut data_file_dir = wallet_home.clone(); - let mut node_secret_path = node_home.clone(); - let mut secret_path = wallet_home.clone(); - let mut log_path = wallet_home.clone(); - let tor_path = wallet_home.clone(); + pub fn update_paths(&mut self, wallet_home: &PathBuf, node_home: &Path) { + let mut data_file_dir = wallet_home.to_path_buf(); + let mut node_secret_path = node_home.to_path_buf(); + let mut secret_path = wallet_home.to_path_buf(); + let mut log_path = wallet_home.to_path_buf(); + let tor_path = wallet_home.to_path_buf(); node_secret_path.push(API_SECRET_FILE_NAME); data_file_dir.push(GRIN_WALLET_DIR); secret_path.push(OWNER_API_SECRET_FILE_NAME); @@ -429,7 +434,7 @@ impl GlobalWalletConfig { ) -> Result { let config: GlobalWalletConfigMembers = toml::from_str(&GlobalWalletConfig::fix_warning_level(config_str.clone())).unwrap(); - if config.config_file_version != None { + if config.config_file_version.is_some() { return Ok(config_str); } let adjusted_config = GlobalWalletConfigMembers { @@ -437,7 +442,7 @@ impl GlobalWalletConfig { tor: Some(TorConfig { bridge: TorBridgeConfig::default(), proxy: TorProxyConfig::default(), - ..config.tor.unwrap_or(TorConfig::default()) + ..config.tor.unwrap_or_default() }), ..config }; diff --git a/src/bin/grin-wallet.rs b/src/bin/grin-wallet.rs index fb23f9a..9189f02 100644 --- a/src/bin/grin-wallet.rs +++ b/src/bin/grin-wallet.rs @@ -93,7 +93,7 @@ fn real_main() -> i32 { let res = args.value_of("top_level_dir"); match res { Some(d) => { - let d = fmt_path(d.to_owned().to_string()); // Fix for fs to work with paths on Linu + let d = fmt_path(d.to_owned().to_string()); // Fix for fs to work with paths on Linux current_dir = Some(PathBuf::from(d)); } None => {