diff --git a/blockchain/sync.rs b/blockchain/sync.rs index 108fce2aa08d44efd0c5927b0e17e6cb09bd69ca..b0766079ae4906c5486f05c56c0797506b3bb614 100644 --- a/blockchain/sync.rs +++ b/blockchain/sync.rs @@ -249,6 +249,9 @@ pub fn sync_ts(conf: &DuniterConf, db_ts_path: PathBuf, cautious: bool, verif_in // Get databases path let db_path = duniter_conf::get_blockchain_db_path(&conf.profile(), ¤cy); + // Write nex conf + duniter_conf::write_conf_file(&conf).expect("Fail to write new conf !"); + // Open wot db let wot_db = open_wot_db::<RustyWebOfTrust>(&db_path).expect("Fail to open WotDB !"); diff --git a/blockchain/ts_parsers.rs b/blockchain/ts_parsers.rs index ef516c8f2a2d6f87f519d1afd50e2a0ddb2659bd..2915f8def24c23e9da48f6097cb73707aea15e98 100644 --- a/blockchain/ts_parsers.rs +++ b/blockchain/ts_parsers.rs @@ -341,14 +341,13 @@ pub fn parse_transaction( let outputs_array = source.get("outputs")?.as_array()?; let mut outputs = Vec::with_capacity(outputs_array.len()); for output in outputs_array { - match TransactionOutput::parse_from_str( - output - .as_str() - .expect(&format!("Fail to parse output : {:?}", output)), - ) { - Ok(output) => outputs.push(output), - Err(_) => panic!("Fail to parse output : {:?}", output), - } + outputs.push( + TransactionOutput::parse_from_str( + output + .as_str() + .expect(&format!("Fail to parse output : {:?}", output)), + ).expect(&format!("Fail to parse output : {:?}", output)), + ); } let signatures_array = source.get("signatures")?.as_array()?; let mut signatures = Vec::with_capacity(signatures_array.len()); diff --git a/conf/lib.rs b/conf/lib.rs index d6bb4a1ad046b2b13bbd72606830657be407f0dd..fe82e0af9cc144e5914b2c8a6919a961cc11709f 100644 --- a/conf/lib.rs +++ b/conf/lib.rs @@ -137,15 +137,9 @@ pub fn get_user_datas_folder() -> &'static str { USER_DATAS_FOLDER } -/// Returns the path to the folder containing the user data of the running profile +/// Returns the path to the folder containing the currency datas of the running profile pub fn datas_path(profile: &str, currency: &Currency) -> PathBuf { - let mut datas_path = match env::home_dir() { - Some(path) => path, - None => panic!("Impossible to get your home dir!"), - }; - datas_path.push(".config/"); - datas_path.push(USER_DATAS_FOLDER); - datas_path.push(profile); + let mut datas_path = get_profile_path(profile); datas_path.push(currency.to_string()); if !datas_path.as_path().exists() { fs::create_dir(datas_path.as_path()).expect("Impossible to create currency dir !"); @@ -153,8 +147,8 @@ pub fn datas_path(profile: &str, currency: &Currency) -> PathBuf { datas_path } -/// Load configuration. -pub fn load_conf(profile: &str) -> (DuniterConf, DuniterKeyPairs) { +/// Returns the path to the folder containing the user data of the running profile +pub fn get_profile_path(profile: &str) -> PathBuf { // Define and create datas directory if not exist let mut profile_path = match env::home_dir() { Some(path) => path, @@ -175,6 +169,12 @@ pub fn load_conf(profile: &str) -> (DuniterConf, DuniterKeyPairs) { if !profile_path.as_path().exists() { fs::create_dir(profile_path.as_path()).expect("Impossible to create your profile dir !"); } + profile_path +} + +/// Load configuration. +pub fn load_conf(profile: &str) -> (DuniterConf, DuniterKeyPairs) { + let mut profile_path = get_profile_path(profile); // Load conf let (conf, keypairs) = load_conf_at_path(profile, &profile_path); @@ -283,7 +283,7 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuniterConf, } } else { // Create conf file with default conf - write_conf_file(&conf_path, &DuniterConf::V1(conf.clone())) + write_conf_file(&DuniterConf::V1(conf.clone())) .expect("Fatal error : fail to write default conf file !"); } @@ -309,10 +309,12 @@ pub fn write_keypairs_file( } /// Save configuration in profile folder -pub fn write_conf_file(file_path: &PathBuf, conf: &DuniterConf) -> Result<(), std::io::Error> { +pub fn write_conf_file(conf: &DuniterConf) -> Result<(), std::io::Error> { + let mut conf_path = get_profile_path(&conf.profile()); + conf_path.push("conf.json"); match *conf { DuniterConf::V1(ref conf_v1) => { - let mut f = try!(File::create(file_path.as_path())); + let mut f = try!(File::create(conf_path.as_path())); try!( f.write_all( serde_json::to_string_pretty(conf_v1) diff --git a/documents/blockchain/v10/documents/transaction.rs b/documents/blockchain/v10/documents/transaction.rs index 5e033578cbbdfc952ffb4a67493fa551620cb8bb..0ed63eed529dca9448b6cd56368c5442755f70ef 100644 --- a/documents/blockchain/v10/documents/transaction.rs +++ b/documents/blockchain/v10/documents/transaction.rs @@ -312,6 +312,11 @@ impl UTXOConditions { self.origin_str = None; } } + /// Check validity of this UTXOConditions + pub fn check(&self) -> bool { + !(self.origin_str.is_some() + && self.origin_str.clone().expect("safe unwrap") != self.conditions.to_string()) + } } impl ToString for UTXOConditions { @@ -417,6 +422,10 @@ impl TransactionOutput { fn reduce(&mut self) { self.conditions.reduce() } + /// Check validity of this output + pub fn check(&self) -> bool { + self.conditions.check() + } } impl ToString for TransactionOutput {