@@ -30,14 +30,37 @@ use lightning::routing::router::{PaymentParameters, RouteParameters};
30
30
31
31
use lightning_types:: payment:: { PaymentHash , PaymentPreimage } ;
32
32
33
- use lightning_invoice:: Bolt11Invoice ;
33
+ use lightning_invoice:: Bolt11Invoice as LdkBolt11Invoice ;
34
34
use lightning_invoice:: Bolt11InvoiceDescription as LdkBolt11InvoiceDescription ;
35
35
36
36
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
37
37
use bitcoin:: hashes:: Hash ;
38
38
39
39
use std:: sync:: { Arc , RwLock } ;
40
40
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 fn maybe_wrap_invoice ( invoice : LdkBolt11Invoice ) -> Bolt11Invoice {
48
+ invoice
49
+ }
50
+ #[ cfg( feature = "uniffi" ) ]
51
+ pub 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
+
41
64
#[ cfg( not( feature = "uniffi" ) ) ]
42
65
type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription ;
43
66
#[ cfg( feature = "uniffi" ) ]
@@ -101,6 +124,7 @@ impl Bolt11Payment {
101
124
pub fn send (
102
125
& self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
103
126
) -> Result < PaymentId , Error > {
127
+ let invoice = maybe_convert_invoice ( invoice) ;
104
128
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
105
129
if rt_lock. is_none ( ) {
106
130
return Err ( Error :: NotRunning ) ;
@@ -209,6 +233,7 @@ impl Bolt11Payment {
209
233
& self , invoice : & Bolt11Invoice , amount_msat : u64 ,
210
234
sending_parameters : Option < SendingParameters > ,
211
235
) -> Result < PaymentId , Error > {
236
+ let invoice = maybe_convert_invoice ( invoice) ;
212
237
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
213
238
if rt_lock. is_none ( ) {
214
239
return Err ( Error :: NotRunning ) ;
@@ -441,7 +466,8 @@ impl Bolt11Payment {
441
466
& self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
442
467
) -> Result < Bolt11Invoice , Error > {
443
468
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) )
445
471
}
446
472
447
473
/// Returns a payable invoice that can be used to request a payment of the amount
@@ -463,7 +489,9 @@ impl Bolt11Payment {
463
489
payment_hash : PaymentHash ,
464
490
) -> Result < Bolt11Invoice , Error > {
465
491
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) )
467
495
}
468
496
469
497
/// Returns a payable invoice that can be used to request and receive a payment for which the
@@ -474,7 +502,8 @@ impl Bolt11Payment {
474
502
& self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
475
503
) -> Result < Bolt11Invoice , Error > {
476
504
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) )
478
507
}
479
508
480
509
/// Returns a payable invoice that can be used to request a payment for the given payment hash
@@ -495,13 +524,14 @@ impl Bolt11Payment {
495
524
& self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
496
525
) -> Result < Bolt11Invoice , Error > {
497
526
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) )
499
529
}
500
530
501
531
pub ( crate ) fn receive_inner (
502
532
& self , amount_msat : Option < u64 > , invoice_description : & LdkBolt11InvoiceDescription ,
503
533
expiry_secs : u32 , manual_claim_payment_hash : Option < PaymentHash > ,
504
- ) -> Result < Bolt11Invoice , Error > {
534
+ ) -> Result < LdkBolt11Invoice , Error > {
505
535
let invoice = {
506
536
let invoice_params = Bolt11InvoiceParameters {
507
537
amount_msats : amount_msat,
@@ -571,13 +601,14 @@ impl Bolt11Payment {
571
601
max_total_lsp_fee_limit_msat : Option < u64 > ,
572
602
) -> Result < Bolt11Invoice , Error > {
573
603
let description = maybe_convert_description ! ( description) ;
574
- self . receive_via_jit_channel_inner (
604
+ let invoice = self . receive_via_jit_channel_inner (
575
605
Some ( amount_msat) ,
576
606
description,
577
607
expiry_secs,
578
608
max_total_lsp_fee_limit_msat,
579
609
None ,
580
- )
610
+ ) ?;
611
+ Ok ( maybe_wrap_invoice ( invoice) )
581
612
}
582
613
583
614
/// Returns a payable invoice that can be used to request a variable amount payment (also known
@@ -596,20 +627,21 @@ impl Bolt11Payment {
596
627
max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
597
628
) -> Result < Bolt11Invoice , Error > {
598
629
let description = maybe_convert_description ! ( description) ;
599
- self . receive_via_jit_channel_inner (
630
+ let invoice = self . receive_via_jit_channel_inner (
600
631
None ,
601
632
description,
602
633
expiry_secs,
603
634
None ,
604
635
max_proportional_lsp_fee_limit_ppm_msat,
605
- )
636
+ ) ?;
637
+ Ok ( maybe_wrap_invoice ( invoice) )
606
638
}
607
639
608
640
fn receive_via_jit_channel_inner (
609
641
& self , amount_msat : Option < u64 > , description : & LdkBolt11InvoiceDescription ,
610
642
expiry_secs : u32 , max_total_lsp_fee_limit_msat : Option < u64 > ,
611
643
max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
612
- ) -> Result < Bolt11Invoice , Error > {
644
+ ) -> Result < LdkBolt11Invoice , Error > {
613
645
let liquidity_source =
614
646
self . liquidity_source . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
615
647
@@ -709,6 +741,7 @@ impl Bolt11Payment {
709
741
/// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send
710
742
/// pre-flight probes.
711
743
pub fn send_probes ( & self , invoice : & Bolt11Invoice ) -> Result < ( ) , Error > {
744
+ let invoice = maybe_convert_invoice ( invoice) ;
712
745
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
713
746
if rt_lock. is_none ( ) {
714
747
return Err ( Error :: NotRunning ) ;
@@ -741,6 +774,7 @@ impl Bolt11Payment {
741
774
pub fn send_probes_using_amount (
742
775
& self , invoice : & Bolt11Invoice , amount_msat : u64 ,
743
776
) -> Result < ( ) , Error > {
777
+ let invoice = maybe_convert_invoice ( invoice) ;
744
778
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
745
779
if rt_lock. is_none ( ) {
746
780
return Err ( Error :: NotRunning ) ;
0 commit comments