1717//! - Wallet and channel states are persisted to disk.
1818//! - Gossip is retrieved over the P2P network.
1919
20- #![ deny( missing_docs) ]
2120#![ deny( broken_intra_doc_links) ]
2221#![ deny( private_intra_doc_links) ]
2322#![ allow( bare_trait_objects) ]
@@ -35,15 +34,16 @@ mod tests;
3534mod types;
3635mod wallet;
3736
38- pub use error:: Error ;
37+ pub use error:: Error as NodeError ;
38+ use error:: Error ;
3939pub use event:: Event ;
4040use event:: { EventHandler , EventQueue } ;
4141use peer_store:: { PeerInfo , PeerInfoStorage } ;
4242use types:: {
4343 ChainMonitor , ChannelManager , GossipSync , InvoicePayer , KeysManager , NetworkGraph ,
4444 OnionMessenger , PaymentInfoStorage , PeerManager , Router , Scorer ,
4545} ;
46- pub use types:: { PaymentInfo , PaymentStatus } ;
46+ pub use types:: { ChannelId , PaymentInfo , PaymentStatus , UserChannelId } ;
4747use wallet:: Wallet ;
4848
4949use logger:: { log_error, log_given_level, log_info, log_internal, FilesystemLogger , Logger } ;
@@ -76,7 +76,7 @@ use bdk::template::Bip84;
7676use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
7777use bitcoin:: hashes:: Hash ;
7878use bitcoin:: secp256k1:: PublicKey ;
79- use bitcoin:: BlockHash ;
79+ use bitcoin:: { Address , BlockHash } ;
8080
8181use rand:: Rng ;
8282
@@ -89,6 +89,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
8989use std:: sync:: { Arc , Mutex , RwLock } ;
9090use std:: time:: { Duration , Instant , SystemTime } ;
9191
92+ uniffi_macros:: include_scaffolding!( "ldk_node" ) ;
93+
9294// The used 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold
9395// number of blocks after which BDK stops looking for scripts belonging to the wallet.
9496const BDK_CLIENT_STOP_GAP : usize = 20 ;
@@ -195,8 +197,8 @@ impl Builder {
195197 self
196198 }
197199
198- /// Builds an [`Node`] instance according to the options previously configured.
199- pub fn build ( & self ) -> Node {
200+ /// Builds a [`Node`] instance according to the options previously configured.
201+ pub fn build ( & self ) -> Arc < Node > {
200202 let config = Arc :: new ( self . config . clone ( ) ) ;
201203
202204 let ldk_data_dir = format ! ( "{}/ldk" , & config. storage_dir_path. clone( ) ) ;
@@ -410,7 +412,7 @@ impl Builder {
410412
411413 let running = RwLock :: new ( None ) ;
412414
413- Node {
415+ Arc :: new ( Node {
414416 running,
415417 config,
416418 wallet,
@@ -429,7 +431,7 @@ impl Builder {
429431 inbound_payments,
430432 outbound_payments,
431433 peer_store,
432- }
434+ } )
433435 }
434436}
435437
@@ -472,7 +474,7 @@ impl Node {
472474 /// Starts the necessary background tasks, such as handling events coming from user input,
473475 /// LDK/BDK, and the peer-to-peer network. After this returns, the [`Node`] instance can be
474476 /// controlled via the provided API methods in a thread-safe manner.
475- pub fn start ( & mut self ) -> Result < ( ) , Error > {
477+ pub fn start ( & self ) -> Result < ( ) , Error > {
476478 // Acquire a run lock and hold it until we're setup.
477479 let mut run_lock = self . running . write ( ) . unwrap ( ) ;
478480 if run_lock. is_some ( ) {
@@ -486,7 +488,7 @@ impl Node {
486488 }
487489
488490 /// Disconnects all peers, stops all running background tasks, and shuts down [`Node`].
489- pub fn stop ( & mut self ) -> Result < ( ) , Error > {
491+ pub fn stop ( & self ) -> Result < ( ) , Error > {
490492 let mut run_lock = self . running . write ( ) . unwrap ( ) ;
491493 if run_lock. is_none ( ) {
492494 return Err ( Error :: NotRunning ) ;
@@ -704,15 +706,15 @@ impl Node {
704706 }
705707
706708 /// Retrieve a new on-chain/funding address.
707- pub fn new_funding_address ( & mut self ) -> Result < bitcoin :: Address , Error > {
709+ pub fn new_funding_address ( & self ) -> Result < Address , Error > {
708710 let funding_address = self . wallet . get_new_address ( ) ?;
709711 log_info ! ( self . logger, "Generated new funding address: {}" , funding_address) ;
710712 Ok ( funding_address)
711713 }
712714
713715 #[ cfg( test) ]
714716 /// Retrieve the current on-chain balance.
715- pub fn on_chain_balance ( & mut self ) -> Result < bdk:: Balance , Error > {
717+ pub fn on_chain_balance ( & self ) -> Result < bdk:: Balance , Error > {
716718 self . wallet . get_balance ( )
717719 }
718720
0 commit comments