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