Skip to content

Commit e239c92

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 7e085c5 commit e239c92

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
@@ -10396,21 +10396,25 @@ where
1039610396
}
1039710397
},
1039810398
OffersMessage::Invoice(invoice) => {
10399-
match invoice.verify(expanded_key, secp_ctx) {
10400-
Err(()) => {
10401-
Some(OffersMessage::InvoiceError(InvoiceError::from_string("Unrecognized invoice".to_owned())))
10402-
},
10403-
Ok(_) if invoice.invoice_features().requires_unknown_bits_from(&self.bolt12_invoice_features()) => {
10404-
Some(OffersMessage::InvoiceError(Bolt12SemanticError::UnknownRequiredFeatures.into()))
10405-
},
10406-
Ok(payment_id) => {
10407-
if let Err(e) = self.send_payment_for_bolt12_invoice(&invoice, payment_id) {
10408-
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
10409-
Some(OffersMessage::InvoiceError(InvoiceError::from_string(format!("{:?}", e))))
10399+
let response = invoice
10400+
.verify(expanded_key, secp_ctx)
10401+
.map_err(|()| InvoiceError::from_string("Unrecognized invoice".to_owned()))
10402+
.and_then(|payment_id| {
10403+
let features = self.bolt12_invoice_features();
10404+
if invoice.invoice_features().requires_unknown_bits_from(&features) {
10405+
Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
1041010406
} else {
10411-
None
10407+
self.send_payment_for_bolt12_invoice(&invoice, payment_id)
10408+
.map_err(|e| {
10409+
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
10410+
InvoiceError::from_string(format!("{:?}", e))
10411+
})
1041210412
}
10413-
},
10413+
});
10414+
10415+
match response {
10416+
Ok(()) => None,
10417+
Err(e) => Some(OffersMessage::InvoiceError(e)),
1041410418
}
1041510419
},
1041610420
OffersMessage::InvoiceError(invoice_error) => {

0 commit comments

Comments
 (0)