@@ -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.
@@ -453,12 +457,11 @@ impl Bolt12Payment {
453457
454458 /// Retrieve an [`Offer`] for receiving async payments as an often-offline recipient.
455459 ///
456- /// Will only return an offer if [`Node ::set_paths_to_static_invoice_server`] was called and we succeeded in
457- /// interactively building a [`StaticInvoice`] with the static invoice server.
460+ /// Will only return an offer if [`Bolt12Payment ::set_paths_to_static_invoice_server`] was called and we succeeded
461+ /// in interactively building a [`StaticInvoice`] with the static invoice server.
458462 ///
459463 /// Useful for posting offers to receive payments later, such as posting an offer on a website.
460464 ///
461- /// [`Node::set_paths_to_static_invoice_server`]: crate::Node::set_paths_to_static_invoice_server
462465 /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
463466 /// [`Offer`]: lightning::offers::offer::Offer
464467 pub fn receive_async ( & self ) -> Result < Offer , Error > {
@@ -467,4 +470,73 @@ impl Bolt12Payment {
467470 . map ( maybe_wrap)
468471 . or ( Err ( Error :: OfferCreationFailed ) )
469472 }
473+
474+ /// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
475+ /// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
476+ ///
477+ /// [`Offer`]: lightning::offers::offer::Offer
478+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
479+ #[ cfg( not( feature = "uniffi" ) ) ]
480+ pub fn set_paths_to_static_invoice_server (
481+ & self , paths : Vec < BlindedMessagePath > ,
482+ ) -> Result < ( ) , Error > {
483+ self . channel_manager
484+ . set_paths_to_static_invoice_server ( paths)
485+ . or ( Err ( Error :: InvalidBlindedPaths ) )
486+ }
487+
488+ /// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
489+ /// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
490+ ///
491+ /// [`Offer`]: lightning::offers::offer::Offer
492+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
493+ #[ cfg( feature = "uniffi" ) ]
494+ pub fn set_paths_to_static_invoice_server ( & self , paths : Vec < u8 > ) -> Result < ( ) , Error > {
495+ let decoded_paths = <Vec < BlindedMessagePath > as Readable >:: read ( & mut & paths[ ..] )
496+ . or ( Err ( Error :: InvalidBlindedPaths ) ) ?;
497+
498+ self . channel_manager
499+ . set_paths_to_static_invoice_server ( decoded_paths)
500+ . or ( Err ( Error :: InvalidBlindedPaths ) )
501+ }
502+
503+ /// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
504+ /// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
505+ ///
506+ /// [`Offer`]: lightning::offers::offer::Offer
507+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
508+ #[ cfg( not( feature = "uniffi" ) ) ]
509+ pub fn blinded_paths_for_async_recipient (
510+ & self , recipient_id : Vec < u8 > ,
511+ ) -> Result < Vec < BlindedMessagePath > , Error > {
512+ self . blinded_paths_for_async_recipient_internal ( recipient_id)
513+ }
514+
515+ /// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
516+ /// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
517+ ///
518+ /// [`Offer`]: lightning::offers::offer::Offer
519+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
520+ #[ cfg( feature = "uniffi" ) ]
521+ pub fn blinded_paths_for_async_recipient (
522+ & self , recipient_id : Vec < u8 > ,
523+ ) -> Result < Vec < u8 > , Error > {
524+ let paths = self . blinded_paths_for_async_recipient_internal ( recipient_id) ?;
525+
526+ let mut bytes = Vec :: new ( ) ;
527+ paths. write ( & mut bytes) . or ( Err ( Error :: InvalidBlindedPaths ) ) ?;
528+ Ok ( bytes)
529+ }
530+
531+ fn blinded_paths_for_async_recipient_internal (
532+ & self , recipient_id : Vec < u8 > ,
533+ ) -> Result < Vec < BlindedMessagePath > , Error > {
534+ if !self . async_payment_services_enabled {
535+ return Err ( Error :: AsyncPaymentServicesDisabled ) ;
536+ }
537+
538+ self . channel_manager
539+ . blinded_paths_for_async_recipient ( recipient_id, None )
540+ . or ( Err ( Error :: InvalidBlindedPaths ) )
541+ }
470542}
0 commit comments