@@ -26,7 +26,7 @@ use lightning_invoice::RawBolt11Invoice;
26
26
27
27
use bdk:: blockchain:: EsploraBlockchain ;
28
28
use bdk:: wallet:: AddressIndex ;
29
- use bdk:: { Balance , SignOptions , SyncOptions } ;
29
+ use bdk:: { SignOptions , SyncOptions } ;
30
30
use bdk_chain:: ChainPosition ;
31
31
use bdk_wallet:: Wallet as BdkWallet ;
32
32
@@ -41,7 +41,7 @@ use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, Signing};
41
41
use bitcoin:: { ScriptBuf , Transaction , TxOut , Txid , WPubkeyHash , WitnessProgram , WitnessVersion } ;
42
42
43
43
use std:: ops:: { Deref , DerefMut } ;
44
- use std:: sync:: { Arc , Mutex , RwLock } ;
44
+ use std:: sync:: { Arc , Mutex } ;
45
45
use std:: time:: Duration ;
46
46
47
47
enum WalletSyncStatus {
64
64
fee_estimator : E ,
65
65
// A Mutex holding the current sync status.
66
66
sync_status : Mutex < WalletSyncStatus > ,
67
- // TODO: Drop this workaround after BDK 1.0 upgrade.
68
- balance_cache : RwLock < Balance > ,
69
67
logger : L ,
70
68
}
71
69
79
77
blockchain : EsploraBlockchain , wallet : BdkWallet , broadcaster : B , fee_estimator : E ,
80
78
logger : L ,
81
79
) -> Self {
82
- let start_balance = wallet. get_balance ( ) . unwrap_or ( Balance {
83
- immature : 0 ,
84
- trusted_pending : 0 ,
85
- untrusted_pending : 0 ,
86
- confirmed : 0 ,
87
- } ) ;
88
-
89
80
let inner = Mutex :: new ( wallet) ;
90
81
let sync_status = Mutex :: new ( WalletSyncStatus :: Completed ) ;
91
- let balance_cache = RwLock :: new ( start_balance) ;
92
- Self { blockchain, inner, broadcaster, fee_estimator, sync_status, balance_cache, logger }
82
+ Self { blockchain, inner, broadcaster, fee_estimator, sync_status, logger }
93
83
}
94
84
95
85
pub ( crate ) async fn sync ( & self ) -> Result < ( ) , Error > {
@@ -112,14 +102,7 @@ where
112
102
113
103
match wallet_sync_timeout_fut. await {
114
104
Ok ( res) => match res {
115
- Ok ( ( ) ) => {
116
- // TODO: Drop this workaround after BDK 1.0 upgrade.
117
- // Update balance cache after syncing.
118
- if let Ok ( balance) = wallet_lock. get_balance ( ) {
119
- * self . balance_cache . write ( ) . unwrap ( ) = balance;
120
- }
121
- Ok ( ( ) )
122
- } ,
105
+ Ok ( ( ) ) => Ok ( ( ) ) ,
123
106
Err ( e) => match e {
124
107
bdk:: Error :: Esplora ( ref be) => match * * be {
125
108
bdk:: blockchain:: esplora:: EsploraError :: Reqwest ( _) => {
@@ -208,22 +191,11 @@ where
208
191
pub ( crate ) fn get_balances (
209
192
& self , total_anchor_channels_reserve_sats : u64 ,
210
193
) -> Result < ( u64 , u64 ) , Error > {
211
- // TODO: Drop this workaround after BDK 1.0 upgrade.
212
- // We get the balance and update our cache if we can do so without blocking on the wallet
213
- // Mutex. Otherwise, we return a cached value.
214
- let balance = match self . inner . try_lock ( ) {
215
- Ok ( wallet_lock) => {
216
- // Update balance cache if we can.
217
- let balance = wallet_lock. get_balance ( ) ?;
218
- * self . balance_cache . write ( ) . unwrap ( ) = balance. clone ( ) ;
219
- balance
220
- } ,
221
- Err ( _) => self . balance_cache . read ( ) . unwrap ( ) . clone ( ) ,
222
- } ;
194
+ let balance = self . inner . lock ( ) . unwrap ( ) . balance ( ) ;
223
195
224
196
let ( total, spendable) = (
225
- balance. get_total ( ) ,
226
- balance. get_spendable ( ) . saturating_sub ( total_anchor_channels_reserve_sats) ,
197
+ balance. total ( ) . to_sat ( ) ,
198
+ balance. trusted_spendable ( ) . to_sat ( ) . saturating_sub ( total_anchor_channels_reserve_sats) ,
227
199
) ;
228
200
229
201
Ok ( ( total, spendable) )
0 commit comments