@@ -102,12 +102,14 @@ impl Bolt11Payment {
102102 pub ( crate ) fn receive_inner (
103103 & self , amount_msat : Option < u64 > , invoice_description : & LdkBolt11InvoiceDescription ,
104104 expiry_secs : u32 , manual_claim_payment_hash : Option < PaymentHash > ,
105+ min_final_cltv_expiry_delta : Option < u16 > ,
105106 ) -> Result < LdkBolt11Invoice , Error > {
106107 let invoice_params = Bolt11InvoiceParameters {
107108 amount_msats : amount_msat,
108109 description : invoice_description. clone ( ) ,
109110 invoice_expiry_delta_secs : Some ( expiry_secs) ,
110111 payment_hash : manual_claim_payment_hash,
112+ min_final_cltv_expiry_delta,
111113 ..Default :: default ( )
112114 } ;
113115
@@ -557,7 +559,8 @@ impl Bolt11Payment {
557559 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
558560 ) -> Result < Bolt11Invoice , Error > {
559561 let description = maybe_try_convert_enum ( description) ?;
560- let invoice = self . receive_inner ( Some ( amount_msat) , & description, expiry_secs, None ) ?;
562+ let invoice =
563+ self . receive_inner ( Some ( amount_msat) , & description, expiry_secs, None , None ) ?;
561564 Ok ( maybe_wrap ( invoice) )
562565 }
563566
@@ -586,8 +589,39 @@ impl Bolt11Payment {
586589 payment_hash : PaymentHash ,
587590 ) -> Result < Bolt11Invoice , Error > {
588591 let description = maybe_try_convert_enum ( description) ?;
589- let invoice =
590- self . receive_inner ( Some ( amount_msat) , & description, expiry_secs, Some ( payment_hash) ) ?;
592+ let invoice = self . receive_inner (
593+ Some ( amount_msat) ,
594+ & description,
595+ expiry_secs,
596+ Some ( payment_hash) ,
597+ None ,
598+ ) ?;
599+ Ok ( maybe_wrap ( invoice) )
600+ }
601+
602+ /// Same as [`receive_for_hash`], but requires the payment's final HTLC to leave at least
603+ /// `min_final_cltv_expiry_delta` blocks until it expires, giving the user that much more time
604+ /// to obtain the preimage.
605+ ///
606+ /// The invoice requests three blocks more than the given value, to allow for blocks being
607+ /// connected while the payment is in flight, and an HTLC arriving with fewer than
608+ /// `min_final_cltv_expiry_delta` blocks left is failed back without a [`PaymentClaimable`]
609+ /// event.
610+ ///
611+ /// [`receive_for_hash`]: Self::receive_for_hash
612+ /// [`PaymentClaimable`]: crate::Event::PaymentClaimable
613+ pub fn receive_for_hash_with_min_final_cltv_expiry_delta (
614+ & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
615+ payment_hash : PaymentHash , min_final_cltv_expiry_delta : u16 ,
616+ ) -> Result < Bolt11Invoice , Error > {
617+ let description = maybe_try_convert_enum ( description) ?;
618+ let invoice = self . receive_inner (
619+ Some ( amount_msat) ,
620+ & description,
621+ expiry_secs,
622+ Some ( payment_hash) ,
623+ Some ( min_final_cltv_expiry_delta) ,
624+ ) ?;
591625 Ok ( maybe_wrap ( invoice) )
592626 }
593627
@@ -599,7 +633,7 @@ impl Bolt11Payment {
599633 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
600634 ) -> Result < Bolt11Invoice , Error > {
601635 let description = maybe_try_convert_enum ( description) ?;
602- let invoice = self . receive_inner ( None , & description, expiry_secs, None ) ?;
636+ let invoice = self . receive_inner ( None , & description, expiry_secs, None , None ) ?;
603637 Ok ( maybe_wrap ( invoice) )
604638 }
605639
@@ -627,7 +661,8 @@ impl Bolt11Payment {
627661 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
628662 ) -> Result < Bolt11Invoice , Error > {
629663 let description = maybe_try_convert_enum ( description) ?;
630- let invoice = self . receive_inner ( None , & description, expiry_secs, Some ( payment_hash) ) ?;
664+ let invoice =
665+ self . receive_inner ( None , & description, expiry_secs, Some ( payment_hash) , None ) ?;
631666 Ok ( maybe_wrap ( invoice) )
632667 }
633668
0 commit comments