Skip to content

Commit 4d7c9f3

Browse files
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!
1 parent 9f27fcb commit 4d7c9f3

File tree

7 files changed

+10
-20
lines changed

7 files changed

+10
-20
lines changed

src/builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ impl NodeBuilder {
184184

185185
/// Creates a new builder instance from an [`Config`].
186186
pub fn from_config(config: Config) -> Self {
187-
let config = config;
188187
let entropy_source_config = None;
189188
let chain_data_source_config = None;
190189
let gossip_source_config = None;
@@ -1034,7 +1033,7 @@ fn seed_bytes_from_config(
10341033
match entropy_source_config {
10351034
Some(EntropySourceConfig::SeedBytes(bytes)) => Ok(bytes.clone()),
10361035
Some(EntropySourceConfig::SeedFile(seed_path)) => {
1037-
Ok(io::utils::read_or_generate_seed_file(&seed_path, Arc::clone(&logger))
1036+
Ok(io::utils::read_or_generate_seed_file(seed_path, Arc::clone(&logger))
10381037
.map_err(|_| BuildError::InvalidSeedFile)?)
10391038
},
10401039
Some(EntropySourceConfig::Bip39Mnemonic { mnemonic, passphrase }) => match passphrase {

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ where
176176

177177
pub(crate) fn next_event(&self) -> Option<Event> {
178178
let locked_queue = self.queue.lock().unwrap();
179-
locked_queue.front().map(|e| e.clone())
179+
locked_queue.front().cloned()
180180
}
181181

182182
pub(crate) async fn next_event_async(&self) -> Event {

src/gossip.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,13 @@ impl GossipSource {
3939
}
4040

4141
pub fn is_rgs(&self) -> bool {
42-
if let Self::RapidGossipSync { .. } = self {
43-
true
44-
} else {
45-
false
46-
}
42+
matches!(self, Self::RapidGossipSync { .. })
4743
}
4844

4945
pub fn as_gossip_sync(&self) -> GossipSync {
5046
match self {
51-
Self::RapidGossipSync { gossip_sync, .. } => {
52-
GossipSync::Rapid(Arc::clone(&gossip_sync))
53-
},
54-
Self::P2PNetwork { gossip_sync, .. } => GossipSync::P2P(Arc::clone(&gossip_sync)),
47+
Self::RapidGossipSync { gossip_sync, .. } => GossipSync::Rapid(Arc::clone(gossip_sync)),
48+
Self::P2PNetwork { gossip_sync, .. } => GossipSync::P2P(Arc::clone(gossip_sync)),
5549
}
5650
}
5751

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ impl Node {
17111711
.output_sweeper
17121712
.tracked_spendable_outputs()
17131713
.into_iter()
1714-
.map(|o| PendingSweepBalance::from_tracked_spendable_output(o))
1714+
.map(PendingSweepBalance::from_tracked_spendable_output)
17151715
.collect();
17161716

17171717
BalanceDetails {
@@ -1772,7 +1772,7 @@ impl Node {
17721772

17731773
// Now add all known-but-offline peers, too.
17741774
for p in self.peer_store.list_peers() {
1775-
if peers.iter().take(connected_peers_len).find(|d| d.node_id == p.node_id).is_some() {
1775+
if peers.iter().take(connected_peers_len).any(|d| d.node_id == p.node_id) {
17761776
continue;
17771777
}
17781778

src/payment_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ mod tests {
265265
let payment_store = PaymentStore::new(Vec::new(), Arc::clone(&store), logger);
266266

267267
let hash = PaymentHash([42u8; 32]);
268-
assert!(!payment_store.get(&hash).is_some());
268+
assert!(payment_store.get(&hash).is_none());
269269

270270
let store_key = hex_utils::to_string(&hash.0);
271271
assert!(store

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl From<LdkChannelDetails> for ChannelDetails {
282282
ChannelDetails {
283283
channel_id: value.channel_id,
284284
counterparty_node_id: value.counterparty.node_id,
285-
funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())),
285+
funding_txo: value.funding_txo.map(|o| o.into_bitcoin_outpoint()),
286286
channel_value_sats: value.channel_value_satoshis,
287287
unspendable_punishment_reserve: value.unspendable_punishment_reserve,
288288
user_channel_id: UserChannelId(value.user_channel_id),

src/wallet.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ where
9292
e
9393
);
9494
let sync_options = SyncOptions { progress: None };
95-
wallet_lock
96-
.sync(&self.blockchain, sync_options)
97-
.await
98-
.map_err(|e| From::from(e))
95+
wallet_lock.sync(&self.blockchain, sync_options).await.map_err(From::from)
9996
},
10097
_ => {
10198
log_error!(self.logger, "Sync failed due to Esplora error: {}", e);

0 commit comments

Comments
 (0)