Add helper function for getting preimage from PaymentPurpose

This commit is contained in:
benthecarman 2023-12-03 12:42:17 -06:00
parent 6b43153861
commit 00f578adee
No known key found for this signature in database
GPG key ID: D7CC770B81FD22A8

View 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),