Merge pull request #2768 from benthecarman/preimage-helper

Add helper function for getting preimage from PaymentPurpose
This commit is contained in:
Matt Corallo 2023-12-04 17:10:33 +00:00 committed by GitHub
commit 1eddd1ef8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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