Skip to content

Commit eec6822

Browse files
committed
Refactor handling of Bolt12Invoice
In order to provide an InvoiceGenerated event, it would be cleaner to have one location where a Bolt12Invoice is successfully created. Refactor the handling code to this end and clean-up line length by making some of the type conversions more streamlined.
1 parent 0f8f48a commit eec6822

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9491,21 +9491,25 @@ where
94919491
}
94929492
},
94939493
OffersMessage::Invoice(invoice) => {
9494-
match invoice.verify(expanded_key, secp_ctx) {
9495-
Err(()) => {
9496-
Some(OffersMessage::InvoiceError(InvoiceError::from_string("Unrecognized invoice".to_owned())))
9497-
},
9498-
Ok(_) if invoice.invoice_features().requires_unknown_bits_from(&self.bolt12_invoice_features()) => {
9499-
Some(OffersMessage::InvoiceError(Bolt12SemanticError::UnknownRequiredFeatures.into()))
9500-
},
9501-
Ok(payment_id) => {
9502-
if let Err(e) = self.send_payment_for_bolt12_invoice(&invoice, payment_id) {
9503-
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
9504-
Some(OffersMessage::InvoiceError(InvoiceError::from_string(format!("{:?}", e))))
9494+
let response = invoice
9495+
.verify(expanded_key, secp_ctx)
9496+
.map_err(|()| InvoiceError::from_string("Unrecognized invoice".to_owned()))
9497+
.and_then(|payment_id| {
9498+
let features = self.bolt12_invoice_features();
9499+
if invoice.invoice_features().requires_unknown_bits_from(&features) {
9500+
Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
95059501
} else {
9506-
None
9502+
self.send_payment_for_bolt12_invoice(&invoice, payment_id)
9503+
.map_err(|e| {
9504+
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
9505+
InvoiceError::from_string(format!("{:?}", e))
9506+
})
95079507
}
9508-
},
9508+
});
9509+
9510+
match response {
9511+
Ok(()) => None,
9512+
Err(e) => Some(OffersMessage::InvoiceError(e)),
95099513
}
95109514
},
95119515
OffersMessage::InvoiceError(invoice_error) => {

0 commit comments

Comments
 (0)