From ef3ec8f146d2a6e9c750113ac8ce5af310fcef34 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 12 Apr 2024 21:21:00 -0500 Subject: [PATCH] Add PaymentPurpose::is_keysend utility method --- lightning/src/events/mod.rs | 7 +++++++ lightning/src/ln/channelmanager.rs | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index d6553ae3a..41ba17806 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -83,6 +83,13 @@ impl PaymentPurpose { PaymentPurpose::SpontaneousPayment(preimage) => Some(*preimage), } } + + pub(crate) fn is_keysend(&self) -> bool { + match self { + PaymentPurpose::Bolt11InvoicePayment { .. } => false, + PaymentPurpose::SpontaneousPayment(..) => true, + } + } } impl_writeable_tlv_based_enum!(PaymentPurpose, diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d9ce1940c..0693f3c64 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -5431,10 +5431,7 @@ where macro_rules! check_total_value { ($purpose: expr) => {{ let mut payment_claimable_generated = false; - let is_keysend = match $purpose { - events::PaymentPurpose::SpontaneousPayment(_) => true, - events::PaymentPurpose::Bolt11InvoicePayment { .. } => false, - }; + let is_keysend = $purpose.is_keysend(); let mut claimable_payments = self.claimable_payments.lock().unwrap(); if claimable_payments.pending_claiming_payments.contains_key(&payment_hash) { fail_htlc!(claimable_htlc, payment_hash); -- 2.39.5