@@ -1970,37 +1970,38 @@ bool CWalletTx::InMempool() const
1970
1970
1971
1971
bool CWalletTx::IsTrusted () const
1972
1972
{
1973
- std::set<uint256> s;
1974
- return IsTrusted (s);
1973
+ std::set<uint256> trusted_parents;
1974
+ LOCK (pwallet->cs_wallet );
1975
+ return pwallet->IsTrusted (*this , trusted_parents);
1975
1976
}
1976
1977
1977
- bool CWalletTx ::IsTrusted (std::set<uint256>& trusted_parents) const
1978
+ bool CWallet ::IsTrusted (const CWalletTx& wtx, std::set<uint256>& trusted_parents) const
1978
1979
{
1980
+ AssertLockHeld (cs_wallet);
1979
1981
// Quick answer in most cases
1980
- if (!pwallet-> chain ().checkFinalTx (*tx)) return false ;
1981
- int nDepth = GetDepthInMainChain ();
1982
+ if (!chain ().checkFinalTx (*wtx. tx )) return false ;
1983
+ int nDepth = wtx. GetDepthInMainChain ();
1982
1984
if (nDepth >= 1 ) return true ;
1983
1985
if (nDepth < 0 ) return false ;
1984
1986
// using wtx's cached debit
1985
- if (!pwallet-> m_spend_zero_conf_change || !IsFromMe (ISMINE_ALL)) return false ;
1987
+ if (!m_spend_zero_conf_change || !wtx. IsFromMe (ISMINE_ALL)) return false ;
1986
1988
1987
1989
// Don't trust unconfirmed transactions from us unless they are in the mempool.
1988
- if (!InMempool ()) return false ;
1990
+ if (!wtx. InMempool ()) return false ;
1989
1991
1990
1992
// Trusted if all inputs are from us and are in the mempool:
1991
- LOCK (pwallet->cs_wallet );
1992
- for (const CTxIn& txin : tx->vin )
1993
+ for (const CTxIn& txin : wtx.tx ->vin )
1993
1994
{
1994
1995
// Transactions not sent by us: not trusted
1995
- const CWalletTx* parent = pwallet-> GetWalletTx (txin.prevout .hash );
1996
+ const CWalletTx* parent = GetWalletTx (txin.prevout .hash );
1996
1997
if (parent == nullptr ) return false ;
1997
1998
const CTxOut& parentOut = parent->tx ->vout [txin.prevout .n ];
1998
1999
// Check that this specific input being spent is trusted
1999
- if (pwallet-> IsMine (parentOut) != ISMINE_SPENDABLE) return false ;
2000
+ if (IsMine (parentOut) != ISMINE_SPENDABLE) return false ;
2000
2001
// If we've already trusted this parent, continue
2001
2002
if (trusted_parents.count (parent->GetHash ())) continue ;
2002
2003
// Recurse to check that the parent is also trusted
2003
- if (!parent-> IsTrusted (trusted_parents)) return false ;
2004
+ if (!IsTrusted (*parent, trusted_parents)) return false ;
2004
2005
trusted_parents.insert (parent->GetHash ());
2005
2006
}
2006
2007
return true ;
@@ -2086,7 +2087,7 @@ CWallet::Balance CWallet::GetBalance(const int min_depth, bool avoid_reuse) cons
2086
2087
for (const auto & entry : mapWallet)
2087
2088
{
2088
2089
const CWalletTx& wtx = entry.second ;
2089
- const bool is_trusted{wtx. IsTrusted (trusted_parents)};
2090
+ const bool is_trusted{IsTrusted (wtx, trusted_parents)};
2090
2091
const int tx_depth{wtx.GetDepthInMainChain ()};
2091
2092
const CAmount tx_credit_mine{wtx.GetAvailableCredit (/* fUseCache */ true , ISMINE_SPENDABLE | reuse_filter)};
2092
2093
const CAmount tx_credit_watchonly{wtx.GetAvailableCredit (/* fUseCache */ true , ISMINE_WATCH_ONLY | reuse_filter)};
@@ -2154,7 +2155,7 @@ void CWallet::AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe, const
2154
2155
if (nDepth == 0 && !wtx.InMempool ())
2155
2156
continue ;
2156
2157
2157
- bool safeTx = wtx. IsTrusted (trusted_parents);
2158
+ bool safeTx = IsTrusted (wtx, trusted_parents);
2158
2159
2159
2160
// We should not consider coins from transactions that are replacing
2160
2161
// other transactions.
@@ -3353,7 +3354,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances() const
3353
3354
{
3354
3355
const CWalletTx& wtx = walletEntry.second ;
3355
3356
3356
- if (!wtx. IsTrusted (trusted_parents))
3357
+ if (!IsTrusted (wtx, trusted_parents))
3357
3358
continue ;
3358
3359
3359
3360
if (wtx.IsImmatureCoinBase ())
0 commit comments