From: benthecarman Date: Sun, 3 Dec 2023 18:42:17 +0000 (-0600) Subject: Add helper function for getting preimage from PaymentPurpose X-Git-Tag: v0.0.119~33^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=00f578adee31e519a977a6b7c980dc4362eae9f9;p=rust-lightning Add helper function for getting preimage from PaymentPurpose --- 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),