@@ -4270,8 +4270,12 @@ where
42704270 ///
42714271 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
42724272 pub fn abandon_payment(&self, payment_id: PaymentId) {
4273+ self.abandon_payment_with_reason(payment_id, PaymentFailureReason::UserAbandoned)
4274+ }
4275+
4276+ fn abandon_payment_with_reason(&self, payment_id: PaymentId, reason: PaymentFailureReason) {
42734277 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4274- self.pending_outbound_payments.abandon_payment(payment_id, PaymentFailureReason::UserAbandoned , &self.pending_events);
4278+ self.pending_outbound_payments.abandon_payment(payment_id, reason , &self.pending_events);
42754279 }
42764280
42774281 /// Send a spontaneous payment, which is a payment that does not require the recipient to have
@@ -10722,17 +10726,6 @@ where
1072210726 let secp_ctx = &self.secp_ctx;
1072310727 let expanded_key = &self.inbound_payment_key;
1072410728
10725- let abandon_if_payment = |context| {
10726- match context {
10727- Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10728- if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
10729- self.abandon_payment(payment_id);
10730- }
10731- },
10732- _ => {},
10733- }
10734- };
10735-
1073610729 match message {
1073710730 OffersMessage::InvoiceRequest(invoice_request) => {
1073810731 let responder = match responder {
@@ -10852,7 +10845,9 @@ where
1085210845 logger, "Invoice requires unknown features: {:?}",
1085310846 invoice.invoice_features(),
1085410847 );
10855- abandon_if_payment(context);
10848+ self.abandon_payment_with_reason(
10849+ payment_id, PaymentFailureReason::UnknownRequiredFeatures,
10850+ );
1085610851
1085710852 let error = InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures);
1085810853 let response = match responder {
@@ -10909,10 +10904,21 @@ where
1090910904 Some(OffersContext::InboundPayment { payment_hash }) => Some(payment_hash),
1091010905 _ => None,
1091110906 };
10907+
1091210908 let logger = WithContext::from(&self.logger, None, None, payment_hash);
1091310909 log_trace!(logger, "Received invoice_error: {}", invoice_error);
1091410910
10915- abandon_if_payment(context);
10911+ match context {
10912+ Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10913+ if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
10914+ self.abandon_payment_with_reason(
10915+ payment_id, PaymentFailureReason::RecipientRejected,
10916+ );
10917+ }
10918+ },
10919+ _ => {},
10920+ }
10921+
1091610922 ResponseInstruction::NoResponse
1091710923 },
1091810924 }
0 commit comments