@@ -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 ( crate ) fn maybe_wrap_invoice ( invoice : LdkBolt11Invoice ) -> Bolt11Invoice {
48+ invoice
49+ }
50+ #[ cfg( feature = "uniffi" ) ]
51+ pub ( crate ) 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 ) ;
@@ -441,7 +466,8 @@ impl Bolt11Payment {
441466 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
442467 ) -> Result < Bolt11Invoice , Error > {
443468 let description = maybe_convert_description ! ( description) ;
444- self . receive_inner ( Some ( amount_msat) , description, expiry_secs, None )
469+ let invoice = self . receive_inner ( Some ( amount_msat) , description, expiry_secs, None ) ?;
470+ Ok ( maybe_wrap_invoice ( invoice) )
445471 }
446472
447473 /// Returns a payable invoice that can be used to request a payment of the amount
@@ -463,7 +489,9 @@ impl Bolt11Payment {
463489 payment_hash : PaymentHash ,
464490 ) -> Result < Bolt11Invoice , Error > {
465491 let description = maybe_convert_description ! ( description) ;
466- self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) )
492+ let invoice =
493+ self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) ) ?;
494+ Ok ( maybe_wrap_invoice ( invoice) )
467495 }
468496
469497 /// Returns a payable invoice that can be used to request and receive a payment for which the
@@ -474,7 +502,8 @@ impl Bolt11Payment {
474502 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
475503 ) -> Result < Bolt11Invoice , Error > {
476504 let description = maybe_convert_description ! ( description) ;
477- self . receive_inner ( None , description, expiry_secs, None )
505+ let invoice = self . receive_inner ( None , description, expiry_secs, None ) ?;
506+ Ok ( maybe_wrap_invoice ( invoice) )
478507 }
479508
480509 /// Returns a payable invoice that can be used to request a payment for the given payment hash
@@ -495,13 +524,14 @@ impl Bolt11Payment {
495524 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
496525 ) -> Result < Bolt11Invoice , Error > {
497526 let description = maybe_convert_description ! ( description) ;
498- self . receive_inner ( None , description, expiry_secs, Some ( payment_hash) )
527+ let invoice = self . receive_inner ( None , description, expiry_secs, Some ( payment_hash) ) ?;
528+ Ok ( maybe_wrap_invoice ( invoice) )
499529 }
500530
501531 pub ( crate ) fn receive_inner (
502532 & self , amount_msat : Option < u64 > , invoice_description : & LdkBolt11InvoiceDescription ,
503533 expiry_secs : u32 , manual_claim_payment_hash : Option < PaymentHash > ,
504- ) -> Result < Bolt11Invoice , Error > {
534+ ) -> Result < LdkBolt11Invoice , Error > {
505535 let invoice = {
506536 let invoice_params = Bolt11InvoiceParameters {
507537 amount_msats : amount_msat,
@@ -571,13 +601,14 @@ impl Bolt11Payment {
571601 max_total_lsp_fee_limit_msat : Option < u64 > ,
572602 ) -> Result < Bolt11Invoice , Error > {
573603 let description = maybe_convert_description ! ( description) ;
574- self . receive_via_jit_channel_inner (
604+ let invoice = self . receive_via_jit_channel_inner (
575605 Some ( amount_msat) ,
576606 description,
577607 expiry_secs,
578608 max_total_lsp_fee_limit_msat,
579609 None ,
580- )
610+ ) ?;
611+ Ok ( maybe_wrap_invoice ( invoice) )
581612 }
582613
583614 /// Returns a payable invoice that can be used to request a variable amount payment (also known
@@ -596,20 +627,21 @@ impl Bolt11Payment {
596627 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
597628 ) -> Result < Bolt11Invoice , Error > {
598629 let description = maybe_convert_description ! ( description) ;
599- self . receive_via_jit_channel_inner (
630+ let invoice = self . receive_via_jit_channel_inner (
600631 None ,
601632 description,
602633 expiry_secs,
603634 None ,
604635 max_proportional_lsp_fee_limit_ppm_msat,
605- )
636+ ) ?;
637+ Ok ( maybe_wrap_invoice ( invoice) )
606638 }
607639
608640 fn receive_via_jit_channel_inner (
609641 & self , amount_msat : Option < u64 > , description : & LdkBolt11InvoiceDescription ,
610642 expiry_secs : u32 , max_total_lsp_fee_limit_msat : Option < u64 > ,
611643 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
612- ) -> Result < Bolt11Invoice , Error > {
644+ ) -> Result < LdkBolt11Invoice , Error > {
613645 let liquidity_source =
614646 self . liquidity_source . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
615647
@@ -709,6 +741,7 @@ impl Bolt11Payment {
709741 /// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send
710742 /// pre-flight probes.
711743 pub fn send_probes ( & self , invoice : & Bolt11Invoice ) -> Result < ( ) , Error > {
744+ let invoice = maybe_convert_invoice ( invoice) ;
712745 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
713746 if rt_lock. is_none ( ) {
714747 return Err ( Error :: NotRunning ) ;
@@ -741,6 +774,7 @@ impl Bolt11Payment {
741774 pub fn send_probes_using_amount (
742775 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
743776 ) -> Result < ( ) , Error > {
777+ let invoice = maybe_convert_invoice ( invoice) ;
744778 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
745779 if rt_lock. is_none ( ) {
746780 return Err ( Error :: NotRunning ) ;
0 commit comments