@@ -1968,7 +1968,7 @@ CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
19681968 return 0 ;
19691969}
19701970
1971- CAmount CWalletTx::GetAvailableCredit (bool fUseCache ) const
1971+ CAmount CWalletTx::GetAvailableCredit (bool fUseCache , const isminefilter& filter ) const
19721972{
19731973 if (pwallet == nullptr )
19741974 return 0 ;
@@ -1977,8 +1977,17 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const
19771977 if (IsCoinBase () && GetBlocksToMaturity () > 0 )
19781978 return 0 ;
19791979
1980- if (fUseCache && fAvailableCreditCached )
1981- return nAvailableCreditCached;
1980+ CAmount* cache = nullptr ;
1981+ bool * cache_used = nullptr ;
1982+
1983+ if (filter == ISMINE_SPENDABLE) {
1984+ cache = &nAvailableCreditCached;
1985+ cache_used = &fAvailableCreditCached ;
1986+ }
1987+
1988+ if (fUseCache && cache_used && *cache_used) {
1989+ return *cache;
1990+ }
19821991
19831992 CAmount nCredit = 0 ;
19841993 uint256 hashTx = GetHash ();
@@ -1987,14 +1996,16 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const
19871996 if (!pwallet->IsSpent (hashTx, i))
19881997 {
19891998 const CTxOut &txout = tx->vout [i];
1990- nCredit += pwallet->GetCredit (txout, ISMINE_SPENDABLE );
1999+ nCredit += pwallet->GetCredit (txout, filter );
19912000 if (!MoneyRange (nCredit))
19922001 throw std::runtime_error (std::string (__func__) + " : value out of range" );
19932002 }
19942003 }
19952004
1996- nAvailableCreditCached = nCredit;
1997- fAvailableCreditCached = true ;
2005+ if (cache) {
2006+ *cache = nCredit;
2007+ *cache_used = true ;
2008+ }
19982009 return nCredit;
19992010}
20002011
@@ -2154,16 +2165,17 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman
21542165 */
21552166
21562167
2157- CAmount CWallet::GetBalance () const
2168+ CAmount CWallet::GetBalance (const isminefilter& filter ) const
21582169{
21592170 CAmount nTotal = 0 ;
21602171 {
21612172 LOCK2 (cs_main, cs_wallet);
21622173 for (const auto & entry : mapWallet)
21632174 {
21642175 const CWalletTx* pcoin = &entry.second ;
2165- if (pcoin->IsTrusted ())
2166- nTotal += pcoin->GetAvailableCredit ();
2176+ if (pcoin->IsTrusted ()) {
2177+ nTotal += pcoin->GetAvailableCredit (true , filter);
2178+ }
21672179 }
21682180 }
21692181
0 commit comments