@@ -913,11 +913,10 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
913
913
CWalletTx& wtx = (*ret.first ).second ;
914
914
wtx.BindWallet (this );
915
915
bool fInsertedNew = ret.second ;
916
- if (fInsertedNew )
917
- {
916
+ if (fInsertedNew ) {
918
917
wtx.nTimeReceived = GetAdjustedTime ();
919
918
wtx.nOrderPos = IncOrderPosNext (&walletdb);
920
- wtxOrdered.insert (std::make_pair (wtx.nOrderPos , TxPair (&wtx, nullptr )));
919
+ wtx. m_it_wtxOrdered = wtxOrdered.insert (std::make_pair (wtx.nOrderPos , TxPair (&wtx, nullptr )));
921
920
wtx.nTimeSmart = ComputeTimeSmart (wtx);
922
921
AddToSpends (hash);
923
922
}
@@ -987,9 +986,12 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
987
986
bool CWallet::LoadToWallet (const CWalletTx& wtxIn)
988
987
{
989
988
uint256 hash = wtxIn.GetHash ();
990
- CWalletTx& wtx = mapWallet.emplace (hash, wtxIn).first ->second ;
989
+ const auto & ins = mapWallet.emplace (hash, wtxIn);
990
+ CWalletTx& wtx = ins.first ->second ;
991
991
wtx.BindWallet (this );
992
- wtxOrdered.insert (std::make_pair (wtx.nOrderPos , TxPair (&wtx, nullptr )));
992
+ if (/* insertion took place */ ins.second ) {
993
+ wtx.m_it_wtxOrdered = wtxOrdered.insert (std::make_pair (wtx.nOrderPos , TxPair (&wtx, nullptr )));
994
+ }
993
995
AddToSpends (hash);
994
996
for (const CTxIn& txin : wtx.tx ->vin ) {
995
997
auto it = mapWallet.find (txin.prevout .hash );
@@ -3123,8 +3125,11 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
3123
3125
{
3124
3126
AssertLockHeld (cs_wallet); // mapWallet
3125
3127
DBErrors nZapSelectTxRet = CWalletDB (*dbw," cr+" ).ZapSelectTx (vHashIn, vHashOut);
3126
- for (uint256 hash : vHashOut)
3127
- mapWallet.erase (hash);
3128
+ for (uint256 hash : vHashOut) {
3129
+ const auto & it = mapWallet.find (hash);
3130
+ wtxOrdered.erase (it->second .m_it_wtxOrdered );
3131
+ mapWallet.erase (it);
3132
+ }
3128
3133
3129
3134
if (nZapSelectTxRet == DB_NEED_REWRITE)
3130
3135
{
0 commit comments