@@ -13,6 +13,7 @@ use crate::config::{Config, LDK_PAYMENT_RETRY_TIMEOUT};
1313use crate :: connection:: ConnectionManager ;
1414use crate :: data_store:: DataStoreUpdateResult ;
1515use crate :: error:: Error ;
16+ use crate :: ffi:: { maybe_convert, maybe_try_convert, maybe_wrap} ;
1617use crate :: liquidity:: LiquiditySource ;
1718use crate :: logger:: { log_error, log_info, LdkLogger , Logger } ;
1819use crate :: payment:: store:: {
@@ -42,43 +43,12 @@ use std::sync::{Arc, RwLock};
4243#[ cfg( not( feature = "uniffi" ) ) ]
4344type Bolt11Invoice = LdkBolt11Invoice ;
4445#[ cfg( feature = "uniffi" ) ]
45- type Bolt11Invoice = Arc < crate :: uniffi_types:: Bolt11Invoice > ;
46-
47- #[ cfg( not( feature = "uniffi" ) ) ]
48- pub ( crate ) fn maybe_wrap_invoice ( invoice : LdkBolt11Invoice ) -> Bolt11Invoice {
49- invoice
50- }
51- #[ cfg( feature = "uniffi" ) ]
52- pub ( crate ) fn maybe_wrap_invoice ( invoice : LdkBolt11Invoice ) -> Bolt11Invoice {
53- Arc :: new ( invoice. into ( ) )
54- }
55-
56- #[ cfg( not( feature = "uniffi" ) ) ]
57- pub fn maybe_convert_invoice ( invoice : & Bolt11Invoice ) -> & LdkBolt11Invoice {
58- invoice
59- }
60- #[ cfg( feature = "uniffi" ) ]
61- pub fn maybe_convert_invoice ( invoice : & Bolt11Invoice ) -> & LdkBolt11Invoice {
62- & invoice. inner
63- }
46+ type Bolt11Invoice = Arc < crate :: ffi:: Bolt11Invoice > ;
6447
6548#[ cfg( not( feature = "uniffi" ) ) ]
6649type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription ;
6750#[ cfg( feature = "uniffi" ) ]
68- type Bolt11InvoiceDescription = crate :: uniffi_types:: Bolt11InvoiceDescription ;
69-
70- macro_rules! maybe_convert_description {
71- ( $description: expr) => { {
72- #[ cfg( not( feature = "uniffi" ) ) ]
73- {
74- $description
75- }
76- #[ cfg( feature = "uniffi" ) ]
77- {
78- & LdkBolt11InvoiceDescription :: try_from( $description) ?
79- }
80- } } ;
81- }
51+ type Bolt11InvoiceDescription = crate :: ffi:: Bolt11InvoiceDescription ;
8252
8353/// A payment handler allowing to create and pay [BOLT 11] invoices.
8454///
@@ -125,7 +95,7 @@ impl Bolt11Payment {
12595 pub fn send (
12696 & self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
12797 ) -> Result < PaymentId , Error > {
128- let invoice = maybe_convert_invoice ( invoice) ;
98+ let invoice = maybe_convert ( invoice) ;
12999 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
130100 if rt_lock. is_none ( ) {
131101 return Err ( Error :: NotRunning ) ;
@@ -234,7 +204,7 @@ impl Bolt11Payment {
234204 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
235205 sending_parameters : Option < SendingParameters > ,
236206 ) -> Result < PaymentId , Error > {
237- let invoice = maybe_convert_invoice ( invoice) ;
207+ let invoice = maybe_convert ( invoice) ;
238208 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
239209 if rt_lock. is_none ( ) {
240210 return Err ( Error :: NotRunning ) ;
@@ -466,9 +436,9 @@ impl Bolt11Payment {
466436 pub fn receive (
467437 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
468438 ) -> Result < Bolt11Invoice , Error > {
469- let description = maybe_convert_description ! ( description) ;
470- let invoice = self . receive_inner ( Some ( amount_msat) , description, expiry_secs, None ) ?;
471- Ok ( maybe_wrap_invoice ( invoice) )
439+ let description = maybe_try_convert ( description) ? ;
440+ let invoice = self . receive_inner ( Some ( amount_msat) , & description, expiry_secs, None ) ?;
441+ Ok ( maybe_wrap ( invoice) )
472442 }
473443
474444 /// Returns a payable invoice that can be used to request a payment of the amount
@@ -489,10 +459,10 @@ impl Bolt11Payment {
489459 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
490460 payment_hash : PaymentHash ,
491461 ) -> Result < Bolt11Invoice , Error > {
492- let description = maybe_convert_description ! ( description) ;
462+ let description = maybe_try_convert ( description) ? ;
493463 let invoice =
494- self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) ) ?;
495- Ok ( maybe_wrap_invoice ( invoice) )
464+ self . receive_inner ( Some ( amount_msat) , & description, expiry_secs, Some ( payment_hash) ) ?;
465+ Ok ( maybe_wrap ( invoice) )
496466 }
497467
498468 /// Returns a payable invoice that can be used to request and receive a payment for which the
@@ -502,9 +472,9 @@ impl Bolt11Payment {
502472 pub fn receive_variable_amount (
503473 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
504474 ) -> Result < Bolt11Invoice , Error > {
505- let description = maybe_convert_description ! ( description) ;
506- let invoice = self . receive_inner ( None , description, expiry_secs, None ) ?;
507- Ok ( maybe_wrap_invoice ( invoice) )
475+ let description = maybe_try_convert ( description) ? ;
476+ let invoice = self . receive_inner ( None , & description, expiry_secs, None ) ?;
477+ Ok ( maybe_wrap ( invoice) )
508478 }
509479
510480 /// Returns a payable invoice that can be used to request a payment for the given payment hash
@@ -524,9 +494,9 @@ impl Bolt11Payment {
524494 pub fn receive_variable_amount_for_hash (
525495 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
526496 ) -> Result < Bolt11Invoice , Error > {
527- let description = maybe_convert_description ! ( description) ;
528- let invoice = self . receive_inner ( None , description, expiry_secs, Some ( payment_hash) ) ?;
529- Ok ( maybe_wrap_invoice ( invoice) )
497+ let description = maybe_try_convert ( description) ? ;
498+ let invoice = self . receive_inner ( None , & description, expiry_secs, Some ( payment_hash) ) ?;
499+ Ok ( maybe_wrap ( invoice) )
530500 }
531501
532502 pub ( crate ) fn receive_inner (
@@ -601,15 +571,15 @@ impl Bolt11Payment {
601571 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
602572 max_total_lsp_fee_limit_msat : Option < u64 > ,
603573 ) -> Result < Bolt11Invoice , Error > {
604- let description = maybe_convert_description ! ( description) ;
574+ let description = maybe_try_convert ( description) ? ;
605575 let invoice = self . receive_via_jit_channel_inner (
606576 Some ( amount_msat) ,
607- description,
577+ & description,
608578 expiry_secs,
609579 max_total_lsp_fee_limit_msat,
610580 None ,
611581 ) ?;
612- Ok ( maybe_wrap_invoice ( invoice) )
582+ Ok ( maybe_wrap ( invoice) )
613583 }
614584
615585 /// Returns a payable invoice that can be used to request a variable amount payment (also known
@@ -627,15 +597,15 @@ impl Bolt11Payment {
627597 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
628598 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
629599 ) -> Result < Bolt11Invoice , Error > {
630- let description = maybe_convert_description ! ( description) ;
600+ let description = maybe_try_convert ( description) ? ;
631601 let invoice = self . receive_via_jit_channel_inner (
632602 None ,
633- description,
603+ & description,
634604 expiry_secs,
635605 None ,
636606 max_proportional_lsp_fee_limit_ppm_msat,
637607 ) ?;
638- Ok ( maybe_wrap_invoice ( invoice) )
608+ Ok ( maybe_wrap ( invoice) )
639609 }
640610
641611 fn receive_via_jit_channel_inner (
@@ -742,7 +712,7 @@ impl Bolt11Payment {
742712 /// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send
743713 /// pre-flight probes.
744714 pub fn send_probes ( & self , invoice : & Bolt11Invoice ) -> Result < ( ) , Error > {
745- let invoice = maybe_convert_invoice ( invoice) ;
715+ let invoice = maybe_convert ( invoice) ;
746716 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
747717 if rt_lock. is_none ( ) {
748718 return Err ( Error :: NotRunning ) ;
@@ -775,7 +745,7 @@ impl Bolt11Payment {
775745 pub fn send_probes_using_amount (
776746 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
777747 ) -> Result < ( ) , Error > {
778- let invoice = maybe_convert_invoice ( invoice) ;
748+ let invoice = maybe_convert ( invoice) ;
779749 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
780750 if rt_lock. is_none ( ) {
781751 return Err ( Error :: NotRunning ) ;
0 commit comments