From: Jeffrey Czyz Date: Sat, 13 Apr 2024 02:21:00 +0000 (-0500) Subject: Add PaymentPurpose::is_keysend utility method X-Git-Tag: v0.0.123-beta~7^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ef3ec8f146d2a6e9c750113ac8ce5af310fcef34;p=rust-lightning Add PaymentPurpose::is_keysend utility method --- 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);