From 00f578adee31e519a977a6b7c980dc4362eae9f9 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Sun, 3 Dec 2023 12:42:17 -0600 Subject: [PATCH] Add helper function for getting preimage from PaymentPurpose --- lightning/src/events/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index adbc7faf7..4e04a3634 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -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 { + 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), -- 2.39.5