diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -554,17 +554,16 @@ std::vector &vOutputs) { LOCK2(cs_main, wallet->cs_wallet); for (const COutPoint &outpoint : vOutpoints) { - if (!wallet->mapWallet.count(outpoint.GetTxId())) { + auto it = wallet->mapWallet.find(outpoint.GetTxId()); + if (it == wallet->mapWallet.end()) { continue; } - int nDepth = - wallet->mapWallet.at(outpoint.GetTxId()).GetDepthInMainChain(); + int nDepth = it->second.GetDepthInMainChain(); if (nDepth < 0) { continue; } - COutput out(&wallet->mapWallet.at(outpoint.GetTxId()), outpoint.GetN(), - nDepth, true /* spendable */, true /* solvable */, - true /* safe */); + COutput out(&it->second, outpoint.GetN(), nDepth, true /* spendable */, + true /* solvable */, true /* safe */); vOutputs.push_back(out); } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2291,12 +2291,13 @@ "Can't read block from disk"); } for (const CTransactionRef &tx : block.vtx) { - if (pwallet->mapWallet.count(tx->GetId()) > 0) { + auto it = pwallet->mapWallet.find(tx->GetId()); + if (it != pwallet->mapWallet.end()) { // We want all transactions regardless of confirmation count to // appear here, even negative confirmation ones, hence the big // negative. - ListTransactions(pwallet, pwallet->mapWallet.at(tx->GetId()), - "*", -100000000, true, removed, filter); + ListTransactions(pwallet, it->second, "*", -100000000, true, + removed, filter); } } paltindex = paltindex->pprev; @@ -2425,12 +2426,12 @@ } UniValue entry(UniValue::VOBJ); - if (!pwallet->mapWallet.count(txid)) { + auto it = pwallet->mapWallet.find(txid); + if (it == pwallet->mapWallet.end()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); } - - const CWalletTx &wtx = pwallet->mapWallet.at(txid); + const CWalletTx &wtx = it->second; Amount nCredit = wtx.GetCredit(filter); Amount nDebit = wtx.GetDebit(filter); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -650,8 +650,9 @@ } void CWallet::AddToSpends(const TxId &wtxid) { - assert(mapWallet.count(wtxid)); - CWalletTx &thisTx = mapWallet.at(wtxid); + auto it = mapWallet.find(wtxid); + assert(it != mapWallet.end()); + CWalletTx &thisTx = it->second; // Coinbases don't spend anything! if (thisTx.IsCoinBase()) { return; @@ -1023,8 +1024,9 @@ wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr))); AddToSpends(txid); for (const CTxIn &txin : wtx.tx->vin) { - if (mapWallet.count(txin.prevout.GetTxId())) { - CWalletTx &prevtx = mapWallet.at(txin.prevout.GetTxId()); + auto it = mapWallet.find(txin.prevout.GetTxId()); + if (it != mapWallet.end()) { + CWalletTx &prevtx = it->second; if (prevtx.nIndex == -1 && !prevtx.hashUnset()) { MarkConflicted(prevtx.hashBlock, wtx.GetId()); } @@ -1138,9 +1140,10 @@ std::set todo; std::set done; - // Can't mark abandoned if confirmed or in mempool. - assert(mapWallet.count(txid)); - CWalletTx &origtx = mapWallet.at(txid); + // Can't mark abandoned if confirmed or in mempool + auto it = mapWallet.find(txid); + assert(it != mapWallet.end()); + CWalletTx &origtx = it->second; if (origtx.GetDepthInMainChain() > 0 || origtx.InMempool()) { return false; } @@ -1151,8 +1154,9 @@ const TxId now = *todo.begin(); todo.erase(now); done.insert(now); - assert(mapWallet.count(now)); - CWalletTx &wtx = mapWallet.at(now); + it = mapWallet.find(now); + assert(it != mapWallet.end()); + CWalletTx &wtx = it->second; int currentconfirm = wtx.GetDepthInMainChain(); // If the orig tx was not in block, none of its spends can be. assert(currentconfirm <= 0); @@ -1182,8 +1186,9 @@ // balance available of the outputs it spends. So force those to be // recomputed. for (const CTxIn &txin : wtx.tx->vin) { - if (mapWallet.count(txin.prevout.GetTxId())) { - mapWallet.at(txin.prevout.GetTxId()).MarkDirty(); + auto it2 = mapWallet.find(txin.prevout.GetTxId()); + if (it2 != mapWallet.end()) { + it2->second.MarkDirty(); } } } @@ -1222,8 +1227,9 @@ const TxId now = *todo.begin(); todo.erase(now); done.insert(now); - assert(mapWallet.count(now)); - CWalletTx &wtx = mapWallet.at(now); + auto it = mapWallet.find(now); + assert(it != mapWallet.end()); + CWalletTx &wtx = it->second; int currentconfirm = wtx.GetDepthInMainChain(); if (conflictconfirms < currentconfirm) { // Block is 'more conflicted' than current confirm; update. @@ -1247,8 +1253,9 @@ // balance available of the outputs it spends. So force those to be // recomputed. for (const CTxIn &txin : wtx.tx->vin) { - if (mapWallet.count(txin.prevout.GetTxId())) { - mapWallet.at(txin.prevout.GetTxId()).MarkDirty(); + auto it2 = mapWallet.find(txin.prevout.GetTxId()); + if (it2 != mapWallet.end()) { + it2->second.MarkDirty(); } } } @@ -1265,11 +1272,12 @@ } // If a transaction changes 'conflicted' state, that changes the balance - // available of the outputs it spends. So force those to be recomputed, - // also: + // available of the outputs it spends. So force those to be + // recomputed, also: for (const CTxIn &txin : tx.vin) { - if (mapWallet.count(txin.prevout.GetTxId())) { - mapWallet.at(txin.prevout.GetTxId()).MarkDirty(); + auto it = mapWallet.find(txin.prevout.GetTxId()); + if (it != mapWallet.end()) { + it->second.MarkDirty(); } } }