Skip to content

Commit 75d56f3

Browse files
committed
Pull out multi-line functions from match statments to variables
1 parent 025257a commit 75d56f3

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6452,10 +6452,11 @@ where
64526452
if let PendingHTLCRouting::Forward { ref onion_packet, .. } = routing {
64536453
let phantom_pubkey_res = self.node_signer.get_node_id(Recipient::PhantomNode);
64546454
if phantom_pubkey_res.is_ok() && fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, short_chan_id, &self.chain_hash) {
6455-
let next_hop = match onion_utils::decode_next_payment_hop(
6455+
let decode_res = onion_utils::decode_next_payment_hop(
64566456
Recipient::PhantomNode, &onion_packet.public_key.unwrap(), &onion_packet.hop_data,
64576457
onion_packet.hmac, payment_hash, None, &*self.node_signer
6458-
) {
6458+
);
6459+
let next_hop = match decode_res {
64596460
Ok(res) => res,
64606461
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, reason }) => {
64616462
let sha256_of_onion = Sha256::hash(&onion_packet.hop_data).to_byte_array();
@@ -6472,10 +6473,11 @@ where
64726473
};
64736474
let phantom_shared_secret = next_hop.shared_secret().secret_bytes();
64746475
let current_height: u32 = self.best_block.read().unwrap().height;
6475-
match create_recv_pending_htlc_info(next_hop,
6476+
let create_res = create_recv_pending_htlc_info(next_hop,
64766477
incoming_shared_secret, payment_hash, outgoing_amt_msat,
64776478
outgoing_cltv_value, Some(phantom_shared_secret), false, None,
6478-
current_height)
6479+
current_height);
6480+
match create_res
64796481
{
64806482
Ok(info) => phantom_receives.push((
64816483
prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
@@ -7016,20 +7018,20 @@ where
70167018
// associated with the same payment_hash pending or not.
70177019
let payment_preimage = if has_recipient_created_payment_secret {
70187020
if let Some(ref payment_data) = payment_data {
7019-
let (payment_preimage, min_final_cltv_expiry_delta) =
7020-
match inbound_payment::verify(
7021-
payment_hash,
7022-
&payment_data,
7023-
self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
7024-
&self.inbound_payment_key,
7025-
&self.logger,
7026-
) {
7027-
Ok(result) => result,
7028-
Err(()) => {
7029-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
7030-
fail_htlc!(claimable_htlc, payment_hash);
7031-
},
7032-
};
7021+
let verify_res = inbound_payment::verify(
7022+
payment_hash,
7023+
&payment_data,
7024+
self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
7025+
&self.inbound_payment_key,
7026+
&self.logger,
7027+
);
7028+
let (payment_preimage, min_final_cltv_expiry_delta) = match verify_res {
7029+
Ok(result) => result,
7030+
Err(()) => {
7031+
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
7032+
fail_htlc!(claimable_htlc, payment_hash);
7033+
},
7034+
};
70337035
if let Some(min_final_cltv_expiry_delta) = min_final_cltv_expiry_delta {
70347036
let expected_min_expiry_height = (self.current_best_block().height
70357037
+ min_final_cltv_expiry_delta as u32)
@@ -7050,11 +7052,12 @@ where
70507052
match claimable_htlc.onion_payload {
70517053
OnionPayload::Invoice { .. } => {
70527054
let payment_data = payment_data.unwrap();
7053-
let purpose = match events::PaymentPurpose::from_parts(
7055+
let from_parts_res = events::PaymentPurpose::from_parts(
70547056
payment_preimage,
70557057
payment_data.payment_secret,
70567058
payment_context,
7057-
) {
7059+
);
7060+
let purpose = match from_parts_res {
70587061
Ok(purpose) => purpose,
70597062
Err(()) => {
70607063
fail_htlc!(claimable_htlc, payment_hash);
@@ -7078,15 +7081,16 @@ where
70787081
},
70797082
};
70807083

7081-
let verified_invreq = match invoice_request_opt.and_then(|invreq| {
7084+
let verify_opt = invoice_request_opt.and_then(|invreq| {
70827085
invreq
70837086
.verify_using_recipient_data(
70847087
offer_nonce,
70857088
&self.inbound_payment_key,
70867089
&self.secp_ctx,
70877090
)
70887091
.ok()
7089-
}) {
7092+
});
7093+
let verified_invreq = match verify_opt {
70907094
Some(verified_invreq) => {
70917095
if let Some(invreq_amt_msat) =
70927096
verified_invreq.amount_msats()
@@ -7106,11 +7110,12 @@ where
71067110
offer_id: verified_invreq.offer_id,
71077111
invoice_request: verified_invreq.fields(),
71087112
});
7109-
match events::PaymentPurpose::from_parts(
7113+
let from_parts_res = events::PaymentPurpose::from_parts(
71107114
Some(keysend_preimage),
71117115
payment_data.payment_secret,
71127116
Some(payment_purpose_context),
7113-
) {
7117+
);
7118+
match from_parts_res {
71147119
Ok(purpose) => purpose,
71157120
Err(()) => {
71167121
fail_htlc!(claimable_htlc, payment_hash);

0 commit comments

Comments
 (0)