@@ -30,14 +30,37 @@ use lightning::routing::router::{PaymentParameters, RouteParameters};
3030
3131use lightning_types:: payment:: { PaymentHash , PaymentPreimage } ;
3232
33- use lightning_invoice:: Bolt11Invoice ;
33+ use lightning_invoice:: Bolt11Invoice as LdkBolt11Invoice ;
3434use lightning_invoice:: Bolt11InvoiceDescription as LdkBolt11InvoiceDescription ;
3535
3636use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
3737use bitcoin:: hashes:: Hash ;
3838
3939use std:: sync:: { Arc , RwLock } ;
4040
41+ #[ cfg( not( feature = "uniffi" ) ) ]
42+ type Bolt11Invoice = LdkBolt11Invoice ;
43+ #[ cfg( feature = "uniffi" ) ]
44+ type Bolt11Invoice = Arc < crate :: uniffi_types:: Bolt11Invoice > ;
45+
46+ #[ cfg( not( feature = "uniffi" ) ) ]
47+ pub fn maybe_wrap_invoice ( invoice : LdkBolt11Invoice ) -> Bolt11Invoice {
48+ invoice
49+ }
50+ #[ cfg( feature = "uniffi" ) ]
51+ pub fn maybe_wrap_invoice ( invoice : LdkBolt11Invoice ) -> Bolt11Invoice {
52+ Arc :: new ( invoice. into ( ) )
53+ }
54+
55+ #[ cfg( not( feature = "uniffi" ) ) ]
56+ pub fn maybe_convert_invoice ( invoice : & Bolt11Invoice ) -> & LdkBolt11Invoice {
57+ invoice
58+ }
59+ #[ cfg( feature = "uniffi" ) ]
60+ pub fn maybe_convert_invoice ( invoice : & Bolt11Invoice ) -> & LdkBolt11Invoice {
61+ & invoice. inner
62+ }
63+
4164#[ cfg( not( feature = "uniffi" ) ) ]
4265type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription ;
4366#[ cfg( feature = "uniffi" ) ]
@@ -101,6 +124,7 @@ impl Bolt11Payment {
101124 pub fn send (
102125 & self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
103126 ) -> Result < PaymentId , Error > {
127+ let invoice = maybe_convert_invoice ( invoice) ;
104128 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
105129 if rt_lock. is_none ( ) {
106130 return Err ( Error :: NotRunning ) ;
@@ -209,6 +233,7 @@ impl Bolt11Payment {
209233 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
210234 sending_parameters : Option < SendingParameters > ,
211235 ) -> Result < PaymentId , Error > {
236+ let invoice = maybe_convert_invoice ( invoice) ;
212237 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
213238 if rt_lock. is_none ( ) {
214239 return Err ( Error :: NotRunning ) ;
@@ -429,7 +454,8 @@ impl Bolt11Payment {
429454 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
430455 ) -> Result < Bolt11Invoice , Error > {
431456 let description = maybe_convert_description ! ( description) ;
432- self . receive_inner ( Some ( amount_msat) , description, expiry_secs, None )
457+ let invoice = self . receive_inner ( Some ( amount_msat) , description, expiry_secs, None ) ?;
458+ Ok ( maybe_wrap_invoice ( invoice) )
433459 }
434460
435461 /// Returns a payable invoice that can be used to request a payment of the amount
@@ -451,7 +477,9 @@ impl Bolt11Payment {
451477 payment_hash : PaymentHash ,
452478 ) -> Result < Bolt11Invoice , Error > {
453479 let description = maybe_convert_description ! ( description) ;
454- self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) )
480+ let invoice =
481+ self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) ) ?;
482+ Ok ( maybe_wrap_invoice ( invoice) )
455483 }
456484
457485 /// Returns a payable invoice that can be used to request and receive a payment for which the
@@ -462,7 +490,8 @@ impl Bolt11Payment {
462490 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
463491 ) -> Result < Bolt11Invoice , Error > {
464492 let description = maybe_convert_description ! ( description) ;
465- self . receive_inner ( None , description, expiry_secs, None )
493+ let invoice = self . receive_inner ( None , description, expiry_secs, None ) ?;
494+ Ok ( maybe_wrap_invoice ( invoice) )
466495 }
467496
468497 /// Returns a payable invoice that can be used to request a payment for the given payment hash
@@ -483,13 +512,14 @@ impl Bolt11Payment {
483512 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
484513 ) -> Result < Bolt11Invoice , Error > {
485514 let description = maybe_convert_description ! ( description) ;
486- self . receive_inner ( None , description, expiry_secs, Some ( payment_hash) )
515+ let invoice = self . receive_inner ( None , description, expiry_secs, Some ( payment_hash) ) ?;
516+ Ok ( maybe_wrap_invoice ( invoice) )
487517 }
488518
489519 pub ( crate ) fn receive_inner (
490520 & self , amount_msat : Option < u64 > , invoice_description : & LdkBolt11InvoiceDescription ,
491521 expiry_secs : u32 , manual_claim_payment_hash : Option < PaymentHash > ,
492- ) -> Result < Bolt11Invoice , Error > {
522+ ) -> Result < LdkBolt11Invoice , Error > {
493523 let invoice = {
494524 let invoice_params = Bolt11InvoiceParameters {
495525 amount_msats : amount_msat,
@@ -559,13 +589,14 @@ impl Bolt11Payment {
559589 max_total_lsp_fee_limit_msat : Option < u64 > ,
560590 ) -> Result < Bolt11Invoice , Error > {
561591 let description = maybe_convert_description ! ( description) ;
562- self . receive_via_jit_channel_inner (
592+ let invoice = self . receive_via_jit_channel_inner (
563593 Some ( amount_msat) ,
564594 description,
565595 expiry_secs,
566596 max_total_lsp_fee_limit_msat,
567597 None ,
568- )
598+ ) ?;
599+ Ok ( maybe_wrap_invoice ( invoice) )
569600 }
570601
571602 /// Returns a payable invoice that can be used to request a variable amount payment (also known
@@ -584,20 +615,21 @@ impl Bolt11Payment {
584615 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
585616 ) -> Result < Bolt11Invoice , Error > {
586617 let description = maybe_convert_description ! ( description) ;
587- self . receive_via_jit_channel_inner (
618+ let invoice = self . receive_via_jit_channel_inner (
588619 None ,
589620 description,
590621 expiry_secs,
591622 None ,
592623 max_proportional_lsp_fee_limit_ppm_msat,
593- )
624+ ) ?;
625+ Ok ( maybe_wrap_invoice ( invoice) )
594626 }
595627
596628 fn receive_via_jit_channel_inner (
597629 & self , amount_msat : Option < u64 > , description : & LdkBolt11InvoiceDescription ,
598630 expiry_secs : u32 , max_total_lsp_fee_limit_msat : Option < u64 > ,
599631 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
600- ) -> Result < Bolt11Invoice , Error > {
632+ ) -> Result < LdkBolt11Invoice , Error > {
601633 let liquidity_source =
602634 self . liquidity_source . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
603635
@@ -697,6 +729,7 @@ impl Bolt11Payment {
697729 /// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send
698730 /// pre-flight probes.
699731 pub fn send_probes ( & self , invoice : & Bolt11Invoice ) -> Result < ( ) , Error > {
732+ let invoice = maybe_convert_invoice ( invoice) ;
700733 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
701734 if rt_lock. is_none ( ) {
702735 return Err ( Error :: NotRunning ) ;
@@ -729,6 +762,7 @@ impl Bolt11Payment {
729762 pub fn send_probes_using_amount (
730763 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
731764 ) -> Result < ( ) , Error > {
765+ let invoice = maybe_convert_invoice ( invoice) ;
732766 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
733767 if rt_lock. is_none ( ) {
734768 return Err ( Error :: NotRunning ) ;
0 commit comments