@@ -22,7 +22,7 @@ use bitcoin::{BlockHash, Script, Transaction, Txid};
22
22
23
23
use std:: collections:: HashSet ;
24
24
use std:: ops:: Deref ;
25
- use std:: sync:: Mutex ;
25
+ use std:: sync:: { Arc , Mutex } ;
26
26
use std:: time:: Instant ;
27
27
28
28
/// Synchronizes LDK with a given Electrum server.
43
43
{
44
44
sync_state : Mutex < SyncState > ,
45
45
queue : Mutex < FilterQueue > ,
46
- client : ElectrumClient ,
46
+ client : Arc < ElectrumClient > ,
47
47
logger : L ,
48
48
}
49
49
@@ -53,18 +53,18 @@ where
53
53
{
54
54
/// Returns a new [`ElectrumSyncClient`] object.
55
55
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| {
57
57
log_error ! ( logger, "Failed to connect to electrum server '{}': {}" , server_url, e) ;
58
58
e
59
- } ) ?;
59
+ } ) ?) ;
60
60
61
61
Self :: from_client ( client, logger)
62
62
}
63
63
64
64
/// Returns a new [`ElectrumSyncClient`] object using the given Electrum client.
65
65
///
66
66
/// 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 > {
68
68
let sync_state = Mutex :: new ( SyncState :: new ( ) ) ;
69
69
let queue = Mutex :: new ( FilterQueue :: new ( ) ) ;
70
70
@@ -489,8 +489,8 @@ where
489
489
/// Returns a reference to the underlying Electrum client.
490
490
///
491
491
/// 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 )
494
494
}
495
495
}
496
496
0 commit comments