@@ -47,6 +47,14 @@ type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription;
4747#[ cfg( feature = "uniffi" ) ]
4848type Bolt11InvoiceDescription = crate :: ffi:: Bolt11InvoiceDescription ;
4949
50+ #[ cfg( not( feature = "uniffi" ) ) ]
51+ pub struct JitChannelManualClaim {
52+ pub invoice : Bolt11Invoice ,
53+ pub preimage : PaymentPreimage ,
54+ }
55+ #[ cfg( feature = "uniffi" ) ]
56+ type JitChannelManualClaim = crate :: ffi:: JitChannelManualClaim ;
57+
5058/// A payment handler allowing to create and pay [BOLT 11] invoices.
5159///
5260/// Should be retrieved by calling [`Node::bolt11_payment`].
@@ -542,13 +550,14 @@ impl Bolt11Payment {
542550 max_total_lsp_fee_limit_msat : Option < u64 > ,
543551 ) -> Result < Bolt11Invoice , Error > {
544552 let description = maybe_try_convert_enum ( description) ?;
545- let invoice = self . receive_via_jit_channel_inner (
553+ let ( invoice, _ ) = self . receive_via_jit_channel_inner (
546554 Some ( amount_msat) ,
547555 & description,
548556 expiry_secs,
549557 max_total_lsp_fee_limit_msat,
550558 None ,
551559 None ,
560+ true ,
552561 ) ?;
553562 Ok ( maybe_wrap ( invoice) )
554563 }
@@ -581,17 +590,40 @@ impl Bolt11Payment {
581590 max_total_lsp_fee_limit_msat : Option < u64 > , payment_hash : PaymentHash ,
582591 ) -> Result < Bolt11Invoice , Error > {
583592 let description = maybe_try_convert_enum ( description) ?;
584- let invoice = self . receive_via_jit_channel_inner (
593+ let ( invoice, _ ) = self . receive_via_jit_channel_inner (
585594 Some ( amount_msat) ,
586595 & description,
587596 expiry_secs,
588597 max_total_lsp_fee_limit_msat,
589598 None ,
590599 Some ( payment_hash) ,
600+ true ,
591601 ) ?;
592602 Ok ( maybe_wrap ( invoice) )
593603 }
594604
605+ /// Returns a payable invoice for manual claiming via a JIT channel.
606+ ///
607+ /// Similar to `receive_via_jit_channel` but requires manual claiming via `claim_for_hash`.
608+ pub fn receive_via_jit_channel_manual_claim (
609+ & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
610+ max_total_lsp_fee_limit_msat : Option < u64 > ,
611+ ) -> Result < JitChannelManualClaim , Error > {
612+ let description = maybe_try_convert_enum ( description) ?;
613+ let ( invoice, preimage) = self . receive_via_jit_channel_inner (
614+ Some ( amount_msat) ,
615+ & description,
616+ expiry_secs,
617+ max_total_lsp_fee_limit_msat,
618+ None ,
619+ None ,
620+ false ,
621+ ) ?;
622+ let preimage = preimage. ok_or ( Error :: InvoiceCreationFailed ) ?;
623+ let invoice = maybe_wrap ( invoice) ;
624+ Ok ( JitChannelManualClaim { invoice, preimage } )
625+ }
626+
595627 /// Returns a payable invoice that can be used to request a variable amount payment (also known
596628 /// as "zero-amount" invoice) and receive it via a newly created just-in-time (JIT) channel.
597629 ///
@@ -608,13 +640,14 @@ impl Bolt11Payment {
608640 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
609641 ) -> Result < Bolt11Invoice , Error > {
610642 let description = maybe_try_convert_enum ( description) ?;
611- let invoice = self . receive_via_jit_channel_inner (
643+ let ( invoice, _ ) = self . receive_via_jit_channel_inner (
612644 None ,
613645 & description,
614646 expiry_secs,
615647 None ,
616648 max_proportional_lsp_fee_limit_ppm_msat,
617649 None ,
650+ true ,
618651 ) ?;
619652 Ok ( maybe_wrap ( invoice) )
620653 }
@@ -648,13 +681,14 @@ impl Bolt11Payment {
648681 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > , payment_hash : PaymentHash ,
649682 ) -> Result < Bolt11Invoice , Error > {
650683 let description = maybe_try_convert_enum ( description) ?;
651- let invoice = self . receive_via_jit_channel_inner (
684+ let ( invoice, _ ) = self . receive_via_jit_channel_inner (
652685 None ,
653686 & description,
654687 expiry_secs,
655688 None ,
656689 max_proportional_lsp_fee_limit_ppm_msat,
657690 Some ( payment_hash) ,
691+ true ,
658692 ) ?;
659693 Ok ( maybe_wrap ( invoice) )
660694 }
@@ -663,7 +697,8 @@ impl Bolt11Payment {
663697 & self , amount_msat : Option < u64 > , description : & LdkBolt11InvoiceDescription ,
664698 expiry_secs : u32 , max_total_lsp_fee_limit_msat : Option < u64 > ,
665699 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > , payment_hash : Option < PaymentHash > ,
666- ) -> Result < LdkBolt11Invoice , Error > {
700+ auto_claim : bool ,
701+ ) -> Result < ( LdkBolt11Invoice , Option < PaymentPreimage > ) , Error > {
667702 let liquidity_source =
668703 self . liquidity_source . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
669704
@@ -721,9 +756,12 @@ impl Bolt11Payment {
721756 let id = PaymentId ( payment_hash. 0 ) ;
722757 let preimage =
723758 self . channel_manager . get_payment_preimage ( payment_hash, payment_secret. clone ( ) ) . ok ( ) ;
759+
760+ let stored_preimage = if auto_claim { preimage } else { None } ;
761+
724762 let kind = PaymentKind :: Bolt11Jit {
725763 hash : payment_hash,
726- preimage,
764+ preimage : stored_preimage ,
727765 secret : Some ( payment_secret. clone ( ) ) ,
728766 counterparty_skimmed_fee_msat : None ,
729767 lsp_fee_limits,
@@ -741,7 +779,7 @@ impl Bolt11Payment {
741779 // Persist LSP peer to make sure we reconnect on restart.
742780 self . peer_store . add_peer ( peer_info) ?;
743781
744- Ok ( invoice)
782+ Ok ( ( invoice, preimage ) )
745783 }
746784
747785 /// Sends payment probes over all paths of a route that would be used to pay the given invoice.
0 commit comments