Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
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