Skip to content

Commit 46ca4f2

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 d9b9d53 commit 46ca4f2

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,
@@ -1115,9 +1116,6 @@ where
11151116
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
11161117
/// valid reply paths for the counterparty to send back the corresponding [`Bolt12Invoice`]
11171118
/// or [`InvoiceError`].
1118-
///
1119-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
1120-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
11211119
pub fn enqueue_invoice_request(
11221120
&self, invoice_request: InvoiceRequest, payment_id: PaymentId, nonce: Nonce,
11231121
peers: Vec<MessageForwardNode>,
@@ -1164,8 +1162,6 @@ where
11641162
/// Reply paths are generated from the given `peers` to allow the counterparty to return
11651163
/// an [`InvoiceError`] in case they fail to process the invoice. If valid reply paths
11661164
/// cannot be constructed, this method returns a [`Bolt12SemanticError::MissingPaths`].
1167-
///
1168-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
11691165
pub fn enqueue_invoice_using_node_id(
11701166
&self, invoice: Bolt12Invoice, destination: PublicKey, peers: Vec<MessageForwardNode>,
11711167
) -> Result<(), Bolt12SemanticError> {
@@ -1220,6 +1216,26 @@ where
12201216
Ok(())
12211217
}
12221218

1219+
/// Enqueues an [`InvoiceError`] to be sent to the counterparty via a specified
1220+
/// [`BlindedMessagePath`].
1221+
///
1222+
/// Since this method returns the invoice error to the counterparty without
1223+
/// expecting back a response, we enqueue it without a reply path.
1224+
pub fn enqueue_invoice_error(
1225+
&self, invoice_error: InvoiceError, path: BlindedMessagePath,
1226+
) -> Result<(), Bolt12SemanticError> {
1227+
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
1228+
1229+
let instructions = MessageSendInstructions::WithoutReplyPath {
1230+
destination: Destination::BlindedPath(path),
1231+
};
1232+
1233+
let message = OffersMessage::InvoiceError(invoice_error);
1234+
pending_offers_messages.push((message, instructions));
1235+
1236+
Ok(())
1237+
}
1238+
12231239
/// Forwards a [`StaticInvoice`] over the provided [`Responder`] in response to an
12241240
/// [`InvoiceRequest`] that we as a static invoice server received on behalf of an often-offline
12251241
/// recipient.
@@ -1267,7 +1283,6 @@ where
12671283
/// contained within the provided [`StaticInvoice`].
12681284
///
12691285
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
1270-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
12711286
pub fn enqueue_held_htlc_available(
12721287
&self, invoice: &StaticInvoice, reply_path_params: HeldHtlcReplyPath,
12731288
) -> Result<(), Bolt12SemanticError> {
@@ -1344,8 +1359,6 @@ where
13441359
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
13451360
/// valid reply paths for the counterparty to send back the corresponding response for
13461361
/// the [`DNSSECQuery`] message.
1347-
///
1348-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
13491362
#[cfg(feature = "dnssec")]
13501363
pub fn enqueue_dns_onion_message(
13511364
&self, message: DNSSECQuery, context: DNSResolverContext, dns_resolvers: Vec<Destination>,

0 commit comments

Comments
 (0)