]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add helper function for getting preimage from PaymentPurpose
authorbenthecarman <benthecarman@live.com>
Sun, 3 Dec 2023 18:42:17 +0000 (12:42 -0600)
committerbenthecarman <benthecarman@live.com>
Sun, 3 Dec 2023 18:42:17 +0000 (12:42 -0600)
lightning/src/events/mod.rs

index adbc7faf7e0f9d0acf1fa3349495733669d41193..4e04a3634e10d3f9152ae6d074bb19365bf989a4 100644 (file)
@@ -72,6 +72,16 @@ pub enum PaymentPurpose {
        SpontaneousPayment(PaymentPreimage),
 }
 
+impl PaymentPurpose {
+       /// Returns the preimage for this payment, if it is known.
+       pub fn preimage(&self) -> Option<PaymentPreimage> {
+               match self {
+                       PaymentPurpose::InvoicePayment { payment_preimage, .. } => *payment_preimage,
+                       PaymentPurpose::SpontaneousPayment(preimage) => Some(*preimage),
+               }
+       }
+}
+
 impl_writeable_tlv_based_enum!(PaymentPurpose,
        (0, InvoicePayment) => {
                (0, payment_preimage, option),