Skip to content

Commit 6c79ef8

Browse files
committed
Introduce InvoiceRequestReceived Event
1. This event will be triggered when user enables manual handling of BOLT12 Messages. 2. With this event they can do some preprocessing on their end to make sure if they want to continue with this inbound payment. 3. For example, this can be used by the user to do the currency conversion on their end and respond to invoice request accordingly.
1 parent 61ed636 commit 6c79ef8

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

lightning/src/events/mod.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::ln::features::ChannelTypeFeatures;
2727
use crate::ln::msgs;
2828
use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
2929
use crate::offers::invoice::Bolt12Invoice;
30+
use crate::offers::invoice_request::InvoiceRequest;
3031
use crate::onion_message::messenger::Responder;
3132
use crate::routing::gossip::NetworkUpdate;
3233
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
@@ -820,6 +821,23 @@ pub enum Event {
820821
/// Sockets for connecting to the node.
821822
addresses: Vec<msgs::SocketAddress>,
822823
},
824+
825+
/// Event triggered when manual handling is enabled, and an invoice request is received.
826+
InvoiceRequestReceived {
827+
/// The invoice request to pay.
828+
invoice_request: InvoiceRequest,
829+
/// The context of the [`BlindedMessagePath`] used to send the invoice request.
830+
///
831+
/// [`BlindedMessagePath`]: crate::blinded_path::message::BlindedMessagePath
832+
context: Option<OffersContext>,
833+
/// A responder for replying with an [`InvoiceError`] if needed.
834+
///
835+
/// `None` if the invoice wasn't sent with a reply path.
836+
///
837+
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
838+
responder: Option<Responder>,
839+
},
840+
823841
/// Indicates a [`Bolt12Invoice`] in response to an [`InvoiceRequest`] or a [`Refund`] was
824842
/// received.
825843
///
@@ -1740,6 +1758,14 @@ impl Writeable for Event {
17401758
(8, former_temporary_channel_id, required),
17411759
});
17421760
},
1761+
&Event::InvoiceRequestReceived { ref invoice_request, ref context, ref responder } => {
1762+
44u8.write(writer)?;
1763+
write_tlv_fields!(writer, {
1764+
(0, invoice_request, required),
1765+
(2, context, option),
1766+
(4, responder, option),
1767+
});
1768+
},
17431769
// Note that, going forward, all new events must only write data inside of
17441770
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
17451771
// data via `write_tlv_fields`.
@@ -2234,6 +2260,21 @@ impl MaybeReadable for Event {
22342260
former_temporary_channel_id: former_temporary_channel_id.0.unwrap(),
22352261
}))
22362262
},
2263+
44u8 => {
2264+
let mut f = || {
2265+
_init_and_read_len_prefixed_tlv_fields!(reader, {
2266+
(0, invoice_request, required),
2267+
(2, context, option),
2268+
(4, responder, option),
2269+
});
2270+
Ok(Some(Event::InvoiceRequestReceived {
2271+
invoice_request: invoice_request.0.unwrap(),
2272+
context,
2273+
responder,
2274+
}))
2275+
};
2276+
f()
2277+
},
22372278
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
22382279
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
22392280
// reads.

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11038,6 +11038,14 @@ where
1103811038

1103911039
match message {
1104011040
OffersMessage::InvoiceRequest(invoice_request) => {
11041+
if self.default_configuration.manually_handle_bolt12_messages {
11042+
let event = Event::InvoiceRequestReceived {
11043+
invoice_request, context, responder,
11044+
};
11045+
self.pending_events.lock().unwrap().push_back((event, None));
11046+
return None;
11047+
}
11048+
1104111049
let responder = match responder {
1104211050
Some(responder) => responder,
1104311051
None => return None,

lightning/src/offers/invoice_request.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ impl AsRef<TaggedHash> for UnsignedInvoiceRequest {
595595
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
596596
/// [`Offer`]: crate::offers::offer::Offer
597597
#[derive(Clone, Debug)]
598-
#[cfg_attr(test, derive(PartialEq))]
599598
pub struct InvoiceRequest {
600599
pub(super) bytes: Vec<u8>,
601600
pub(super) contents: InvoiceRequestContents,
@@ -1145,6 +1144,14 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
11451144
}
11461145
}
11471146

1147+
impl PartialEq for InvoiceRequest {
1148+
fn eq(&self, other: &Self) -> bool {
1149+
self.bytes.eq(&other.bytes)
1150+
}
1151+
}
1152+
1153+
impl Eq for InvoiceRequest {}
1154+
11481155
impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
11491156
type Error = Bolt12SemanticError;
11501157

0 commit comments

Comments
 (0)