@@ -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};
@@ -6880,6 +6880,69 @@ where
6880
6880
Ok(builder)
6881
6881
}
6882
6882
6883
+ /// Creates an [`InvoiceRequest`] for an [`Offer`] from the given parameters and enqueues it to
6884
+ /// be sent via an onion message.
6885
+ ///
6886
+ /// Use [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
6887
+ /// the [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the request.
6888
+ ///
6889
+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the request.
6890
+ ///
6891
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6892
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6893
+ pub fn request_invoice(
6894
+ &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
6895
+ payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry
6896
+ ) -> Result<(), Bolt12SemanticError> {
6897
+ let expanded_key = &self.inbound_payment_key;
6898
+ let entropy = &*self.entropy_source;
6899
+ let secp_ctx = &self.secp_ctx;
6900
+
6901
+ let builder = offer.request_invoice_deriving_payer_id(
6902
+ expanded_key, entropy, secp_ctx, payment_id
6903
+ )?;
6904
+ let builder = match quantity {
6905
+ None => builder,
6906
+ Some(quantity) => builder.quantity(quantity)?,
6907
+ };
6908
+ let builder = match amount_msats {
6909
+ None => builder,
6910
+ Some(amount_msats) => builder.amount_msats(amount_msats)?,
6911
+ };
6912
+ let builder = match payer_note {
6913
+ None => builder,
6914
+ Some(payer_note) => builder.payer_note(payer_note),
6915
+ };
6916
+
6917
+ let invoice_request = builder.build_and_sign()?;
6918
+ let reply_path = self.create_one_hop_blinded_path();
6919
+
6920
+ self.pending_outbound_payments
6921
+ .add_new_awaiting_invoice(payment_id, retry_strategy)
6922
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
6923
+
6924
+ let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
6925
+ if offer.paths().is_empty() {
6926
+ let message = PendingOnionMessage {
6927
+ contents: OffersMessage::InvoiceRequest(invoice_request),
6928
+ destination: Destination::Node(offer.signing_pubkey()),
6929
+ reply_path: Some(reply_path),
6930
+ };
6931
+ pending_offers_messages.push(message);
6932
+ } else {
6933
+ for path in offer.paths() {
6934
+ let message = PendingOnionMessage {
6935
+ contents: OffersMessage::InvoiceRequest(invoice_request.clone()),
6936
+ destination: Destination::BlindedPath(path.clone()),
6937
+ reply_path: Some(reply_path.clone()),
6938
+ };
6939
+ pending_offers_messages.push(message);
6940
+ }
6941
+ }
6942
+
6943
+ Ok(())
6944
+ }
6945
+
6883
6946
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
6884
6947
/// to pay us.
6885
6948
///
0 commit comments