Skip to content

Commit 249020a

Browse files
committed
Introduce enqueue_invoice_error API
Adds an API to send an `InvoiceError` to the counterparty via the flow. This becomes useful with the introduction of Flow events in upcoming commits, where the user can choose to either respond to Offers Messages or return an `InvoiceError`. Note: Given the small scope of changes in this commit, we also take the opportunity to perform minor documentation cleanups in `flow.rs`.
1 parent a6b1f32 commit 249020a

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lightning/src/offers/flow.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use crate::offers::invoice::{
3939
Bolt12Invoice, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder,
4040
DEFAULT_RELATIVE_EXPIRY,
4141
};
42+
use crate::offers::invoice_error::InvoiceError;
4243
use crate::offers::invoice_request::{
4344
CurrencyConversion, InvoiceRequest, InvoiceRequestBuilder, InvoiceRequestVerifiedFromOffer,
4445
VerifiedInvoiceRequest,
@@ -1104,9 +1105,6 @@ where
11041105
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
11051106
/// valid reply paths for the counterparty to send back the corresponding [`Bolt12Invoice`]
11061107
/// or [`InvoiceError`].
1107-
///
1108-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
1109-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
11101108
pub fn enqueue_invoice_request(
11111109
&self, invoice_request: InvoiceRequest, payment_id: PaymentId, nonce: Nonce,
11121110
peers: Vec<MessageForwardNode>,
@@ -1153,8 +1151,6 @@ where
11531151
/// Reply paths are generated from the given `peers` to allow the counterparty to return
11541152
/// an [`InvoiceError`] in case they fail to process the invoice. If valid reply paths
11551153
/// cannot be constructed, this method returns a [`Bolt12SemanticError::MissingPaths`].
1156-
///
1157-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
11581154
pub fn enqueue_invoice_using_node_id(
11591155
&self, invoice: Bolt12Invoice, destination: PublicKey, peers: Vec<MessageForwardNode>,
11601156
) -> Result<(), Bolt12SemanticError> {
@@ -1209,6 +1205,26 @@ where
12091205
Ok(())
12101206
}
12111207

1208+
/// Enqueues an [`InvoiceError`] to be sent to the counterparty via a specified
1209+
/// [`BlindedMessagePath`].
1210+
///
1211+
/// Since this method returns the invoice error to the counterparty without
1212+
/// expecting back a response, we enqueue it without a reply path.
1213+
pub fn enqueue_invoice_error(
1214+
&self, invoice_error: InvoiceError, path: BlindedMessagePath,
1215+
) -> Result<(), Bolt12SemanticError> {
1216+
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
1217+
1218+
let instructions = MessageSendInstructions::WithoutReplyPath {
1219+
destination: Destination::BlindedPath(path),
1220+
};
1221+
1222+
let message = OffersMessage::InvoiceError(invoice_error);
1223+
pending_offers_messages.push((message, instructions));
1224+
1225+
Ok(())
1226+
}
1227+
12121228
/// Forwards a [`StaticInvoice`] over the provided [`Responder`] in response to an
12131229
/// [`InvoiceRequest`] that we as a static invoice server received on behalf of an often-offline
12141230
/// recipient.
@@ -1256,7 +1272,6 @@ where
12561272
/// contained within the provided [`StaticInvoice`].
12571273
///
12581274
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
1259-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
12601275
pub fn enqueue_held_htlc_available(
12611276
&self, invoice: &StaticInvoice, reply_path_params: HeldHtlcReplyPath,
12621277
) -> Result<(), Bolt12SemanticError> {
@@ -1333,8 +1348,6 @@ where
13331348
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
13341349
/// valid reply paths for the counterparty to send back the corresponding response for
13351350
/// the [`DNSSECQuery`] message.
1336-
///
1337-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
13381351
#[cfg(feature = "dnssec")]
13391352
pub fn enqueue_dns_onion_message(
13401353
&self, message: DNSSECQuery, context: DNSResolverContext, dns_resolvers: Vec<Destination>,

0 commit comments

Comments
 (0)