diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -580,11 +580,10 @@ int nMinOrderPos = std::numeric_limits::max(); const CWalletTx *copyFrom = nullptr; for (TxSpends::iterator it = range.first; it != range.second; ++it) { - const TxId &txid = it->second; - int n = mapWallet[txid].nOrderPos; - if (n < nMinOrderPos) { - nMinOrderPos = n; - copyFrom = &mapWallet[txid]; + const CWalletTx *wtx = &mapWallet[it->second]; + if (wtx->nOrderPos < nMinOrderPos) { + nMinOrderPos = wtx->nOrderPos; + copyFrom = wtx; } } @@ -1011,9 +1010,7 @@ bool CWallet::LoadToWallet(const CWalletTx &wtxIn) { const TxId &txid = wtxIn.GetId(); - - mapWallet[txid] = wtxIn; - CWalletTx &wtx = mapWallet[txid]; + CWalletTx &wtx = mapWallet.emplace(txid, wtxIn).first->second; wtx.BindWallet(this); wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr))); AddToSpends(txid);