@@ -1028,19 +1028,6 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
1028
1028
return true ;
1029
1029
}
1030
1030
1031
- /* *
1032
- * Add a transaction to the wallet, or update it. pIndex and posInBlock should
1033
- * be set when the transaction was known to be included in a block. When
1034
- * pIndex == nullptr, then wallet state is not updated in AddToWallet, but
1035
- * notifications happen and cached balances are marked dirty.
1036
- *
1037
- * If fUpdate is true, existing transactions will be updated.
1038
- * TODO: One exception to this is that the abandoned state is cleared under the
1039
- * assumption that any further notification of a transaction that was considered
1040
- * abandoned is an indication that it is not safe to be considered abandoned.
1041
- * Abandoned state should probably be more carefully tracked via different
1042
- * posInBlock signals or by checking mempool presence when necessary.
1043
- */
1044
1031
bool CWallet::AddToWalletIfInvolvingMe (const CTransactionRef& ptx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate )
1045
1032
{
1046
1033
const CTransaction& tx = *ptx;
@@ -1107,6 +1094,16 @@ bool CWallet::TransactionCanBeAbandoned(const uint256& hashTx) const
1107
1094
return wtx && !wtx->isAbandoned () && wtx->GetDepthInMainChain () == 0 && !wtx->InMempool ();
1108
1095
}
1109
1096
1097
+ void CWallet::MarkInputsDirty (const CTransactionRef& tx)
1098
+ {
1099
+ for (const CTxIn& txin : tx->vin ) {
1100
+ auto it = mapWallet.find (txin.prevout .hash );
1101
+ if (it != mapWallet.end ()) {
1102
+ it->second .MarkDirty ();
1103
+ }
1104
+ }
1105
+ }
1106
+
1110
1107
bool CWallet::AbandonTransaction (const uint256& hashTx)
1111
1108
{
1112
1109
LOCK2 (cs_main, cs_wallet);
@@ -1155,13 +1152,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
1155
1152
}
1156
1153
// If a transaction changes 'conflicted' state, that changes the balance
1157
1154
// 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
- }
1155
+ MarkInputsDirty (wtx.tx );
1165
1156
}
1166
1157
}
1167
1158
@@ -1217,31 +1208,19 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
1217
1208
}
1218
1209
// If a transaction changes 'conflicted' state, that changes the balance
1219
1210
// 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
- }
1211
+ MarkInputsDirty (wtx.tx );
1226
1212
}
1227
1213
}
1228
1214
}
1229
1215
1230
1216
void CWallet::SyncTransaction (const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock, bool update_tx) {
1231
- const CTransaction& tx = *ptx;
1232
-
1233
1217
if (!AddToWalletIfInvolvingMe (ptx, pindex, posInBlock, update_tx))
1234
1218
return ; // Not one of ours
1235
1219
1236
1220
// If a transaction changes 'conflicted' state, that changes the balance
1237
1221
// available of the outputs it spends. So force those to be
1238
1222
// 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
- }
1223
+ MarkInputsDirty (ptx);
1245
1224
}
1246
1225
1247
1226
void CWallet::TransactionAddedToMempool (const CTransactionRef& ptx) {
0 commit comments