@@ -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};
@@ -7134,6 +7134,71 @@ where
7134
7134
Ok(builder)
7135
7135
}
7136
7136
7137
+ /// Creates an [`InvoiceRequest`] for an [`Offer`] from the given parameters and enqueues it to
7138
+ /// be sent via an onion message.
7139
+ ///
7140
+ /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
7141
+ /// the [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the request.
7142
+ ///
7143
+ /// The provided `payment_id` is used to ensure that only one invoice is paid for the request.
7144
+ ///
7145
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
7146
+ /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
7147
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
7148
+ pub fn request_invoice(
7149
+ &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
7150
+ payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
7151
+ max_total_routing_fee_msat: Option<u64>
7152
+ ) -> Result<(), Bolt12SemanticError> {
7153
+ let expanded_key = &self.inbound_payment_key;
7154
+ let entropy = &*self.entropy_source;
7155
+ let secp_ctx = &self.secp_ctx;
7156
+
7157
+ let builder = offer.request_invoice_deriving_payer_id(
7158
+ expanded_key, entropy, secp_ctx, payment_id
7159
+ )?;
7160
+ let builder = match quantity {
7161
+ None => builder,
7162
+ Some(quantity) => builder.quantity(quantity)?,
7163
+ };
7164
+ let builder = match amount_msats {
7165
+ None => builder,
7166
+ Some(amount_msats) => builder.amount_msats(amount_msats)?,
7167
+ };
7168
+ let builder = match payer_note {
7169
+ None => builder,
7170
+ Some(payer_note) => builder.payer_note(payer_note),
7171
+ };
7172
+
7173
+ let invoice_request = builder.build_and_sign()?;
7174
+ let reply_path = self.create_one_hop_blinded_path();
7175
+
7176
+ self.pending_outbound_payments
7177
+ .add_new_awaiting_invoice(payment_id, retry_strategy, max_total_routing_fee_msat)
7178
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
7179
+
7180
+ let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
7181
+ if offer.paths().is_empty() {
7182
+ let message = PendingOnionMessage {
7183
+ contents: OffersMessage::InvoiceRequest(invoice_request),
7184
+ destination: Destination::Node(offer.signing_pubkey()),
7185
+ reply_path: Some(reply_path),
7186
+ };
7187
+ pending_offers_messages.push(message);
7188
+ } else {
7189
+ for path in offer.paths() {
7190
+ let message = PendingOnionMessage {
7191
+ contents: OffersMessage::InvoiceRequest(invoice_request.clone()),
7192
+ destination: Destination::BlindedPath(path.clone()),
7193
+ reply_path: Some(reply_path.clone()),
7194
+ };
7195
+ pending_offers_messages.push(message);
7196
+ }
7197
+ }
7198
+
7199
+ Ok(())
7200
+ }
7201
+
7137
7202
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
7138
7203
/// to pay us.
7139
7204
///
0 commit comments