1
- use crate :: logger:: { log_error, log_info, log_trace, FilesystemLogger , Logger } ;
1
+ use crate :: logger:: { log_error, log_info, log_trace, Logger } ;
2
2
3
3
use crate :: Error ;
4
4
@@ -27,12 +27,14 @@ use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, Signing};
27
27
use bitcoin:: { Script , Transaction , TxOut , Txid } ;
28
28
29
29
use std:: collections:: HashMap ;
30
+ use std:: ops:: Deref ;
30
31
use std:: sync:: { Arc , Condvar , Mutex , RwLock } ;
31
32
use std:: time:: Duration ;
32
33
33
- pub struct Wallet < D >
34
+ pub struct Wallet < D , L : Deref >
34
35
where
35
36
D : BatchDatabase ,
37
+ L :: Target : Logger ,
36
38
{
37
39
// A BDK blockchain used for wallet sync.
38
40
blockchain : EsploraBlockchain ,
@@ -42,16 +44,17 @@ where
42
44
fee_rate_cache : RwLock < HashMap < ConfirmationTarget , FeeRate > > ,
43
45
runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > ,
44
46
sync_lock : ( Mutex < ( ) > , Condvar ) ,
45
- logger : Arc < FilesystemLogger > ,
47
+ logger : L ,
46
48
}
47
49
48
- impl < D > Wallet < D >
50
+ impl < D , L : Deref > Wallet < D , L >
49
51
where
50
52
D : BatchDatabase ,
53
+ L :: Target : Logger ,
51
54
{
52
55
pub ( crate ) fn new (
53
56
blockchain : EsploraBlockchain , wallet : bdk:: Wallet < D > ,
54
- runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > , logger : Arc < FilesystemLogger > ,
57
+ runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > , logger : L ,
55
58
) -> Self {
56
59
let inner = Mutex :: new ( wallet) ;
57
60
let fee_rate_cache = RwLock :: new ( HashMap :: new ( ) ) ;
@@ -286,19 +289,21 @@ where
286
289
}
287
290
}
288
291
289
- impl < D > FeeEstimator for Wallet < D >
292
+ impl < D , L : Deref > FeeEstimator for Wallet < D , L >
290
293
where
291
294
D : BatchDatabase ,
295
+ L :: Target : Logger ,
292
296
{
293
297
fn get_est_sat_per_1000_weight ( & self , confirmation_target : ConfirmationTarget ) -> u32 {
294
298
( self . estimate_fee_rate ( confirmation_target) . fee_wu ( 1000 ) as u32 )
295
299
. max ( FEERATE_FLOOR_SATS_PER_KW )
296
300
}
297
301
}
298
302
299
- impl < D > BroadcasterInterface for Wallet < D >
303
+ impl < D , L : Deref > BroadcasterInterface for Wallet < D , L >
300
304
where
301
305
D : BatchDatabase ,
306
+ L :: Target : Logger ,
302
307
{
303
308
fn broadcast_transaction ( & self , tx : & Transaction ) {
304
309
let locked_runtime = self . runtime . read ( ) . unwrap ( ) ;
@@ -325,24 +330,27 @@ where
325
330
326
331
/// Similar to [`KeysManager`], but overrides the destination and shutdown scripts so they are
327
332
/// directly spendable by the BDK wallet.
328
- pub struct WalletKeysManager < D >
333
+ pub struct WalletKeysManager < D , L : Deref >
329
334
where
330
335
D : BatchDatabase ,
336
+ L :: Target : Logger ,
331
337
{
332
338
inner : KeysManager ,
333
- wallet : Arc < Wallet < D > > ,
339
+ wallet : Arc < Wallet < D , L > > ,
334
340
}
335
341
336
- impl < D > WalletKeysManager < D >
342
+ impl < D , L : Deref > WalletKeysManager < D , L >
337
343
where
338
344
D : BatchDatabase ,
345
+ L :: Target : Logger ,
339
346
{
340
347
/// Constructs a `WalletKeysManager` that overrides the destination and shutdown scripts.
341
348
///
342
349
/// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
343
350
/// `starting_time_nanos`.
344
351
pub fn new (
345
- seed : & [ u8 ; 32 ] , starting_time_secs : u64 , starting_time_nanos : u32 , wallet : Arc < Wallet < D > > ,
352
+ seed : & [ u8 ; 32 ] , starting_time_secs : u64 , starting_time_nanos : u32 ,
353
+ wallet : Arc < Wallet < D , L > > ,
346
354
) -> Self {
347
355
let inner = KeysManager :: new ( seed, starting_time_secs, starting_time_nanos) ;
348
356
Self { inner, wallet }
@@ -378,9 +386,10 @@ where
378
386
}
379
387
}
380
388
381
- impl < D > NodeSigner for WalletKeysManager < D >
389
+ impl < D , L : Deref > NodeSigner for WalletKeysManager < D , L >
382
390
where
383
391
D : BatchDatabase ,
392
+ L :: Target : Logger ,
384
393
{
385
394
fn get_node_id ( & self , recipient : Recipient ) -> Result < PublicKey , ( ) > {
386
395
self . inner . get_node_id ( recipient)
@@ -407,18 +416,20 @@ where
407
416
}
408
417
}
409
418
410
- impl < D > EntropySource for WalletKeysManager < D >
419
+ impl < D , L : Deref > EntropySource for WalletKeysManager < D , L >
411
420
where
412
421
D : BatchDatabase ,
422
+ L :: Target : Logger ,
413
423
{
414
424
fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] {
415
425
self . inner . get_secure_random_bytes ( )
416
426
}
417
427
}
418
428
419
- impl < D > SignerProvider for WalletKeysManager < D >
429
+ impl < D , L : Deref > SignerProvider for WalletKeysManager < D , L >
420
430
where
421
431
D : BatchDatabase ,
432
+ L :: Target : Logger ,
422
433
{
423
434
type Signer = InMemorySigner ;
424
435
0 commit comments