wallet: Store a copy of m_from_me in WalletTXOs and use for "from me"

Since we need to know whether the transaction that creates a WalletTXO
is "from me", we should store this state in the WalletTXO too, copied
from its parent CWalletTx.
This commit is contained in:
Ava Chow 2024-02-20 11:54:39 -05:00
parent ba24bf61cd
commit 78d97b0aed
3 changed files with 8 additions and 4 deletions

View file

@ -322,7 +322,7 @@ std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet)
if (wallet.IsTXOInImmatureCoinBase(txo)) continue;
int nDepth = wallet.GetTxStateDepthInMainChain(txo.GetState());
if (nDepth < (CheckIsFromMeMap(txo.GetWalletTx().m_from_me, ISMINE_ALL) ? 0 : 1)) continue;
if (nDepth < (CheckIsFromMeMap(txo.GetTxFromMe(), ISMINE_ALL) ? 0 : 1)) continue;
CTxDestination addr;
Assume(wallet.IsMine(txo.GetTxOut()));

View file

@ -380,14 +380,16 @@ private:
isminetype m_ismine;
TxState m_tx_state;
bool m_tx_coinbase;
std::map<isminefilter, bool> m_tx_from_me;
public:
WalletTXO(const CWalletTx& wtx, const CTxOut& output, const isminetype ismine, const TxState& state, bool coinbase)
WalletTXO(const CWalletTx& wtx, const CTxOut& output, const isminetype ismine, const TxState& state, bool coinbase, const std::map<isminefilter, bool>& tx_from_me)
: m_wtx(wtx),
m_output(output),
m_ismine(ismine),
m_tx_state(state),
m_tx_coinbase(coinbase)
m_tx_coinbase(coinbase),
m_tx_from_me(tx_from_me)
{}
const CWalletTx& GetWalletTx() const { return m_wtx; }
@ -401,6 +403,8 @@ public:
void SetState(const TxState& state) { m_tx_state = state; }
bool IsTxCoinBase() const { return m_tx_coinbase; }
const std::map<isminefilter, bool>& GetTxFromMe() const { return m_tx_from_me; }
};
} // namespace wallet

View file

@ -4709,7 +4709,7 @@ void CWallet::RefreshSingleTxTXOs(const CWalletTx& wtx)
it->second.SetIsMine(ismine);
it->second.SetState(wtx.m_state);
} else {
m_txos.emplace(outpoint, WalletTXO{wtx, txout, ismine, wtx.m_state, wtx.IsCoinBase()});
m_txos.emplace(outpoint, WalletTXO{wtx, txout, ismine, wtx.m_state, wtx.IsCoinBase(), wtx.m_from_me});
}
}
}