Skip to content

Commit

Permalink
wallet: add min/max conf filter to GetWatchOnlyBalance()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Jun 27, 2018
1 parent 7c1570d commit 61cb9c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,16 +2186,21 @@ CAmount CWallet::GetImmatureBalance() const
return nTotal;
}

CAmount CWallet::GetWatchOnlyBalance() const
CAmount CWallet::GetWatchOnlyBalance(int min_depth, int max_depth) const
{
CAmount nTotal = 0;
{
LOCK2(cs_main, cs_wallet);
for (const auto& entry : mapWallet)
{
const CWalletTx* pcoin = &entry.second;
if (pcoin->IsTrusted())
int depth = pcoin->GetDepthInMainChain();
if ( (min_depth == 0 && !pcoin->IsTrusted() && depth == 0 && pcoin->InMempool()) /* either 0 conf... */
||
(pcoin->IsTrusted() && (min_depth == 1 || depth >= min_depth) && (max_depth < 0 || depth <= max_depth)) /*... or within depth limits (if set) */
) {
nTotal += pcoin->GetAvailableWatchOnlyCredit();
}
}
}

Expand All @@ -2204,17 +2209,7 @@ CAmount CWallet::GetWatchOnlyBalance() const

CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const
{
CAmount nTotal = 0;
{
LOCK2(cs_main, cs_wallet);
for (const auto& entry : mapWallet)
{
const CWalletTx* pcoin = &entry.second;
if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool())
nTotal += pcoin->GetAvailableWatchOnlyCredit();
}
}
return nTotal;
return GetWatchOnlyBalance(0, 0);
}

CAmount CWallet::GetImmatureWatchOnlyBalance() const
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
CAmount GetBalance() const;
CAmount GetUnconfirmedBalance() const;
CAmount GetImmatureBalance() const;
CAmount GetWatchOnlyBalance() const;
CAmount GetWatchOnlyBalance(int min_depth = 1, int max_depth = -1 /* unlimited */) const;
CAmount GetUnconfirmedWatchOnlyBalance() const;
CAmount GetImmatureWatchOnlyBalance() const;
CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const;
Expand Down

0 comments on commit 61cb9c8

Please sign in to comment.