@@ -94,7 +94,9 @@ pub mod logger;
9494mod message_handler;
9595pub mod payment;
9696mod peer_store;
97+ mod rate_limiter;
9798mod runtime;
99+ mod static_invoice_store;
98100mod tx_broadcaster;
99101mod types;
100102mod wallet;
@@ -150,13 +152,16 @@ pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, UserChannelId};
150152
151153use logger:: { log_debug, log_error, log_info, log_trace, LdkLogger , Logger } ;
152154
155+ use lightning:: blinded_path:: message:: BlindedMessagePath ;
153156use lightning:: chain:: BestBlock ;
154157use lightning:: events:: bump_transaction:: Wallet as LdkWallet ;
155158use lightning:: impl_writeable_tlv_based;
156159use lightning:: ln:: channel_state:: ChannelShutdownState ;
157160use lightning:: ln:: channelmanager:: PaymentId ;
158161use lightning:: ln:: msgs:: SocketAddress ;
159162use lightning:: routing:: gossip:: NodeAlias ;
163+ use lightning:: util:: ser:: Readable ;
164+ use lightning:: util:: ser:: Writeable ;
160165
161166use lightning_background_processor:: process_events_async_with_kv_store_sync;
162167
@@ -170,6 +175,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
170175use std:: sync:: { Arc , Mutex , RwLock } ;
171176use std:: time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
172177
178+ use crate :: static_invoice_store:: StaticInvoiceStore ;
179+
173180#[ cfg( feature = "uniffi" ) ]
174181uniffi:: include_scaffolding!( "ldk_node" ) ;
175182
@@ -498,6 +505,8 @@ impl Node {
498505 Arc :: clone ( & self . logger ) ,
499506 ) ) ;
500507
508+ let static_invoice_store = StaticInvoiceStore :: new ( Arc :: clone ( & self . kv_store ) ) ;
509+
501510 let event_handler = Arc :: new ( EventHandler :: new (
502511 Arc :: clone ( & self . event_queue ) ,
503512 Arc :: clone ( & self . wallet ) ,
@@ -509,6 +518,7 @@ impl Node {
509518 self . liquidity_source . clone ( ) ,
510519 Arc :: clone ( & self . payment_store ) ,
511520 Arc :: clone ( & self . peer_store ) ,
521+ static_invoice_store,
512522 Arc :: clone ( & self . runtime ) ,
513523 Arc :: clone ( & self . logger ) ,
514524 Arc :: clone ( & self . config ) ,
@@ -1476,6 +1486,39 @@ impl Node {
14761486 Error :: PersistenceFailed
14771487 } )
14781488 }
1489+
1490+ /// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
1491+ /// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
1492+ ///
1493+ /// [`Offer`]: lightning::offers::offer::Offer
1494+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
1495+ pub fn set_paths_to_static_invoice_server ( & self , paths : Vec < u8 > ) -> Result < ( ) , Error > {
1496+ let decoded_paths = <Vec < BlindedMessagePath > as Readable >:: read ( & mut & paths[ ..] )
1497+ . or ( Err ( Error :: InvalidBlindedPaths ) ) ?;
1498+
1499+ self . channel_manager
1500+ . set_paths_to_static_invoice_server ( decoded_paths)
1501+ . or ( Err ( Error :: InvalidBlindedPaths ) )
1502+ }
1503+
1504+ /// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
1505+ /// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
1506+ ///
1507+ /// [`Offer`]: lightning::offers::offer::Offer
1508+ /// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
1509+ pub fn blinded_paths_for_async_recipient (
1510+ & self , recipient_id : Vec < u8 > ,
1511+ ) -> Result < Vec < u8 > , Error > {
1512+ let paths = self
1513+ . channel_manager
1514+ . blinded_paths_for_async_recipient ( recipient_id, None )
1515+ . or ( Err ( Error :: OperationFailed ) ) ?;
1516+
1517+ let mut bytes = Vec :: new ( ) ;
1518+ paths. write ( & mut bytes) . or ( Err ( Error :: OperationFailed ) ) ?;
1519+
1520+ Ok ( bytes)
1521+ }
14791522}
14801523
14811524impl Drop for Node {
0 commit comments