refactor: restructure balance
This commit is contained in:
@@ -49,18 +49,18 @@ enum ChangeSpendPolicy {
|
||||
"ChangeForbidden"
|
||||
};
|
||||
|
||||
interface Balance {
|
||||
u64 immature();
|
||||
dictionary Balance {
|
||||
u64 immature;
|
||||
|
||||
u64 trusted_pending();
|
||||
u64 trusted_pending;
|
||||
|
||||
u64 untrusted_pending();
|
||||
u64 untrusted_pending;
|
||||
|
||||
u64 confirmed();
|
||||
u64 confirmed;
|
||||
|
||||
u64 trusted_spendable();
|
||||
u64 trusted_spendable;
|
||||
|
||||
u64 total();
|
||||
u64 total;
|
||||
};
|
||||
|
||||
dictionary AddressInfo {
|
||||
|
||||
@@ -177,47 +177,33 @@ impl From<&BdkAddressIndex> for AddressIndex {
|
||||
// }
|
||||
|
||||
pub struct Balance {
|
||||
pub inner: BdkBalance,
|
||||
// All coinbase outputs not yet matured
|
||||
pub immature: u64,
|
||||
/// Unconfirmed UTXOs generated by a wallet tx
|
||||
pub trusted_pending: u64,
|
||||
/// Unconfirmed UTXOs received from an external wallet
|
||||
pub untrusted_pending: u64,
|
||||
/// Confirmed and immediately spendable balance
|
||||
pub confirmed: u64,
|
||||
/// Get sum of trusted_pending and confirmed coins
|
||||
pub trusted_spendable: u64,
|
||||
/// Get the whole balance visible to the wallet
|
||||
pub total: u64,
|
||||
}
|
||||
|
||||
impl Balance {
|
||||
/// All coinbase outputs not yet matured.
|
||||
fn immature(&self) -> u64 {
|
||||
self.inner.immature
|
||||
}
|
||||
|
||||
/// Unconfirmed UTXOs generated by a wallet tx.
|
||||
fn trusted_pending(&self) -> u64 {
|
||||
self.inner.trusted_pending
|
||||
}
|
||||
|
||||
/// Unconfirmed UTXOs received from an external wallet.
|
||||
fn untrusted_pending(&self) -> u64 {
|
||||
self.inner.untrusted_pending
|
||||
}
|
||||
|
||||
/// Confirmed and immediately spendable balance.
|
||||
fn confirmed(&self) -> u64 {
|
||||
self.inner.confirmed
|
||||
}
|
||||
|
||||
/// Get sum of trusted_pending and confirmed coins.
|
||||
fn trusted_spendable(&self) -> u64 {
|
||||
self.inner.trusted_spendable()
|
||||
}
|
||||
|
||||
/// Get the whole balance visible to the wallet.
|
||||
fn total(&self) -> u64 {
|
||||
self.inner.total()
|
||||
impl From<BdkBalance> for Balance {
|
||||
fn from(bdk_balance: BdkBalance) -> Self {
|
||||
Balance {
|
||||
immature: bdk_balance.immature,
|
||||
trusted_pending: bdk_balance.trusted_pending,
|
||||
untrusted_pending: bdk_balance.untrusted_pending,
|
||||
confirmed: bdk_balance.confirmed,
|
||||
trusted_spendable: bdk_balance.trusted_spendable(),
|
||||
total: bdk_balance.total(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl From<BdkBalance> for Balance {
|
||||
// fn from(bdk_balance: BdkBalance) -> Self {
|
||||
// Balance { inner: bdk_balance }
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// A transaction output, which defines new coins to be created from old ones.
|
||||
// #[derive(Debug, Clone)]
|
||||
// pub struct TxOut {
|
||||
|
||||
@@ -55,11 +55,9 @@ impl Wallet {
|
||||
.into()
|
||||
}
|
||||
|
||||
// TODO 16: Why is the Arc required here?
|
||||
pub fn get_balance(&self) -> Arc<Balance> {
|
||||
let bdk_balance = self.get_wallet().get_balance();
|
||||
let balance = Balance { inner: bdk_balance };
|
||||
Arc::new(balance)
|
||||
pub fn get_balance(&self) -> Balance {
|
||||
let bdk_balance: bdk::wallet::Balance = self.get_wallet().get_balance();
|
||||
Balance::from(bdk_balance)
|
||||
}
|
||||
|
||||
pub fn apply_update(&self, update: Arc<Update>) -> Result<(), BdkError> {
|
||||
|
||||
Reference in New Issue
Block a user