@@ -56,10 +56,10 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
56
56
use crate::ln::outbound_payment;
57
57
use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs};
58
58
use crate::ln::wire::Encode;
59
- use crate::offers::offer::{DerivedMetadata, OfferBuilder};
59
+ use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
60
60
use crate::offers::parse::Bolt12SemanticError;
61
61
use crate::offers::refund::RefundBuilder;
62
- use crate::onion_message::{OffersMessage, PendingOnionMessage};
62
+ use crate::onion_message::{Destination, OffersMessage, PendingOnionMessage};
63
63
use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, WriteableEcdsaChannelSigner};
64
64
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
65
65
use crate::util::wakers::{Future, Notifier};
@@ -6884,6 +6884,70 @@ where
6884
6884
Ok(builder)
6885
6885
}
6886
6886
6887
+ /// Creates an [`InvoiceRequest`] for an [`Offer`] from the given parameters and enqueues it to
6888
+ /// be sent via an onion message.
6889
+ ///
6890
+ /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
6891
+ /// the [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the request.
6892
+ ///
6893
+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the request.
6894
+ ///
6895
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6896
+ /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
6897
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6898
+ pub fn request_invoice(
6899
+ &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
6900
+ payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry
6901
+ ) -> Result<(), Bolt12SemanticError> {
6902
+ let expanded_key = &self.inbound_payment_key;
6903
+ let entropy = &*self.entropy_source;
6904
+ let secp_ctx = &self.secp_ctx;
6905
+
6906
+ let builder = offer.request_invoice_deriving_payer_id(
6907
+ expanded_key, entropy, secp_ctx, payment_id
6908
+ )?;
6909
+ let builder = match quantity {
6910
+ None => builder,
6911
+ Some(quantity) => builder.quantity(quantity)?,
6912
+ };
6913
+ let builder = match amount_msats {
6914
+ None => builder,
6915
+ Some(amount_msats) => builder.amount_msats(amount_msats)?,
6916
+ };
6917
+ let builder = match payer_note {
6918
+ None => builder,
6919
+ Some(payer_note) => builder.payer_note(payer_note),
6920
+ };
6921
+
6922
+ let invoice_request = builder.build_and_sign()?;
6923
+ let reply_path = self.create_one_hop_blinded_path();
6924
+
6925
+ self.pending_outbound_payments
6926
+ .add_new_awaiting_invoice(payment_id, retry_strategy)
6927
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6928
+
6929
+ let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
6930
+ if offer.paths().is_empty() {
6931
+ let message = PendingOnionMessage {
6932
+ contents: OffersMessage::InvoiceRequest(invoice_request),
6933
+ destination: Destination::Node(offer.signing_pubkey()),
6934
+ reply_path: Some(reply_path),
6935
+ };
6936
+ pending_offers_messages.push(message);
6937
+ } else {
6938
+ for path in offer.paths() {
6939
+ let message = PendingOnionMessage {
6940
+ contents: OffersMessage::InvoiceRequest(invoice_request.clone()),
6941
+ destination: Destination::BlindedPath(path.clone()),
6942
+ reply_path: Some(reply_path.clone()),
6943
+ };
6944
+ pending_offers_messages.push(message);
6945
+ }
6946
+ }
6947
+
6948
+ Ok(())
6949
+ }
6950
+
6887
6951
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
6888
6952
/// to pay us.
6889
6953
///
0 commit comments