-
Notifications
You must be signed in to change notification settings - Fork 11
fix: unify immature balance tracking with remaining balances #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,18 +268,21 @@ impl ManagedAccount { | |
| pub fn update_balance(&mut self, synced_height: u32) { | ||
| let mut spendable = 0; | ||
| let mut unconfirmed = 0; | ||
| let mut immature = 0; | ||
| let mut locked = 0; | ||
| for utxo in self.utxos.values() { | ||
| let value = utxo.txout.value; | ||
| if utxo.is_locked { | ||
| locked += value; | ||
| } else if !utxo.is_mature(synced_height) { | ||
| immature += value; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally the check for immature balance was fn immature_balance(&self) -> u64 {
self.utxos()
.iter()
.filter(|utxo| utxo.is_coinbase && !utxo.is_mature(self.synced_height()))
.map(|utxo| utxo.value())
.sum()
}Is it safe to skip the utxo.is_coinbase check??
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's implied. Basically only coinbase can be immature and there is a |
||
| } else if utxo.is_spendable(synced_height) { | ||
| spendable += value; | ||
| } else { | ||
| unconfirmed += value; | ||
| } | ||
| } | ||
| self.balance = WalletBalance::new(spendable, unconfirmed, locked); | ||
| self.balance = WalletBalance::new(spendable, unconfirmed, immature, locked); | ||
| self.metadata.last_used = Some(Self::current_timestamp()); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| use crate::account::StandardAccountType; | ||
| use crate::managed_account::address_pool::{AddressPool, AddressPoolType, KeySource}; | ||
| use crate::managed_account::managed_account_type::ManagedAccountType; | ||
| use crate::managed_account::ManagedAccount; | ||
| use crate::{DerivationPath, Network}; | ||
|
|
||
| impl ManagedAccount { | ||
| /// Create a test managed account with a standard BIP44 type and empty address pools | ||
| pub fn new_test_bip44(network: Network) -> Self { | ||
| let base_path = DerivationPath::master(); | ||
|
|
||
| let external_pool = AddressPool::new( | ||
| base_path.clone(), | ||
| AddressPoolType::External, | ||
| 20, | ||
| network, | ||
| &KeySource::NoKeySource, | ||
| ) | ||
| .expect("Failed to create external address pool"); | ||
|
|
||
| let internal_pool = AddressPool::new( | ||
| base_path, | ||
| AddressPoolType::Internal, | ||
| 20, | ||
| network, | ||
| &KeySource::NoKeySource, | ||
| ) | ||
| .expect("Failed to create internal address pool"); | ||
|
|
||
| let account_type = ManagedAccountType::Standard { | ||
| index: 0, | ||
| standard_account_type: StandardAccountType::BIP44Account, | ||
| external_addresses: external_pool, | ||
| internal_addresses: internal_pool, | ||
| }; | ||
|
|
||
| ManagedAccount::new(account_type, network, false) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| mod account; | ||
| mod address; | ||
| mod utxo; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.