Skip to content

Commit c5c5465

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 9e46350 commit c5c5465

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;
@@ -685,6 +687,22 @@ pub enum Event {
685687
/// The `payment_id` to have been associated with payment for the requested invoice.
686688
payment_id: PaymentId,
687689
},
690+
/// Indicates a [`Bolt12Invoice`] in response to an [`InvoiceRequest`] or a [`Refund`] was
691+
/// received.
692+
///
693+
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
694+
/// [`Refund`]: crate::offers::refund::Refund
695+
InvoiceReceived {
696+
/// The `payment_id` associated with payment for the invoice.
697+
payment_id: PaymentId,
698+
/// The invoice to pay.
699+
invoice: Bolt12Invoice,
700+
/// A responder for replying with an [`InvoiceError`] if needed. `None` if the invoice
701+
/// wasn't sent with a reply path.
702+
///
703+
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
704+
responder: Option<Responder>,
705+
},
688706
/// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
689707
/// and we got back the payment preimage for it).
690708
///
@@ -1440,7 +1458,15 @@ impl Writeable for Event {
14401458
write_tlv_fields!(writer, {
14411459
(0, peer_node_id, required),
14421460
});
1443-
}
1461+
},
1462+
&Event::InvoiceReceived { ref payment_id, ref invoice, ref responder } => {
1463+
41u8.write(writer)?;
1464+
write_tlv_fields!(writer, {
1465+
(0, payment_id, required),
1466+
(2, invoice, required),
1467+
(4, responder, option),
1468+
})
1469+
},
14441470
// Note that, going forward, all new events must only write data inside of
14451471
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
14461472
// data via `write_tlv_fields`.
@@ -1874,6 +1900,21 @@ impl MaybeReadable for Event {
18741900
};
18751901
f()
18761902
},
1903+
41u8 => {
1904+
let mut f = || {
1905+
_init_and_read_len_prefixed_tlv_fields!(reader, {
1906+
(0, payment_id, required),
1907+
(2, invoice, required),
1908+
(4, responder, option),
1909+
});
1910+
Ok(Some(Event::InvoiceReceived {
1911+
payment_id: payment_id.0.unwrap(),
1912+
invoice: invoice.0.unwrap(),
1913+
responder,
1914+
}))
1915+
};
1916+
f()
1917+
},
18771918
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
18781919
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
18791920
// reads.

0 commit comments

Comments
 (0)