Skip to content

Commit ee26f5c

Browse files
committed
Default to requiring payment_metadata when building BOLT 11s
Now that we commit to payment metadata fields and require them implicitly as a part of payments, we should match that in `lightning-invoice` - instead marking them as required by default.
1 parent aec456f commit ee26f5c

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

lightning-invoice/src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,10 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool>
880880
{
881881
/// Sets the payment metadata.
882882
///
883-
/// By default features are set to *optionally* allow the sender to include the payment metadata.
884-
/// If you wish to require that the sender include the metadata (and fail to parse the invoice if
885-
/// they don't support payment metadata fields), you need to call
886-
/// [`InvoiceBuilder::require_payment_metadata`] after this.
887-
pub fn payment_metadata(
883+
/// This marks the payment metadata as optional, allowing a legacy sender that doesn't
884+
/// understand payment metadata to ignore it. Note that LDK by default commits to the payment
885+
/// metadata in its payment secret, implicitly making it required.
886+
pub fn optional_payment_metadata(
888887
mut self, payment_metadata: Vec<u8>,
889888
) -> InvoiceBuilder<D, H, T, C, S, tb::True> {
890889
self.tagged_fields.push(TaggedField::PaymentMetadata(payment_metadata));
@@ -902,20 +901,23 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool>
902901
}
903902
self.set_flags()
904903
}
905-
}
906904

907-
impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool>
908-
InvoiceBuilder<D, H, T, C, S, tb::True>
909-
{
910-
/// Sets forwarding of payment metadata as required. A reader of the invoice which does not
911-
/// support sending payment metadata will fail to read the invoice.
912-
pub fn require_payment_metadata(mut self) -> InvoiceBuilder<D, H, T, C, S, tb::True> {
913-
for field in self.tagged_fields.iter_mut() {
905+
/// Sets the payment metadata.
906+
///
907+
/// By default features are set to *require* the sender to include the payment metadata.
908+
/// If you wish to support legacy senders that ignore the metadata, you can call
909+
/// [`InvoiceBuilder::optional_payment_metadata`] instead. Note that LDK by default commits to
910+
/// the payment metadata in its payment secret, implicitly making it required.
911+
pub fn payment_metadata(
912+
self, payment_metadata: Vec<u8>,
913+
) -> InvoiceBuilder<D, H, T, C, S, tb::True> {
914+
let mut res = self.optional_payment_metadata(payment_metadata);
915+
for field in res.tagged_fields.iter_mut() {
914916
if let TaggedField::Features(f) = field {
915917
f.set_payment_metadata_required();
916918
}
917919
}
918-
self
920+
res
919921
}
920922
}
921923

lightning-invoice/tests/ser_de.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
418418
))
419419
.description("payment metadata inside".to_owned())
420420
.payment_metadata(<Vec<u8>>::from_hex("01fafaf0").unwrap())
421-
.require_payment_metadata()
422421
.payee_pub_key(PublicKey::from_slice(&<Vec<u8>>::from_hex(
423422
"03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad"
424423
).unwrap()).unwrap())
@@ -450,7 +449,6 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
450449
))
451450
.description("payment metadata inside".to_owned())
452451
.payment_metadata(<Vec<u8>>::from_hex("01fafaf0").unwrap())
453-
.require_payment_metadata()
454452
.payment_secret(PaymentSecret([0x11; 32]))
455453
.build_raw()
456454
.unwrap()

0 commit comments

Comments
 (0)