Skip to content

Commit 0f1b395

Browse files
committed
Add an InvoiceReceived event
Some users may want to handle a Bolt12Invoice asynchronously, either in a different process or by first performing additional verification before paying the invoice. Add an InvoiceReceived event to facilitate this.
1 parent 4c297c9 commit 0f1b395

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

lightning/src/events/mod.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
2525
use crate::ln::features::ChannelTypeFeatures;
2626
use crate::ln::msgs;
2727
use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
28+
use crate::offers::invoice::Bolt12Invoice;
29+
use crate::onion_message::messenger::Responder;
2830
use crate::routing::gossip::NetworkUpdate;
2931
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
3032
use crate::sign::SpendableOutputDescriptor;
@@ -715,6 +717,22 @@ pub enum Event {
715717
/// The `payment_id` to have been associated with payment for the requested invoice.
716718
payment_id: PaymentId,
717719
},
720+
/// Indicates a [`Bolt12Invoice`] in response to an [`InvoiceRequest`] or a [`Refund`] was
721+
/// received.
722+
///
723+
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
724+
/// [`Refund`]: crate::offers::refund::Refund
725+
InvoiceReceived {
726+
/// The `payment_id` associated with payment for the invoice.
727+
payment_id: PaymentId,
728+
/// The invoice to pay.
729+
invoice: Bolt12Invoice,
730+
/// A responder for replying with an [`InvoiceError`] if needed. `None` if the invoice
731+
/// wasn't sent with a reply path.
732+
///
733+
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
734+
responder: Option<Responder>,
735+
},
718736
/// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
719737
/// and we got back the payment preimage for it).
720738
///
@@ -1471,7 +1489,15 @@ impl Writeable for Event {
14711489
write_tlv_fields!(writer, {
14721490
(0, peer_node_id, required),
14731491
});
1474-
}
1492+
},
1493+
&Event::InvoiceReceived { ref payment_id, ref invoice, ref responder } => {
1494+
41u8.write(writer)?;
1495+
write_tlv_fields!(writer, {
1496+
(0, payment_id, required),
1497+
(2, invoice, required),
1498+
(4, responder, option),
1499+
})
1500+
},
14751501
// Note that, going forward, all new events must only write data inside of
14761502
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
14771503
// data via `write_tlv_fields`.
@@ -1908,6 +1934,21 @@ impl MaybeReadable for Event {
19081934
};
19091935
f()
19101936
},
1937+
41u8 => {
1938+
let mut f = || {
1939+
_init_and_read_len_prefixed_tlv_fields!(reader, {
1940+
(0, payment_id, required),
1941+
(2, invoice, required),
1942+
(4, responder, option),
1943+
});
1944+
Ok(Some(Event::InvoiceReceived {
1945+
payment_id: payment_id.0.unwrap(),
1946+
invoice: invoice.0.unwrap(),
1947+
responder,
1948+
}))
1949+
};
1950+
f()
1951+
},
19111952
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
19121953
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
19131954
// reads.

0 commit comments

Comments
 (0)