mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
DRY handling when initiating payment to BOLT 12 invoice.
This commit is contained in:
parent
b6f44798fc
commit
28269a7879
1 changed files with 33 additions and 50 deletions
|
@ -10943,6 +10943,35 @@ where
|
|||
let secp_ctx = &self.secp_ctx;
|
||||
let expanded_key = &self.inbound_payment_key;
|
||||
|
||||
macro_rules! handle_pay_invoice_res {
|
||||
($res: expr, $invoice: expr, $logger: expr) => {{
|
||||
let error = match $res {
|
||||
Err(Bolt12PaymentError::UnknownRequiredFeatures) => {
|
||||
log_trace!(
|
||||
$logger, "Invoice requires unknown features: {:?}",
|
||||
$invoice.invoice_features()
|
||||
);
|
||||
InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures)
|
||||
},
|
||||
Err(Bolt12PaymentError::SendingFailed(e)) => {
|
||||
log_trace!($logger, "Failed paying invoice: {:?}", e);
|
||||
InvoiceError::from_string(format!("{:?}", e))
|
||||
},
|
||||
Err(Bolt12PaymentError::UnexpectedInvoice)
|
||||
| Err(Bolt12PaymentError::DuplicateInvoice)
|
||||
| Ok(()) => return None,
|
||||
};
|
||||
|
||||
match responder {
|
||||
Some(responder) => return Some((OffersMessage::InvoiceError(error), responder.respond())),
|
||||
None => {
|
||||
log_trace!($logger, "No reply path to send error: {:?}", error);
|
||||
return None
|
||||
},
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
match message {
|
||||
OffersMessage::InvoiceRequest(invoice_request) => {
|
||||
let responder = match responder {
|
||||
|
@ -11069,32 +11098,8 @@ where
|
|||
return None;
|
||||
}
|
||||
|
||||
let error = match self.send_payment_for_verified_bolt12_invoice(
|
||||
&invoice, payment_id,
|
||||
) {
|
||||
Err(Bolt12PaymentError::UnknownRequiredFeatures) => {
|
||||
log_trace!(
|
||||
logger, "Invoice requires unknown features: {:?}",
|
||||
invoice.invoice_features()
|
||||
);
|
||||
InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures)
|
||||
},
|
||||
Err(Bolt12PaymentError::SendingFailed(e)) => {
|
||||
log_trace!(logger, "Failed paying invoice: {:?}", e);
|
||||
InvoiceError::from_string(format!("{:?}", e))
|
||||
},
|
||||
Err(Bolt12PaymentError::UnexpectedInvoice)
|
||||
| Err(Bolt12PaymentError::DuplicateInvoice)
|
||||
| Ok(()) => return None,
|
||||
};
|
||||
|
||||
match responder {
|
||||
Some(responder) => Some((OffersMessage::InvoiceError(error), responder.respond())),
|
||||
None => {
|
||||
log_trace!(logger, "No reply path to send error: {:?}", error);
|
||||
None
|
||||
},
|
||||
}
|
||||
let res = self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id);
|
||||
handle_pay_invoice_res!(res, invoice, logger);
|
||||
},
|
||||
#[cfg(async_payments)]
|
||||
OffersMessage::StaticInvoice(invoice) => {
|
||||
|
@ -11107,30 +11112,8 @@ where
|
|||
},
|
||||
_ => return None
|
||||
};
|
||||
// TODO: DRY this with the above regular invoice error handling
|
||||
let error = match self.initiate_async_payment(&invoice, payment_id) {
|
||||
Err(Bolt12PaymentError::UnknownRequiredFeatures) => {
|
||||
log_trace!(
|
||||
self.logger, "Invoice requires unknown features: {:?}",
|
||||
invoice.invoice_features()
|
||||
);
|
||||
InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures)
|
||||
},
|
||||
Err(Bolt12PaymentError::SendingFailed(e)) => {
|
||||
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
|
||||
InvoiceError::from_string(format!("{:?}", e))
|
||||
},
|
||||
Err(Bolt12PaymentError::UnexpectedInvoice)
|
||||
| Err(Bolt12PaymentError::DuplicateInvoice)
|
||||
| Ok(()) => return None,
|
||||
};
|
||||
match responder {
|
||||
Some(responder) => Some((OffersMessage::InvoiceError(error), responder.respond())),
|
||||
None => {
|
||||
log_trace!(self.logger, "No reply path to send error: {:?}", error);
|
||||
None
|
||||
},
|
||||
}
|
||||
let res = self.initiate_async_payment(&invoice, payment_id);
|
||||
handle_pay_invoice_res!(res, invoice, self.logger);
|
||||
},
|
||||
OffersMessage::InvoiceError(invoice_error) => {
|
||||
let payment_hash = match context {
|
||||
|
|
Loading…
Add table
Reference in a new issue