Skip to content

Commit f366d99

Browse files
committed
f store and if let instead of directly if let'ing
1 parent a870810 commit f366d99

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,11 +1377,12 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13771377

13781378
let mut confirmed_txid = us.funding_spend_confirmed;
13791379
let mut pending_commitment_tx_conf_thresh = None;
1380-
if let Some((txid, conf_thresh)) = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
1380+
let funding_spend_pending = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
13811381
if let OnchainEvent::FundingSpendConfirmation { .. } = event.event {
13821382
Some((event.txid, event.confirmation_threshold()))
13831383
} else { None }
1384-
}) {
1384+
});
1385+
if let Some((txid, conf_thresh)) = funding_spend_pending {
13851386
debug_assert!(us.funding_spend_confirmed.is_none(),
13861387
"We have a pending funding spend awaiting anti-reorg confirmation, we can't have confirmed it already!");
13871388
confirmed_txid = Some(txid);
@@ -1398,11 +1399,12 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13981399
// If the payment was outbound, check if there's an HTLCUpdate
13991400
// indicating we have spent this HTLC with a timeout, claiming it back
14001401
// and awaiting confirmations on it.
1401-
if let Some(conf_thresh) = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
1402+
let htlc_update_pending = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
14021403
if let OnchainEvent::HTLCUpdate { input_idx: Some(input_idx), .. } = event.event {
14031404
if input_idx == htlc_input_idx { Some(event.confirmation_threshold()) } else { None }
14041405
} else { None }
1405-
}) {
1406+
});
1407+
if let Some(conf_thresh) = htlc_update_pending {
14061408
res.push(ClaimableBalance::ClaimableAwaitingConfirmations {
14071409
claimable_amount_satoshis: htlc.amount_msat / 1000,
14081410
confirmation_height: conf_thresh,
@@ -1419,15 +1421,14 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
14191421
// Note that if there is a pending claim, but it did not use the
14201422
// preimage, we lost funds to our counterparty! We will then continue
14211423
// to show it as ContentiousClaimable until ANTI_REORG_DELAY.
1422-
if let Some((conf_thresh, true)) =
1423-
us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
1424-
if let OnchainEvent::HTLCSpendConfirmation { input_idx, preimage, .. } = event.event {
1425-
if input_idx == htlc_input_idx {
1426-
Some((event.confirmation_threshold(), preimage.is_some()))
1427-
} else { None }
1424+
let htlc_spend_pending = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
1425+
if let OnchainEvent::HTLCSpendConfirmation { input_idx, preimage, .. } = event.event {
1426+
if input_idx == htlc_input_idx {
1427+
Some((event.confirmation_threshold(), preimage.is_some()))
14281428
} else { None }
1429-
}
1430-
) {
1429+
} else { None }
1430+
});
1431+
if let Some((conf_thresh, true)) = htlc_spend_pending {
14311432
res.push(ClaimableBalance::ClaimableAwaitingConfirmations {
14321433
claimable_amount_satoshis: htlc.amount_msat / 1000,
14331434
confirmation_height: conf_thresh,

0 commit comments

Comments
 (0)