Skip to content

Commit 20e776b

Browse files
committed
Add basic_mpp support to InvoiceBuilder
Since InvoiceFeatures are an implementation detail of InvoiceBuilder, an explicit call is needed to support the basic_mpp feature. Since it is dependent on the payment_secret feature, conditionally define the builder's method only when payment_secret has been set.
1 parent b5f0eba commit 20e776b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lightning-invoice/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,20 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool> InvoiceBuilder<D, H, T,
607607
}
608608
}
609609

610+
impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool> InvoiceBuilder<D, H, T, C, tb::True> {
611+
/// Sets the `basic_mpp` feature as optional.
612+
pub fn basic_mpp(mut self) -> Self {
613+
self.tagged_fields = self.tagged_fields
614+
.drain(..)
615+
.map(|field| match field {
616+
TaggedField::Features(f) => TaggedField::Features(f.set_basic_mpp_optional()),
617+
_ => field,
618+
})
619+
.collect();
620+
self
621+
}
622+
}
623+
610624
impl<S: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, S> {
611625
/// Builds and signs an invoice using the supplied `sign_function`. This function MAY NOT fail
612626
/// and MUST produce a recoverable signature valid for the given hash and if applicable also for

lightning-invoice/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ where
6464
.payee_pub_key(our_node_pubkey)
6565
.payment_hash(Hash::from_slice(&payment_hash.0).unwrap())
6666
.payment_secret(payment_secret)
67+
.basic_mpp()
6768
.min_final_cltv_expiry(MIN_FINAL_CLTV_EXPIRY.into());
6869
if let Some(amt) = amt_msat {
6970
invoice = invoice.amount_pico_btc(amt * 10);

0 commit comments

Comments
 (0)