diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -558,11 +558,11 @@ continue; } int nDepth = - wallet->mapWallet[outpoint.GetTxId()].GetDepthInMainChain(); + wallet->mapWallet.at(outpoint.GetTxId()).GetDepthInMainChain(); if (nDepth < 0) { continue; } - COutput out(&wallet->mapWallet[outpoint.GetTxId()], outpoint.GetN(), + COutput out(&wallet->mapWallet.at(outpoint.GetTxId()), 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 @@ -2370,7 +2370,7 @@ "Invalid or non-wallet transaction id"); } - const CWalletTx &wtx = pwallet->mapWallet[txid]; + const CWalletTx &wtx = pwallet->mapWallet.at(txid); Amount nCredit = wtx.GetCredit(filter); Amount nDebit = wtx.GetDebit(filter); diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp --- a/src/wallet/test/accounting_tests.cpp +++ b/src/wallet/test/accounting_tests.cpp @@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) { std::vector vpwtx; - CWalletTx wtx; + CWalletTx wtx(nullptr /* pwallet */, MakeTransactionRef()); CAccountingEntry ae; std::map results; @@ -42,7 +42,7 @@ wtx.mapValue["comment"] = "z"; pwalletMain->AddToWallet(wtx); - vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetId()]); + vpwtx.push_back(&pwalletMain->mapWallet.at(wtx.GetId())); vpwtx[0]->nTimeReceived = (unsigned int)1333333335; vpwtx[0]->nOrderPos = -1; @@ -83,7 +83,7 @@ wtx.SetTx(MakeTransactionRef(std::move(tx))); } pwalletMain->AddToWallet(wtx); - vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetId()]); + vpwtx.push_back(&pwalletMain->mapWallet.at(wtx.GetId())); vpwtx[1]->nTimeReceived = (unsigned int)1333333336; wtx.mapValue["comment"] = "x"; @@ -94,7 +94,7 @@ wtx.SetTx(MakeTransactionRef(std::move(tx))); } pwalletMain->AddToWallet(wtx); - vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetId()]); + vpwtx.push_back(&pwalletMain->mapWallet.at(wtx.GetId())); vpwtx[2]->nTimeReceived = (unsigned int)1333333329; vpwtx[2]->nOrderPos = -1; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -322,8 +322,6 @@ mutable Amount nAvailableWatchCreditCached; mutable Amount nChangeCached; - CWalletTx() { Init(nullptr); } - CWalletTx(const CWallet *pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg)) { Init(pwalletIn); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -584,7 +584,7 @@ int nMinOrderPos = std::numeric_limits::max(); const CWalletTx *copyFrom = nullptr; for (TxSpends::iterator it = range.first; it != range.second; ++it) { - const CWalletTx *wtx = &mapWallet[it->second]; + const CWalletTx *wtx = &mapWallet.at(it->second); if (wtx->nOrderPos < nMinOrderPos) { nMinOrderPos = wtx->nOrderPos; copyFrom = wtx; @@ -594,7 +594,7 @@ // Now copy data from copyFrom to rest: for (TxSpends::iterator it = range.first; it != range.second; ++it) { const TxId &txid = it->second; - CWalletTx *copyTo = &mapWallet[txid]; + CWalletTx *copyTo = &mapWallet.at(txid); if (copyFrom == copyTo) { continue; } @@ -651,7 +651,7 @@ void CWallet::AddToSpends(const TxId &wtxid) { assert(mapWallet.count(wtxid)); - CWalletTx &thisTx = mapWallet[wtxid]; + CWalletTx &thisTx = mapWallet.at(wtxid); // Coinbases don't spend anything! if (thisTx.IsCoinBase()) { return; @@ -1024,7 +1024,7 @@ AddToSpends(txid); for (const CTxIn &txin : wtx.tx->vin) { if (mapWallet.count(txin.prevout.GetTxId())) { - CWalletTx &prevtx = mapWallet[txin.prevout.GetTxId()]; + CWalletTx &prevtx = mapWallet.at(txin.prevout.GetTxId()); if (prevtx.nIndex == -1 && !prevtx.hashUnset()) { MarkConflicted(prevtx.hashBlock, wtx.GetId()); } @@ -1140,7 +1140,7 @@ // Can't mark abandoned if confirmed or in mempool. assert(mapWallet.count(txid)); - CWalletTx &origtx = mapWallet[txid]; + CWalletTx &origtx = mapWallet.at(txid); if (origtx.GetDepthInMainChain() > 0 || origtx.InMempool()) { return false; } @@ -1152,7 +1152,7 @@ todo.erase(now); done.insert(now); assert(mapWallet.count(now)); - CWalletTx &wtx = mapWallet[now]; + CWalletTx &wtx = mapWallet.at(now); int currentconfirm = wtx.GetDepthInMainChain(); // If the orig tx was not in block, none of its spends can be. assert(currentconfirm <= 0); @@ -1183,7 +1183,7 @@ // recomputed. for (const CTxIn &txin : wtx.tx->vin) { if (mapWallet.count(txin.prevout.GetTxId())) { - mapWallet[txin.prevout.GetTxId()].MarkDirty(); + mapWallet.at(txin.prevout.GetTxId()).MarkDirty(); } } } @@ -1223,7 +1223,7 @@ todo.erase(now); done.insert(now); assert(mapWallet.count(now)); - CWalletTx &wtx = mapWallet[now]; + CWalletTx &wtx = mapWallet.at(now); int currentconfirm = wtx.GetDepthInMainChain(); if (conflictconfirms < currentconfirm) { // Block is 'more conflicted' than current confirm; update. @@ -1248,7 +1248,7 @@ // recomputed. for (const CTxIn &txin : wtx.tx->vin) { if (mapWallet.count(txin.prevout.GetTxId())) { - mapWallet[txin.prevout.GetTxId()].MarkDirty(); + mapWallet.at(txin.prevout.GetTxId()).MarkDirty(); } } } @@ -1269,7 +1269,7 @@ // also: for (const CTxIn &txin : tx.vin) { if (mapWallet.count(txin.prevout.GetTxId())) { - mapWallet[txin.prevout.GetTxId()].MarkDirty(); + mapWallet.at(txin.prevout.GetTxId()).MarkDirty(); } } } @@ -3253,7 +3253,7 @@ // Notify that old coins are spent. for (const CTxIn &txin : wtxNew.tx->vin) { - CWalletTx &coin = mapWallet[txin.prevout.GetTxId()]; + CWalletTx &coin = mapWallet.at(txin.prevout.GetTxId()); coin.BindWallet(this); NotifyTransactionChanged(this, coin.GetId(), CT_UPDATED); } @@ -3263,7 +3263,7 @@ // Get the inserted-CWalletTx from mapWallet so that the // fInMempool flag is cached properly - CWalletTx &wtx = mapWallet[wtxNew.GetId()]; + CWalletTx &wtx = mapWallet.at(wtxNew.GetId()); if (fBroadcastTransactions) { // Broadcast @@ -3747,7 +3747,7 @@ continue; } - if (!ExtractDestination(mapWallet[txin.prevout.GetTxId()] + if (!ExtractDestination(mapWallet.at(txin.prevout.GetTxId()) .tx->vout[txin.prevout.GetN()] .scriptPubKey, address)) { diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -298,7 +298,7 @@ } else if (strType == "tx") { TxId txid; ssKey >> txid; - CWalletTx wtx; + CWalletTx wtx(nullptr /* pwallet */, MakeTransactionRef()); ssValue >> wtx; CValidationState state; bool isValid = wtx.IsCoinBase() @@ -611,7 +611,7 @@ } for (const TxId &txid : wss.vWalletUpgrade) { - WriteTx(pwallet->mapWallet[txid]); + WriteTx(pwallet->mapWallet.at(txid)); } // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: @@ -679,7 +679,7 @@ TxId txid; ssKey >> txid; - CWalletTx wtx; + CWalletTx wtx(nullptr /* pwallet */, MakeTransactionRef()); ssValue >> wtx; txIds.push_back(txid);