@@ -30,13 +30,13 @@ 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 , Bolt11InvoiceDescription , Description } ;
3434
35- use bitcoin:: hashes:: Hash ;
3635use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
36+ use bitcoin:: hashes:: Hash ;
3737
38- use std:: sync:: { Arc , RwLock } ;
3938use std:: str:: FromStr ;
39+ use std:: sync:: { Arc , RwLock } ;
4040
4141/// A payment handler allowing to create and pay [BOLT 11] invoices.
4242///
@@ -418,7 +418,6 @@ impl Bolt11Payment {
418418 let invoice_description: Bolt11InvoiceDescription = description. try_into ( ) ?;
419419 self . receive_inner ( Some ( amount_msat) , & invoice_description, expiry_secs, None )
420420 }
421-
422421
423422 /// Returns a payable invoice that can be used to request a payment of the amount
424423 /// given for the given payment hash.
@@ -436,14 +435,16 @@ impl Bolt11Payment {
436435 /// [`fail_for_hash`]: Self::fail_for_hash
437436 #[ cfg( not( feature = "uniffi" ) ) ]
438437 pub fn receive_for_hash (
439- & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
438+ & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
439+ payment_hash : PaymentHash ,
440440 ) -> Result < Bolt11Invoice , Error > {
441441 self . receive_inner ( Some ( amount_msat) , description, expiry_secs, Some ( payment_hash) )
442442 }
443-
443+
444444 #[ cfg( feature = "uniffi" ) ]
445445 pub fn receive_for_hash (
446- & self , amount_msat : u64 , description : & Bolt11InvoiceStringDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
446+ & self , amount_msat : u64 , description : & Bolt11InvoiceStringDescription , expiry_secs : u32 ,
447+ payment_hash : PaymentHash ,
447448 ) -> Result < Bolt11Invoice , Error > {
448449 let invoice_description: Bolt11InvoiceDescription = description. try_into ( ) ?;
449450 self . receive_inner ( Some ( amount_msat) , & invoice_description, expiry_secs, Some ( payment_hash) )
@@ -491,15 +492,16 @@ impl Bolt11Payment {
491492
492493 #[ cfg( feature = "uniffi" ) ]
493494 pub fn receive_variable_amount_for_hash (
494- & self , description : & Bolt11InvoiceStringDescription , expiry_secs : u32 , payment_hash : PaymentHash ,
495+ & self , description : & Bolt11InvoiceStringDescription , expiry_secs : u32 ,
496+ payment_hash : PaymentHash ,
495497 ) -> Result < Bolt11Invoice , Error > {
496498 let invoice_description: Bolt11InvoiceDescription = description. try_into ( ) ?;
497499 self . receive_inner ( None , & invoice_description, expiry_secs, Some ( payment_hash) )
498500 }
499501
500502 pub ( crate ) fn receive_inner (
501- & self , amount_msat : Option < u64 > , invoice_description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
502- manual_claim_payment_hash : Option < PaymentHash > ,
503+ & self , amount_msat : Option < u64 > , invoice_description : & Bolt11InvoiceDescription ,
504+ expiry_secs : u32 , manual_claim_payment_hash : Option < PaymentHash > ,
503505 ) -> Result < Bolt11Invoice , Error > {
504506 let invoice = {
505507 let invoice_params = Bolt11InvoiceParameters {
@@ -564,8 +566,9 @@ impl Bolt11Payment {
564566 /// channel to us. We'll use its cheapest offer otherwise.
565567 ///
566568 /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
569+ #[ cfg( not( feature = "uniffi" ) ) ]
567570 pub fn receive_via_jit_channel (
568- & self , amount_msat : u64 , description : & str , expiry_secs : u32 ,
571+ & self , amount_msat : u64 , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
569572 max_total_lsp_fee_limit_msat : Option < u64 > ,
570573 ) -> Result < Bolt11Invoice , Error > {
571574 self . receive_via_jit_channel_inner (
@@ -577,6 +580,21 @@ impl Bolt11Payment {
577580 )
578581 }
579582
583+ #[ cfg( feature = "uniffi" ) ]
584+ pub fn receive_via_jit_channel (
585+ & self , amount_msat : u64 , description : & Bolt11InvoiceStringDescription , expiry_secs : u32 ,
586+ max_total_lsp_fee_limit_msat : Option < u64 > ,
587+ ) -> Result < Bolt11Invoice , Error > {
588+ let invoice_description: Bolt11InvoiceDescription = description. try_into ( ) ?;
589+ self . receive_via_jit_channel_inner (
590+ Some ( amount_msat) ,
591+ & invoice_description,
592+ expiry_secs,
593+ max_total_lsp_fee_limit_msat,
594+ None ,
595+ )
596+ }
597+
580598 /// Returns a payable invoice that can be used to request a variable amount payment (also known
581599 /// as "zero-amount" invoice) and receive it via a newly created just-in-time (JIT) channel.
582600 ///
@@ -588,8 +606,9 @@ impl Bolt11Payment {
588606 /// We'll use its cheapest offer otherwise.
589607 ///
590608 /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
609+ #[ cfg( not( feature = "uniffi" ) ) ]
591610 pub fn receive_variable_amount_via_jit_channel (
592- & self , description : & str , expiry_secs : u32 ,
611+ & self , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
593612 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
594613 ) -> Result < Bolt11Invoice , Error > {
595614 self . receive_via_jit_channel_inner (
@@ -601,8 +620,23 @@ impl Bolt11Payment {
601620 )
602621 }
603622
623+ #[ cfg( feature = "uniffi" ) ]
624+ pub fn receive_variable_amount_via_jit_channel (
625+ & self , description : & Bolt11InvoiceStringDescription , expiry_secs : u32 ,
626+ max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
627+ ) -> Result < Bolt11Invoice , Error > {
628+ let invoice_description: Bolt11InvoiceDescription = description. try_into ( ) ?;
629+ self . receive_via_jit_channel_inner (
630+ None ,
631+ & invoice_description,
632+ expiry_secs,
633+ None ,
634+ max_proportional_lsp_fee_limit_ppm_msat,
635+ )
636+ }
637+
604638 fn receive_via_jit_channel_inner (
605- & self , amount_msat : Option < u64 > , description : & str , expiry_secs : u32 ,
639+ & self , amount_msat : Option < u64 > , description : & Bolt11InvoiceDescription , expiry_secs : u32 ,
606640 max_total_lsp_fee_limit_msat : Option < u64 > ,
607641 max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
608642 ) -> Result < Bolt11Invoice , Error > {
@@ -777,30 +811,34 @@ impl Bolt11Payment {
777811
778812/// Represents the description of an invoice which has to be either a directly included string or
779813/// a hash of a description provided out of band.
780- pub enum Bolt11InvoiceStringDescription { // use same name (no string)
814+ pub enum Bolt11InvoiceStringDescription {
815+ // use same name (no string)
781816 /// Contains a full description.
782- Direct {
817+ Direct {
783818 /// Description of what the invoice is for
784- description : String
819+ description : String ,
785820 } ,
786821 /// Contains a hash.
787- Hash {
822+ Hash {
788823 /// Hash of the description of what the invoice is for
789- hash : String
790- }
824+ hash : String ,
825+ } ,
791826}
792827
793828impl TryInto < Bolt11InvoiceDescription > for & Bolt11InvoiceStringDescription {
794829 type Error = Error ;
795830
796831 fn try_into ( self ) -> Result < Bolt11InvoiceDescription , Self :: Error > {
797832 match self {
798- Bolt11InvoiceStringDescription :: Direct { description} => {
799- Description :: new ( description. clone ( ) ) . map ( Bolt11InvoiceDescription :: Direct ) . map_err ( |_| Error :: InvalidInvoice )
800- } ,
801- Bolt11InvoiceStringDescription :: Hash { hash} => {
802- Sha256 :: from_str ( & hash) . map ( lightning_invoice:: Sha256 ) . map ( Bolt11InvoiceDescription :: Hash ) . map_err ( |_| Error :: InvalidInvoice )
833+ Bolt11InvoiceStringDescription :: Direct { description } => {
834+ Description :: new ( description. clone ( ) )
835+ . map ( Bolt11InvoiceDescription :: Direct )
836+ . map_err ( |_| Error :: InvalidInvoice )
803837 } ,
838+ Bolt11InvoiceStringDescription :: Hash { hash } => Sha256 :: from_str ( & hash)
839+ . map ( lightning_invoice:: Sha256 )
840+ . map ( Bolt11InvoiceDescription :: Hash )
841+ . map_err ( |_| Error :: InvalidInvoice ) ,
804842 }
805843 }
806- }
844+ }
0 commit comments