@@ -23,8 +23,8 @@ use bdk::wallet::tx_builder::ChangeSpendPolicy;
2323use bdk:: wallet:: AddressIndex as BdkAddressIndex ;
2424use bdk:: wallet:: AddressInfo as BdkAddressInfo ;
2525use bdk:: {
26- BlockTime , Error , FeeRate , KeychainKind , SignOptions , SyncOptions as BdkSyncOptions ,
27- Wallet as BdkWallet ,
26+ Balance as BdkBalance , BlockTime , Error , FeeRate , KeychainKind , SignOptions ,
27+ SyncOptions as BdkSyncOptions , Wallet as BdkWallet ,
2828} ;
2929use std:: collections:: HashSet ;
3030use std:: convert:: { From , TryFrom } ;
@@ -150,7 +150,7 @@ pub struct TransactionDetails {
150150 /// Sent value (sats)
151151 /// Sum of owned inputs of this transaction.
152152 pub sent : u64 ,
153- /// Fee value (sats) if available .
153+ /// Fee value (sats) if confirmed .
154154 /// The availability of the fee depends on the backend. It's never None with an Electrum
155155 /// Server backend, but it could be None with a Bitcoin RPC node without txindex that receive
156156 /// funds while offline.
@@ -273,6 +273,34 @@ impl From<&OutPoint> for BdkOutPoint {
273273 }
274274}
275275
276+ pub struct Balance {
277+ // All coinbase outputs not yet matured
278+ pub immature : u64 ,
279+ /// Unconfirmed UTXOs generated by a wallet tx
280+ pub trusted_pending : u64 ,
281+ /// Unconfirmed UTXOs received from an external wallet
282+ pub untrusted_pending : u64 ,
283+ /// Confirmed and immediately spendable balance
284+ pub confirmed : u64 ,
285+ /// Get sum of trusted_pending and confirmed coins
286+ pub spendable : u64 ,
287+ /// Get the whole balance visible to the wallet
288+ pub total : u64 ,
289+ }
290+
291+ impl From < BdkBalance > for Balance {
292+ fn from ( bdk_balance : BdkBalance ) -> Self {
293+ Balance {
294+ immature : bdk_balance. immature ,
295+ trusted_pending : bdk_balance. trusted_pending ,
296+ untrusted_pending : bdk_balance. untrusted_pending ,
297+ confirmed : bdk_balance. confirmed ,
298+ spendable : bdk_balance. get_spendable ( ) ,
299+ total : bdk_balance. get_total ( ) ,
300+ }
301+ }
302+ }
303+
276304/// A transaction output, which defines new coins to be created from old ones.
277305pub struct TxOut {
278306 /// The value of the output, in satoshis.
@@ -429,8 +457,8 @@ impl Wallet {
429457
430458 /// Return the balance, meaning the sum of this wallet’s unspent outputs’ values. Note that this method only operates
431459 /// on the internal database, which first needs to be Wallet.sync manually.
432- fn get_balance ( & self ) -> Result < u64 , Error > {
433- self . get_wallet ( ) . get_balance ( )
460+ fn get_balance ( & self ) -> Result < Balance , Error > {
461+ self . get_wallet ( ) . get_balance ( ) . map ( |b| b . into ( ) )
434462 }
435463
436464 /// Sign a transaction with all the wallet’s signers.
0 commit comments