diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8e63c60cfa6f..238f90b4a9d7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1701,7 +1701,7 @@ void CWallet::ResendWalletTransactions() * @{ */ -CAmount CWallet::loopTxsBalance(std::functionmethod) const +CAmount CWallet::loopTxsBalance(std::function method) const { CAmount nTotal = 0; { @@ -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