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