@@ -78,7 +78,7 @@ mod error;
7878mod event;
7979mod gossip;
8080mod hex_utils;
81- mod io;
81+ pub mod io;
8282mod logger;
8383mod payment_store;
8484mod peer_store;
@@ -317,8 +317,18 @@ impl Builder {
317317 self
318318 }
319319
320+ /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
321+ /// previously configured.
322+ pub fn build ( & self ) -> Arc < Node < FilesystemStore > > {
323+ let ldk_data_dir = format ! ( "{}/ldk" , self . config. storage_dir_path) ;
324+ let kv_store = Arc :: new ( FilesystemStore :: new ( ldk_data_dir. clone ( ) . into ( ) ) ) ;
325+ self . build_with_store ( kv_store)
326+ }
327+
320328 /// Builds a [`Node`] instance according to the options previously configured.
321- pub fn build ( & self ) -> Arc < Node > {
329+ pub fn build_with_store < K : KVStore + Sync + Send + ' static > (
330+ & self , kv_store : Arc < K > ,
331+ ) -> Arc < Node < K > > {
322332 let config = Arc :: new ( self . config . clone ( ) ) ;
323333
324334 let ldk_data_dir = format ! ( "{}/ldk" , config. storage_dir_path) ;
@@ -389,10 +399,8 @@ impl Builder {
389399 Arc :: clone ( & logger) ,
390400 ) ) ;
391401
392- let kv_store = Arc :: new ( FilesystemStore :: new ( ldk_data_dir. clone ( ) . into ( ) ) ) ;
393-
394402 // Initialize the ChainMonitor
395- let chain_monitor: Arc < ChainMonitor > = Arc :: new ( chainmonitor:: ChainMonitor :: new (
403+ let chain_monitor: Arc < ChainMonitor < K > > = Arc :: new ( chainmonitor:: ChainMonitor :: new (
396404 Some ( Arc :: clone ( & tx_sync) ) ,
397405 Arc :: clone ( & wallet) ,
398406 Arc :: clone ( & logger) ,
@@ -489,7 +497,7 @@ impl Builder {
489497 channel_monitor_references,
490498 ) ;
491499 let ( _hash, channel_manager) =
492- <( BlockHash , ChannelManager ) >:: read ( & mut reader, read_args)
500+ <( BlockHash , ChannelManager < K > ) >:: read ( & mut reader, read_args)
493501 . expect ( "Failed to read channel manager from store" ) ;
494502 channel_manager
495503 } else {
@@ -659,31 +667,35 @@ impl Builder {
659667 }
660668}
661669
670+ /// This type alias is required as Uniffi doesn't support generics, i.e., we can only expose the
671+ /// concretized types via this aliasing hack.
672+ type LDKNode = Node < FilesystemStore > ;
673+
662674/// The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
663675///
664676/// Needs to be initialized and instantiated through [`Builder::build`].
665- pub struct Node {
677+ pub struct Node < K : KVStore + Sync + Send + ' static > {
666678 runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > ,
667679 stop_sender : tokio:: sync:: watch:: Sender < ( ) > ,
668680 stop_receiver : tokio:: sync:: watch:: Receiver < ( ) > ,
669681 config : Arc < Config > ,
670682 wallet : Arc < Wallet < bdk:: database:: SqliteDatabase > > ,
671683 tx_sync : Arc < EsploraSyncClient < Arc < FilesystemLogger > > > ,
672- event_queue : Arc < EventQueue < Arc < FilesystemStore > , Arc < FilesystemLogger > > > ,
673- channel_manager : Arc < ChannelManager > ,
674- chain_monitor : Arc < ChainMonitor > ,
675- peer_manager : Arc < PeerManager > ,
684+ event_queue : Arc < EventQueue < K , Arc < FilesystemLogger > > > ,
685+ channel_manager : Arc < ChannelManager < K > > ,
686+ chain_monitor : Arc < ChainMonitor < K > > ,
687+ peer_manager : Arc < PeerManager < K > > ,
676688 keys_manager : Arc < KeysManager > ,
677689 network_graph : Arc < NetworkGraph > ,
678690 gossip_source : Arc < GossipSource > ,
679- kv_store : Arc < FilesystemStore > ,
691+ kv_store : Arc < K > ,
680692 logger : Arc < FilesystemLogger > ,
681693 scorer : Arc < Mutex < Scorer > > ,
682- peer_store : Arc < PeerStore < Arc < FilesystemStore > , Arc < FilesystemLogger > > > ,
683- payment_store : Arc < PaymentStore < Arc < FilesystemStore > , Arc < FilesystemLogger > > > ,
694+ peer_store : Arc < PeerStore < K , Arc < FilesystemLogger > > > ,
695+ payment_store : Arc < PaymentStore < K , Arc < FilesystemLogger > > > ,
684696}
685697
686- impl Node {
698+ impl < K : KVStore + Sync + Send + ' static > Node < K > {
687699 /// Starts the necessary background tasks, such as handling events coming from user input,
688700 /// LDK/BDK, and the peer-to-peer network.
689701 ///
@@ -1624,14 +1636,14 @@ impl Node {
16241636 }
16251637}
16261638
1627- impl Drop for Node {
1639+ impl < K : KVStore + Sync + Send + ' static > Drop for Node < K > {
16281640 fn drop ( & mut self ) {
16291641 let _ = self . stop ( ) ;
16301642 }
16311643}
16321644
1633- async fn connect_peer_if_necessary (
1634- node_id : PublicKey , addr : NetAddress , peer_manager : Arc < PeerManager > ,
1645+ async fn connect_peer_if_necessary < K : KVStore + Sync + Send + ' static + ' static > (
1646+ node_id : PublicKey , addr : NetAddress , peer_manager : Arc < PeerManager < K > > ,
16351647 logger : Arc < FilesystemLogger > ,
16361648) -> Result < ( ) , Error > {
16371649 for ( pman_node_id, _pman_addr) in peer_manager. get_peer_node_ids ( ) {
@@ -1643,8 +1655,8 @@ async fn connect_peer_if_necessary(
16431655 do_connect_peer ( node_id, addr, peer_manager, logger) . await
16441656}
16451657
1646- async fn do_connect_peer (
1647- node_id : PublicKey , addr : NetAddress , peer_manager : Arc < PeerManager > ,
1658+ async fn do_connect_peer < K : KVStore + Sync + Send + ' static + ' static > (
1659+ node_id : PublicKey , addr : NetAddress , peer_manager : Arc < PeerManager < K > > ,
16481660 logger : Arc < FilesystemLogger > ,
16491661) -> Result < ( ) , Error > {
16501662 log_info ! ( logger, "Connecting to peer: {}@{}" , node_id, addr) ;
0 commit comments