Skip to content
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

[Wallet] Fix staking balance calculation #1369

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/wallet/wallet.cpp
Expand Up @@ -1701,7 +1701,7 @@ void CWallet::ResendWalletTransactions()
* @{
*/

CAmount CWallet::loopTxsBalance(std::function<void(const uint256&, const CWalletTx&, CAmount&)>method) const
CAmount CWallet::loopTxsBalance(std::function<void(const uint256&, const CWalletTx&, CAmount&)> method) const
{
CAmount nTotal = 0;
{
Expand Down Expand Up @@ -1731,7 +1731,16 @@ CAmount CWallet::GetColdStakingBalance() const

CAmount CWallet::GetStakingBalance(const bool fIncludeColdStaking) const
{
return GetBalance() + (fIncludeColdStaking ? GetColdStakingBalance() : 0);
return std::max(CAmount(0), loopTxsBalance(
[fIncludeColdStaking](const uint256& id, const CWalletTx& pcoin, CAmount& nTotal) {
if (pcoin.IsTrusted() && pcoin.GetDepthInMainChain() >= Params().GetConsensus().nStakeMinDepth) {
nTotal += pcoin.GetAvailableCredit(); // available coins
nTotal -= pcoin.GetStakeDelegationCredit(); // minus delegated coins, if any
nTotal -= pcoin.GetLockedCredit(); // minus locked coins, if any
if (fIncludeColdStaking)
nTotal += pcoin.GetColdStakingCredit(); // plus cold coins, if any and if requested
}
}));
}

CAmount CWallet::GetDelegatedBalance() const
Expand Down