@@ -25,6 +25,7 @@ use crate::ln::features::ChannelTypeFeatures;
25
25
use crate :: ln:: msgs;
26
26
use crate :: ln:: { ChannelId , PaymentPreimage , PaymentHash , PaymentSecret } ;
27
27
use crate :: chain:: transaction;
28
+ use crate :: offers:: invoice:: Bolt12Invoice ;
28
29
use crate :: routing:: gossip:: NetworkUpdate ;
29
30
use crate :: util:: errors:: APIError ;
30
31
use crate :: util:: ser:: { BigSize , FixedLengthReader , Writeable , Writer , MaybeReadable , Readable , RequiredWrapper , UpgradableRequired , WithoutLength } ;
@@ -582,6 +583,39 @@ pub enum Event {
582
583
/// The `payment_id` to have been associated with payment for the requested invoice.
583
584
payment_id : PaymentId ,
584
585
} ,
586
+ /// Indicates that a [`Bolt12Invoice`] was generated in response to an [`InvoiceRequest`] and is
587
+ /// being prepared to be sent via an [`OnionMessage`].
588
+ ///
589
+ /// Note that this doesn't necessarily mean that the invoice was sent and -- once sent -- it may
590
+ /// never reach its destination because of the unreliable nature of onion messages. Any of the
591
+ /// following scenarios may occur.
592
+ /// - Dropped by a node along the path to the destination
593
+ /// - Dropped upon node restart prior to being sent
594
+ /// - Buffered waiting to be sent by [`PeerManager`]
595
+ /// - Buffered waiting for an [`Event::ConnectionNeeded`] to be handled and peer connected
596
+ /// - Dropped waiting too long for such a peer connection
597
+ /// - Dropped because the onion message buffer was full
598
+ /// - Dropped because the [`MessageRouter`] failed to find an [`OnionMessagePath`] to the
599
+ /// destination
600
+ ///
601
+ /// Thus, this event is largely for informational purposes as the corresponding [`Offer`] and
602
+ /// [`InvoiceRequest`] fields are accessible from the invoice. In particular:
603
+ /// - [`Bolt12Invoice::metadata`] can help identify the corresponding [`Offer`]
604
+ /// - A common [`Bolt12Invoice::payer_id`] indicates the payer sent multiple requests for
605
+ /// redundancy, though in that case the [`Bolt12Invoice::payment_hash`] used may be different.
606
+ ///
607
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
608
+ /// [`OnionMessage`]: crate::ln::msgs::OnionMessage
609
+ /// [`PeerManager`]: crate::ln::peer_handler::PeerManager
610
+ /// [`MessageRouter`]: crate::onion_message::messenger::MessageRouter
611
+ /// [`OnionMessagePath`]: crate::onion_message::messenger::OnionMessagePath
612
+ /// [`Offer`]: crate::offers::offer::Offer
613
+ InvoiceGenerated {
614
+ /// An invoice that was generated in response to an [`InvoiceRequest`].
615
+ ///
616
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
617
+ invoice : Bolt12Invoice ,
618
+ } ,
585
619
/// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
586
620
/// and we got back the payment preimage for it).
587
621
///
@@ -1262,6 +1296,12 @@ impl Writeable for Event {
1262
1296
35u8 . write ( writer) ?;
1263
1297
// Never write ConnectionNeeded events as buffered onion messages aren't serialized.
1264
1298
} ,
1299
+ & Event :: InvoiceGenerated { ref invoice } => {
1300
+ 37u8 . write ( writer) ?;
1301
+ write_tlv_fields ! ( writer, {
1302
+ ( 0 , invoice, required) ,
1303
+ } )
1304
+ } ,
1265
1305
// Note that, going forward, all new events must only write data inside of
1266
1306
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
1267
1307
// data via `write_tlv_fields`.
@@ -1668,6 +1708,18 @@ impl MaybeReadable for Event {
1668
1708
} ,
1669
1709
// Note that we do not write a length-prefixed TLV for ConnectionNeeded events.
1670
1710
35u8 => Ok ( None ) ,
1711
+ 37u8 => {
1712
+ let f = || {
1713
+ let mut invoice_bytes = WithoutLength ( Vec :: new ( ) ) ;
1714
+ read_tlv_fields ! ( reader, {
1715
+ ( 0 , invoice_bytes, required) ,
1716
+ } ) ;
1717
+ let invoice = Bolt12Invoice :: try_from ( invoice_bytes. 0 )
1718
+ . map_err ( |_| msgs:: DecodeError :: InvalidValue ) ?;
1719
+ Ok ( Some ( Event :: InvoiceGenerated { invoice } ) )
1720
+ } ;
1721
+ f ( )
1722
+ } ,
1671
1723
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
1672
1724
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
1673
1725
// reads.
0 commit comments