@@ -4106,15 +4106,35 @@ where
4106
4106
/// whether or not the payment was successful.
4107
4107
///
4108
4108
/// [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 ) {
4113
4113
Ok(payment_id) => self.send_payment_for_verified_bolt12_invoice(invoice, payment_id),
4114
4114
Err(()) => Err(Bolt12PaymentError::UnexpectedInvoice),
4115
4115
}
4116
4116
}
4117
4117
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
+
4118
4138
fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
4119
4139
let best_block_height = self.best_block.read().unwrap().height;
4120
4140
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -10623,30 +10643,15 @@ where
10623
10643
}
10624
10644
},
10625
10645
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,
10630
10649
};
10631
10650
10632
10651
let logger = WithContext::from(
10633
10652
&self.logger, None, None, Some(invoice.payment_hash()),
10634
10653
);
10635
10654
10636
- let 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
- payment_id
10640
- } else {
10641
- return ResponseInstruction::NoResponse;
10642
- }
10643
- },
10644
- None => match invoice.verify(expanded_key, secp_ctx) {
10645
- Ok(payment_id) => payment_id,
10646
- Err(()) => return ResponseInstruction::NoResponse,
10647
- },
10648
- };
10649
-
10650
10655
let result = {
10651
10656
let features = self.bolt12_invoice_features();
10652
10657
if invoice.invoice_features().requires_unknown_bits_from(&features) {
0 commit comments