Skip to content

Commit 12ad811

Browse files
committed
Pull out multi-line functions from match statements to variables
1 parent 64c47c5 commit 12ad811

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
@@ -6383,10 +6383,11 @@ where
63836383
if let PendingHTLCRouting::Forward { ref onion_packet, .. } = routing {
63846384
let phantom_pubkey_res = self.node_signer.get_node_id(Recipient::PhantomNode);
63856385
if phantom_pubkey_res.is_ok() && fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, short_chan_id, &self.chain_hash) {
6386-
let next_hop = match onion_utils::decode_next_payment_hop(
6386+
let decode_res = onion_utils::decode_next_payment_hop(
63876387
Recipient::PhantomNode, &onion_packet.public_key.unwrap(), &onion_packet.hop_data,
63886388
onion_packet.hmac, payment_hash, None, &*self.node_signer
6389-
) {
6389+
);
6390+
let next_hop = match decode_res {
63906391
Ok(res) => res,
63916392
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, reason }) => {
63926393
let sha256_of_onion = Sha256::hash(&onion_packet.hop_data).to_byte_array();
@@ -6403,10 +6404,11 @@ where
64036404
};
64046405
let phantom_shared_secret = next_hop.shared_secret().secret_bytes();
64056406
let current_height: u32 = self.best_block.read().unwrap().height;
6406-
match create_recv_pending_htlc_info(next_hop,
6407+
let create_res = create_recv_pending_htlc_info(next_hop,
64076408
incoming_shared_secret, payment_hash, outgoing_amt_msat,
64086409
outgoing_cltv_value, Some(phantom_shared_secret), false, None,
6409-
current_height)
6410+
current_height);
6411+
match create_res
64106412
{
64116413
Ok(info) => phantom_receives.push((
64126414
prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
@@ -6941,20 +6943,20 @@ where
69416943
// associated with the same payment_hash pending or not.
69426944
let payment_preimage = if has_recipient_created_payment_secret {
69436945
if let Some(ref payment_data) = payment_data {
6944-
let (payment_preimage, min_final_cltv_expiry_delta) =
6945-
match inbound_payment::verify(
6946-
payment_hash,
6947-
&payment_data,
6948-
self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
6949-
&self.inbound_payment_key,
6950-
&self.logger,
6951-
) {
6952-
Ok(result) => result,
6953-
Err(()) => {
6954-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
6955-
fail_htlc!(claimable_htlc, payment_hash);
6956-
},
6957-
};
6946+
let verify_res = inbound_payment::verify(
6947+
payment_hash,
6948+
&payment_data,
6949+
self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
6950+
&self.inbound_payment_key,
6951+
&self.logger,
6952+
);
6953+
let (payment_preimage, min_final_cltv_expiry_delta) = match verify_res {
6954+
Ok(result) => result,
6955+
Err(()) => {
6956+
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
6957+
fail_htlc!(claimable_htlc, payment_hash);
6958+
},
6959+
};
69586960
if let Some(min_final_cltv_expiry_delta) = min_final_cltv_expiry_delta {
69596961
let expected_min_expiry_height = (self.current_best_block().height
69606962
+ min_final_cltv_expiry_delta as u32)
@@ -6975,11 +6977,12 @@ where
69756977
match claimable_htlc.onion_payload {
69766978
OnionPayload::Invoice { .. } => {
69776979
let payment_data = payment_data.unwrap();
6978-
let purpose = match events::PaymentPurpose::from_parts(
6980+
let from_parts_res = events::PaymentPurpose::from_parts(
69796981
payment_preimage,
69806982
payment_data.payment_secret,
69816983
payment_context,
6982-
) {
6984+
);
6985+
let purpose = match from_parts_res {
69836986
Ok(purpose) => purpose,
69846987
Err(()) => {
69856988
fail_htlc!(claimable_htlc, payment_hash);
@@ -7003,15 +7006,16 @@ where
70037006
},
70047007
};
70057008

7006-
let verified_invreq = match invoice_request_opt.and_then(|invreq| {
7009+
let verify_opt = invoice_request_opt.and_then(|invreq| {
70077010
invreq
70087011
.verify_using_recipient_data(
70097012
offer_nonce,
70107013
&self.inbound_payment_key,
70117014
&self.secp_ctx,
70127015
)
70137016
.ok()
7014-
}) {
7017+
});
7018+
let verified_invreq = match verify_opt {
70157019
Some(verified_invreq) => {
70167020
if let Some(invreq_amt_msat) =
70177021
verified_invreq.amount_msats()
@@ -7031,11 +7035,12 @@ where
70317035
offer_id: verified_invreq.offer_id,
70327036
invoice_request: verified_invreq.fields(),
70337037
});
7034-
match events::PaymentPurpose::from_parts(
7038+
let from_parts_res = events::PaymentPurpose::from_parts(
70357039
Some(keysend_preimage),
70367040
payment_data.payment_secret,
70377041
Some(payment_purpose_context),
7038-
) {
7042+
);
7043+
match from_parts_res {
70397044
Ok(purpose) => purpose,
70407045
Err(()) => {
70417046
fail_htlc!(claimable_htlc, payment_hash);

0 commit comments

Comments
 (0)