Skip to content

Commit 1eddd1e

Browse files
authored
Merge pull request #2768 from benthecarman/preimage-helper
Add helper function for getting preimage from PaymentPurpose
2 parents ac06a6a + 00f578a commit 1eddd1e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lightning/src/events/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ pub enum PaymentPurpose {
7272
SpontaneousPayment(PaymentPreimage),
7373
}
7474

75+
impl PaymentPurpose {
76+
/// Returns the preimage for this payment, if it is known.
77+
pub fn preimage(&self) -> Option<PaymentPreimage> {
78+
match self {
79+
PaymentPurpose::InvoicePayment { payment_preimage, .. } => *payment_preimage,
80+
PaymentPurpose::SpontaneousPayment(preimage) => Some(*preimage),
81+
}
82+
}
83+
}
84+
7585
impl_writeable_tlv_based_enum!(PaymentPurpose,
7686
(0, InvoicePayment) => {
7787
(0, payment_preimage, option),

0 commit comments

Comments
 (0)