diff --git a/blockchain/apply_valid_block.rs b/blockchain/apply_valid_block.rs index 32f477adb347eda1c8704086ae9624cc0c2ad6a5..f731e93a41da8ffc6e86621cc5333ea33e1b0066 100644 --- a/blockchain/apply_valid_block.rs +++ b/blockchain/apply_valid_block.rs @@ -71,7 +71,8 @@ pub fn apply_valid_block<W: WebOfTrust>( wot_db .write(|db| { db.add_node(); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_index.insert(pubkey, wotb_id); wot_dbs_requests.push(WotsDBsWriteQuery::CreateIdentity( wotb_id, @@ -86,7 +87,8 @@ pub fn apply_valid_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(wotb_id, true); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RenewalIdentity( joiner.issuers()[0], wotb_id, @@ -102,7 +104,8 @@ pub fn apply_valid_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(wotb_id, true); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RenewalIdentity( pubkey, wotb_id, @@ -120,7 +123,8 @@ pub fn apply_valid_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(*wot_id, false); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::ExcludeIdentity( exclusion, block.blockstamp(), @@ -136,7 +140,8 @@ pub fn apply_valid_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(*wot_id, false); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RevokeIdentity( compact_revoc.issuer, block.blockstamp(), @@ -158,7 +163,8 @@ pub fn apply_valid_block<W: WebOfTrust>( wotb_node_from.0, wotb_node_to.0, result ), } - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::CreateCert( compact_cert.issuer, wotb_node_from, @@ -182,7 +188,8 @@ pub fn apply_valid_block<W: WebOfTrust>( RemLinkResult::Removed(_) => {} _ => panic!("Fail to rem_link {}->{} : {:?}", source.0, target.0, result), } - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); } } if let Some(du_amount) = block.dividend { @@ -208,53 +215,53 @@ pub fn apply_valid_block<W: WebOfTrust>( } /*// Calculate the state of the wot - if !wot_events.is_empty() && verif_level != SyncVerificationLevel::FastSync() { - // Calculate sentries_count - let sentries_count = wot.get_sentries(3).len(); - // Calculate average_density - let average_density = calculate_average_density::<W>(&wot); - let sentry_requirement = - get_sentry_requirement(block.members_count, G1_PARAMS.step_max); - // Calculate distances and connectivities - let (average_distance, distances, average_connectivity, connectivities) = - compute_distances::<W>( - &wot, - sentry_requirement, - G1_PARAMS.step_max, - G1_PARAMS.x_percent, - ); - // Calculate centralities and average_centrality - let centralities = - calculate_distance_stress_centralities::<W>(&wot, G1_PARAMS.step_max); - let average_centrality = - (centralities.iter().sum::<u64>() as f64 / centralities.len() as f64) as usize; - // Register the state of the wot - let max_connectivity = currency_params.max_connectivity(); - duniter_dal::register_wot_state( - db, - &WotState { - block_number: block.number.0, - block_hash: block.hash.expect("Fail to get block hash").to_string(), - sentries_count, - average_density, - average_distance, - distances, - average_connectivity, - connectivities: connectivities - .iter() - .map(|c| { - if *c > max_connectivity { - max_connectivity - } else { - *c - } - }) - .collect(), - average_centrality, - centralities, - }, + if !wot_events.is_empty() && verif_level != SyncVerificationLevel::FastSync() { + // Calculate sentries_count + let sentries_count = wot.get_sentries(3).len(); + // Calculate average_density + let average_density = calculate_average_density::<W>(&wot); + let sentry_requirement = + get_sentry_requirement(block.members_count, G1_PARAMS.step_max); + // Calculate distances and connectivities + let (average_distance, distances, average_connectivity, connectivities) = + compute_distances::<W>( + &wot, + sentry_requirement, + G1_PARAMS.step_max, + G1_PARAMS.x_percent, ); - }*/ + // Calculate centralities and average_centrality + let centralities = + calculate_distance_stress_centralities::<W>(&wot, G1_PARAMS.step_max); + let average_centrality = + (centralities.iter().sum::<u64>() as f64 / centralities.len() as f64) as usize; + // Register the state of the wot + let max_connectivity = currency_params.max_connectivity(); + duniter_dal::register_wot_state( + db, + &WotState { + block_number: block.number.0, + block_hash: block.hash.expect("Fail to get block hash").to_string(), + sentries_count, + average_density, + average_distance, + distances, + average_connectivity, + connectivities: connectivities + .iter() + .map(|c| { + if *c > max_connectivity { + max_connectivity + } else { + *c + } + }) + .collect(), + average_centrality, + centralities, + }, + ); + }*/ // Create DALBlock let mut block = block.clone(); let previous_blockcstamp = block.previous_blockstamp(); diff --git a/blockchain/check_and_apply_block.rs b/blockchain/check_and_apply_block.rs index 62366dd6548a25fbd6b6d7e8b4e44cafb7662834..9851bf29fcd754eb51ad09e17e4948eb86e45eff 100644 --- a/blockchain/check_and_apply_block.rs +++ b/blockchain/check_and_apply_block.rs @@ -155,7 +155,8 @@ pub fn check_and_apply_block<W: WebOfTrust>( None, false, false, - ).expect("duniter_dal::writers::block::write() : DALError") + ) + .expect("duniter_dal::writers::block::write() : DALError") } Block::LocalBlock(block_doc) => { let old_fork_id = None; @@ -173,7 +174,8 @@ pub fn check_and_apply_block<W: WebOfTrust>( old_fork_id, false, false, - ).expect("duniter_dal::writers::block::write() : DALError") + ) + .expect("duniter_dal::writers::block::write() : DALError") } }; } else { diff --git a/blockchain/dbex.rs b/blockchain/dbex.rs index 9c09b6aa80fe02dd308d7f103f8dcc5e920e0af8..33d263e0e68ec24f09654efd91c1d90a0080e62d 100644 --- a/blockchain/dbex.rs +++ b/blockchain/dbex.rs @@ -83,7 +83,8 @@ pub fn dbex_tx<DC: DuniterConf>(profile: &str, conf: &DC, _csv: bool, query: &DB } else if let Some(pubkey) = duniter_dal::identity::get_pubkey_from_uid( &wot_databases.identities_db, address_str, - ).expect("get_uid : DALError") + ) + .expect("get_uid : DALError") { pubkey } else { @@ -94,7 +95,8 @@ pub fn dbex_tx<DC: DuniterConf>(profile: &str, conf: &DC, _csv: bool, query: &DB let address_balance = duniter_dal::balance::get_address_balance( ¤cy_databases.balances_db, &address, - ).expect("get_address_balance : DALError") + ) + .expect("get_address_balance : DALError") .expect("Address not found in balances DB."); println!( "Balance={},{} Ğ1", @@ -151,7 +153,8 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB db.iter() .map(|(_, idty)| (idty.wot_id, String::from(idty.idty_doc.username()))) .collect() - }).expect("Fail to read IdentitiesDB !"); + }) + .expect("Fail to read IdentitiesDB !"); // Open wot db let wot_db = open_wot_db::<RustyWebOfTrust>(Some(&db_path)).expect("Fail to open WotDB !"); @@ -185,10 +188,13 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB step_max: currency_params.step_max as u32, x_percent: currency_params.x_percent, }, - ).expect("Fail to get distance !"), + ) + .expect("Fail to get distance !"), ) - }).collect() - }).expect("Fail to read WotDB"); + }) + .collect() + }) + .expect("Fail to read WotDB"); let compute_distances_duration = SystemTime::now() .duration_since(compute_distances_begin) .expect("duration_since error"); @@ -231,7 +237,8 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB .map(|(block_id, dal_block)| (*block_id, dal_block.block.median_time)) .collect(), ) - }).expect("Fail to read blockchain db"); + }) + .expect("Fail to read blockchain db"); // Get expire_dates let min_created_ms_time = current_bc_time - currency_params.ms_validity; let mut expire_dates: Vec<(NodeId, u64)> = wot_databases @@ -250,7 +257,8 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB } } expire_dates - }).expect("Fail to read ms db"); + }) + .expect("Fail to read ms db"); if *reverse { expire_dates.sort_unstable_by(|(_, d1), (_, d2)| d1.cmp(&d2)); } else { @@ -284,7 +292,8 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB x_percent: currency_params.x_percent, }, ) - }).expect("Fail to read WotDB") + }) + .expect("Fail to read WotDB") .expect("Fail to get distance !"); let distance_percent: f64 = f64::from(distance_datas.success) / f64::from(distance_datas.sentries) * 100.0; @@ -301,7 +310,8 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB let source_uid = duniter_dal::identity::get_uid( &wot_databases.identities_db, *(wot_reverse_index[&source]), - ).expect("get_uid() : DALError") + ) + .expect("get_uid() : DALError") .expect("Not found source_uid !"); println!("{}: {}", i + 1, source_uid); } diff --git a/blockchain/lib.rs b/blockchain/lib.rs index 8bf1fc90f9d549f8b1cc3c6242d019277fab2c0c..f94cb1300c1e95508c278658afb995ad2d9184ab 100644 --- a/blockchain/lib.rs +++ b/blockchain/lib.rs @@ -359,7 +359,8 @@ impl BlockchainModule { self.forks_states = duniter_dal::block::get_forks( &self.blocks_databases.forks_db, current_blockstamp, - ).expect("get_forks() : DALError"); + ) + .expect("get_forks() : DALError"); save_blocks_dbs = true; if !wot_dbs_reqs.is_empty() { save_wots_dbs = true; @@ -463,7 +464,8 @@ impl BlockchainModule { self.forks_states = duniter_dal::block::get_forks( &self.blocks_databases.forks_db, current_blockstamp, - ).expect("get_forks() : DALError"); + ) + .expect("get_forks() : DALError"); // Apply db requests bc_db_query .apply(&self.blocks_databases, false) @@ -665,7 +667,8 @@ impl BlockchainModule { .tx_db .read(|db| db.clone()) .expect("Fail to read TxDB."), - ).expect("Fail to revert block"); + ) + .expect("Fail to revert block"); } } } @@ -686,7 +689,8 @@ impl BlockchainModule { self.forks_states = duniter_dal::block::get_forks( &self.blocks_databases.forks_db, current_blockstamp, - ).expect("get_forks() : DALError"); + ) + .expect("get_forks() : DALError"); } } } @@ -722,7 +726,8 @@ impl BlockchainModule { &self.blocks_databases.forks_db, &self.blocks_databases.forks_blocks_db, ¤t_blockstamp, - ).expect("Fatal error : Fail to read ForksV10DB !"); + ) + .expect("Fatal error : Fail to read ForksV10DB !"); if stackable_blocks.is_empty() { break; } else { @@ -781,7 +786,8 @@ impl BlockchainModule { &self.blocks_databases.forks_db, &self.blocks_databases.forks_blocks_db, stackable_block.fork_id, - ).expect("delete_fork() : DALError"); + ) + .expect("delete_fork() : DALError"); // Update forks states self.forks_states[stackable_block.fork_id.0] = ForkStatus::Free(); } diff --git a/blockchain/revert_block.rs b/blockchain/revert_block.rs index eabcb9f5334fa6b22f858706fe7b6f8eba780888..4ac1e0f48bebd0cfdfc1ade1033dd60e41e271cc 100644 --- a/blockchain/revert_block.rs +++ b/blockchain/revert_block.rs @@ -62,7 +62,8 @@ pub fn revert_block<W: WebOfTrust>( .map(|tx_enum| match *tx_enum { TxDocOrTxHash::TxHash(ref tx_hash) => txs[tx_hash].clone(), TxDocOrTxHash::TxDoc(ref _dal_tx) => panic!("Try to revert not reduce block !"), - }).collect(); + }) + .collect(); // Revert reduce block block.compute_inner_hash(); @@ -108,7 +109,8 @@ pub fn revert_block<W: WebOfTrust>( NewLinkResult::Ok(_) => {} _ => panic!("Fail to add_link {}->{} : {:?}", source.0, target.0, result), } - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RevertExpireCert( source, target, @@ -132,7 +134,8 @@ pub fn revert_block<W: WebOfTrust>( wotb_node_from.0, wotb_node_to.0, result ), } - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RevertCert( compact_cert, wotb_node_from, @@ -151,7 +154,8 @@ pub fn revert_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(*wot_id, false); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RevertRevokeIdentity( compact_revoc.issuer, block.blockstamp(), @@ -168,7 +172,8 @@ pub fn revert_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(*wot_id, false); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RevertExcludeIdentity( exclusion, block.blockstamp(), @@ -187,7 +192,8 @@ pub fn revert_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(wotb_id, true); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RevertRenewalIdentity( pubkey, wotb_id, @@ -204,7 +210,8 @@ pub fn revert_block<W: WebOfTrust>( wot_db .write(|db| { db.rem_node(); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_index.remove(&pubkey); wot_dbs_requests.push(WotsDBsWriteQuery::RevertCreateIdentity(pubkey)); } else { @@ -213,7 +220,8 @@ pub fn revert_block<W: WebOfTrust>( wot_db .write(|db| { db.set_enabled(wotb_id, true); - }).expect("Fail to write in WotDB"); + }) + .expect("Fail to write in WotDB"); wot_dbs_requests.push(WotsDBsWriteQuery::RevertRenewalIdentity( joiner.issuers()[0], wotb_id, diff --git a/blockchain/sync.rs b/blockchain/sync.rs index 5fa7e31299119eb3e793738fc97f7a1a436ed07d..28bd026212048eb7a8802d31a506a5519dc37bf5 100644 --- a/blockchain/sync.rs +++ b/blockchain/sync.rs @@ -345,32 +345,33 @@ pub fn sync_ts<DC: DuniterConf>( // Indexing blockchain meta datas info!("Indexing blockchain meta datas..."); /*let blockchain_meta_datas: HashMap<PreviousBlockstamp, BlockHash> = databases - .blockchain_db - .read(|db| { - let mut blockchain_meta_datas: HashMap< - PreviousBlockstamp, - BlockHash, - > = HashMap::new(); - for dal_block in db.values() { - let block_previous_hash = if dal_block.block.number.0 == 0 { - PreviousBlockstamp::default() - } else { - PreviousBlockstamp { - id: BlockId(dal_block.block.number.0 - 1), - hash: BlockHash(dal_block.block.previous_hash), - } - }; - blockchain_meta_datas - .insert(block_previous_hash, dal_block.block.expect("Try to get hash of an uncompleted or reduce block !")); - } + .blockchain_db + .read(|db| { + let mut blockchain_meta_datas: HashMap< + PreviousBlockstamp, + BlockHash, + > = HashMap::new(); + for dal_block in db.values() { + let block_previous_hash = if dal_block.block.number.0 == 0 { + PreviousBlockstamp::default() + } else { + PreviousBlockstamp { + id: BlockId(dal_block.block.number.0 - 1), + hash: BlockHash(dal_block.block.previous_hash), + } + }; blockchain_meta_datas - }) - .expect("Indexing blockchain meta datas : DALError");*/ + .insert(block_previous_hash, dal_block.block.expect("Try to get hash of an uncompleted or reduce block !")); + } + blockchain_meta_datas + }) + .expect("Indexing blockchain meta datas : DALError");*/ databases .forks_db .write(|db| { db.insert(ForkId(0), blockchain_meta_datas); - }).expect("Indexing blockchain meta datas : DALError"); + }) + .expect("Indexing blockchain meta datas : DALError"); // Increment progress bar (last chunk) apply_pb.inc(); @@ -505,7 +506,8 @@ pub fn sync_ts<DC: DuniterConf>( .write(|db| { db.0 = block_doc.currency.clone(); db.1 = block_doc.parameters.unwrap(); - }).expect("fail to write in params DB"); + }) + .expect("fail to write in params DB"); currency_params = CurrencyParameters::from(( block_doc.currency.clone(), block_doc.parameters.unwrap(), @@ -568,13 +570,15 @@ pub fn sync_ts<DC: DuniterConf>( db.get(&created_block_id).cloned().unwrap_or_default(); created_certs.insert((*source, *target)); db.insert(*created_block_id, created_certs); - }).expect("RustBreakError : please reset data and resync !"); + }) + .expect("RustBreakError : please reset data and resync !"); } sender_wot_thread .send(SyncJobsMess::WotsDBsWriteQuery( req.clone(), Box::new(currency_params), - )).expect( + )) + .expect( "Fail to communicate with tx worker thread, please reset data & resync !", ) } diff --git a/blockchain/ts_parsers.rs b/blockchain/ts_parsers.rs index 27782b1cbcbe1db3d066d8a8bc6f9ce5fb2376db..e41c1f009fd4b4bed8e0155f957e8acf4d5706f4 100644 --- a/blockchain/ts_parsers.rs +++ b/blockchain/ts_parsers.rs @@ -47,7 +47,8 @@ pub fn parse_ts_block(row: &[sqlite::Value]) -> NetworkBlock { issuer: PubKey::Ed25519( ed25519::PublicKey::from_base58( row[4].as_string().expect("Fail to parse block issuer"), - ).expect("Failt to parse block issuer (2)"), + ) + .expect("Failt to parse block issuer (2)"), ), }; let previous_header = if current_header.number.0 > 0 { @@ -58,14 +59,16 @@ pub fn parse_ts_block(row: &[sqlite::Value]) -> NetworkBlock { row[6] .as_string() .expect("Fail to parse block previous hash"), - ).expect("Fail to parse block previous hash (2)"), + ) + .expect("Fail to parse block previous hash (2)"), ), issuer: PubKey::Ed25519( ed25519::PublicKey::from_base58( row[7] .as_string() .expect("Fail to parse previous block issuer"), - ).expect("Fail to parse previous block issuer (2)"), + ) + .expect("Fail to parse previous block issuer (2)"), ), }) } else { @@ -157,17 +160,20 @@ pub fn parse_ts_block(row: &[sqlite::Value]) -> NetworkBlock { currency, MembershipType::In(), row[21].as_string().expect("Fail to parse joiners"), - ).expect("Fail to parse joiners (2)"), + ) + .expect("Fail to parse joiners (2)"), actives: parse_memberships( currency, MembershipType::In(), row[22].as_string().expect("Fail to parse actives"), - ).expect("Fail to parse actives (2)"), + ) + .expect("Fail to parse actives (2)"), leavers: parse_memberships( currency, MembershipType::In(), row[23].as_string().expect("Fail to parse leavers"), - ).expect("Fail to parse leavers (2)"), + ) + .expect("Fail to parse leavers (2)"), revoked: Vec::new(), excluded: excluded .as_array() @@ -178,9 +184,11 @@ pub fn parse_ts_block(row: &[sqlite::Value]) -> NetworkBlock { PubKey::Ed25519( ed25519::PublicKey::from_base58( e.as_str().expect("Fail to parse excluded (4)"), - ).expect("Fail to parse excluded (5)"), + ) + .expect("Fail to parse excluded (5)"), ) - }).collect(), + }) + .collect(), certifications: Vec::new(), transactions, inner_hash_and_nonce_str: String::new(), @@ -250,11 +258,13 @@ pub fn parse_memberships( currency, membership_type, raw_memberships.as_array().unwrap(), - ).iter() + ) + .iter() .map(|m| { m.clone() .expect("Fatal error : Fail to parse membership from local DB !") - }).collect(), + }) + .collect(), ); } None @@ -288,7 +298,8 @@ pub fn parse_memberships_from_json_value( } else { Err(MembershipParseError::WrongFormat()) } - }).collect() + }) + .collect() } /// Parse transaction from json value @@ -343,7 +354,8 @@ pub fn parse_transaction( output .as_str() .unwrap_or_else(|| panic!("Fail to parse output : {:?}", output)), - ).unwrap_or_else(|_| panic!("Fail to parse output : {:?}", output)), + ) + .unwrap_or_else(|_| panic!("Fail to parse output : {:?}", output)), ); } let signatures_array = source.get("signatures")?.as_array()?; diff --git a/core/lib.rs b/core/lib.rs index e5e21ac59607705190b48ff41b9332c7472e563f..92b62560562eecf0cc4213d868f19cdb21d37d48 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -272,21 +272,23 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> { opts.csv, &DBExQuery::WotQuery(DBExWotQuery::MemberDatas(member_opts.uid)), ), - DbExSubCommand::MembersOpt(members_opts) => if members_opts.expire { - dbex( - profile.as_str(), - &conf, - opts.csv, - &DBExQuery::WotQuery(DBExWotQuery::ExpireMembers(members_opts.reverse)), - ); - } else { - dbex( - profile.as_str(), - &conf, - opts.csv, - &DBExQuery::WotQuery(DBExWotQuery::ListMembers(members_opts.reverse)), - ); - }, + DbExSubCommand::MembersOpt(members_opts) => { + if members_opts.expire { + dbex( + profile.as_str(), + &conf, + opts.csv, + &DBExQuery::WotQuery(DBExWotQuery::ExpireMembers(members_opts.reverse)), + ); + } else { + dbex( + profile.as_str(), + &conf, + opts.csv, + &DBExQuery::WotQuery(DBExWotQuery::ListMembers(members_opts.reverse)), + ); + } + } DbExSubCommand::BalanceOpt(balance_opts) => dbex( &profile, &conf, @@ -421,7 +423,8 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> { module_conf, rooter_sender, sync_params, - ).unwrap_or_else(|_| { + ) + .unwrap_or_else(|_| { panic!( "Fatal error : fail to load {} Module !", NM::id().to_string() @@ -480,7 +483,8 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> { module_conf, rooter_sender_clone, false, - ).unwrap_or_else(|_| { + ) + .unwrap_or_else(|_| { panic!( "Fatal error : fail to load {} Module !", M::id().to_string() @@ -733,7 +737,8 @@ pub fn init_logger(profile: &str, soft_name: &'static str, cli_args: &ArgMatches log_file_path .to_str() .expect("Fatal error : fail to get log file path !"), - ).expect("Fatal error : fail to create log file path !"); + ) + .expect("Fatal error : fail to create log file path !"); } CombinedLogger::init(vec![WriteLogger::new( @@ -746,6 +751,8 @@ pub fn init_logger(profile: &str, soft_name: &'static str, cli_args: &ArgMatches log_file_path .to_str() .expect("Fatal error : fail to get log file path !"), - ).expect("Fatal error : fail to open log file !"), - )]).expect("Fatal error : fail to init logger !"); + ) + .expect("Fatal error : fail to open log file !"), + )]) + .expect("Fatal error : fail to init logger !"); } diff --git a/crypto/keys/ed25519.rs b/crypto/keys/ed25519.rs index 3e36cc38d0b620963b1a67e02d1173dcfb5924d6..752cd5701de0c506531a65e105736f40a92d545f 100644 --- a/crypto/keys/ed25519.rs +++ b/crypto/keys/ed25519.rs @@ -478,13 +478,15 @@ mod tests { assert_eq!( super::PrivateKey::from_base58( "468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9", - ).unwrap_err(), + ) + .unwrap_err(), BaseConvertionError::InvalidKeyLendth(53, 64) ); assert_eq!( super::PrivateKey::from_base58( "468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9<<", - ).unwrap_err(), + ) + .unwrap_err(), BaseConvertionError::InvalidCharacter('<', 73) ); } @@ -538,14 +540,16 @@ mod tests { super::Signature::from_base64( "YmhlaW9iaHNlcGlvaGVvaXNlcGl2ZXBvdm5pc2V2c2JlaW9idmVpb3Zqc\ 2V2Z3BpaHNlamVwZ25qZXNqb2dwZWpnaW9zZXNkdnNic3JicmJyZGJyZGI=", - ).unwrap_err(), + ) + .unwrap_err(), BaseConvertionError::InvalidKeyLendth(86, 64) ); assert_eq!( super::Signature::from_base64( "1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FGMM\ mQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAgdha<<", - ).unwrap_err(), + ) + .unwrap_err(), BaseConvertionError::InvalidCharacter('<', 89) ); } @@ -558,12 +562,14 @@ mod tests { let prikey = super::PrivateKey::from_base58( "468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt\ 5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7", - ).unwrap(); + ) + .unwrap(); let expected_signature = super::Signature::from_base64( "1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FG\ MMmQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg==", - ).unwrap(); + ) + .unwrap(); let message = "Version: 10 Type: Identity diff --git a/crypto/keys/mod.rs b/crypto/keys/mod.rs index b110b95eb32c5c7d91bca71f7732eccb0231a8cb..02eeab5d0e28a917e9a282b061b43824350b34df 100644 --- a/crypto/keys/mod.rs +++ b/crypto/keys/mod.rs @@ -286,11 +286,13 @@ impl PublicKey for PubKey { } fn verify(&self, message: &[u8], signature: &Self::Signature) -> bool { match *self { - PubKey::Ed25519(ed25519_pubkey) => if let Sig::Ed25519(ed25519_sig) = signature { - ed25519_pubkey.verify(message, ed25519_sig) - } else { - panic!("Try to verify a signature with public key of a different algorithm !\nSignature={:?}\nPublickey={:?}", signature, self) - }, + PubKey::Ed25519(ed25519_pubkey) => { + if let Sig::Ed25519(ed25519_sig) = signature { + ed25519_pubkey.verify(message, ed25519_sig) + } else { + panic!("Try to verify a signature with public key of a different algorithm !\nSignature={:?}\nPublickey={:?}", signature, self) + } + } PubKey::Schnorr() => panic!("Schnorr algo not yet supported !"), } } @@ -440,11 +442,13 @@ impl KeyPair for KeyPairEnum { } fn verify(&self, message: &[u8], signature: &Sig) -> bool { match *self { - KeyPairEnum::Ed25519(ed25519_keypair) => if let Sig::Ed25519(ed25519_sig) = signature { - ed25519_keypair.verify(message, ed25519_sig) - } else { - panic!("Try to verify a signature with key pair of a different algorithm !\nSignature={:?}\nKeyPair={:?}", signature, self) - }, + KeyPairEnum::Ed25519(ed25519_keypair) => { + if let Sig::Ed25519(ed25519_sig) = signature { + ed25519_keypair.verify(message, ed25519_sig) + } else { + panic!("Try to verify a signature with key pair of a different algorithm !\nSignature={:?}\nKeyPair={:?}", signature, self) + } + } KeyPairEnum::Schnorr() => panic!("Schnorr algo not yet supported !"), } } diff --git a/dal/block.rs b/dal/block.rs index 532aa9f3bf5bea74d150d03b7d036e8360ba4af5..8ca38a5388f0b3b7e21a325c3bed44d3bf363670 100644 --- a/dal/block.rs +++ b/dal/block.rs @@ -392,7 +392,7 @@ impl DALBlock { median_index = self.block.issuers_count - 1; } self.median_frame = current_frame_vec[median_index]; - + // Calculate second tiercile index let mut second_tiercile_index = match self.block.issuers_count % 3 { 1 | 2 => (self.block.issuers_count as f64 * (2.0 / 3.0)) as usize + 1, diff --git a/dal/identity.rs b/dal/identity.rs index c2af1aca008d66967f1ecb330c539bb596949234..03467a869814d51c3314612337b4d8791b9b1880 100644 --- a/dal/identity.rs +++ b/dal/identity.rs @@ -170,11 +170,13 @@ impl DALIdentity { DALIdentityState::ExpireMember(renewed_counts) => { DALIdentityState::ExplicitExpireRevoked(renewed_counts) } - DALIdentityState::Member(renewed_counts) => if explicit { - DALIdentityState::ExplicitRevoked(renewed_counts) - } else { - DALIdentityState::ImplicitRevoked(renewed_counts) - }, + DALIdentityState::Member(renewed_counts) => { + if explicit { + DALIdentityState::ExplicitRevoked(renewed_counts) + } else { + DALIdentityState::ImplicitRevoked(renewed_counts) + } + } _ => panic!("Try to revert revoke an already revoked idty !"), } }; diff --git a/dal/tools.rs b/dal/tools.rs index 43950523ac4bbf8c05e19257e10be6311fc0e6d0..b3509912f6ec8d926565c071b81537cc5690dcda 100644 --- a/dal/tools.rs +++ b/dal/tools.rs @@ -113,7 +113,8 @@ pub fn compute_distances<T: WebOfTrust + Sync>( step_max, x_percent, }, - ).expect("Fatal Error: compute_distance return None !"); + ) + .expect("Fatal Error: compute_distance return None !"); let mut distance = ((f64::from(distance_datas.success) / (x_percent * f64::from(distance_datas.sentries))) * 100.0) as usize; diff --git a/dal/writers/block.rs b/dal/writers/block.rs index 03c556722c7814e9ebbc790eb59c08b10b8ae4ee..d447ad41666b55d09ebb301e736b9c21a422b59a 100644 --- a/dal/writers/block.rs +++ b/dal/writers/block.rs @@ -101,7 +101,8 @@ pub fn write( forks_db .write(|db| { db.insert(ForkId(0), blockchain_meta_datas); - }).expect("Write blockchain meta datas : DALError"); + }) + .expect("Write blockchain meta datas : DALError"); } Ok(()) } diff --git a/dal/writers/dividend.rs b/dal/writers/dividend.rs index e5d64193c7dbf4de63ca53b7cb80fcc07d9bc021..648240fbecc6b8c7d9b86a8a99efe78f3b87d9d3 100644 --- a/dal/writers/dividend.rs +++ b/dal/writers/dividend.rs @@ -50,7 +50,8 @@ pub fn create_du( *pubkey, db.get(&UTXOConditionsGroup::Single( TransactionOutputCondition::Sig(*pubkey), - )).cloned() + )) + .cloned() .unwrap_or_default(), ); } @@ -66,7 +67,8 @@ pub fn create_du( *balance + *du_amount }; (*pubkey, (new_balance, utxos_indexs.clone())) - }).collect(); + }) + .collect(); // Write new members balance balances_db.write(|db| { for (pubkey, (balance, utxos_indexs)) in members_balances { diff --git a/dal/writers/transaction.rs b/dal/writers/transaction.rs index 634c471d9e7cd51dc88400239a4d1af9bd0c93b3..6fb57faaef3608f834048fe83d7b136b36b31cfb 100644 --- a/dal/writers/transaction.rs +++ b/dal/writers/transaction.rs @@ -141,7 +141,8 @@ pub fn revert_tx(dbs: &CurrencyV10DBs, dal_tx: &DALTxV10) -> Result<(), DALError SourceIndexV10::UTXO(UTXOIndexV10(hash, tx_index)), SourceAmount(tx_amout, tx_amout_base), ), - }).collect(); + }) + .collect(); // Find adress of recreated sources let recreated_adress: HashMap<UTXOConditionsGroup, (SourceAmount, HashSet<UTXOIndexV10>)> = dbs.utxos_db.read(|db| { @@ -256,7 +257,8 @@ pub fn apply_and_write_tx( SourceIndexV10::UTXO(UTXOIndexV10(hash, tx_index)), SourceAmount(tx_amout, tx_amout_base), ), - }).collect(); + }) + .collect(); // Find adress of consumed sources let consumed_adress: HashMap<UTXOConditionsGroup, (SourceAmount, HashSet<UTXOIndexV10>)> = dbs.utxos_db.read(|db| { @@ -423,7 +425,8 @@ mod tests { ).unwrap()); let block = Blockstamp::from_string( "50-00001DAA4559FEDB8320D1040B0F22B631459F36F237A0D9BC1EB923C12A12E7", - ).unwrap(); + ) + .unwrap(); let builder = TransactionDocumentBuilder { currency: "g1", blockstamp: &block, @@ -432,7 +435,8 @@ mod tests { inputs: &vec![ TransactionInput::parse_from_str( "1000:0:D:2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ:1", - ).expect("fail to parse input !"), + ) + .expect("fail to parse input !"), ], unlocks: &vec![ TransactionInputUnlocks::parse_from_str("0:SIG(0)") @@ -441,10 +445,12 @@ mod tests { outputs: &vec![ TransactionOutput::parse_from_str( "1:0:SIG(Com8rJukCozHZyFao6AheSsfDQdPApxQRnz7QYFf64mm)", - ).expect("fail to parse output !"), + ) + .expect("fail to parse output !"), TransactionOutput::parse_from_str( "999:0:SIG(2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ)", - ).expect("fail to parse output !"), + ) + .expect("fail to parse output !"), ], comment: "TEST", hash: None, @@ -472,15 +478,18 @@ mod tests { BlockId(1), &vec![tx_doc.issuers()[0], tortue_pubkey], false, - ).expect("Fail to create first g1 UD !"); + ) + .expect("Fail to create first g1 UD !"); // Check members balance let cgeek_new_balance = currency_dbs .balances_db .read(|db| { db.get(&UTXOConditionsGroup::Single( TransactionOutputCondition::Sig(tx_doc.issuers()[0]), - )).cloned() - }).expect("Fail to read cgeek new balance") + )) + .cloned() + }) + .expect("Fail to read cgeek new balance") .expect("Error : cgeek is not referenced in balances_db !"); assert_eq!(cgeek_new_balance.0, SourceAmount(TxAmount(1000), TxBase(0))); let tortue_new_balance = currency_dbs @@ -488,8 +497,10 @@ mod tests { .read(|db| { db.get(&UTXOConditionsGroup::Single( TransactionOutputCondition::Sig(tortue_pubkey), - )).cloned() - }).expect("Fail to read receiver new balance") + )) + .cloned() + }) + .expect("Fail to read receiver new balance") .expect("Error : receiver is not referenced in balances_db !"); assert_eq!( tortue_new_balance.0, @@ -503,8 +514,10 @@ mod tests { .read(|db| { db.get(&UTXOConditionsGroup::Single( TransactionOutputCondition::Sig(tx_doc.issuers()[0]), - )).cloned() - }).expect("Fail to read cgeek new balance") + )) + .cloned() + }) + .expect("Fail to read cgeek new balance") .expect("Error : cgeek is not referenced in balances_db !"); assert_eq!(cgeek_new_balance.0, SourceAmount(TxAmount(999), TxBase(0))); @@ -514,8 +527,10 @@ mod tests { .read(|db| { db.get(&UTXOConditionsGroup::Single( TransactionOutputCondition::Sig(tortue_pubkey), - )).cloned() - }).expect("Fail to read receiver new balance") + )) + .cloned() + }) + .expect("Fail to read receiver new balance") .expect("Error : receiver is not referenced in balances_db !"); assert_eq!( receiver_new_balance.0, @@ -529,7 +544,8 @@ mod tests { tx_doc: tx_doc.clone(), sources_destroyed: HashSet::with_capacity(0), }, - ).expect("Fail to revert first g1 tx"); + ) + .expect("Fail to revert first g1 tx"); // Check issuer new balance let cgeek_new_balance = currency_dbs @@ -537,8 +553,10 @@ mod tests { .read(|db| { db.get(&UTXOConditionsGroup::Single( TransactionOutputCondition::Sig(tx_doc.issuers()[0]), - )).cloned() - }).expect("Fail to read cgeek new balance") + )) + .cloned() + }) + .expect("Fail to read cgeek new balance") .expect("Error : cgeek is not referenced in balances_db !"); assert_eq!(cgeek_new_balance.0, SourceAmount(TxAmount(1000), TxBase(0))); @@ -548,8 +566,10 @@ mod tests { .read(|db| { db.get(&UTXOConditionsGroup::Single( TransactionOutputCondition::Sig(tortue_pubkey), - )).cloned() - }).expect("Fail to read receiver new balance") + )) + .cloned() + }) + .expect("Fail to read receiver new balance") .expect("Error : receiver is not referenced in balances_db !"); assert_eq!( receiver_new_balance.0, diff --git a/documents/blockchain/mod.rs b/documents/blockchain/mod.rs index 4ddea4f316c2dcbec5c72265242e2da8d3e1bdfd..64edf826a48de9a18793acf829dde9dd8735e0bd 100644 --- a/documents/blockchain/mod.rs +++ b/documents/blockchain/mod.rs @@ -202,7 +202,8 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 ed25519::Signature::from_base64( "1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FGMM\ mQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg==", - ).unwrap(), + ) + .unwrap(), ); // incorrect pair @@ -215,7 +216,8 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 ed25519::Signature::from_base64( "1eubHHbuNfilHHH0G2bI30iZzebQ2cQ1PC7uPAw08FGMM\ mQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg==", - ).unwrap(), + ) + .unwrap(), ); { diff --git a/documents/blockchain/v10/documents/certification.rs b/documents/blockchain/v10/documents/certification.rs index 0d2b889e0f0dd89cee75dc4ab0904af685a7b93c..e03213f00917646239df20f8d8270860efa8c172 100644 --- a/documents/blockchain/v10/documents/certification.rs +++ b/documents/blockchain/v10/documents/certification.rs @@ -301,7 +301,8 @@ mod tests { let identity_blockstamp = Blockstamp::from_string( "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - ).unwrap(); + ) + .unwrap(); let identity_sig = Sig::Ed25519(ed25519::Signature::from_base64( "1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FGMMmQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg==", @@ -309,7 +310,8 @@ mod tests { let blockstamp = Blockstamp::from_string( "36-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B865", - ).unwrap(); + ) + .unwrap(); let builder = CertificationDocumentBuilder { currency: "duniter_unit_test_currency", @@ -378,11 +380,11 @@ CertTimestamp: 167884-0001DFCA28002A8C96575E53B8CEF8317453A7B0BA255542CCF0EC8AB5 println!("Doc : {:?}", doc); assert_eq!(doc.verify_signatures(), VerificationResult::Valid()); /*assert_eq!( - doc.generate_compact_text(), - "2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT:\ - 7jzkd8GiFnpys4X7mP78w2Y3y3kwdK6fVSLEaojd3aH9:99956:\ - Hkps1QU4HxIcNXKT8YmprYTVByBhPP1U2tIM7Z8wENzLKIWAvQClkAvBE7pW9dnVa18sJIJhVZUcRrPAZfmjBA==" - );*/ + doc.generate_compact_text(), + "2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT:\ + 7jzkd8GiFnpys4X7mP78w2Y3y3kwdK6fVSLEaojd3aH9:99956:\ + Hkps1QU4HxIcNXKT8YmprYTVByBhPP1U2tIM7Z8wENzLKIWAvQClkAvBE7pW9dnVa18sJIJhVZUcRrPAZfmjBA==" + );*/ } else { panic!("Wrong document type"); } diff --git a/documents/blockchain/v10/documents/identity.rs b/documents/blockchain/v10/documents/identity.rs index efa612facf7dca786bd8a87c2588a8305a94b949..4eacf71e517e38cf909d46a1c5ccc4ef4a621dfc 100644 --- a/documents/blockchain/v10/documents/identity.rs +++ b/documents/blockchain/v10/documents/identity.rs @@ -254,19 +254,22 @@ mod tests { ed25519::PrivateKey::from_base58( "468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5G\ iERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7", - ).unwrap(), + ) + .unwrap(), ); let sig = Sig::Ed25519( ed25519::Signature::from_base64( "1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FGM\ MmQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg==", - ).unwrap(), + ) + .unwrap(), ); let block = Blockstamp::from_string( "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - ).unwrap(); + ) + .unwrap(); let builder = IdentityDocumentBuilder { currency: "duniter_unit_test_currency", diff --git a/documents/blockchain/v10/documents/membership.rs b/documents/blockchain/v10/documents/membership.rs index 2d30391a8c2431b6e5f6ef6665bb7cc3e88bda5f..3e3fb554a114a3b3bca72af5167c073e4795680a 100644 --- a/documents/blockchain/v10/documents/membership.rs +++ b/documents/blockchain/v10/documents/membership.rs @@ -29,7 +29,8 @@ lazy_static! { Membership: (?P<membership>(IN|OUT))\n\ UserID: (?P<ity_user>[[:alnum:]_-]+)\n\ CertTS: (?P<ity_block>[0-9]+-[0-9A-F]{64})\n$" - ).unwrap(); + ) + .unwrap(); } /// Type of a Membership. @@ -320,19 +321,22 @@ mod tests { ed25519::PrivateKey::from_base58( "468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5G\ iERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7", - ).unwrap(), + ) + .unwrap(), ); let sig = Sig::Ed25519( ed25519::Signature::from_base64( "s2hUbokkibTAWGEwErw6hyXSWlWFQ2UWs2PWx8d/kkEl\ AyuuWaQq4Tsonuweh1xn4AC1TVWt4yMR3WrDdkhnAw==", - ).unwrap(), + ) + .unwrap(), ); let block = Blockstamp::from_string( "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - ).unwrap(); + ) + .unwrap(); let builder = MembershipDocumentBuilder { currency: "duniter_unit_test_currency", diff --git a/documents/blockchain/v10/documents/mod.rs b/documents/blockchain/v10/documents/mod.rs index 1cb541650b0479fc316bee80c4a27391db113044..3e3d2137834cf3b39e400e49c0858e4b84306538 100644 --- a/documents/blockchain/v10/documents/mod.rs +++ b/documents/blockchain/v10/documents/mod.rs @@ -49,7 +49,8 @@ lazy_static! { Currency: (?P<currency>[[:alnum:] _-]+)\n\ (?P<body>(?:.*\n)+?))\ (?P<sigs>([[:alnum:]+/=]+\n)*([[:alnum:]+/=]+))$" - ).unwrap(); + ) + .unwrap(); static ref SIGNATURES_REGEX: Regex = Regex::new("[[:alnum:]+/=]+\n?").unwrap(); } @@ -321,7 +322,8 @@ SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneN 42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r 2D96KZwNUvVtcapQPq2mm7J9isFcDCfykwJpVEZwBc7tCgL4qPyu17BT5ePozAE9HS6Yvj51f62Mp4n9d9dkzJoX 2XiBDpuUdu6zCPWGzHXXy8c4ATSscfFQG9DjmqMZUxDZVt1Dp4m2N5oHYVUfoPdrU9SLk4qxi65RNrfCVnvQtQJk" - ).count(), + ) + .count(), 3 ); @@ -331,7 +333,8 @@ SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneN " 42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r 2XiBDpuUdu6zCPWGzHXXy8c4ATSscfFQG9DjmqMZUxDZVt1Dp4m2N5oHYVUfoPdrU9SLk4qxi65RNrfCVnvQtQJk" - ).count(), + ) + .count(), 2 ); } diff --git a/documents/blockchain/v10/documents/revocation.rs b/documents/blockchain/v10/documents/revocation.rs index 41032871f1e1a3236e62e31d4b86906057162a40..2b059615dd288fe146d215be1dfb0bbe1382554c 100644 --- a/documents/blockchain/v10/documents/revocation.rs +++ b/documents/blockchain/v10/documents/revocation.rs @@ -252,7 +252,8 @@ mod tests { ed25519::PrivateKey::from_base58( "468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5G\ iERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7", - ).unwrap(), + ) + .unwrap(), ); let sig = Sig::Ed25519(ed25519::Signature::from_base64( @@ -261,7 +262,8 @@ mod tests { let identity_blockstamp = Blockstamp::from_string( "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - ).unwrap(); + ) + .unwrap(); let identity_sig = Sig::Ed25519(ed25519::Signature::from_base64( "1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FGMMmQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg==", diff --git a/documents/blockchain/v10/documents/transaction.rs b/documents/blockchain/v10/documents/transaction.rs index 30b0207acc95b7e366f3736b2f0b677fdb3866ab..94006b10d83835b2bff23022c92aeffeaa6d087c 100644 --- a/documents/blockchain/v10/documents/transaction.rs +++ b/documents/blockchain/v10/documents/transaction.rs @@ -825,7 +825,8 @@ mod tests { ed25519::PrivateKey::from_base58( "468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5G\ iERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7", - ).unwrap(), + ) + .unwrap(), ); let sig = Sig::Ed25519(ed25519::Signature::from_base64( @@ -834,7 +835,8 @@ mod tests { let block = Blockstamp::from_string( "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - ).unwrap(); + ) + .unwrap(); let builder = TransactionDocumentBuilder { currency: "duniter_unit_test_currency", @@ -844,7 +846,8 @@ mod tests { inputs: &vec![ TransactionInput::parse_from_str( "10:0:D:DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV:0", - ).expect("fail to parse input !"), + ) + .expect("fail to parse input !"), ], unlocks: &vec![ TransactionInputUnlocks::parse_from_str("0:SIG(0)") @@ -853,7 +856,8 @@ mod tests { outputs: &vec![ TransactionOutput::parse_from_str( "10:0:SIG(FD9wujR7KABw88RyKEGBYRLz8PA6jzVCbcBAsrBXBqSa)", - ).expect("fail to parse output !"), + ) + .expect("fail to parse output !"), ], comment: "test", hash: None, @@ -885,7 +889,8 @@ mod tests { let block = Blockstamp::from_string( "60-00001FE00410FCD5991EDD18AA7DDF15F4C8393A64FA92A1DB1C1CA2E220128D", - ).unwrap(); + ) + .unwrap(); let builder = TransactionDocumentBuilder { currency: "g1", @@ -895,7 +900,8 @@ mod tests { inputs: &vec![ TransactionInput::parse_from_str( "950:0:T:2CF1ACD8FE8DC93EE39A1D55881C50D87C55892AE8E4DB71D4EBAB3D412AA8FD:1", - ).expect("fail to parse input !"), + ) + .expect("fail to parse input !"), ], unlocks: &vec![ TransactionInputUnlocks::parse_from_str("0:SIG(0)") @@ -904,10 +910,12 @@ mod tests { outputs: &vec![ TransactionOutput::parse_from_str( "30:0:SIG(38MEAZN68Pz1DTvT3tqgxx4yQP6snJCQhPqEFxbDk4aE)", - ).expect("fail to parse output !"), + ) + .expect("fail to parse output !"), TransactionOutput::parse_from_str( "920:0:SIG(FEkbc4BfJukSWnCU6Hed6dgwwTuPFTVdgz5LpL4iHr9J)", - ).expect("fail to parse output !"), + ) + .expect("fail to parse output !"), ], comment: "Pour cesium merci", hash: None, diff --git a/network/network_head_v3.rs b/network/network_head_v3.rs index 99ac157f48bfa8165809f07a4b5aec9d041977e2..b227b94b1d4ce0f0195a2e32fee488f5e0af62dd 100644 --- a/network/network_head_v3.rs +++ b/network/network_head_v3.rs @@ -166,7 +166,8 @@ mod tests { pubkey: PubKey::Ed25519(keypair1().public_key()), blockstamp: Blockstamp::from_string( "50-000005B1CEB4EC5245EF7E33101A330A1C9A358EC45A25FC13F78BB58C9E7370", - ).unwrap(), + ) + .unwrap(), software: String::from("durs"), soft_version: String::from("0.1.0-a0.1"), signature: None, diff --git a/network/network_peer.rs b/network/network_peer.rs index 8a62a434ed2aa3730b27c2f5b8fb91714a7cdbc1..d0b7bf9f30acc55155456c3811f43129bd857364 100644 --- a/network/network_peer.rs +++ b/network/network_peer.rs @@ -194,7 +194,8 @@ mod tests { node_id: NodeId(0), blockstamp: Blockstamp::from_string( "50-000005B1CEB4EC5245EF7E33101A330A1C9A358EC45A25FC13F78BB58C9E7370", - ).unwrap(), + ) + .unwrap(), endpoints: vec![ EndpointEnum::V2(create_endpoint_v2()), EndpointEnum::V2(create_second_endpoint_v2()), diff --git a/tui/lib.rs b/tui/lib.rs index be19e5780641d9122e355720713a4dea627df02e..242b5a06ea793e6a2c8e8a834e685006dfc69c3d 100644 --- a/tui/lib.rs +++ b/tui/lib.rs @@ -182,7 +182,8 @@ impl TuiModuleDatas { color::Bg(color::Black), clear::All, cursor::Goto(1, 1) - ).unwrap(); + ) + .unwrap(); // Draw headers let mut line = 1; @@ -192,7 +193,8 @@ impl TuiModuleDatas { cursor::Goto(1, line), color::Fg(color::White), out_established_conns.len() - ).unwrap(); + ) + .unwrap(); line += 1; write!( stdout, @@ -200,7 +202,8 @@ impl TuiModuleDatas { cursor::Goto(1, line), color::Fg(color::White), style::Italic, - ).unwrap(); + ) + .unwrap(); // Draw inter-nodes established connections if out_established_conns.is_empty() { @@ -211,7 +214,8 @@ impl TuiModuleDatas { cursor::Goto(2, line), color::Fg(color::Red), style::Bold, - ).unwrap(); + ) + .unwrap(); } else { for (ref node_full_id, ref uid, ref url) in out_established_conns { line += 1; @@ -227,7 +231,8 @@ impl TuiModuleDatas { node_full_id.to_human_string(), uid_string, url, - ).unwrap(); + ) + .unwrap(); } } @@ -244,7 +249,8 @@ impl TuiModuleDatas { out_trying_conns_count, out_denial_conns_count, out_disconnected_conns_count, - ).unwrap(); + ) + .unwrap(); // Draw separated line line += 1; @@ -258,7 +264,8 @@ impl TuiModuleDatas { cursor::Goto(1, line), color::Fg(color::White), separated_line, - ).unwrap(); + ) + .unwrap(); // Draw HEADs line += 1; @@ -268,7 +275,8 @@ impl TuiModuleDatas { cursor::Goto(1, line), color::Fg(color::White), heads.len() - ).unwrap(); + ) + .unwrap(); line += 1; if heads_index > 0 { write!( @@ -276,14 +284,16 @@ impl TuiModuleDatas { "{}{}/\\", cursor::Goto(35, line), color::Fg(color::Green), - ).unwrap(); + ) + .unwrap(); } else { write!( stdout, "{}{}/\\", cursor::Goto(35, line), color::Fg(color::Black), - ).unwrap(); + ) + .unwrap(); } line += 1; write!( @@ -302,7 +312,8 @@ impl TuiModuleDatas { cursor::Goto(1, line), color::Fg(color::Blue), head.to_human_string(w as usize), - ).unwrap(); + ) + .unwrap(); } else { write!( stdout, @@ -310,7 +321,8 @@ impl TuiModuleDatas { cursor::Goto(1, line), color::Fg(color::Green), head.to_human_string(w as usize), - ).unwrap(); + ) + .unwrap(); } } else { break; @@ -323,14 +335,16 @@ impl TuiModuleDatas { "{}{}\\/", cursor::Goto(35, line), color::Fg(color::Green), - ).unwrap(); + ) + .unwrap(); } else { write!( stdout, "{}{}\\/", cursor::Goto(35, line), color::Fg(color::Black), - ).unwrap(); + ) + .unwrap(); } // Draw footer @@ -353,7 +367,8 @@ impl TuiModuleDatas { color::Bg(color::Blue), color::Fg(color::White), runtime_str, - ).unwrap(); + ) + .unwrap(); write!( stdout, "{}{}{}q : quit{}", @@ -361,7 +376,8 @@ impl TuiModuleDatas { color::Bg(color::Blue), color::Fg(color::White), cursor::Hide, - ).unwrap(); + ) + .unwrap(); // Flush stdout (i.e. make the output appear). stdout.flush().unwrap(); @@ -498,7 +514,8 @@ impl DuniterModule<DuRsConf, DuniterMessage> for TuiModule { tui_sender .send(TuiMess::TermionEvent( c.expect("error to read stdin event !"), - )).expect("Fatal error : tui stdin thread module fail to send message !"); + )) + .expect("Fatal error : tui stdin thread module fail to send message !"); trace!("Send stdin event to tui main thread."); } }); @@ -520,7 +537,8 @@ impl DuniterModule<DuRsConf, DuniterMessage> for TuiModule { color::Bg(color::Reset), cursor::Show, clear::All, - ).unwrap(); + ) + .unwrap(); let _result_stop_propagation: Result< (), mpsc::SendError<DuniterMessage>, @@ -575,7 +593,8 @@ impl DuniterModule<DuRsConf, DuniterMessage> for TuiModule { .iter() .map(|h| { tui.heads_cache.insert(h.node_full_id(), h.clone()) - }).for_each(drop); + }) + .for_each(drop); } _ => {} }, @@ -593,7 +612,8 @@ impl DuniterModule<DuRsConf, DuniterMessage> for TuiModule { color::Bg(color::Reset), cursor::Show, clear::All, - ).unwrap(); + ) + .unwrap(); let _result_stop_propagation: Result< (), mpsc::SendError<DuniterMessage>, diff --git a/wotb/data/rusty.rs b/wotb/data/rusty.rs index 35cbaed96401f739d2673e3301cd3785ce9dec9e..22cdd86612fa5e8fd2e51d02f17195572e1844a7 100644 --- a/wotb/data/rusty.rs +++ b/wotb/data/rusty.rs @@ -199,7 +199,8 @@ impl WebOfTrust for RustyWebOfTrust { n.enabled && n.issued_count >= sentry_requirement && n.links_source.len() >= sentry_requirement - }).map(|(i, _)| NodeId(i)) + }) + .map(|(i, _)| NodeId(i)) .collect() } @@ -211,7 +212,8 @@ impl WebOfTrust for RustyWebOfTrust { n.enabled && (n.issued_count < sentry_requirement || n.links_source.len() < sentry_requirement) - }).map(|(i, _)| NodeId(i)) + }) + .map(|(i, _)| NodeId(i)) .collect() } } diff --git a/wotb/lib.rs b/wotb/lib.rs index d8d324e9552b69f7c2688554470d43f2e88e2c08..3926037bfc22061f3f942d610f0fc797807c2337 100644 --- a/wotb/lib.rs +++ b/wotb/lib.rs @@ -497,7 +497,8 @@ mod tests { &wot, &[0b0000_0000, 0b0000_0001, 0b0000_0001, 0b0000_0000], "test.wot" - ).unwrap(), + ) + .unwrap(), () ); diff --git a/wotb/operations/distance.rs b/wotb/operations/distance.rs index 14105d595399b71915c84cb088c6a90fdaa7954c..46949ad205c0760554d1ee0f4267bd44196f2c0b 100644 --- a/wotb/operations/distance.rs +++ b/wotb/operations/distance.rs @@ -93,7 +93,8 @@ impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator { .filter(|source| !area.contains(source)) .cloned() .collect::<HashSet<_>>() - }).reduce(HashSet::new, |mut acc, sources| { + }) + .reduce(HashSet::new, |mut acc, sources| { for source in sources { acc.insert(source); } diff --git a/ws2p-messages/lib.rs b/ws2p-messages/lib.rs index e7e0e9c602a46089e16d8c4df5875a3b8a73bcbd..1f156894283c8de2a680e82b3e8f69c21f6712e7 100644 --- a/ws2p-messages/lib.rs +++ b/ws2p-messages/lib.rs @@ -109,7 +109,8 @@ mod tests { node_id: NodeId(0), blockstamp: Blockstamp::from_string( "50-000005B1CEB4EC5245EF7E33101A330A1C9A358EC45A25FC13F78BB58C9E7370", - ).unwrap(), + ) + .unwrap(), endpoints: vec![create_endpoint_v11(), create_second_endpoint_v11()], sig: None, } @@ -168,7 +169,8 @@ mod tests { let blockstamp = Blockstamp::from_string( "36-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B865", - ).unwrap(); + ) + .unwrap(); CompactCertificationDocument { issuer: PubKey::Ed25519( diff --git a/ws2p-messages/v2/connect.rs b/ws2p-messages/v2/connect.rs index 3ed23827ad012a8215e1887c8ccb28e2778cb215..f1ad97ae6b54c8ba0dd310dc63f7c6e75df6e385 100644 --- a/ws2p-messages/v2/connect.rs +++ b/ws2p-messages/v2/connect.rs @@ -98,14 +98,16 @@ mod tests { let connect_msg = WS2Pv2ConnectMsg { challenge: Hash::from_hex( "000007722B243094269E548F600BD34D73449F7578C05BD370A6D301D20B5F10", - ).unwrap(), + ) + .unwrap(), api_features: WS2PFeatures(vec![7u8]), flags_queries: WS2PConnectFlags(vec![]), peer_card: Some(peer), chunkstamp: Some( Blockstamp::from_string( "499-000011BABEEE1020B1F6B2627E2BC1C35BCD24375E114349634404D2C266D84F", - ).unwrap(), + ) + .unwrap(), ), }; test_ws2p_message(WS2Pv0MessagePayload::Connect(Box::new(connect_msg))); diff --git a/ws2p-messages/v2/ok.rs b/ws2p-messages/v2/ok.rs index e442e373aac0b413b0f4b81b8075692a0cbe8858..e480524975988f82afe27642ea6e986f7a02a1e9 100644 --- a/ws2p-messages/v2/ok.rs +++ b/ws2p-messages/v2/ok.rs @@ -59,14 +59,17 @@ mod tests { sync_target: Some(WS2Pv2SyncTarget { target_blockstamp: Blockstamp::from_string( "500-000011BABEEE1020B1F6B2627E2BC1C35BCD24375E114349634404D2C266D84F", - ).unwrap(), + ) + .unwrap(), chunks_hash: vec![ Hash::from_hex( "000007722B243094269E548F600BD34D73449F7578C05BD370A6D301D20B5F10", - ).unwrap(), + ) + .unwrap(), Hash::from_hex( "0000095FD4C8EA96DE2844E3A4B62FD18761E9B4C13A74FAB716A4C81F438D91", - ).unwrap(), + ) + .unwrap(), ], }), }; diff --git a/ws2p-messages/v2/req_responses.rs b/ws2p-messages/v2/req_responses.rs index 0a46a21d786298cc88cee8dc4de059d161b88238..ed81adbc5cfc62e6d4d2dd133284877f4e025aff 100644 --- a/ws2p-messages/v2/req_responses.rs +++ b/ws2p-messages/v2/req_responses.rs @@ -88,7 +88,8 @@ mod tests { fn test_ws2p_message_req_res_current() { let blockstamp = Blockstamp::from_string( "499-000011BABEEE1020B1F6B2627E2BC1C35BCD24375E114349634404D2C266D84F", - ).unwrap(); + ) + .unwrap(); let response = WS2Pv2ReqRes { id: 28, body: WS2Pv2ReqResBody::Current(blockstamp), diff --git a/ws2p-messages/v2/requests.rs b/ws2p-messages/v2/requests.rs index 3290ceaa4006473e64f16727e244e09aaad7292a..e160f7e126a4683348e8a04db77cf103b41c0e19 100644 --- a/ws2p-messages/v2/requests.rs +++ b/ws2p-messages/v2/requests.rs @@ -81,7 +81,8 @@ mod tests { fn test_ws2p_message_request() { let chunkstamp = Blockstamp::from_string( "499-000011BABEEE1020B1F6B2627E2BC1C35BCD24375E114349634404D2C266D84F", - ).unwrap(); + ) + .unwrap(); let request = WS2Pv2Request { id: 27, body: WS2Pv2RequestBody::ChunkByHash(chunkstamp), diff --git a/ws2p-v1-legacy/datas.rs b/ws2p-v1-legacy/datas.rs index d45707ca35bcb24c10b3aec66cc92dcc272051a5..1eacd904b2f86f4e3b15ae26ff4c3f71b2db993c 100644 --- a/ws2p-v1-legacy/datas.rs +++ b/ws2p-v1-legacy/datas.rs @@ -184,7 +184,8 @@ impl WS2PModuleDatas { &endpoint .node_full_id() .expect("WS2P: Fail to get ep.node_full_id() !"), - ).expect("WS2P: Fail to get_mut() a ws2p_endpoint !") + ) + .expect("WS2P: Fail to get_mut() a ws2p_endpoint !") .1 = WS2PConnectionState::NeverTry; } None => { @@ -272,7 +273,8 @@ impl WS2PModuleDatas { .get_mut(&ws2p_full_id) .unwrap_or_else(|| { panic!("Fatal error : no websocket for {} !", ws2p_full_id) - }).0 + }) + .0 .send(Message::text(r)) .expect("WS2P: Fail to send Message in websocket !"); } @@ -436,34 +438,34 @@ impl WS2PModuleDatas { } } /* NetworkRequest::GetBlock(req_full_id, number) => {} */ - NetworkRequest::GetBlocks(_req_full_id, _receiver, _count, _from_number) => {} - NetworkRequest::GetRequirementsPending(req_full_id, _receiver, min_cert) => { - for (ws2p_full_id, (_ep, state)) in self.ws2p_endpoints.clone() { - if let WS2PConnectionState::Established = state { - let ws2p_request = NetworkRequest::GetRequirementsPending( - ModuleReqFullId( - req_full_id.0, - ModuleReqId(self.requests_awaiting_response.len() as u32), - ), - ws2p_full_id, - min_cert, - ); - match self.send_request_to_specific_node(&ws2p_full_id, &ws2p_request) { - Ok(_) => count_successful_sending += 1, - Err(e) => errors.push(e), - }; - } - } - } - _ => { - return Err(SendRequestError::RequestTypeMustNotBeTransmitted()); - } - } - debug!("count_successful_sending = {}", count_successful_sending); - if !errors.is_empty() { - return Err(SendRequestError::WSError(count_successful_sending, errors)); - } - Ok(()) + NetworkRequest::GetBlocks(_req_full_id, _receiver, _count, _from_number) => {} + NetworkRequest::GetRequirementsPending(req_full_id, _receiver, min_cert) => { + for (ws2p_full_id, (_ep, state)) in self.ws2p_endpoints.clone() { + if let WS2PConnectionState::Established = state { + let ws2p_request = NetworkRequest::GetRequirementsPending( + ModuleReqFullId( + req_full_id.0, + ModuleReqId(self.requests_awaiting_response.len() as u32), + ), + ws2p_full_id, + min_cert, + ); + match self.send_request_to_specific_node(&ws2p_full_id, &ws2p_request) { + Ok(_) => count_successful_sending += 1, + Err(e) => errors.push(e), + }; + } + } + } + _ => { + return Err(SendRequestError::RequestTypeMustNotBeTransmitted()); + } + } + debug!("count_successful_sending = {}", count_successful_sending); + if !errors.is_empty() { + return Err(SendRequestError::WSError(count_successful_sending, errors)); + } + Ok(()) }*/ pub fn send_request_to_specific_node( diff --git a/ws2p-v1-legacy/lib.rs b/ws2p-v1-legacy/lib.rs index 78fac44136e31eae8b01666e1e508c589d258b85..3170ce9e28ec635d449ad30ee82aa1a5e57e708d 100644 --- a/ws2p-v1-legacy/lib.rs +++ b/ws2p-v1-legacy/lib.rs @@ -108,23 +108,27 @@ impl Default for WS2PConf { PubKey::Ed25519( ed25519::PublicKey::from_base58( "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx", - ).unwrap(), + ) + .unwrap(), ), 0, 0, 1u16, - ).unwrap(), + ) + .unwrap(), EndpointEnum::parse_from_raw( "WS2P b48824f0 g1.monnaielibreoccitanie.org 443 /ws2p", PubKey::Ed25519( ed25519::PublicKey::from_base58( "7v2J4badvfWQ6qwRdCwhhJfAsmKwoxRUNpJHiJHj7zef", - ).unwrap(), + ) + .unwrap(), ), 0, 0, 1u16, - ).unwrap(), + ) + .unwrap(), ], } } @@ -519,9 +523,11 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { "body": { "heads": [my_json_head] } - }).to_string(), + }) + .to_string(), )) - }).collect(); + }) + .collect(); } DALEvent::RevertBlocks(ref _blocks) => {} _ => {} @@ -721,7 +727,8 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { new_head.set_uid(uid); } new_head - }).collect(), + }) + .collect(), )); } WS2PSignal::Document(ws2p_full_id, network_doc) => { @@ -871,9 +878,9 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { && SystemTime::now().duration_since(start_time).unwrap() > Duration::new(10, 0) { /*info!("get pending_identities from all connections..."); - let _blocks_request_result = ws2p_module.send_request_to_all_connections( - &NetworkRequest::GetRequirementsPending(ModuleReqId(0 as u32), 5), - );*/ + let _blocks_request_result = ws2p_module.send_request_to_all_connections( + &NetworkRequest::GetRequirementsPending(ModuleReqId(0 as u32), 5), + );*/ last_identities_request = SystemTime::now(); } // Write pending endpoints @@ -885,14 +892,14 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { ws2p_module.ws2p_endpoints.get(&ep_full_id) { /*let dal_endpoint = duniter_dal::endpoint::DALEndpoint::new( - state.clone() as u32, - ep.node_uuid().unwrap().0, - ep.pubkey(), - duniter_dal::endpoint::string_to_api(&ep.api().0).unwrap(), - 1, - ep.to_string(), - received_time.duration_since(UNIX_EPOCH).unwrap(), - );*/ + state.clone() as u32, + ep.node_uuid().unwrap().0, + ep.pubkey(), + duniter_dal::endpoint::string_to_api(&ep.api().0).unwrap(), + 1, + ep.to_string(), + received_time.duration_since(UNIX_EPOCH).unwrap(), + );*/ ws2p_db::write_endpoint( &db, &ep, @@ -1133,7 +1140,8 @@ mod tests { 1, current_time.as_secs(), 1, - ).expect("Failt to parse test endpoint !"); + ) + .expect("Failt to parse test endpoint !"); ws2p_db::write_endpoint(&db, &endpoint, 1, current_time.as_secs()); let mut written_endpoints = diff --git a/ws2p-v1-legacy/parsers/blocks.rs b/ws2p-v1-legacy/parsers/blocks.rs index 4a8fdc0c972d65508a139f1dd5c7e82be21e0256..ae3aa8dd3ea4b0475bc84275974742830f653e52 100644 --- a/ws2p-v1-legacy/parsers/blocks.rs +++ b/ws2p-v1-legacy/parsers/blocks.rs @@ -19,11 +19,13 @@ fn parse_previous_hash(block_number: BlockId, source: &serde_json::Value) -> Opt Ok(hash) => Some(hash), Err(_) => None, }, - None => if block_number.0 > 0 { - None - } else { - Some(Hash::default()) - }, + None => { + if block_number.0 > 0 { + None + } else { + Some(Hash::default()) + } + } } } diff --git a/ws2p-v1-legacy/parsers/identities.rs b/ws2p-v1-legacy/parsers/identities.rs index 3de01344f5e9d5d4c1f4c17417b64add3d11b84e..ef62335415055c325cef050850d8957efc949fb9 100644 --- a/ws2p-v1-legacy/parsers/identities.rs +++ b/ws2p-v1-legacy/parsers/identities.rs @@ -20,7 +20,8 @@ pub fn parse_identities(currency: &str, json_datas: &str) -> Option<Vec<Identity .map(|i| { i.clone() .expect("Fatal error : Fail to parse identity from local DB !") - }).collect(), + }) + .collect(), ); } None @@ -50,7 +51,8 @@ pub fn parse_identities_from_json_value( } else { Err(IdentityParseError::WrongFormat()) } - }).collect() + }) + .collect() } pub fn parse_compact_identity( diff --git a/ws2p-v1-legacy/parsers/memberships.rs b/ws2p-v1-legacy/parsers/memberships.rs index 1d9c76bdbea1fc8b4dc70c5bdc0760a709fcdccd..a193d5e64ea9ed393bd606eb63b85fd4a29d77a2 100644 --- a/ws2p-v1-legacy/parsers/memberships.rs +++ b/ws2p-v1-legacy/parsers/memberships.rs @@ -25,11 +25,13 @@ pub fn parse_memberships( currency, membership_type, raw_memberships.as_array().unwrap(), - ).iter() + ) + .iter() .map(|m| { m.clone() .expect("Fatal error : Fail to parse membership from local DB !") - }).collect(), + }) + .collect(), ); } None @@ -62,5 +64,6 @@ pub fn parse_memberships_from_json_value( } else { Err(MembershipParseError::WrongFormat()) } - }).collect() + }) + .collect() } diff --git a/ws2p-v1-legacy/parsers/mod.rs b/ws2p-v1-legacy/parsers/mod.rs index 4865af2852d5b8bc7d4e1040da072e78313533a0..7796b278e480cfc8e02a2530a9d2366ca0d5f949 100644 --- a/ws2p-v1-legacy/parsers/mod.rs +++ b/ws2p-v1-legacy/parsers/mod.rs @@ -58,7 +58,8 @@ mod tests { currency: "g1", blockstamp: &Blockstamp::from_string( "112533-000002150F2E805E604D9B31212D079570AAD8D3A4D8BB75F2C15A94A345B6B1", - ).unwrap(), + ) + .unwrap(), locktime: &0, issuers: &vec![PubKey::Ed25519( ed25519::PublicKey::from_base58("51EFVNZwpfmTXU7BSLpeh3PZFgfdmm5hq5MzCDopdH2") @@ -67,12 +68,14 @@ mod tests { inputs: &vec![ TransactionInput::parse_from_str( "1000:0:D:51EFVNZwpfmTXU7BSLpeh3PZFgfdmm5hq5MzCDopdH2:46496", - ).unwrap(), + ) + .unwrap(), ], outputs: &vec![ TransactionOutput::parse_from_str( "1000:0:SIG(2yN8BRSkARcqE8NCxKMBiHfTpx1EvwULFn56Myf6qRmy)", - ).unwrap(), + ) + .unwrap(), ], unlocks: &vec![TransactionInputUnlocks::parse_from_str("0:SIG(0)").unwrap()], comment: "Merci pour la calligraphie ;) de Liam", @@ -118,7 +121,8 @@ mod tests { currency: "g1", blockstamp: &Blockstamp::from_string( "58-00005B9167EBA1E32C6EAD42AE7F72D8F14B765D3C9E47D233B553D47C5AEE0C", - ).unwrap(), + ) + .unwrap(), locktime: &0, issuers: &vec![PubKey::Ed25519( ed25519::PublicKey::from_base58("FVUFRrk1K5TQGsY7PRLwqHgdHRoHrwb1hcucp4C2N5tD") @@ -127,15 +131,18 @@ mod tests { inputs: &vec![ TransactionInput::parse_from_str( "1000:0:D:FVUFRrk1K5TQGsY7PRLwqHgdHRoHrwb1hcucp4C2N5tD:1", - ).unwrap(), + ) + .unwrap(), ], outputs: &vec![ TransactionOutput::parse_from_str( "3:0:SIG(7vU9BMDhN6fBuRa2iK3JRbC6pqQKb4qDMGsFcQuT5cz)", - ).unwrap(), + ) + .unwrap(), TransactionOutput::parse_from_str( "997:0:SIG(FVUFRrk1K5TQGsY7PRLwqHgdHRoHrwb1hcucp4C2N5tD)", - ).unwrap(), + ) + .unwrap(), ], unlocks: &vec![TransactionInputUnlocks::parse_from_str("0:SIG(0)").unwrap()], comment: "Un petit cafe ;-)", diff --git a/ws2p-v1-legacy/parsers/transactions.rs b/ws2p-v1-legacy/parsers/transactions.rs index fdd1dd353470e270e33ee7fb3f76642cd59d3db9..2484034c468f51e66c5fbbf16fb938b818ddb128 100644 --- a/ws2p-v1-legacy/parsers/transactions.rs +++ b/ws2p-v1-legacy/parsers/transactions.rs @@ -114,7 +114,8 @@ Merci pour la calligraphie ;) de Liam$\ currency: "g1", blockstamp: &Blockstamp::from_string( "112533-000002150F2E805E604D9B31212D079570AAD8D3A4D8BB75F2C15A94A345B6B1", - ).unwrap(), + ) + .unwrap(), locktime: &0, issuers: &vec![PubKey::Ed25519( ed25519::PublicKey::from_base58("51EFVNZwpfmTXU7BSLpeh3PZFgfdmm5hq5MzCDopdH2") @@ -123,12 +124,14 @@ Merci pour la calligraphie ;) de Liam$\ inputs: &vec![ TransactionInput::parse_from_str( "1000:0:D:51EFVNZwpfmTXU7BSLpeh3PZFgfdmm5hq5MzCDopdH2:46496", - ).unwrap(), + ) + .unwrap(), ], outputs: &vec![ TransactionOutput::parse_from_str( "1000:0:SIG(2yN8BRSkARcqE8NCxKMBiHfTpx1EvwULFn56Myf6qRmy)", - ).unwrap(), + ) + .unwrap(), ], unlocks: &vec![TransactionInputUnlocks::parse_from_str("0:SIG(0)").unwrap()], comment: "Merci pour la calligraphie ;) de Liam", diff --git a/ws2p-v1-legacy/ws2p_connection.rs b/ws2p-v1-legacy/ws2p_connection.rs index cdc43a9160acc32f788add3e952dbea8331d5def..11969541bf44553b647af4e5210b996361b651eb 100644 --- a/ws2p-v1-legacy/ws2p_connection.rs +++ b/ws2p-v1-legacy/ws2p_connection.rs @@ -479,45 +479,52 @@ impl WS2PConnectionMetaDatas { } if let Some(body) = m.get("body") { match body.get("name") { - Some(s) => if s.is_string() { - match s.as_str().unwrap() { - "BLOCK" => match body.get("block") { - Some(block) => { - if let Some(network_block) = parse_json_block(&block) { - return WS2PConnectionMessagePayload::Document( - NetworkDocument::Block(network_block), - ); - } else { - info!("WS2PSignal: receive invalid block (wrong format)."); - }; - } - None => return WS2PConnectionMessagePayload::WrongFormatMessage, - }, - "HEAD" => match body.get("heads") { - Some(heads) => match heads.as_array() { - Some(heads_array) => { - return WS2PConnectionMessagePayload::Heads(heads_array.clone()) + Some(s) => { + if s.is_string() { + match s.as_str().unwrap() { + "BLOCK" => match body.get("block") { + Some(block) => { + if let Some(network_block) = parse_json_block(&block) { + return WS2PConnectionMessagePayload::Document( + NetworkDocument::Block(network_block), + ); + } else { + info!("WS2PSignal: receive invalid block (wrong format)."); + }; } None => return WS2PConnectionMessagePayload::WrongFormatMessage, }, - None => return WS2PConnectionMessagePayload::WrongFormatMessage, - }, - "PEER" => return self.parse_and_check_peer_message(body), - "CERTIFICATION" => { - trace!("WS2P : Receive CERTIFICATION from {}.", self.node_full_id()); - /*return WS2PConnectionMessagePayload::Document( - NetworkDocument::Certification(_) - );*/ - } - _ => { - /*trace!( - "WS2P : Receive Unknow Message from {}.", - self.node_full_id() - );*/ - return WS2PConnectionMessagePayload::UnknowMessage; - } - }; - }, + "HEAD" => match body.get("heads") { + Some(heads) => match heads.as_array() { + Some(heads_array) => { + return WS2PConnectionMessagePayload::Heads( + heads_array.clone(), + ) + } + None => return WS2PConnectionMessagePayload::WrongFormatMessage, + }, + None => return WS2PConnectionMessagePayload::WrongFormatMessage, + }, + "PEER" => return self.parse_and_check_peer_message(body), + "CERTIFICATION" => { + trace!( + "WS2P : Receive CERTIFICATION from {}.", + self.node_full_id() + ); + /*return WS2PConnectionMessagePayload::Document( + NetworkDocument::Certification(_) + );*/ + } + _ => { + /*trace!( + "WS2P : Receive Unknow Message from {}.", + self.node_full_id() + );*/ + return WS2PConnectionMessagePayload::UnknowMessage; + } + }; + } + } None => { warn!("WS2P Error : invalid format : Body must contain a field name !"); return WS2PConnectionMessagePayload::WrongFormatMessage; diff --git a/ws2p-v1-legacy/ws2p_db.rs b/ws2p-v1-legacy/ws2p_db.rs index 725347be2659331e049b69db1e96218b38b16bda..88f165a7d7f76f2a2f68eeb017add0e1d841e558 100644 --- a/ws2p-v1-legacy/ws2p_db.rs +++ b/ws2p-v1-legacy/ws2p_db.rs @@ -121,7 +121,8 @@ pub fn write_endpoint( "UPDATE endpoints SET status={} WHERE hash_full_id='{}'", endpoint.status(), hash_full_id - )).expect("Fail to parse SQL request update endpoint status !"); + )) + .expect("Fail to parse SQL request update endpoint status !"); } } else if let EndpointEnum::V1(ref ep_v10) = *endpoint { db diff --git a/ws2p/lib.rs b/ws2p/lib.rs index b3c04bd0333013d8701970d984ef5e4bf639c286..c8a485af4ae6f7bd41897b7c365146db1a45f2d7 100644 --- a/ws2p/lib.rs +++ b/ws2p/lib.rs @@ -71,23 +71,27 @@ impl Default for WS2PConf { PubKey::Ed25519( ed25519::PublicKey::from_base58( "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx", - ).unwrap(), + ) + .unwrap(), ), 0, 0, 1u16, - ).unwrap(), + ) + .unwrap(), EndpointEnum::parse_from_raw( "WS2P b48824f0 g1.monnaielibreoccitanie.org 443 /ws2p", PubKey::Ed25519( ed25519::PublicKey::from_base58( "7v2J4badvfWQ6qwRdCwhhJfAsmKwoxRUNpJHiJHj7zef", - ).unwrap(), + ) + .unwrap(), ), 0, 0, 1u16, - ).unwrap(), + ) + .unwrap(), ], } }