@@ -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.
@@ -453,12 +457,11 @@ impl Bolt12Payment {
453
457
454
458
/// Retrieve an [`Offer`] for receiving async payments as an often-offline recipient.
455
459
///
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.
458
462
///
459
463
/// Useful for posting offers to receive payments later, such as posting an offer on a website.
460
464
///
461
- /// [`Node::set_paths_to_static_invoice_server`]: crate::Node::set_paths_to_static_invoice_server
462
465
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
463
466
/// [`Offer`]: lightning::offers::offer::Offer
464
467
pub fn receive_async ( & self ) -> Result < Offer , Error > {
@@ -467,4 +470,73 @@ impl Bolt12Payment {
467
470
. map ( maybe_wrap)
468
471
. or ( Err ( Error :: OfferCreationFailed ) )
469
472
}
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
+ }
470
542
}
0 commit comments