mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
In the middle of debugging hell, default overwrite any updates to the config made earlier, its never written to a file when running init
This commit is contained in:
Generated
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
@@ -1531,6 +1531,7 @@ dependencies = [
|
|||||||
"byteorder",
|
"byteorder",
|
||||||
"chrono",
|
"chrono",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
|
"dirs 2.0.2",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
"futures 0.3.31",
|
"futures 0.3.31",
|
||||||
"grin_api",
|
"grin_api",
|
||||||
|
|||||||
+40
-45
@@ -35,7 +35,7 @@ use crate::util::logger::LoggingConfig;
|
|||||||
/// Wallet configuration file name
|
/// Wallet configuration file name
|
||||||
pub const WALLET_CONFIG_FILE_NAME: &str = "grin-wallet.toml";
|
pub const WALLET_CONFIG_FILE_NAME: &str = "grin-wallet.toml";
|
||||||
const WALLET_LOG_FILE_NAME: &str = "grin-wallet.log";
|
const WALLET_LOG_FILE_NAME: &str = "grin-wallet.log";
|
||||||
const GRIN_HOME: &str = ".grin";
|
pub const GRIN_HOME: &str = ".grin";
|
||||||
/// Wallet data directory
|
/// Wallet data directory
|
||||||
pub const GRIN_WALLET_DIR: &str = "wallet_data";
|
pub const GRIN_WALLET_DIR: &str = "wallet_data";
|
||||||
/// Node API secret
|
/// Node API secret
|
||||||
@@ -43,28 +43,28 @@ pub const API_SECRET_FILE_NAME: &str = ".foreign_api_secret";
|
|||||||
/// Owner API secret
|
/// Owner API secret
|
||||||
pub const OWNER_API_SECRET_FILE_NAME: &str = ".owner_api_secret";
|
pub const OWNER_API_SECRET_FILE_NAME: &str = ".owner_api_secret";
|
||||||
|
|
||||||
fn get_grin_path(
|
fn get_grin_wallet_path(
|
||||||
chain_type: &global::ChainTypes,
|
chain_type: &global::ChainTypes,
|
||||||
create_path: bool,
|
create_path: bool,
|
||||||
) -> Result<PathBuf, ConfigError> {
|
) -> Result<PathBuf, ConfigError> {
|
||||||
// Check if grin dir exists
|
// Check if grin dir exists
|
||||||
let mut grin_path = match dirs::home_dir() {
|
let mut grin_wallet_path = match dirs::home_dir() {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => PathBuf::new(),
|
None => PathBuf::new(),
|
||||||
};
|
};
|
||||||
grin_path.push(GRIN_HOME);
|
grin_wallet_path.push(GRIN_HOME);
|
||||||
grin_path.push(chain_type.shortname());
|
grin_wallet_path.push(chain_type.shortname());
|
||||||
// Create if the default path doesn't exist
|
// Create if the default path doesn't exist
|
||||||
if !grin_path.exists() && create_path {
|
if !grin_wallet_path.exists() && create_path {
|
||||||
fs::create_dir_all(grin_path.clone())?;
|
fs::create_dir_all(grin_wallet_path.clone())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !grin_path.exists() {
|
if !grin_wallet_path.exists() {
|
||||||
Err(ConfigError::PathNotFoundError(String::from(
|
Err(ConfigError::PathNotFoundError(String::from(
|
||||||
grin_path.to_str().unwrap(),
|
grin_wallet_path.to_str().unwrap(),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
Ok(grin_path)
|
Ok(grin_wallet_path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,22 +83,6 @@ fn check_config_current_dir(path: &str) -> Option<PathBuf> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the node api secret in wallet dir, else return default path
|
|
||||||
fn check_node_api_exists(path: &str) -> Option<PathBuf> {
|
|
||||||
let p = env::current_dir();
|
|
||||||
let mut c = match p {
|
|
||||||
Ok(c) => c,
|
|
||||||
Err(_) => {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
c.push(path);
|
|
||||||
if c.exists() {
|
|
||||||
return Some(c);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether a config file exists at the given directory
|
/// Whether a config file exists at the given directory
|
||||||
pub fn config_file_exists(path: &str) -> bool {
|
pub fn config_file_exists(path: &str) -> bool {
|
||||||
let mut path = PathBuf::from(path);
|
let mut path = PathBuf::from(path);
|
||||||
@@ -136,11 +120,11 @@ fn check_api_secret_file(
|
|||||||
data_path: Option<PathBuf>,
|
data_path: Option<PathBuf>,
|
||||||
file_name: &str,
|
file_name: &str,
|
||||||
) -> Result<(), ConfigError> {
|
) -> Result<(), ConfigError> {
|
||||||
let grin_path = match data_path {
|
let grin_wallet_path = match data_path {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => get_grin_path(chain_type, false)?,
|
None => get_grin_wallet_path(chain_type, false)?,
|
||||||
};
|
};
|
||||||
let mut api_secret_path = grin_path;
|
let mut api_secret_path = grin_wallet_path;
|
||||||
api_secret_path.push(file_name);
|
api_secret_path.push(file_name);
|
||||||
if !api_secret_path.exists() {
|
if !api_secret_path.exists() {
|
||||||
init_api_secret(&api_secret_path)
|
init_api_secret(&api_secret_path)
|
||||||
@@ -167,13 +151,14 @@ pub fn initial_setup_wallet(
|
|||||||
(path, GlobalWalletConfig::new(p.to_str().unwrap())?)
|
(path, GlobalWalletConfig::new(p.to_str().unwrap())?)
|
||||||
} else {
|
} else {
|
||||||
// Check if grin dir exists
|
// Check if grin dir exists
|
||||||
let grin_path = match data_path {
|
let node_path = get_grin_wallet_path(chain_type, create_path)?;
|
||||||
|
let grin_wallet_path = match data_path {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => get_grin_path(chain_type, create_path)?,
|
None => node_path.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get path to default config file
|
// Get path to default config file
|
||||||
let mut config_path = grin_path.clone();
|
let mut config_path = grin_wallet_path.clone();
|
||||||
config_path.push(WALLET_CONFIG_FILE_NAME);
|
config_path.push(WALLET_CONFIG_FILE_NAME);
|
||||||
|
|
||||||
// Return defaults if file doesn't exist
|
// Return defaults if file doesn't exist
|
||||||
@@ -181,9 +166,21 @@ pub fn initial_setup_wallet(
|
|||||||
false => {
|
false => {
|
||||||
let mut default_config = GlobalWalletConfig::for_chain(chain_type);
|
let mut default_config = GlobalWalletConfig::for_chain(chain_type);
|
||||||
default_config.config_file_path = Some(config_path);
|
default_config.config_file_path = Some(config_path);
|
||||||
// update paths relative to current dir
|
// update paths relative to current dir, assumes node secret is in user home
|
||||||
default_config.update_paths(&grin_path);
|
default_config.update_paths(&grin_wallet_path, &node_path);
|
||||||
(grin_path, default_config)
|
// Write config file, otherwise default will writen
|
||||||
|
default_config.write_to_file(
|
||||||
|
&default_config
|
||||||
|
.config_file_path
|
||||||
|
.clone()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
(grin_wallet_path, default_config)
|
||||||
}
|
}
|
||||||
true => {
|
true => {
|
||||||
let mut path = config_path.clone();
|
let mut path = config_path.clone();
|
||||||
@@ -195,9 +192,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.clone()), OWNER_API_SECRET_FILE_NAME)?;
|
||||||
check_api_secret_file(chain_type, Some(path), 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 APPEARS TO BE OK");
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +282,7 @@ impl GlobalWalletConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update paths
|
/// Update paths
|
||||||
pub fn update_paths(&mut self, wallet_home: &PathBuf) {
|
pub fn update_paths(&mut self, wallet_home: &PathBuf, node_home: &PathBuf) {
|
||||||
let mut wallet_path = wallet_home.clone();
|
let mut wallet_path = wallet_home.clone();
|
||||||
wallet_path.push(GRIN_WALLET_DIR);
|
wallet_path.push(GRIN_WALLET_DIR);
|
||||||
self.members.as_mut().unwrap().wallet.data_file_dir =
|
self.members.as_mut().unwrap().wallet.data_file_dir =
|
||||||
@@ -293,15 +291,12 @@ impl GlobalWalletConfig {
|
|||||||
secret_path.push(OWNER_API_SECRET_FILE_NAME);
|
secret_path.push(OWNER_API_SECRET_FILE_NAME);
|
||||||
self.members.as_mut().unwrap().wallet.api_secret_path =
|
self.members.as_mut().unwrap().wallet.api_secret_path =
|
||||||
Some(secret_path.to_str().unwrap().to_owned());
|
Some(secret_path.to_str().unwrap().to_owned());
|
||||||
let mut node_secret_path = wallet_home.clone();
|
let mut node_secret_path = node_home.clone();
|
||||||
node_secret_path.push(API_SECRET_FILE_NAME);
|
node_secret_path.push(API_SECRET_FILE_NAME);
|
||||||
// Set node API secret path to the wallet dir if it exists, else keep default home dir
|
dbg!(&node_secret_path);
|
||||||
// if node_secret_path.exists(){
|
self.members.as_mut().unwrap().wallet.node_api_secret_path =
|
||||||
// self.members.as_mut().unwrap().wallet.node_api_secret_path =
|
Some(node_secret_path.to_str().unwrap().to_owned());
|
||||||
// Some(node_secret_path.to_str().unwrap().to_owned());
|
dbg!(&self.members.as_mut().unwrap().wallet.node_api_secret_path);
|
||||||
// println!("It node path does actually exists")
|
|
||||||
// }
|
|
||||||
|
|
||||||
let mut log_path = wallet_home.clone();
|
let mut log_path = wallet_home.clone();
|
||||||
log_path.push(WALLET_LOG_FILE_NAME);
|
log_path.push(WALLET_LOG_FILE_NAME);
|
||||||
self.members
|
self.members
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ serde_derive = "1"
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
ring = "0.16"
|
ring = "0.16"
|
||||||
|
dirs = "2.0"
|
||||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||||
chrono = { version = "0.4.11", features = ["serde"] }
|
chrono = { version = "0.4.11", features = ["serde"] }
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! Default wallet lifecycle provider
|
//! Default wallet lifecycle provider
|
||||||
|
|
||||||
use crate::config::{
|
use crate::config::{
|
||||||
config, GlobalWalletConfig, GlobalWalletConfigMembers, TorConfig, WalletConfig, GRIN_WALLET_DIR,
|
config, GlobalWalletConfig, GlobalWalletConfigMembers, TorConfig, WalletConfig, GRIN_WALLET_DIR,
|
||||||
};
|
};
|
||||||
@@ -137,10 +136,13 @@ where
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut abs_path = std::env::current_dir()?;
|
// let mut abs_path_node = std::env::current_dir()?;
|
||||||
abs_path.push(self.data_dir.clone());
|
// let mut abs_path_wallet = std::env::current_dir()?;
|
||||||
|
// abs_path_wallet.push(self.data_dir.clone());
|
||||||
|
// abs_path_node.push(self.data_dir.clone());
|
||||||
|
// default_config.update_paths(&abs_path_wallet,&abs_path_node);
|
||||||
|
// println!("here, updating and writing config in default");
|
||||||
|
|
||||||
default_config.update_paths(&abs_path);
|
|
||||||
let res =
|
let res =
|
||||||
default_config.write_to_file(config_file_name.to_str().unwrap(), false, None, None);
|
default_config.write_to_file(config_file_name.to_str().unwrap(), false, None, None);
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ fn real_main() -> i32 {
|
|||||||
|
|
||||||
// Load relevant config, try and load a wallet config file
|
// Load relevant config, try and load a wallet config file
|
||||||
// Use defaults for configuration if config file not found anywhere
|
// 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) {
|
let mut config = match config::initial_setup_wallet(&chain_type, current_dir, create_path) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => match e {
|
Err(e) => match e {
|
||||||
@@ -138,7 +139,7 @@ fn real_main() -> i32 {
|
|||||||
"Using wallet configuration file at {}",
|
"Using wallet configuration file at {}",
|
||||||
config.config_file_path.as_ref().unwrap().to_str().unwrap()
|
config.config_file_path.as_ref().unwrap().to_str().unwrap()
|
||||||
);
|
);
|
||||||
|
println!("here3");
|
||||||
log_build_info();
|
log_build_info();
|
||||||
|
|
||||||
global::init_global_chain_type(
|
global::init_global_chain_type(
|
||||||
@@ -152,11 +153,14 @@ fn real_main() -> i32 {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.clone(),
|
.clone(),
|
||||||
);
|
);
|
||||||
|
println!("here4");
|
||||||
global::init_global_accept_fee_base(config.members.as_ref().unwrap().wallet.accept_fee_base());
|
global::init_global_accept_fee_base(config.members.as_ref().unwrap().wallet.accept_fee_base());
|
||||||
|
|
||||||
let wallet_config = config.clone().members.unwrap().wallet;
|
let wallet_config = config.clone().members.unwrap().wallet;
|
||||||
|
println!("here5");
|
||||||
let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None).unwrap();
|
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)
|
cmd::wallet_command(&args, config, node_client)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user