@@ -1968,7 +1968,7 @@ CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
1968
1968
return 0 ;
1969
1969
}
1970
1970
1971
- CAmount CWalletTx::GetAvailableCredit (bool fUseCache ) const
1971
+ CAmount CWalletTx::GetAvailableCredit (bool fUseCache , const isminefilter& filter ) const
1972
1972
{
1973
1973
if (pwallet == nullptr )
1974
1974
return 0 ;
@@ -1977,8 +1977,17 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const
1977
1977
if (IsCoinBase () && GetBlocksToMaturity () > 0 )
1978
1978
return 0 ;
1979
1979
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
+ }
1982
1991
1983
1992
CAmount nCredit = 0 ;
1984
1993
uint256 hashTx = GetHash ();
@@ -1987,14 +1996,16 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const
1987
1996
if (!pwallet->IsSpent (hashTx, i))
1988
1997
{
1989
1998
const CTxOut &txout = tx->vout [i];
1990
- nCredit += pwallet->GetCredit (txout, ISMINE_SPENDABLE );
1999
+ nCredit += pwallet->GetCredit (txout, filter );
1991
2000
if (!MoneyRange (nCredit))
1992
2001
throw std::runtime_error (std::string (__func__) + " : value out of range" );
1993
2002
}
1994
2003
}
1995
2004
1996
- nAvailableCreditCached = nCredit;
1997
- fAvailableCreditCached = true ;
2005
+ if (cache) {
2006
+ *cache = nCredit;
2007
+ *cache_used = true ;
2008
+ }
1998
2009
return nCredit;
1999
2010
}
2000
2011
@@ -2154,16 +2165,17 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman
2154
2165
*/
2155
2166
2156
2167
2157
- CAmount CWallet::GetBalance () const
2168
+ CAmount CWallet::GetBalance (const isminefilter& filter ) const
2158
2169
{
2159
2170
CAmount nTotal = 0 ;
2160
2171
{
2161
2172
LOCK2 (cs_main, cs_wallet);
2162
2173
for (const auto & entry : mapWallet)
2163
2174
{
2164
2175
const CWalletTx* pcoin = &entry.second ;
2165
- if (pcoin->IsTrusted ())
2166
- nTotal += pcoin->GetAvailableCredit ();
2176
+ if (pcoin->IsTrusted ()) {
2177
+ nTotal += pcoin->GetAvailableCredit (true , filter);
2178
+ }
2167
2179
}
2168
2180
}
2169
2181
0 commit comments