@@ -30,13 +30,32 @@ use lightning::routing::router::{PaymentParameters, RouteParameters};
3030
3131use lightning_types:: payment:: { PaymentHash , PaymentPreimage } ;
3232
33- use lightning_invoice:: { Bolt11Invoice , Bolt11InvoiceDescription , Description } ;
33+ use lightning_invoice:: Bolt11Invoice ;
34+ use lightning_invoice:: Bolt11InvoiceDescription as LdkBolt11InvoiceDescription ;
3435
3536use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
3637use bitcoin:: hashes:: Hash ;
3738
3839use std:: sync:: { Arc , RwLock } ;
3940
41+ #[ cfg( not( feature = "uniffi" ) ) ]
42+ type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription ;
43+ #[ cfg( feature = "uniffi" ) ]
44+ type Bolt11InvoiceDescription = crate :: uniffi_types:: Bolt11InvoiceDescription ;
45+
46+ macro_rules! maybe_convert_description {
47+ ( $description: expr) => { {
48+ #[ cfg( not( feature = "uniffi" ) ) ]
49+ {
50+ $description
51+ }
52+ #[ cfg( feature = "uniffi" ) ]
53+ {
54+ & LdkBolt11InvoiceDescription :: try_from( $description) ?
55+ }
56+ } } ;
57+ }
58+
4059/// A payment handler allowing to create and pay [BOLT 11] invoices.
4160///
4261/// Should be retrieved by calling [`Node::bolt11_payment`].
@@ -404,8 +423,9 @@ impl Bolt11Payment {
404423 ///
405424 /// The inbound payment will be automatically claimed upon arrival.
406425 pub fn receive (
407- & self , amount_msat : u64 , description : & str , expiry_secs : u32 ,
426+ & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
408427 ) -> Result < Bolt11Invoice , Error > {
428+ let description = maybe_convert_description ! ( description) ;
409429 self . receive_inner ( Some ( amount_msat) , description, expiry_secs, None )
410430 }
411431
@@ -424,8 +444,10 @@ impl Bolt11Payment {
424444 /// [`claim_for_hash`]: Self::claim_for_hash
425445 /// [`fail_for_hash`]: Self::fail_for_hash
426446 pub fn receive_for_hash (
427- & self , amount_msat : u64 , description : & str , expiry_secs : u32 , payment_hash : PaymentHash ,
447+ & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
448+ payment_hash : PaymentHash ,
428449 ) -> Result < Bolt11Invoice , Error > {
450+ let description = maybe_convert_description ! ( description) ;
429451 self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) )
430452 }
431453
@@ -434,8 +456,9 @@ impl Bolt11Payment {
434456 ///
435457 /// The inbound payment will be automatically claimed upon arrival.
436458 pub fn receive_variable_amount (
437- & self , description : & str , expiry_secs : u32 ,
459+ & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
438460 ) -> Result < Bolt11Invoice , Error > {
461+ let description = maybe_convert_description ! ( description) ;
439462 self . receive_inner ( None , description, expiry_secs, None )
440463 }
441464
@@ -454,23 +477,20 @@ impl Bolt11Payment {
454477 /// [`claim_for_hash`]: Self::claim_for_hash
455478 /// [`fail_for_hash`]: Self::fail_for_hash
456479 pub fn receive_variable_amount_for_hash (
457- & self , description : & str , expiry_secs : u32 , payment_hash : PaymentHash ,
480+ & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
458481 ) -> Result < Bolt11Invoice , Error > {
482+ let description = maybe_convert_description ! ( description) ;
459483 self . receive_inner ( None , description, expiry_secs, Some ( payment_hash) )
460484 }
461485
462- fn receive_inner (
463- & self , amount_msat : Option < u64 > , description : & str , expiry_secs : u32 ,
464- manual_claim_payment_hash : Option < PaymentHash > ,
486+ pub ( crate ) fn receive_inner (
487+ & self , amount_msat : Option < u64 > , invoice_description : & LdkBolt11InvoiceDescription ,
488+ expiry_secs : u32 , manual_claim_payment_hash : Option < PaymentHash > ,
465489 ) -> Result < Bolt11Invoice , Error > {
466- let invoice_description = Bolt11InvoiceDescription :: Direct (
467- Description :: new ( description. to_string ( ) ) . map_err ( |_| Error :: InvoiceCreationFailed ) ?,
468- ) ;
469-
470490 let invoice = {
471491 let invoice_params = Bolt11InvoiceParameters {
472492 amount_msats : amount_msat,
473- description : invoice_description,
493+ description : invoice_description. clone ( ) ,
474494 invoice_expiry_delta_secs : Some ( expiry_secs) ,
475495 payment_hash : manual_claim_payment_hash,
476496 ..Default :: default ( )
@@ -531,9 +551,10 @@ impl Bolt11Payment {
531551 ///
532552 /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
533553 pub fn receive_via_jit_channel (
534- & self , amount_msat : u64 , description : & str , expiry_secs : u32 ,
554+ & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
535555 max_total_lsp_fee_limit_msat : Option < u64 > ,
536556 ) -> Result < Bolt11Invoice , Error > {
557+ let description = maybe_convert_description ! ( description) ;
537558 self . receive_via_jit_channel_inner (
538559 Some ( amount_msat) ,
539560 description,
@@ -555,9 +576,10 @@ impl Bolt11Payment {
555576 ///
556577 /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
557578 pub fn receive_variable_amount_via_jit_channel (
558- & self , description : & str , expiry_secs : u32 ,
579+ & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
559580 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
560581 ) -> Result < Bolt11Invoice , Error > {
582+ let description = maybe_convert_description ! ( description) ;
561583 self . receive_via_jit_channel_inner (
562584 None ,
563585 description,
@@ -568,8 +590,8 @@ impl Bolt11Payment {
568590 }
569591
570592 fn receive_via_jit_channel_inner (
571- & self , amount_msat : Option < u64 > , description : & str , expiry_secs : u32 ,
572- max_total_lsp_fee_limit_msat : Option < u64 > ,
593+ & self , amount_msat : Option < u64 > , description : & LdkBolt11InvoiceDescription ,
594+ expiry_secs : u32 , max_total_lsp_fee_limit_msat : Option < u64 > ,
573595 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
574596 ) -> Result < Bolt11Invoice , Error > {
575597 let liquidity_source =
0 commit comments