diff options
author | John Newbery <john@johnnewbery.com> | 2018-06-27 11:46:27 -0400 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2018-06-28 17:56:57 -0400 |
commit | 7110c830f8c5de3570178bf4e5d28fe3e4f109e1 (patch) | |
tree | 0c8b6fc0cea2a16974e374f47b0878e8fcc2a439 /src/wallet | |
parent | ef7bc8893c7a953953aa457736d79c28a4f45792 (diff) | |
download | bitcoin-7110c830f8c5de3570178bf4e5d28fe3e4f109e1.tar.xz |
[wallet] deduplicate GetAvailableCredit logic
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet.cpp | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f999394062..4d3263671c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1983,6 +1983,9 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter if (filter == ISMINE_SPENDABLE) { cache = &nAvailableCreditCached; cache_used = &fAvailableCreditCached; + } else if (filter == ISMINE_WATCH_ONLY) { + cache = &nAvailableWatchCreditCached; + cache_used = &fAvailableWatchCreditCached; } if (fUseCache && cache_used && *cache_used) { @@ -2025,31 +2028,7 @@ CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const CAmount CWalletTx::GetAvailableWatchOnlyCredit(const bool fUseCache) const { - if (pwallet == nullptr) - return 0; - - // Must wait until coinbase is safely deep enough in the chain before valuing it - if (IsCoinBase() && GetBlocksToMaturity() > 0) - return 0; - - if (fUseCache && fAvailableWatchCreditCached) - return nAvailableWatchCreditCached; - - CAmount nCredit = 0; - for (unsigned int i = 0; i < tx->vout.size(); i++) - { - if (!pwallet->IsSpent(GetHash(), i)) - { - const CTxOut &txout = tx->vout[i]; - nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); - if (!MoneyRange(nCredit)) - throw std::runtime_error(std::string(__func__) + ": value out of range"); - } - } - - nAvailableWatchCreditCached = nCredit; - fAvailableWatchCreditCached = true; - return nCredit; + return GetAvailableCredit(fUseCache, ISMINE_WATCH_ONLY); } CAmount CWalletTx::GetChange() const |