From 4d7c9f3205d9fd31b27a9f4602e86fce996acd6a Mon Sep 17 00:00:00 2001 From: Srikanth Iyengar Date: Tue, 30 Apr 2024 23:02:36 +0530 Subject: [PATCH] Refactored necessary files to improve code quality * Removed a useless shadowing in builder.rs * Passed directly the closure itself instead of making a inline closure * Refactored usage of map which returns boolean to matches! --- src/builder.rs | 3 +-- src/event.rs | 2 +- src/gossip.rs | 12 +++--------- src/lib.rs | 4 ++-- src/payment_store.rs | 2 +- src/types.rs | 2 +- src/wallet.rs | 5 +---- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 6b4da6b57..204088c6a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -184,7 +184,6 @@ impl NodeBuilder { /// Creates a new builder instance from an [`Config`]. pub fn from_config(config: Config) -> Self { - let config = config; let entropy_source_config = None; let chain_data_source_config = None; let gossip_source_config = None; @@ -1034,7 +1033,7 @@ fn seed_bytes_from_config( match entropy_source_config { Some(EntropySourceConfig::SeedBytes(bytes)) => Ok(bytes.clone()), Some(EntropySourceConfig::SeedFile(seed_path)) => { - Ok(io::utils::read_or_generate_seed_file(&seed_path, Arc::clone(&logger)) + Ok(io::utils::read_or_generate_seed_file(seed_path, Arc::clone(&logger)) .map_err(|_| BuildError::InvalidSeedFile)?) }, Some(EntropySourceConfig::Bip39Mnemonic { mnemonic, passphrase }) => match passphrase { diff --git a/src/event.rs b/src/event.rs index acdf12e4c..6e9ab587c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -176,7 +176,7 @@ where pub(crate) fn next_event(&self) -> Option { let locked_queue = self.queue.lock().unwrap(); - locked_queue.front().map(|e| e.clone()) + locked_queue.front().cloned() } pub(crate) async fn next_event_async(&self) -> Event { diff --git a/src/gossip.rs b/src/gossip.rs index 9fb5e6a84..de98d441e 100644 --- a/src/gossip.rs +++ b/src/gossip.rs @@ -39,19 +39,13 @@ impl GossipSource { } pub fn is_rgs(&self) -> bool { - if let Self::RapidGossipSync { .. } = self { - true - } else { - false - } + matches!(self, Self::RapidGossipSync { .. }) } pub fn as_gossip_sync(&self) -> GossipSync { match self { - Self::RapidGossipSync { gossip_sync, .. } => { - GossipSync::Rapid(Arc::clone(&gossip_sync)) - }, - Self::P2PNetwork { gossip_sync, .. } => GossipSync::P2P(Arc::clone(&gossip_sync)), + Self::RapidGossipSync { gossip_sync, .. } => GossipSync::Rapid(Arc::clone(gossip_sync)), + Self::P2PNetwork { gossip_sync, .. } => GossipSync::P2P(Arc::clone(gossip_sync)), } } diff --git a/src/lib.rs b/src/lib.rs index f6082d4d3..a803730c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1711,7 +1711,7 @@ impl Node { .output_sweeper .tracked_spendable_outputs() .into_iter() - .map(|o| PendingSweepBalance::from_tracked_spendable_output(o)) + .map(PendingSweepBalance::from_tracked_spendable_output) .collect(); BalanceDetails { @@ -1772,7 +1772,7 @@ impl Node { // Now add all known-but-offline peers, too. for p in self.peer_store.list_peers() { - if peers.iter().take(connected_peers_len).find(|d| d.node_id == p.node_id).is_some() { + if peers.iter().take(connected_peers_len).any(|d| d.node_id == p.node_id) { continue; } diff --git a/src/payment_store.rs b/src/payment_store.rs index 12e331ad4..524984e9e 100644 --- a/src/payment_store.rs +++ b/src/payment_store.rs @@ -265,7 +265,7 @@ mod tests { let payment_store = PaymentStore::new(Vec::new(), Arc::clone(&store), logger); let hash = PaymentHash([42u8; 32]); - assert!(!payment_store.get(&hash).is_some()); + assert!(payment_store.get(&hash).is_none()); let store_key = hex_utils::to_string(&hash.0); assert!(store diff --git a/src/types.rs b/src/types.rs index bf467dc49..68ed36361 100644 --- a/src/types.rs +++ b/src/types.rs @@ -282,7 +282,7 @@ impl From for ChannelDetails { ChannelDetails { channel_id: value.channel_id, counterparty_node_id: value.counterparty.node_id, - funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())), + funding_txo: value.funding_txo.map(|o| o.into_bitcoin_outpoint()), channel_value_sats: value.channel_value_satoshis, unspendable_punishment_reserve: value.unspendable_punishment_reserve, user_channel_id: UserChannelId(value.user_channel_id), diff --git a/src/wallet.rs b/src/wallet.rs index 2b01d1b49..674cb6786 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -92,10 +92,7 @@ where e ); let sync_options = SyncOptions { progress: None }; - wallet_lock - .sync(&self.blockchain, sync_options) - .await - .map_err(|e| From::from(e)) + wallet_lock.sync(&self.blockchain, sync_options).await.map_err(From::from) }, _ => { log_error!(self.logger, "Sync failed due to Esplora error: {}", e);