@@ -57,7 +57,7 @@ use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
57
57
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
58
58
#[cfg(test)]
59
59
use crate::ln::outbound_payment;
60
- use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs, StaleExpiration};
60
+ use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs, StaleExpiration};
61
61
use crate::ln::wire::Encode;
62
62
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice};
63
63
use crate::offers::invoice_error::InvoiceError;
@@ -104,7 +104,7 @@ use core::time::Duration;
104
104
use core::ops::Deref;
105
105
106
106
// Re-export this for use in the public API.
107
- pub use crate::ln::outbound_payment::{PaymentSendFailure, ProbeSendFailure, Retry, RetryableSendFailure, RecipientOnionFields};
107
+ pub use crate::ln::outbound_payment::{Bolt12PaymentError, PaymentSendFailure, ProbeSendFailure, Retry, RetryableSendFailure, RecipientOnionFields};
108
108
use crate::ln::script::ShutdownScript;
109
109
110
110
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
@@ -4272,7 +4272,28 @@ where
4272
4272
self.pending_outbound_payments.test_set_payment_metadata(payment_id, new_payment_metadata);
4273
4273
}
4274
4274
4275
- pub(super) fn send_payment_for_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
4275
+ /// Pays the [`Bolt12Invoice`] associated with the `payment_id` encoded in its `payer_metadata`.
4276
+ ///
4277
+ /// The invoice's `payer_metadata` is used to authenticate that the invoice was indeed requested
4278
+ /// before attempting a payment. [`Bolt12PaymentError::UnexpectedInvoice`] is returned if this
4279
+ /// fails or if the encoded `payment_id` is not recognized. The latter may happen once the
4280
+ /// invoice is paid and the payment no longer tracked.
4281
+ ///
4282
+ /// Attempting to pay the same invoice twice while the first payment is still pending will
4283
+ /// result in a [`Bolt12PaymentError::DuplicateInvoice`].
4284
+ ///
4285
+ /// Otherwise, either [`Event::PaymentSent`] or [`Event::PaymentFailed`] are used to indicate
4286
+ /// whether or not the payment was successful.
4287
+ pub fn send_payment_for_bolt12_invoice(&self, invoice: &Bolt12Invoice) -> Result<(), Bolt12PaymentError> {
4288
+ let secp_ctx = &self.secp_ctx;
4289
+ let expanded_key = &self.inbound_payment_key;
4290
+ match invoice.verify(expanded_key, secp_ctx) {
4291
+ Ok(payment_id) => self.send_payment_for_verified_bolt12_invoice(invoice, payment_id),
4292
+ Err(()) => Err(Bolt12PaymentError::UnexpectedInvoice),
4293
+ }
4294
+ }
4295
+
4296
+ fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
4276
4297
let best_block_height = self.best_block.read().unwrap().height;
4277
4298
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4278
4299
self.pending_outbound_payments
@@ -10453,7 +10474,7 @@ where
10453
10474
self.pending_events.lock().unwrap().push_back((event, None));
10454
10475
return ResponseInstruction::NoResponse;
10455
10476
} else {
10456
- self.send_payment_for_bolt12_invoice (&invoice, payment_id)
10477
+ self.send_payment_for_verified_bolt12_invoice (&invoice, payment_id)
10457
10478
.map_err(|e| {
10458
10479
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
10459
10480
InvoiceError::from_string(format!("{:?}", e))
0 commit comments