Add basic_mpp support to InvoiceBuilder
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 28 Apr 2021 16:29:23 +0000 (09:29 -0700)
committerJeffrey Czyz <jkczyz@gmail.com>
Mon, 3 May 2021 23:23:27 +0000 (16:23 -0700)
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
lightning-invoice/src/utils.rs

index 11406a4644dd0f0e0c5133dc89cf8c84c55f7bbb..9ee8e49b7dcb8d2a2b307f12087b815659764dc0 100644 (file)
@@ -607,6 +607,20 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool> InvoiceBuilder<D, H, T,
        }
 }
 
+impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool> InvoiceBuilder<D, H, T, C, tb::True> {
+       /// 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<S: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, S> {
        /// 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
index c53afdee7b3e644d12d66ec8ab5fc119964e1072..70df3c4553134bbe675253af349520521924a6bb 100644 (file)
@@ -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);