Skip to content

Commit

Permalink
Add an InvoiceRequestFailed event
Browse files Browse the repository at this point in the history
When an invoice is requested but either receives an error or never
receives a response, surface an event to indicate to the user that the
corresponding future payment has failed.
  • Loading branch information
jkczyz committed Aug 23, 2023
1 parent 3e3cbbd commit b8770c0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ pub enum Event {
/// spontaneous payment.
purpose: PaymentPurpose,
},
/// Indicates a request for invoice failed to yield a response in a reasonable amount of time.
InvoiceRequestFailed {
/// The `payment_id` to have been associated with payment for the requested invoice.
payment_id: PaymentId,
},
/// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
/// and we got back the payment preimage for it).
///
Expand Down Expand Up @@ -1063,6 +1068,12 @@ impl Writeable for Event {
(8, funding_txo, required),
});
},
&Event::InvoiceRequestFailed { ref payment_id } => {
33u8.write(writer)?;
write_tlv_fields!(writer, {
(0, payment_id, required),
})
},
// Note that, going forward, all new events must only write data inside of
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
// data via `write_tlv_fields`.
Expand Down Expand Up @@ -1437,6 +1448,17 @@ impl MaybeReadable for Event {
};
f()
},
33u8 => {
let f = || {
_init_and_read_tlv_fields!(reader, {
(0, payment_id, required),
});
Ok(Some(Event::InvoiceRequestFailed {
payment_id: payment_id.0.unwrap(),
}))
};
f()
},
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
// reads.
Expand Down

0 comments on commit b8770c0

Please sign in to comment.