@@ -21,6 +21,7 @@ use crate::payment::store::{
2121use crate :: payment:: SendingParameters ;
2222use crate :: peer_store:: { PeerInfo , PeerStore } ;
2323use crate :: types:: ChannelManager ;
24+ use crate :: uniffi_conversions:: { maybe_convert, maybe_wrap} ;
2425
2526use lightning:: ln:: bolt11_payment;
2627use lightning:: ln:: channelmanager:: {
@@ -43,42 +44,11 @@ type Bolt11Invoice = LdkBolt11Invoice;
4344#[ cfg( feature = "uniffi" ) ]
4445type Bolt11Invoice = Arc < crate :: uniffi_types:: Bolt11Invoice > ;
4546
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-
6447#[ cfg( not( feature = "uniffi" ) ) ]
6548type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription ;
6649#[ cfg( feature = "uniffi" ) ]
6750type Bolt11InvoiceDescription = crate :: uniffi_types:: Bolt11InvoiceDescription ;
6851
69- macro_rules! maybe_convert_description {
70- ( $description: expr) => { {
71- #[ cfg( not( feature = "uniffi" ) ) ]
72- {
73- $description
74- }
75- #[ cfg( feature = "uniffi" ) ]
76- {
77- & LdkBolt11InvoiceDescription :: try_from( $description) ?
78- }
79- } } ;
80- }
81-
8252/// A payment handler allowing to create and pay [BOLT 11] invoices.
8353///
8454/// Should be retrieved by calling [`Node::bolt11_payment`].
@@ -124,7 +94,7 @@ impl Bolt11Payment {
12494 pub fn send (
12595 & self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
12696 ) -> Result < PaymentId , Error > {
127- let invoice = maybe_convert_invoice ( invoice) ;
97+ let invoice = maybe_convert ( invoice) ;
12898 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
12999 if rt_lock. is_none ( ) {
130100 return Err ( Error :: NotRunning ) ;
@@ -233,7 +203,7 @@ impl Bolt11Payment {
233203 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
234204 sending_parameters : Option < SendingParameters > ,
235205 ) -> Result < PaymentId , Error > {
236- let invoice = maybe_convert_invoice ( invoice) ;
206+ let invoice = maybe_convert ( invoice) ;
237207 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
238208 if rt_lock. is_none ( ) {
239209 return Err ( Error :: NotRunning ) ;
@@ -465,9 +435,9 @@ impl Bolt11Payment {
465435 pub fn receive (
466436 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
467437 ) -> Result < Bolt11Invoice , Error > {
468- let description = maybe_convert_description ! ( description) ;
469- let invoice = self . receive_inner ( Some ( amount_msat) , description, expiry_secs, None ) ?;
470- Ok ( maybe_wrap_invoice ( invoice) )
438+ let description = maybe_convert ( description) ;
439+ let invoice = self . receive_inner ( Some ( amount_msat) , & description, expiry_secs, None ) ?;
440+ Ok ( maybe_wrap ( invoice) )
471441 }
472442
473443 /// Returns a payable invoice that can be used to request a payment of the amount
@@ -488,10 +458,10 @@ impl Bolt11Payment {
488458 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
489459 payment_hash : PaymentHash ,
490460 ) -> Result < Bolt11Invoice , Error > {
491- let description = maybe_convert_description ! ( description) ;
461+ let description = maybe_convert ( description) ;
492462 let invoice =
493- self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) ) ?;
494- Ok ( maybe_wrap_invoice ( invoice) )
463+ self . receive_inner ( Some ( amount_msat) , & description, expiry_secs, Some ( payment_hash) ) ?;
464+ Ok ( maybe_wrap ( invoice) )
495465 }
496466
497467 /// Returns a payable invoice that can be used to request and receive a payment for which the
@@ -501,9 +471,9 @@ impl Bolt11Payment {
501471 pub fn receive_variable_amount (
502472 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
503473 ) -> Result < Bolt11Invoice , Error > {
504- let description = maybe_convert_description ! ( description) ;
505- let invoice = self . receive_inner ( None , description, expiry_secs, None ) ?;
506- Ok ( maybe_wrap_invoice ( invoice) )
474+ let description = maybe_convert ( description) ;
475+ let invoice = self . receive_inner ( None , & description, expiry_secs, None ) ?;
476+ Ok ( maybe_wrap ( invoice) )
507477 }
508478
509479 /// Returns a payable invoice that can be used to request a payment for the given payment hash
@@ -523,9 +493,9 @@ impl Bolt11Payment {
523493 pub fn receive_variable_amount_for_hash (
524494 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
525495 ) -> Result < Bolt11Invoice , Error > {
526- let description = maybe_convert_description ! ( description) ;
527- let invoice = self . receive_inner ( None , description, expiry_secs, Some ( payment_hash) ) ?;
528- Ok ( maybe_wrap_invoice ( invoice) )
496+ let description = maybe_convert ( description) ;
497+ let invoice = self . receive_inner ( None , & description, expiry_secs, Some ( payment_hash) ) ?;
498+ Ok ( maybe_wrap ( invoice) )
529499 }
530500
531501 pub ( crate ) fn receive_inner (
@@ -600,15 +570,15 @@ impl Bolt11Payment {
600570 & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
601571 max_total_lsp_fee_limit_msat : Option < u64 > ,
602572 ) -> Result < Bolt11Invoice , Error > {
603- let description = maybe_convert_description ! ( description) ;
573+ let description = maybe_convert ( description) ;
604574 let invoice = self . receive_via_jit_channel_inner (
605575 Some ( amount_msat) ,
606- description,
576+ & description,
607577 expiry_secs,
608578 max_total_lsp_fee_limit_msat,
609579 None ,
610580 ) ?;
611- Ok ( maybe_wrap_invoice ( invoice) )
581+ Ok ( maybe_wrap ( invoice) )
612582 }
613583
614584 /// Returns a payable invoice that can be used to request a variable amount payment (also known
@@ -626,15 +596,15 @@ impl Bolt11Payment {
626596 & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
627597 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
628598 ) -> Result < Bolt11Invoice , Error > {
629- let description = maybe_convert_description ! ( description) ;
599+ let description = maybe_convert ( description) ;
630600 let invoice = self . receive_via_jit_channel_inner (
631601 None ,
632- description,
602+ & description,
633603 expiry_secs,
634604 None ,
635605 max_proportional_lsp_fee_limit_ppm_msat,
636606 ) ?;
637- Ok ( maybe_wrap_invoice ( invoice) )
607+ Ok ( maybe_wrap ( invoice) )
638608 }
639609
640610 fn receive_via_jit_channel_inner (
@@ -741,7 +711,7 @@ impl Bolt11Payment {
741711 /// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send
742712 /// pre-flight probes.
743713 pub fn send_probes ( & self , invoice : & Bolt11Invoice ) -> Result < ( ) , Error > {
744- let invoice = maybe_convert_invoice ( invoice) ;
714+ let invoice = maybe_convert ( invoice) ;
745715 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
746716 if rt_lock. is_none ( ) {
747717 return Err ( Error :: NotRunning ) ;
@@ -774,7 +744,7 @@ impl Bolt11Payment {
774744 pub fn send_probes_using_amount (
775745 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
776746 ) -> Result < ( ) , Error > {
777- let invoice = maybe_convert_invoice ( invoice) ;
747+ let invoice = maybe_convert ( invoice) ;
778748 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
779749 if rt_lock. is_none ( ) {
780750 return Err ( Error :: NotRunning ) ;
0 commit comments