Skip to content

Commit b7f5650

Browse files
committed
Extract CWallet::MarkInputsDirty
To avoid repeated implementations.
1 parent 619cd29 commit b7f5650

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/wallet/wallet.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,16 @@ bool CWallet::TransactionCanBeAbandoned(const uint256& hashTx) const
11071107
return wtx && !wtx->isAbandoned() && wtx->GetDepthInMainChain() == 0 && !wtx->InMempool();
11081108
}
11091109

1110+
void CWallet::MarkInputsDirty(const CTransactionRef& tx)
1111+
{
1112+
for (const CTxIn& txin : tx->vin) {
1113+
auto it = mapWallet.find(txin.prevout.hash);
1114+
if (it != mapWallet.end()) {
1115+
it->second.MarkDirty();
1116+
}
1117+
}
1118+
}
1119+
11101120
bool CWallet::AbandonTransaction(const uint256& hashTx)
11111121
{
11121122
LOCK2(cs_main, cs_wallet);
@@ -1155,13 +1165,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
11551165
}
11561166
// If a transaction changes 'conflicted' state, that changes the balance
11571167
// available of the outputs it spends. So force those to be recomputed
1158-
for (const CTxIn& txin : wtx.tx->vin)
1159-
{
1160-
auto it = mapWallet.find(txin.prevout.hash);
1161-
if (it != mapWallet.end()) {
1162-
it->second.MarkDirty();
1163-
}
1164-
}
1168+
MarkInputsDirty(wtx.tx);
11651169
}
11661170
}
11671171

@@ -1217,31 +1221,19 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
12171221
}
12181222
// If a transaction changes 'conflicted' state, that changes the balance
12191223
// available of the outputs it spends. So force those to be recomputed
1220-
for (const CTxIn& txin : wtx.tx->vin) {
1221-
auto it = mapWallet.find(txin.prevout.hash);
1222-
if (it != mapWallet.end()) {
1223-
it->second.MarkDirty();
1224-
}
1225-
}
1224+
MarkInputsDirty(wtx.tx);
12261225
}
12271226
}
12281227
}
12291228

12301229
void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock, bool update_tx) {
1231-
const CTransaction& tx = *ptx;
1232-
12331230
if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, update_tx))
12341231
return; // Not one of ours
12351232

12361233
// If a transaction changes 'conflicted' state, that changes the balance
12371234
// available of the outputs it spends. So force those to be
12381235
// recomputed, also:
1239-
for (const CTxIn& txin : tx.vin) {
1240-
auto it = mapWallet.find(txin.prevout.hash);
1241-
if (it != mapWallet.end()) {
1242-
it->second.MarkDirty();
1243-
}
1244-
}
1236+
MarkInputsDirty(ptx);
12451237
}
12461238

12471239
void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) {

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,9 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
706706
/* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
707707
void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
708708

709+
/* Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed */
710+
void MarkInputsDirty(const CTransactionRef& tx);
711+
709712
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
710713

711714
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions.

0 commit comments

Comments
 (0)