@@ -16,11 +16,14 @@ use crate::logger::{log_error, log_info, LdkLogger, Logger};
1616use crate :: payment:: store:: { PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus } ;
1717use crate :: types:: { ChannelManager , PaymentStore } ;
1818
19+ use lightning:: blinded_path:: message:: BlindedMessagePath ;
1920use lightning:: ln:: channelmanager:: { PaymentId , Retry } ;
2021use lightning:: offers:: offer:: { Amount , Offer as LdkOffer , Quantity } ;
2122use lightning:: offers:: parse:: Bolt12SemanticError ;
2223use lightning:: routing:: router:: RouteParametersConfig ;
2324
25+ #[ cfg( feature = "uniffi" ) ]
26+ use lightning:: util:: ser:: { Readable , Writeable } ;
2427use lightning_types:: string:: UntrustedString ;
2528
2629use rand:: RngCore ;
@@ -54,15 +57,16 @@ pub struct Bolt12Payment {
5457 channel_manager : Arc < ChannelManager > ,
5558 payment_store : Arc < PaymentStore > ,
5659 is_running : Arc < RwLock < bool > > ,
60+ async_payment_services_enabled : bool ,
5761 logger : Arc < Logger > ,
5862}
5963
6064impl Bolt12Payment {
6165 pub ( crate ) fn new (
6266 channel_manager : Arc < ChannelManager > , payment_store : Arc < PaymentStore > ,
63- is_running : Arc < RwLock < bool > > , logger : Arc < Logger > ,
67+ async_payment_services_enabled : bool , is_running : Arc < RwLock < bool > > , logger : Arc < Logger > ,
6468 ) -> Self {
65- Self { channel_manager, payment_store, is_running, logger }
69+ Self { channel_manager, payment_store, async_payment_services_enabled , is_running, logger }
6670 }
6771
6872 /// Send a payment given an offer.
@@ -467,4 +471,73 @@ impl Bolt12Payment {
467471 . map ( maybe_wrap)
468472 . or ( Err ( Error :: OfferCreationFailed ) )
469473 }
474+
475+ /// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
476+ /// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
477+ ///
478+ /// [`Offer`]: lightning::offers::offer::Offer
479+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
480+ #[ cfg( not( feature = "uniffi" ) ) ]
481+ pub fn set_paths_to_static_invoice_server (
482+ & self , paths : Vec < BlindedMessagePath > ,
483+ ) -> Result < ( ) , Error > {
484+ self . channel_manager
485+ . set_paths_to_static_invoice_server ( paths)
486+ . or ( Err ( Error :: InvalidBlindedPaths ) )
487+ }
488+
489+ /// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
490+ /// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
491+ ///
492+ /// [`Offer`]: lightning::offers::offer::Offer
493+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
494+ #[ cfg( feature = "uniffi" ) ]
495+ pub fn set_paths_to_static_invoice_server ( & self , paths : Vec < u8 > ) -> Result < ( ) , Error > {
496+ let decoded_paths = <Vec < BlindedMessagePath > as Readable >:: read ( & mut & paths[ ..] )
497+ . or ( Err ( Error :: InvalidBlindedPaths ) ) ?;
498+
499+ self . channel_manager
500+ . set_paths_to_static_invoice_server ( decoded_paths)
501+ . or ( Err ( Error :: InvalidBlindedPaths ) )
502+ }
503+
504+ /// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
505+ /// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
506+ ///
507+ /// [`Offer`]: lightning::offers::offer::Offer
508+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
509+ #[ cfg( not( feature = "uniffi" ) ) ]
510+ pub fn blinded_paths_for_async_recipient (
511+ & self , recipient_id : Vec < u8 > ,
512+ ) -> Result < Vec < BlindedMessagePath > , Error > {
513+ self . blinded_paths_internal ( recipient_id)
514+ }
515+
516+ /// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
517+ /// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
518+ ///
519+ /// [`Offer`]: lightning::offers::offer::Offer
520+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
521+ #[ cfg( feature = "uniffi" ) ]
522+ pub fn blinded_paths_for_async_recipient (
523+ & self , recipient_id : Vec < u8 > ,
524+ ) -> Result < Vec < u8 > , Error > {
525+ let paths = self . blinded_paths_internal ( recipient_id) ?;
526+
527+ let mut bytes = Vec :: new ( ) ;
528+ paths. write ( & mut bytes) . or ( Err ( Error :: InvalidBlindedPaths ) ) ?;
529+ Ok ( bytes)
530+ }
531+
532+ fn blinded_paths_internal (
533+ & self , recipient_id : Vec < u8 > ,
534+ ) -> Result < Vec < BlindedMessagePath > , Error > {
535+ if !self . async_payment_services_enabled {
536+ return Err ( Error :: AsyncPaymentServicesDisabled ) ;
537+ }
538+
539+ self . channel_manager
540+ . blinded_paths_for_async_recipient ( recipient_id, None )
541+ . or ( Err ( Error :: InvalidBlindedPaths ) )
542+ }
470543}
0 commit comments