X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fwallet.cpp;fp=src%2Fwallet.cpp;h=04ce99531a300dcb8ce527960e62a4c8089d8975;hp=83cc2748bc06f0c299ef6c56b237b25d897f8307;hb=5098ea454db9132aa0f576921ca9d1a69429d146;hpb=47d3ceb3da845e216fc9577cbf52f8b5600e5f93 diff --git a/src/wallet.cpp b/src/wallet.cpp index 83cc274..04ce995 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -246,7 +246,7 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase) { LOCK(cs_wallet); - BOOST_FOREACH(const MasterKeyMap::value_type& pMasterKey, mapMasterKeys) + for (const MasterKeyMap::value_type& pMasterKey : mapMasterKeys) { if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) return false; @@ -269,7 +269,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, CCrypter crypter; CKeyingMaterial vMasterKey; - BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys) + for (MasterKeyMap::value_type& pMasterKey : mapMasterKeys) { if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) return false; @@ -455,7 +455,7 @@ bool CWallet::DecryptWallet(const SecureString& strWalletPassphrase) { LOCK(cs_wallet); - BOOST_FOREACH(const MasterKeyMap::value_type& pMasterKey, mapMasterKeys) + for (const MasterKeyMap::value_type& pMasterKey : mapMasterKeys) { if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) return false; @@ -546,16 +546,16 @@ CWallet::TxItems CWallet::OrderedTxItems(std::list& acentries, // Note: maintaining indices in the database of (account,time) --> txid and (account, time) --> acentry // would make this much faster for applications that do this a lot. - for (map::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto & it : mapWallet) { - CWalletTx* wtx = &((*it).second); - txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)0))); + CWalletTx* wtx = &(it.second); + txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)nullptr))); } acentries.clear(); walletdb.ListAccountCreditDebit(strAccount, acentries); - BOOST_FOREACH(CAccountingEntry& entry, acentries) + for (CAccountingEntry& entry : acentries) { - txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry))); + txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)nullptr, &entry))); } return txOrdered; @@ -568,7 +568,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) // restored from backup or the user making copies of wallet.dat. { LOCK(cs_wallet); - BOOST_FOREACH(const CTxIn& txin, tx.vin) + for (const CTxIn& txin : tx.vin) { map::iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) @@ -593,7 +593,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) map::iterator mi = mapWallet.find(hash); CWalletTx& wtx = (*mi).second; - BOOST_FOREACH(const CTxOut& txout, tx.vout) + for (const CTxOut& txout : tx.vout) { if (IsMine(txout)) { @@ -612,7 +612,7 @@ void CWallet::MarkDirty() { { LOCK(cs_wallet); - BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) + for (auto& item : mapWallet) item.second.MarkDirty(); } } @@ -713,7 +713,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) // If default receiving address gets used, replace it with a new one CScript scriptDefaultKey; scriptDefaultKey.SetDestination(vchDefaultKey.GetID()); - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (const CTxOut& txout : wtx.vout) { if (txout.scriptPubKey == scriptDefaultKey) { @@ -924,7 +924,7 @@ int64_t CWallet::GetChange(const CTxOut& txout) const bool CWallet::IsMine(const CTransaction& tx) const { - BOOST_FOREACH(const CTxOut& txout, tx.vout) + for (const CTxOut& txout : tx.vout) if (IsMine(txout) && txout.nValue >= nMinimumInputValue) return true; return false; @@ -938,7 +938,7 @@ bool CWallet::IsFromMe(const CTransaction& tx) const int64_t CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) const { int64_t nDebit = 0; - BOOST_FOREACH(const CTxIn& txin, tx.vin) + for (const CTxIn& txin : tx.vin) { nDebit += GetDebit(txin, filter); if (!MoneyRange(nDebit)) @@ -950,7 +950,7 @@ int64_t CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) co int64_t CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) const { int64_t nCredit = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) + for (const CTxOut& txout : tx.vout) { nCredit += GetCredit(txout, filter); if (!MoneyRange(nCredit)) @@ -962,7 +962,7 @@ int64_t CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) c int64_t CWallet::GetChange(const CTransaction& tx) const { int64_t nChange = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) + for (const CTxOut& txout : tx.vout) { nChange += GetChange(txout); if (!MoneyRange(nChange)) @@ -1042,7 +1042,7 @@ bool CWalletTx::IsTrusted() const return false; // Trusted if all inputs are from us and are in the mempool: - BOOST_FOREACH(const CTxIn& txin, vin) + for (const CTxIn& txin : vin) { // Transactions not sent by us: not trusted const CWalletTx* parent = pwallet->GetWalletTx(txin.prevout.hash); @@ -1241,7 +1241,7 @@ void CWalletTx::GetAmounts(int64_t& nGeneratedImmature, int64_t& nGeneratedMatur } // Sent/received. - BOOST_FOREACH(const CTxOut& txout, vout) + for (const CTxOut& txout : vout) { isminetype fIsMine = pwallet->IsMine(txout); // Only need to handle txouts if AT LEAST one of these is true: @@ -1292,13 +1292,13 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nGenerated, nGenerated = allGeneratedMature; if (strAccount == strSentAccount) { - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64_t)& s, listSent) + for (const auto& s : listSent) nSent += s.second; nFee = allFee; } { LOCK(pwallet->cs_wallet); - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64_t)& r, listReceived) + for (const auto& r : listReceived) { if (pwallet->mapAddressBook.count(r.first)) { @@ -1322,7 +1322,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) if (SetMerkleBranch() < COPY_DEPTH) { vector vWorkQueue; - BOOST_FOREACH(const CTxIn& txin, vin) + for (const CTxIn& txin : vin) vWorkQueue.push_back(txin.prevout.hash); // This critsect is OK because txdb is already open @@ -1342,7 +1342,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) if (mi != pwallet->mapWallet.end()) { tx = (*mi).second; - BOOST_FOREACH(const CMerkleTx& txWalletPrev, (*mi).second.vtxPrev) + for (const CMerkleTx& txWalletPrev : (*mi).second.vtxPrev) mapWalletPrev[txWalletPrev.GetHash()] = &txWalletPrev; } else if (mapWalletPrev.count(hash)) @@ -1364,7 +1364,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) if (nDepth < COPY_DEPTH) { - BOOST_FOREACH(const CTxIn& txin, tx.vin) + for (const CTxIn& txin : tx.vin) vWorkQueue.push_back(txin.prevout.hash); } } @@ -1393,7 +1393,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) { CBlock block; block.ReadFromDisk(pindex, true); - BOOST_FOREACH(CTransaction& tx, block.vtx) + for (CTransaction& tx : block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) ret++; @@ -1422,7 +1422,7 @@ void CWallet::ReacceptWalletTransactions() LOCK(cs_wallet); fRepeat = false; vector vMissingTx; - BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) + for (auto& item : mapWallet) { CWalletTx& wtx = item.second; if ((wtx.IsCoinBase() && wtx.IsSpent(0)) || (wtx.IsCoinStake() && wtx.IsSpent(1))) @@ -1508,7 +1508,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) LOCK(cs_wallet); // Sort them in chronological order map mapSorted; - BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) + for (auto& item : mapWallet) { CWalletTx& wtx = item.second; // Don't rebroadcast if newer than nTime: @@ -1516,7 +1516,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) continue; mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx)); } - BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) + for (auto& item : mapSorted) { CWalletTx& wtx = *item.second; if (wtx.RelayWalletTransaction()) @@ -1820,7 +1820,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, std::mt19937 g(rd()); shuffle(vCoins.begin(), vCoins.end(), g); - BOOST_FOREACH(const COutput &output, vCoins) + for (const COutput &output : vCoins) { if (!output.fSpendable) continue; @@ -1924,7 +1924,7 @@ bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, set return all selected outputs (we want all selected to go into the transaction for sure) if (coinControl && coinControl->HasSelected()) { - BOOST_FOREACH(const COutput& out, vCoins) + for (const COutput& out : vCoins) { if(!out.fSpendable) continue; @@ -1948,7 +1948,7 @@ bool CWallet::SelectCoinsSimple(int64_t nTargetValue, int64_t nMinValue, int64_t setCoinsRet.clear(); nValueRet = 0; - BOOST_FOREACH(COutput output, vCoins) + for (COutput output : vCoins) { if(!output.fSpendable) continue; @@ -1992,7 +1992,7 @@ bool CWallet::SelectCoinsSimple(int64_t nTargetValue, int64_t nMinValue, int64_t bool CWallet::CreateTransaction(const vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl) { int64_t nValue = 0; - BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) + for (const auto& s : vecSend) { if (nValue < 0) return false; @@ -2018,7 +2018,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, int64_t nTotalValue = nValue + nFeeRet; double dPriority = 0; // vouts to the payees - BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) + for (const auto& s : vecSend) wtxNew.vout.push_back(CTxOut(s.second, s.first)); // Choose coins to use @@ -2026,7 +2026,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, int64_t nValueIn = 0; if (!SelectCoins(nTotalValue, wtxNew.nTime, setCoins, nValueIn, coinControl)) return false; - BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) + for (auto pcoin : setCoins) { int64_t nCredit = pcoin.first->vout[pcoin.second].nValue; dPriority += (double)nCredit * pcoin.first->GetDepthInMainChain(); @@ -2068,12 +2068,12 @@ bool CWallet::CreateTransaction(const vector >& vecSend, reservekey.ReturnKey(); // Fill vin - BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins) + for (const auto& coin : setCoins) wtxNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second)); // Sign int nIn = 0; - BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins) + for (const auto& coin : setCoins) if (!SignSignature(*this, *coin.first, wtxNew, nIn++)) return false; @@ -2160,7 +2160,7 @@ bool CWallet::MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const wtxNew.vout.push_back(CTxOut(0, scriptOutput)); double dWeight = 0; - BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) + for (auto pcoin : setCoins) { int64_t nCredit = pcoin.first->vout[pcoin.second].nValue; @@ -2410,7 +2410,7 @@ bool CWallet::CreateCoinStake(uint256 &hashTx, uint32_t nOut, uint32_t nGenerati // Sign int nIn = 0; - BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev) + for (const CWalletTx* pcoin : vwtxPrev) { if (!SignSignature(*this, *pcoin, txNew, nIn++)) return error("CreateCoinStake : failed to sign coinstake\n"); @@ -2474,7 +2474,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) AddToWallet(wtxNew); // Mark old coins as spent - BOOST_FOREACH(const CTxIn& txin, wtxNew.vin) + for (const CTxIn& txin : wtxNew.vin) { CWalletTx &coin = mapWallet[txin.prevout.hash]; coin.BindWallet(this); @@ -2670,7 +2670,7 @@ bool CWallet::NewKeyPool(unsigned int nSize) { LOCK(cs_wallet); CWalletDB walletdb(strWalletFile); - BOOST_FOREACH(int64_t nIndex, setKeyPool) + for (int64_t nIndex : setKeyPool) walletdb.ErasePool(nIndex); setKeyPool.clear(); @@ -2832,7 +2832,7 @@ std::map CWallet::GetAddressBalances() { LOCK(cs_wallet); - BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet) + for (auto walletEntry : mapWallet) { CWalletTx *pcoin = &walletEntry.second; @@ -2871,7 +2871,7 @@ set< set > CWallet::GetAddressGroupings() set< set > groupings; set grouping; - BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet) + for (auto& walletEntry : mapWallet) { CWalletTx *pcoin = &walletEntry.second; @@ -2879,7 +2879,7 @@ set< set > CWallet::GetAddressGroupings() { bool any_mine = false; // group all input addresses with each other - BOOST_FOREACH(CTxIn txin, pcoin->vin) + for (CTxIn txin : pcoin->vin) { CBitcoinAddress address; if(!IsMine(txin)) // If this input isn't mine, ignore it @@ -2893,7 +2893,7 @@ set< set > CWallet::GetAddressGroupings() // group change with input addresses if (any_mine) { - BOOST_FOREACH(CTxOut txout, pcoin->vout) + for (CTxOut txout : pcoin->vout) if (IsChange(txout)) { CBitcoinAddress txoutAddr; @@ -2924,18 +2924,18 @@ set< set > CWallet::GetAddressGroupings() set< set* > uniqueGroupings; // a set of pointers to groups of addresses map< CBitcoinAddress, set* > setmap; // map addresses to the unique group containing it - BOOST_FOREACH(set grouping, groupings) + for (set grouping : groupings) { // make a set of all the groups hit by this new group set< set* > hits; map< CBitcoinAddress, set* >::iterator it; - BOOST_FOREACH(CBitcoinAddress address, grouping) + for (CBitcoinAddress address : grouping) if ((it = setmap.find(address)) != setmap.end()) hits.insert((*it).second); // merge all hit groups into a new single group and delete old groups set* merged = new set(grouping); - BOOST_FOREACH(set* hit, hits) + for (set* hit : hits) { merged->insert(hit->begin(), hit->end()); uniqueGroupings.erase(hit); @@ -2944,12 +2944,12 @@ set< set > CWallet::GetAddressGroupings() uniqueGroupings.insert(merged); // update setmap - BOOST_FOREACH(CBitcoinAddress element, *merged) + for (CBitcoinAddress element : *merged) setmap[element] = merged; } set< set > ret; - BOOST_FOREACH(set* uniqueGrouping, uniqueGroupings) + for (set* uniqueGrouping : uniqueGroupings) { ret.insert(*uniqueGrouping); delete uniqueGrouping; @@ -2972,7 +2972,7 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bo vCoins.push_back(&(*it).second); CTxDB txdb("r"); - BOOST_FOREACH(CWalletTx* pcoin, vCoins) + for (CWalletTx* pcoin : vCoins) { // Find the corresponding transaction index CTxIndex txindex; @@ -3025,7 +3025,7 @@ void CWallet::DisableTransaction(const CTransaction &tx) return; // only disconnecting coinstake requires marking input unspent LOCK(cs_wallet); - BOOST_FOREACH(const CTxIn& txin, tx.vin) + for (const CTxIn& txin : tx.vin) { map::iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) @@ -3081,7 +3081,7 @@ void CWallet::GetAllReserveKeys(set& setAddress) const CWalletDB walletdb(strWalletFile); LOCK2(cs_main, cs_wallet); - BOOST_FOREACH(const int64_t& id, setKeyPool) + for (const int64_t& id : setKeyPool) { CKeyPool keypool; if (!walletdb.ReadPool(id, keypool))