@@ -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.
@@ -246,6 +246,34 @@ impl From<&OutPoint> for BdkOutPoint {
246246 }
247247}
248248
249+ pub struct Balance {
250+ // All coinbase outputs not yet matured
251+ pub immature : u64 ,
252+ /// Unconfirmed UTXOs generated by a wallet tx
253+ pub trusted_pending : u64 ,
254+ /// Unconfirmed UTXOs received from an external wallet
255+ pub untrusted_pending : u64 ,
256+ /// Confirmed and immediately spendable balance
257+ pub confirmed : u64 ,
258+ /// Get sum of trusted_pending and confirmed coins
259+ pub spendable : u64 ,
260+ /// Get the whole balance visible to the wallet
261+ pub total : u64 ,
262+ }
263+
264+ impl From < BdkBalance > for Balance {
265+ fn from ( bdk_balance : BdkBalance ) -> Self {
266+ Balance {
267+ immature : bdk_balance. immature ,
268+ trusted_pending : bdk_balance. trusted_pending ,
269+ untrusted_pending : bdk_balance. untrusted_pending ,
270+ confirmed : bdk_balance. confirmed ,
271+ spendable : bdk_balance. get_spendable ( ) ,
272+ total : bdk_balance. get_total ( ) ,
273+ }
274+ }
275+ }
276+
249277/// A transaction output, which defines new coins to be created from old ones.
250278pub struct TxOut {
251279 /// The value of the output, in satoshis.
@@ -402,8 +430,8 @@ impl Wallet {
402430
403431 /// Return the balance, meaning the sum of this wallet’s unspent outputs’ values. Note that this method only operates
404432 /// on the internal database, which first needs to be Wallet.sync manually.
405- fn get_balance ( & self ) -> Result < u64 , Error > {
406- self . get_wallet ( ) . get_balance ( )
433+ fn get_balance ( & self ) -> Result < Balance , Error > {
434+ self . get_wallet ( ) . get_balance ( ) . map ( |b| b . into ( ) )
407435 }
408436
409437 /// Sign a transaction with all the wallet’s signers.
0 commit comments