From f1aecdb9b200b65b891ce7f1285099a0c58edc67 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Wed, 27 Jun 2018 11:46:27 -0400 Subject: [PATCH] [wallet] deduplicate GetAvailableCredit logic (cherry picked from commit 7110c830f8c5de3570178bf4e5d28fe3e4f109e1) --- src/wallet/wallet.cpp | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c1600e269..c1689e901 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2992,6 +2992,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) { @@ -3034,31 +3037,7 @@ CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool& fUseCache) const CAmount CWalletTx::GetAvailableWatchOnlyCredit(const bool& fUseCache) const { - if (pwallet == 0) - 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 < vout.size(); i++) - { - if (!pwallet->IsSpent(GetHash(), i)) - { - const CTxOut &txout = vout[i]; - nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); - } - } - - nAvailableWatchCreditCached = nCredit; - fAvailableWatchCreditCached = true; - return nCredit; + return GetAvailableCredit(fUseCache, ISMINE_WATCH_ONLY); } CAmount CWalletTx::GetChange() const