Skip to content

Commit

Permalink
[Wallet] Fix staking balance calculation
Browse files Browse the repository at this point in the history
exclude delegated balance and locked coins (if any)
  • Loading branch information
random-zebra committed Mar 3, 2020
1 parent 1517dbe commit b496d04
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit b496d04

Please sign in to comment.