@@ -21,6 +21,7 @@ use crate::payment::store::{
21
21
use crate :: payment:: SendingParameters ;
22
22
use crate :: peer_store:: { PeerInfo , PeerStore } ;
23
23
use crate :: types:: ChannelManager ;
24
+ use crate :: uniffi_conversions:: { maybe_convert, maybe_wrap} ;
24
25
25
26
use lightning:: ln:: bolt11_payment;
26
27
use lightning:: ln:: channelmanager:: {
@@ -43,42 +44,11 @@ type Bolt11Invoice = LdkBolt11Invoice;
43
44
#[ cfg( feature = "uniffi" ) ]
44
45
type Bolt11Invoice = Arc < crate :: uniffi_types:: Bolt11Invoice > ;
45
46
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
-
64
47
#[ cfg( not( feature = "uniffi" ) ) ]
65
48
type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription ;
66
49
#[ cfg( feature = "uniffi" ) ]
67
50
type Bolt11InvoiceDescription = crate :: uniffi_types:: Bolt11InvoiceDescription ;
68
51
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
-
82
52
/// A payment handler allowing to create and pay [BOLT 11] invoices.
83
53
///
84
54
/// Should be retrieved by calling [`Node::bolt11_payment`].
@@ -124,7 +94,7 @@ impl Bolt11Payment {
124
94
pub fn send (
125
95
& self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
126
96
) -> Result < PaymentId , Error > {
127
- let invoice = maybe_convert_invoice ( invoice) ;
97
+ let invoice = maybe_convert ( invoice) ;
128
98
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
129
99
if rt_lock. is_none ( ) {
130
100
return Err ( Error :: NotRunning ) ;
@@ -233,7 +203,7 @@ impl Bolt11Payment {
233
203
& self , invoice : & Bolt11Invoice , amount_msat : u64 ,
234
204
sending_parameters : Option < SendingParameters > ,
235
205
) -> Result < PaymentId , Error > {
236
- let invoice = maybe_convert_invoice ( invoice) ;
206
+ let invoice = maybe_convert ( invoice) ;
237
207
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
238
208
if rt_lock. is_none ( ) {
239
209
return Err ( Error :: NotRunning ) ;
@@ -465,9 +435,9 @@ impl Bolt11Payment {
465
435
pub fn receive (
466
436
& self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
467
437
) -> 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) )
471
441
}
472
442
473
443
/// Returns a payable invoice that can be used to request a payment of the amount
@@ -488,10 +458,10 @@ impl Bolt11Payment {
488
458
& self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
489
459
payment_hash : PaymentHash ,
490
460
) -> Result < Bolt11Invoice , Error > {
491
- let description = maybe_convert_description ! ( description) ;
461
+ let description = maybe_convert ( description) ;
492
462
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) )
495
465
}
496
466
497
467
/// Returns a payable invoice that can be used to request and receive a payment for which the
@@ -501,9 +471,9 @@ impl Bolt11Payment {
501
471
pub fn receive_variable_amount (
502
472
& self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
503
473
) -> 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) )
507
477
}
508
478
509
479
/// Returns a payable invoice that can be used to request a payment for the given payment hash
@@ -523,9 +493,9 @@ impl Bolt11Payment {
523
493
pub fn receive_variable_amount_for_hash (
524
494
& self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
525
495
) -> 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) )
529
499
}
530
500
531
501
pub ( crate ) fn receive_inner (
@@ -600,15 +570,15 @@ impl Bolt11Payment {
600
570
& self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
601
571
max_total_lsp_fee_limit_msat : Option < u64 > ,
602
572
) -> Result < Bolt11Invoice , Error > {
603
- let description = maybe_convert_description ! ( description) ;
573
+ let description = maybe_convert ( description) ;
604
574
let invoice = self . receive_via_jit_channel_inner (
605
575
Some ( amount_msat) ,
606
- description,
576
+ & description,
607
577
expiry_secs,
608
578
max_total_lsp_fee_limit_msat,
609
579
None ,
610
580
) ?;
611
- Ok ( maybe_wrap_invoice ( invoice) )
581
+ Ok ( maybe_wrap ( invoice) )
612
582
}
613
583
614
584
/// Returns a payable invoice that can be used to request a variable amount payment (also known
@@ -626,15 +596,15 @@ impl Bolt11Payment {
626
596
& self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
627
597
max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
628
598
) -> Result < Bolt11Invoice , Error > {
629
- let description = maybe_convert_description ! ( description) ;
599
+ let description = maybe_convert ( description) ;
630
600
let invoice = self . receive_via_jit_channel_inner (
631
601
None ,
632
- description,
602
+ & description,
633
603
expiry_secs,
634
604
None ,
635
605
max_proportional_lsp_fee_limit_ppm_msat,
636
606
) ?;
637
- Ok ( maybe_wrap_invoice ( invoice) )
607
+ Ok ( maybe_wrap ( invoice) )
638
608
}
639
609
640
610
fn receive_via_jit_channel_inner (
@@ -741,7 +711,7 @@ impl Bolt11Payment {
741
711
/// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send
742
712
/// pre-flight probes.
743
713
pub fn send_probes ( & self , invoice : & Bolt11Invoice ) -> Result < ( ) , Error > {
744
- let invoice = maybe_convert_invoice ( invoice) ;
714
+ let invoice = maybe_convert ( invoice) ;
745
715
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
746
716
if rt_lock. is_none ( ) {
747
717
return Err ( Error :: NotRunning ) ;
@@ -774,7 +744,7 @@ impl Bolt11Payment {
774
744
pub fn send_probes_using_amount (
775
745
& self , invoice : & Bolt11Invoice , amount_msat : u64 ,
776
746
) -> Result < ( ) , Error > {
777
- let invoice = maybe_convert_invoice ( invoice) ;
747
+ let invoice = maybe_convert ( invoice) ;
778
748
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
779
749
if rt_lock. is_none ( ) {
780
750
return Err ( Error :: NotRunning ) ;
0 commit comments