Skip to content
Merged
Show file tree
Hide file tree
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: 9 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,9 @@ UniValue getreceivedbylabel(const JSONRPCRequest& request)

UniValue getbalance(const JSONRPCRequest& request)
{
if (request.fHelp || (request.params.size() > 4 && IsDeprecatedRPCEnabled("accounts")) || (request.params.size() != 0 && !IsDeprecatedRPCEnabled("accounts")))
if (request.fHelp ||
(request.params.size() > 4 && IsDeprecatedRPCEnabled("accounts")) ||
(request.params.size() > 3 && !IsDeprecatedRPCEnabled("accounts")))
throw std::runtime_error(
"getbalance ( \"account\" minconf includeWatchonly includeDelegated )\n"
"\nIf account is not specified, returns the server's total available balance (excluding zerocoins).\n"
Expand Down Expand Up @@ -1544,9 +1546,12 @@ UniValue getbalance(const JSONRPCRequest& request)
return ValueFromAmount(pwalletMain->GetLegacyBalance(filter, nMinDepth, account));
}

// TODO: re-incorporate the includeDelegated argument
// after 4.2 branch off for 5.0
return ValueFromAmount(pwalletMain->GetAvailableBalance());
const int paramsSize = request.params.size();
const int nMinDepth = (paramsSize > 0 ? request.params[0].get_int() : 0);
isminefilter filter = ISMINE_SPENDABLE | (paramsSize > 1 && request.params[1].get_bool() ? ISMINE_WATCH_ONLY : ISMINE_NO);
filter |= (paramsSize <= 2 || request.params[2].get_bool() ? ISMINE_SPENDABLE_DELEGATED : ISMINE_NO);

return ValueFromAmount(pwalletMain->GetAvailableBalance(filter, true, nMinDepth));
}

UniValue getcoldstakingbalance(const JSONRPCRequest& request)
Expand Down
15 changes: 11 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,10 +1814,17 @@ CAmount CWallet::loopTxsBalance(std::function<void(const uint256&, const CWallet

CAmount CWallet::GetAvailableBalance(bool fIncludeDelegated) const
{
isminetype filter = fIncludeDelegated ? ISMINE_SPENDABLE_ALL : ISMINE_SPENDABLE;
return loopTxsBalance([filter](const uint256& id, const CWalletTx& pcoin, CAmount& nTotal){
if (pcoin.IsTrusted()) {
nTotal += pcoin.GetAvailableCredit(true, filter);
isminefilter filter = fIncludeDelegated ? ISMINE_SPENDABLE_ALL : ISMINE_SPENDABLE;
return GetAvailableBalance(filter, true, 0);
}

CAmount CWallet::GetAvailableBalance(isminefilter& filter, bool useCache, int minDepth) const
{
return loopTxsBalance([filter, useCache, minDepth](const uint256& id, const CWalletTx& pcoin, CAmount& nTotal){
bool fConflicted;
int depth;
if (pcoin.IsTrusted(depth, fConflicted) && depth >= minDepth) {
nTotal += pcoin.GetAvailableCredit(useCache, filter);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface

CAmount loopTxsBalance(std::function<void(const uint256&, const CWalletTx&, CAmount&)>method) const;
CAmount GetAvailableBalance(bool fIncludeDelegated = true) const;
CAmount GetAvailableBalance(isminefilter& filter, bool useCache = false, int minDepth = 1) const;
CAmount GetColdStakingBalance() const; // delegated coins for which we have the staking key
CAmount GetImmatureColdStakingBalance() const;
CAmount GetStakingBalance(const bool fIncludeColdStaking = true) const;
Expand Down