@@ -16,11 +16,14 @@ use crate::logger::{log_error, log_info, LdkLogger, Logger};
16
16
use crate :: payment:: store:: { PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus } ;
17
17
use crate :: types:: { ChannelManager , PaymentStore } ;
18
18
19
+ use lightning:: blinded_path:: message:: BlindedMessagePath ;
19
20
use lightning:: ln:: channelmanager:: { PaymentId , Retry } ;
20
21
use lightning:: offers:: offer:: { Amount , Offer as LdkOffer , Quantity } ;
21
22
use lightning:: offers:: parse:: Bolt12SemanticError ;
22
23
use lightning:: routing:: router:: RouteParametersConfig ;
23
24
25
+ #[ cfg( feature = "uniffi" ) ]
26
+ use lightning:: util:: ser:: { Readable , Writeable } ;
24
27
use lightning_types:: string:: UntrustedString ;
25
28
26
29
use rand:: RngCore ;
@@ -54,15 +57,16 @@ pub struct Bolt12Payment {
54
57
channel_manager : Arc < ChannelManager > ,
55
58
payment_store : Arc < PaymentStore > ,
56
59
is_running : Arc < RwLock < bool > > ,
60
+ async_payment_services_enabled : bool ,
57
61
logger : Arc < Logger > ,
58
62
}
59
63
60
64
impl Bolt12Payment {
61
65
pub ( crate ) fn new (
62
66
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 > ,
64
68
) -> Self {
65
- Self { channel_manager, payment_store, is_running, logger }
69
+ Self { channel_manager, payment_store, async_payment_services_enabled , is_running, logger }
66
70
}
67
71
68
72
/// Send a payment given an offer.
@@ -467,4 +471,73 @@ impl Bolt12Payment {
467
471
. map ( maybe_wrap)
468
472
. or ( Err ( Error :: OfferCreationFailed ) )
469
473
}
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
+ }
470
543
}
0 commit comments