-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support paying static invoices #3140
Changes from 1 commit
732ee14
a3216ac
e162278
3d5d64a
cff6e34
ad63a70
c3ed4a2
7fb16ea
c976e4c
b6f4479
28269a7
e4d7681
8569830
69356e7
0297a1e
985e6ac
6d415b1
7dd1787
c4f3e25
5a7f523
615eefb
26d1582
4bcf53e
6e27aec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is gonna take some extra work because |
||
|
@@ -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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a separate commit? Why not just squash the macro into the previous commit instead of having non-DRY code at all?