@@ -22,7 +22,7 @@ use bitcoin::{BlockHash, Script, Transaction, Txid};
2222
2323use std:: collections:: HashSet ;
2424use std:: ops:: Deref ;
25- use std:: sync:: Mutex ;
25+ use std:: sync:: { Arc , Mutex } ;
2626use std:: time:: Instant ;
2727
2828/// Synchronizes LDK with a given Electrum server.
4343{
4444 sync_state : Mutex < SyncState > ,
4545 queue : Mutex < FilterQueue > ,
46- client : ElectrumClient ,
46+ client : Arc < ElectrumClient > ,
4747 logger : L ,
4848}
4949
@@ -53,18 +53,18 @@ where
5353{
5454 /// Returns a new [`ElectrumSyncClient`] object.
5555 pub fn new ( server_url : String , logger : L ) -> Result < Self , TxSyncError > {
56- let client = ElectrumClient :: new ( & server_url) . map_err ( |e| {
56+ let client = Arc :: new ( ElectrumClient :: new ( & server_url) . map_err ( |e| {
5757 log_error ! ( logger, "Failed to connect to electrum server '{}': {}" , server_url, e) ;
5858 e
59- } ) ?;
59+ } ) ?) ;
6060
6161 Self :: from_client ( client, logger)
6262 }
6363
6464 /// Returns a new [`ElectrumSyncClient`] object using the given Electrum client.
6565 ///
6666 /// This is not exported to bindings users as the underlying client from BDK is not exported.
67- pub fn from_client ( client : ElectrumClient , logger : L ) -> Result < Self , TxSyncError > {
67+ pub fn from_client ( client : Arc < ElectrumClient > , logger : L ) -> Result < Self , TxSyncError > {
6868 let sync_state = Mutex :: new ( SyncState :: new ( ) ) ;
6969 let queue = Mutex :: new ( FilterQueue :: new ( ) ) ;
7070
@@ -489,8 +489,8 @@ where
489489 /// Returns a reference to the underlying Electrum client.
490490 ///
491491 /// This is not exported to bindings users as the underlying client from BDK is not exported.
492- pub fn client ( & self ) -> & ElectrumClient {
493- & self . client
492+ pub fn client ( & self ) -> Arc < ElectrumClient > {
493+ Arc :: clone ( & self . client )
494494 }
495495}
496496
0 commit comments