@@ -4106,15 +4106,35 @@ where
41064106 /// whether or not the payment was successful.
41074107 ///
41084108 /// [timer tick]: Self::timer_tick_occurred
4109- pub fn send_payment_for_bolt12_invoice(&self, invoice: &Bolt12Invoice) -> Result<(), Bolt12PaymentError> {
4110- let secp_ctx = &self.secp_ctx;
4111- let expanded_key = &self.inbound_payment_key;
4112- match invoice.verify(expanded_key, secp_ctx ) {
4109+ pub fn send_payment_for_bolt12_invoice(
4110+ &self, invoice: &Bolt12Invoice, context: &OffersContext,
4111+ ) -> Result<(), Bolt12PaymentError> {
4112+ match self.verify_bolt12_invoice(invoice, context ) {
41134113 Ok(payment_id) => self.send_payment_for_verified_bolt12_invoice(invoice, payment_id),
41144114 Err(()) => Err(Bolt12PaymentError::UnexpectedInvoice),
41154115 }
41164116 }
41174117
4118+ fn verify_bolt12_invoice(
4119+ &self, invoice: &Bolt12Invoice, context: &OffersContext,
4120+ ) -> Result<PaymentId, ()> {
4121+ let secp_ctx = &self.secp_ctx;
4122+ let expanded_key = &self.inbound_payment_key;
4123+
4124+ match context {
4125+ OffersContext::Unknown {} if invoice.is_for_refund_without_paths() => {
4126+ invoice.verify(expanded_key, secp_ctx)
4127+ },
4128+ OffersContext::OutboundPayment { payment_id, nonce } => {
4129+ invoice
4130+ .verify_using_payer_data(*payment_id, *nonce, expanded_key, secp_ctx)
4131+ .then(|| *payment_id)
4132+ .ok_or(())
4133+ },
4134+ _ => Err(()),
4135+ }
4136+ }
4137+
41184138 fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
41194139 let best_block_height = self.best_block.read().unwrap().height;
41204140 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -10623,30 +10643,15 @@ where
1062310643 }
1062410644 },
1062510645 OffersMessage::Invoice(invoice) => {
10626- let payer_data = match context {
10627- OffersContext::Unknown {} if invoice.is_for_refund_without_paths() => None,
10628- OffersContext::OutboundPayment { payment_id, nonce } => Some((payment_id, nonce)),
10629- _ => return ResponseInstruction::NoResponse,
10646+ let payment_id = match self.verify_bolt12_invoice(&invoice, &context) {
10647+ Ok(payment_id) => payment_id,
10648+ Err(()) => return ResponseInstruction::NoResponse,
1063010649 };
1063110650
1063210651 let logger = WithContext::from(
1063310652 &self.logger, None, None, Some(invoice.payment_hash()),
1063410653 );
1063510654
10636- let (invoice, payment_id) = match payer_data {
10637- Some((payment_id, nonce)) => {
10638- if invoice.verify_using_payer_data(payment_id, nonce, expanded_key, secp_ctx) {
10639- (invoice, payment_id)
10640- } else {
10641- return ResponseInstruction::NoResponse;
10642- }
10643- },
10644- None => match invoice.verify(expanded_key, secp_ctx) {
10645- Ok(payment_id) => (invoice, payment_id),
10646- Err(()) => return ResponseInstruction::NoResponse,
10647- },
10648- };
10649-
1065010655 let result = {
1065110656 let features = self.bolt12_invoice_features();
1065210657 if invoice.invoice_features().requires_unknown_bits_from(&features) {
0 commit comments