mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
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.
This commit is contained in:
parent
4666c33c0f
commit
a9dcfaf952
3 changed files with 23 additions and 7 deletions
|
@ -870,7 +870,7 @@ mod tests {
|
|||
// our network key
|
||||
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
|
||||
// config
|
||||
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000", &mut test);
|
||||
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000", &mut test);
|
||||
|
||||
// new outbound connection with id 0
|
||||
ext_from_hex("00", &mut test);
|
||||
|
@ -1383,7 +1383,7 @@ mod tests {
|
|||
// our network key
|
||||
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
|
||||
// config
|
||||
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000", &mut test);
|
||||
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000", &mut test);
|
||||
|
||||
// new outbound connection with id 0
|
||||
ext_from_hex("00", &mut test);
|
||||
|
|
|
@ -10277,13 +10277,15 @@ where
|
|||
}
|
||||
},
|
||||
OffersMessage::Invoice(invoice) => {
|
||||
let result = invoice
|
||||
.verify(expanded_key, secp_ctx)
|
||||
.map_err(|()| InvoiceError::from_string("Unrecognized invoice".to_owned()))
|
||||
.and_then(|payment_id| {
|
||||
let result = match invoice.verify(expanded_key, secp_ctx) {
|
||||
Ok(payment_id) => {
|
||||
let features = self.bolt12_invoice_features();
|
||||
if invoice.invoice_features().requires_unknown_bits_from(&features) {
|
||||
Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
|
||||
} else if self.default_configuration.manually_handle_bolt12_invoices {
|
||||
let event = Event::InvoiceReceived { payment_id, invoice, responder };
|
||||
self.pending_events.lock().unwrap().push_back((event, None));
|
||||
return ResponseInstruction::NoResponse;
|
||||
} else {
|
||||
self.send_payment_for_bolt12_invoice(&invoice, payment_id)
|
||||
.map_err(|e| {
|
||||
|
@ -10291,7 +10293,9 @@ where
|
|||
InvoiceError::from_string(format!("{:?}", e))
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
Err(()) => Err(InvoiceError::from_string("Unrecognized invoice".to_owned())),
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(()) => ResponseInstruction::NoResponse,
|
||||
|
|
|
@ -847,6 +847,16 @@ pub struct UserConfig {
|
|||
///
|
||||
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
|
||||
pub accept_mpp_keysend: bool,
|
||||
/// If this is set to true, the user needs to manually pay [`Bolt12Invoice`]s when received.
|
||||
///
|
||||
/// When set to true, [`Event::InvoiceReceived`] will be generated for each received
|
||||
/// [`Bolt12Invoice`] instead of being automatically paid after verification.
|
||||
///
|
||||
/// Default value: false.
|
||||
///
|
||||
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
|
||||
/// [`Event::InvoiceReceived`]: crate::events::Event::InvoiceReceived
|
||||
pub manually_handle_bolt12_invoices: bool,
|
||||
}
|
||||
|
||||
impl Default for UserConfig {
|
||||
|
@ -860,6 +870,7 @@ impl Default for UserConfig {
|
|||
manually_accept_inbound_channels: false,
|
||||
accept_intercept_htlcs: false,
|
||||
accept_mpp_keysend: false,
|
||||
manually_handle_bolt12_invoices: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -879,6 +890,7 @@ impl Readable for UserConfig {
|
|||
manually_accept_inbound_channels: Readable::read(reader)?,
|
||||
accept_intercept_htlcs: Readable::read(reader)?,
|
||||
accept_mpp_keysend: Readable::read(reader)?,
|
||||
manually_handle_bolt12_invoices: Readable::read(reader)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue