@@ -569,11 +569,17 @@ std::set<uint256> CWallet::GetConflicts(const uint256& txid) const
569569 return result;
570570}
571571
572- bool CWallet::HasWalletSpend (const uint256& txid ) const
572+ bool CWallet::HasWalletSpend (const CTransactionRef& tx ) const
573573{
574574 AssertLockHeld (cs_wallet);
575- auto iter = mapTxSpends.lower_bound (COutPoint (txid, 0 ));
576- return (iter != mapTxSpends.end () && iter->first .hash == txid);
575+ const uint256& txid = tx->GetHash ();
576+ for (unsigned int i = 0 ; i < tx->vout .size (); ++i) {
577+ auto iter = mapTxSpends.find (COutPoint (txid, i));
578+ if (iter != mapTxSpends.end ()) {
579+ return true ;
580+ }
581+ }
582+ return false ;
577583}
578584
579585void CWallet::Flush ()
@@ -1191,12 +1197,13 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
11911197 batch.WriteTx (wtx);
11921198 NotifyTransactionChanged (wtx.GetHash (), CT_UPDATED);
11931199 // Iterate over all its outputs, and mark transactions in the wallet that spend them abandoned too
1194- TxSpends::const_iterator iter = mapTxSpends.lower_bound (COutPoint (now, 0 ));
1195- while (iter != mapTxSpends.end () && iter->first .hash == now) {
1196- if (!done.count (iter->second )) {
1197- todo.insert (iter->second );
1200+ for (unsigned int i = 0 ; i < wtx.tx ->vout .size (); ++i) {
1201+ std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range (COutPoint (now, i));
1202+ for (TxSpends::const_iterator iter = range.first ; iter != range.second ; ++iter) {
1203+ if (!done.count (iter->second )) {
1204+ todo.insert (iter->second );
1205+ }
11981206 }
1199- iter++;
12001207 }
12011208 // If a transaction changes 'conflicted' state, that changes the balance
12021209 // available of the outputs it spends. So force those to be recomputed
@@ -1242,12 +1249,13 @@ void CWallet::MarkConflicted(const uint256& hashBlock, int conflicting_height, c
12421249 wtx.MarkDirty ();
12431250 batch.WriteTx (wtx);
12441251 // Iterate over all its outputs, and mark transactions in the wallet that spend them conflicted too
1245- TxSpends::const_iterator iter = mapTxSpends.lower_bound (COutPoint (now, 0 ));
1246- while (iter != mapTxSpends.end () && iter->first .hash == now) {
1247- if (!done.count (iter->second )) {
1248- todo.insert (iter->second );
1249- }
1250- iter++;
1252+ for (unsigned int i = 0 ; i < wtx.tx ->vout .size (); ++i) {
1253+ std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range (COutPoint (now, i));
1254+ for (TxSpends::const_iterator iter = range.first ; iter != range.second ; ++iter) {
1255+ if (!done.count (iter->second )) {
1256+ todo.insert (iter->second );
1257+ }
1258+ }
12511259 }
12521260 // If a transaction changes 'conflicted' state, that changes the balance
12531261 // available of the outputs it spends. So force those to be recomputed
0 commit comments