Skip to content

Commit d64922b

Browse files
committed
wallet refactor: use CWalletTx member functions to determine tx state
1 parent ffe5ff1 commit d64922b

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

src/wallet/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ WalletTxStatus MakeWalletTxStatus(const CWallet& wallet, const CWalletTx& wtx)
101101
result.is_trusted = CachedTxIsTrusted(wallet, wtx);
102102
result.is_abandoned = wtx.isAbandoned();
103103
result.is_coinbase = wtx.IsCoinBase();
104-
result.is_in_main_chain = wallet.IsTxInMainChain(wtx);
104+
result.is_in_main_chain = wtx.isConfirmed();
105105
return result;
106106
}
107107

src/wallet/receive.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ CAmount CachedTxGetImmatureCredit(const CWallet& wallet, const CWalletTx& wtx, c
149149
{
150150
AssertLockHeld(wallet.cs_wallet);
151151

152-
if (wallet.IsTxImmatureCoinBase(wtx) && wallet.IsTxInMainChain(wtx)) {
152+
if (wallet.IsTxImmatureCoinBase(wtx) && wtx.isConfirmed()) {
153153
return GetCachableAmount(wallet, wtx, CWalletTx::IMMATURE_CREDIT, filter);
154154
}
155155

@@ -256,9 +256,8 @@ bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminef
256256
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uint256>& trusted_parents)
257257
{
258258
AssertLockHeld(wallet.cs_wallet);
259-
int nDepth = wallet.GetTxDepthInMainChain(wtx);
260-
if (nDepth >= 1) return true;
261-
if (nDepth < 0) return false;
259+
if (wtx.isConfirmed()) return true;
260+
if (wtx.isBlockConflicted()) return false;
262261
// using wtx's cached debit
263262
if (!wallet.m_spend_zero_conf_change || !CachedTxIsFromMe(wallet, wtx, ISMINE_ALL)) return false;
264263

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,8 @@ bool CWallet::IsSpent(const COutPoint& outpoint) const
752752
const uint256& wtxid = it->second;
753753
const auto mit = mapWallet.find(wtxid);
754754
if (mit != mapWallet.end()) {
755-
int depth = GetTxDepthInMainChain(mit->second);
756-
if (depth > 0 || (depth == 0 && !mit->second.isAbandoned()))
755+
const auto& wtx = mit->second;
756+
if (!wtx.isAbandoned() && !wtx.isBlockConflicted())
757757
return true; // Spent
758758
}
759759
}

src/wallet/wallet.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
515515
* referenced in transaction, and might cause assert failures.
516516
*/
517517
int GetTxDepthInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
518-
bool IsTxInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
519-
{
520-
AssertLockHeld(cs_wallet);
521-
return GetTxDepthInMainChain(wtx) > 0;
522-
}
523518

524519
/**
525520
* @return number of blocks to maturity for this transaction:

0 commit comments

Comments
 (0)