Skip to content

Commit e13ec31

Browse files
committed
Add UserConfig::manually_handle_bolt12_invoices
BOLT12 invoices are automatically paid once they have been verified. Users may want to manually pay them by first performing additional checks. Add a manually_handle_bolt12_invoices configuration option that when set generates an Event::InvoiceReceived instead of paying the invoice.
1 parent c5c5465 commit e13ec31

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10443,21 +10443,25 @@ where
1044310443
}
1044410444
},
1044510445
OffersMessage::Invoice(invoice) => {
10446-
let result = invoice
10447-
.verify(expanded_key, secp_ctx)
10448-
.map_err(|()| InvoiceError::from_string("Unrecognized invoice".to_owned()))
10449-
.and_then(|payment_id| {
10446+
let result = match invoice.verify(expanded_key, secp_ctx) {
10447+
Ok(payment_id) => {
1045010448
let features = self.bolt12_invoice_features();
1045110449
if invoice.invoice_features().requires_unknown_bits_from(&features) {
1045210450
Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
10451+
} else if self.default_configuration.manually_handle_bolt12_invoices {
10452+
let event = Event::InvoiceReceived { payment_id, invoice, responder };
10453+
self.pending_events.lock().unwrap().push_back((event, None));
10454+
return ResponseInstruction::NoResponse;
1045310455
} else {
1045410456
self.send_payment_for_bolt12_invoice(&invoice, payment_id)
1045510457
.map_err(|e| {
1045610458
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
1045710459
InvoiceError::from_string(format!("{:?}", e))
1045810460
})
1045910461
}
10460-
});
10462+
},
10463+
Err(()) => Err(InvoiceError::from_string("Unrecognized invoice".to_owned())),
10464+
};
1046110465

1046210466
match result {
1046310467
Ok(()) => ResponseInstruction::NoResponse,

lightning/src/util/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,16 @@ pub struct UserConfig {
847847
///
848848
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
849849
pub accept_mpp_keysend: bool,
850+
/// If this is set to true, the user needs to manually pay [`Bolt12Invoice`]s when received.
851+
///
852+
/// When set to true, [`Event::InvoiceReceived`] will be generated for each received
853+
/// [`Bolt12Invoice`] instead of being automatically paid after verification.
854+
///
855+
/// Default value: false.
856+
///
857+
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
858+
/// [`Event::InvoiceReceived`]: crate::events::Event::InvoiceReceived
859+
pub manually_handle_bolt12_invoices: bool,
850860
}
851861

852862
impl Default for UserConfig {
@@ -860,6 +870,7 @@ impl Default for UserConfig {
860870
manually_accept_inbound_channels: false,
861871
accept_intercept_htlcs: false,
862872
accept_mpp_keysend: false,
873+
manually_handle_bolt12_invoices: false,
863874
}
864875
}
865876
}
@@ -879,6 +890,7 @@ impl Readable for UserConfig {
879890
manually_accept_inbound_channels: Readable::read(reader)?,
880891
accept_intercept_htlcs: Readable::read(reader)?,
881892
accept_mpp_keysend: Readable::read(reader)?,
893+
manually_handle_bolt12_invoices: Readable::read(reader)?,
882894
})
883895
}
884896
}

0 commit comments

Comments
 (0)