From 20e776bc8e2ebe7af3df99227c1f1a5467f42fc3 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 28 Apr 2021 09:29:23 -0700 Subject: [PATCH] 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. --- lightning-invoice/src/lib.rs | 14 ++++++++++++++ lightning-invoice/src/utils.rs | 1 + 2 files changed, 15 insertions(+) diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 11406a464..9ee8e49b7 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -607,6 +607,20 @@ impl InvoiceBuilder InvoiceBuilder { + /// Sets the `basic_mpp` feature as optional. + pub fn basic_mpp(mut self) -> Self { + self.tagged_fields = self.tagged_fields + .drain(..) + .map(|field| match field { + TaggedField::Features(f) => TaggedField::Features(f.set_basic_mpp_optional()), + _ => field, + }) + .collect(); + self + } +} + impl InvoiceBuilder { /// Builds and signs an invoice using the supplied `sign_function`. This function MAY NOT fail /// and MUST produce a recoverable signature valid for the given hash and if applicable also for diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index c53afdee7..70df3c455 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -64,6 +64,7 @@ where .payee_pub_key(our_node_pubkey) .payment_hash(Hash::from_slice(&payment_hash.0).unwrap()) .payment_secret(payment_secret) + .basic_mpp() .min_final_cltv_expiry(MIN_FINAL_CLTV_EXPIRY.into()); if let Some(amt) = amt_msat { invoice = invoice.amount_pico_btc(amt * 10); -- 2.39.5