Skip to content

Commit

Permalink
Refactored necessary files to improve code quality
Browse files Browse the repository at this point in the history
* 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!
  • Loading branch information
srikanth-iyengar committed May 13, 2024
1 parent 9f27fcb commit 4d7c9f3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where

pub(crate) fn next_event(&self) -> Option<Event> {
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 {
Expand Down
12 changes: 3 additions & 9 deletions src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/payment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl From<LdkChannelDetails> 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),
Expand Down
5 changes: 1 addition & 4 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4d7c9f3

Please sign in to comment.