mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +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 secp_ctx = &self.secp_ctx;
|
||||||
let expanded_key = &self.inbound_payment_key;
|
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 {
|
match message {
|
||||||
OffersMessage::InvoiceRequest(invoice_request) => {
|
OffersMessage::InvoiceRequest(invoice_request) => {
|
||||||
let responder = match responder {
|
let responder = match responder {
|
||||||
|
@ -11069,32 +11098,8 @@ where
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let error = match self.send_payment_for_verified_bolt12_invoice(
|
let res = self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id);
|
||||||
&invoice, payment_id,
|
handle_pay_invoice_res!(res, invoice, logger);
|
||||||
) {
|
|
||||||
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
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
#[cfg(async_payments)]
|
#[cfg(async_payments)]
|
||||||
OffersMessage::StaticInvoice(invoice) => {
|
OffersMessage::StaticInvoice(invoice) => {
|
||||||
|
@ -11107,30 +11112,8 @@ where
|
||||||
},
|
},
|
||||||
_ => return None
|
_ => return None
|
||||||
};
|
};
|
||||||
// TODO: DRY this with the above regular invoice error handling
|
let res = self.initiate_async_payment(&invoice, payment_id);
|
||||||
let error = match self.initiate_async_payment(&invoice, payment_id) {
|
handle_pay_invoice_res!(res, invoice, self.logger);
|
||||||
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
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
OffersMessage::InvoiceError(invoice_error) => {
|
OffersMessage::InvoiceError(invoice_error) => {
|
||||||
let payment_hash = match context {
|
let payment_hash = match context {
|
||||||
|
|
Loading…
Add table
Reference in a new issue