From 15e057edcc1c3ed116e8733054e61a4ab033ed48 Mon Sep 17 00:00:00 2001 From: svost Date: Sat, 17 Feb 2024 19:44:03 +0300 Subject: [PATCH] Wipeout using namespace std --- src/init.cpp | 25 ++--- src/main.cpp | 186 ++++++++++++++++----------------- src/net.cpp | 81 +++++++------- src/rpcwallet.cpp | 301 ++++++++++++++++++++++++++--------------------------- src/wallet.cpp | 222 ++++++++++++++++++++-------------------- 5 files changed, 404 insertions(+), 411 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index dddb575..84e2f3a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -26,9 +26,6 @@ #endif -using namespace std; - - CWallet* pwalletMain; CClientUIInterface uiInterface; std::string strWalletFileName; @@ -234,7 +231,7 @@ bool static Bind(const CService &addr, bool fError = true) { // Core-specific options shared between UI and daemon std::string HelpMessage() { - string strUsage = _("Options:") + "\n" + + std::string strUsage = _("Options:") + "\n" + " -? " + _("This help message") + "\n" + " -conf= " + _("Specify configuration file (default: novacoin.conf)") + "\n" + " -pid= " + _("Specify pid file (default: novacoind.pid)") + "\n" + @@ -376,7 +373,7 @@ bool AppInit2() fUseMemoryLog = GetBoolArg("-memorylog", true); // Ping and address broadcast intervals - nPingInterval = max(10 * 60, GetArg("-keepalive", 30 * 60)); + nPingInterval = std::max(10 * 60, GetArg("-keepalive", 30 * 60)); CheckpointsMode = Checkpoints::STRICT; std::string strCpMode = GetArg("-cppolicy", "strict"); @@ -567,7 +564,7 @@ bool AppInit2() if (!bitdb.Open(GetDataDir())) { - string msg = strprintf(_("Error initializing database environment %s!" + std::string msg = strprintf(_("Error initializing database environment %s!" " To recover, BACKUP THAT DIRECTORY, then remove" " everything from it except for wallet.dat."), strDataDir.c_str()); return InitError(msg); @@ -585,7 +582,7 @@ bool AppInit2() CDBEnv::VerifyResult r = bitdb.Verify(strWalletFileName, CWalletDB::Recover); if (r == CDBEnv::RECOVER_OK) { - string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!" + std::string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!" " Original wallet.dat saved as wallet.{timestamp}.bak in %s; if" " your balance or transactions are incorrect you should" " restore from a backup."), strDataDir.c_str()); @@ -712,7 +709,7 @@ bool AppInit2() if (mapArgs.count("-externalip")) { - for (string strAddr : mapMultiArgs["-externalip"]) { + for (std::string strAddr : mapMultiArgs["-externalip"]) { CService addrLocal(strAddr, GetListenPort(), fNameLookup); if (!addrLocal.IsValid()) return InitError(strprintf(_("Cannot resolve -externalip address: '%s'"), strAddr.c_str())); @@ -735,14 +732,14 @@ bool AppInit2() InitError(_("Unable to sign checkpoint, wrong checkpointkey?\n")); } - for (string strDest : mapMultiArgs["-seednode"]) + for (std::string strDest : mapMultiArgs["-seednode"]) AddOneShot(strDest); // ********************************************************* Step 7: load blockchain if (!bitdb.Open(GetDataDir())) { - string msg = strprintf(_("Error initializing database environment %s!" + std::string msg = strprintf(_("Error initializing database environment %s!" " To recover, BACKUP THAT DIRECTORY, then remove" " everything from it except for wallet.dat."), strDataDir.c_str()); return InitError(msg); @@ -804,9 +801,9 @@ bool AppInit2() if (mapArgs.count("-printblock")) { - string strMatch = mapArgs["-printblock"]; + std::string strMatch = mapArgs["-printblock"]; int nFound = 0; - for (map::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) + for (auto mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) { uint256 hash = (*mi).first; if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0) @@ -852,7 +849,7 @@ bool AppInit2() strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n"; else if (nLoadWalletRet == DB_NONCRITICAL_ERROR) { - string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data" + std::string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data" " or address book entries might be missing or incorrect.")); uiInterface.ThreadSafeMessageBox(msg, _("NovaCoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL); } @@ -934,7 +931,7 @@ bool AppInit2() { uiInterface.InitMessage(_("Importing blockchain data file.")); - for (string strFile : mapMultiArgs["-loadblock"]) + for (std::string strFile : mapMultiArgs["-loadblock"]) { FILE *file = fopen(strFile.c_str(), "rb"); if (file) diff --git a/src/main.cpp b/src/main.cpp index d864ade..8b36a45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,19 +21,17 @@ #include -using namespace std; - CCriticalSection cs_setpwalletRegistered; -set setpwalletRegistered; +std::set setpwalletRegistered; CCriticalSection cs_main; CTxMemPool mempool; unsigned int nTransactionsUpdated = 0; -map mapBlockIndex; -set > setStakeSeen; +std::map mapBlockIndex; +std::set > setStakeSeen; CBigNum bnProofOfWorkLimit(~uint256(0) >> 20); // "standard" scrypt target limit for proof of work, results with 0,000244140625 proof-of-work difficulty CBigNum bnProofOfStakeLegacyLimit(~uint256(0) >> 24); // proof of stake target limit from block #15000 and until 20 June 2013, results with 0,00390625 proof of stake difficulty @@ -63,18 +61,18 @@ int nScriptCheckThreads = 0; CMedianFilter cPeerBlockCounts(5, 0); // Amount of blocks that other nodes claim to have -map mapOrphanBlocks; -multimap mapOrphanBlocksByPrev; -set > setStakeSeenOrphan; -map mapProofOfStake; +std::map mapOrphanBlocks; +std::multimap mapOrphanBlocksByPrev; +std::set > setStakeSeenOrphan; +std::map mapProofOfStake; -map mapOrphanTransactions; -map > mapOrphanTransactionsByPrev; +std::map mapOrphanTransactions; +std::map > mapOrphanTransactionsByPrev; // Constant stuff for coinbase transactions we create: CScript COINBASE_FLAGS; -const string strMessageMagic = "NovaCoin Signed Message:\n"; +const std::string strMessageMagic = "NovaCoin Signed Message:\n"; // Settings int64_t nTransactionFee = MIN_TX_FEE; @@ -242,7 +240,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) { // Evict a random orphan: uint256 randomhash = GetRandHash(); - map::iterator it = mapOrphanTransactions.lower_bound(randomhash); + std::map::iterator it = mapOrphanTransactions.lower_bound(randomhash); if (it == mapOrphanTransactions.end()) it = mapOrphanTransactions.begin(); EraseOrphanTx(it->first); @@ -290,7 +288,7 @@ bool CTransaction::ReadFromDisk(COutPoint prevout) return ReadFromDisk(txdb, prevout, txindex); } -bool CTransaction::IsStandard(string& strReason) const +bool CTransaction::IsStandard(std::string& strReason) const { if (nVersion > CTransaction::CURRENT_VERSION) { @@ -372,7 +370,7 @@ bool CTransaction::AreInputsStandard(const MapPrevTx& mapInputs) const { const CTxOut& prev = GetOutputFor(vin[i], mapInputs); - vector > vSolutions; + std::vector > vSolutions; txnouttype whichType; // get the scriptPubKey corresponding to this input: const CScript& prevScript = prev.scriptPubKey; @@ -387,7 +385,7 @@ bool CTransaction::AreInputsStandard(const MapPrevTx& mapInputs) const // be quick, because if there are any operations // beside "push data" in the scriptSig the // IsStandard() call returns false - vector > stack; + std::vector > stack; if (!EvalScript(stack, vin[i].scriptSig, *this, i, false, 0)) return false; @@ -396,7 +394,7 @@ bool CTransaction::AreInputsStandard(const MapPrevTx& mapInputs) const if (stack.empty()) return false; CScript subscript(stack.back().begin(), stack.back().end()); - vector > vSolutions2; + std::vector > vSolutions2; txnouttype whichType2; if (!Solver(subscript, whichType2, vSolutions2)) return false; @@ -479,7 +477,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock) } // Is the tx in a block that's in the main chain - map::iterator mi = mapBlockIndex.find(hashBlock); + auto mi = mapBlockIndex.find(hashBlock); if (mi == mapBlockIndex.end()) return 0; const CBlockIndex* pindex = (*mi).second; @@ -518,7 +516,7 @@ bool CTransaction::CheckTransaction() const } // Check for duplicate inputs - set vInOutPoints; + std::set vInOutPoints; for (const CTxIn& txin : vin) { if (vInOutPoints.count(txin.prevout)) @@ -624,7 +622,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, return error("CTxMemPool::accept() : not accepting nLockTime beyond 2038 yet"); // Rather not work on nonstandard transactions (unless -testnet) - string strNonStd; + std::string strNonStd; if (!fTestNet && !tx.IsStandard(strNonStd)) return error("CTxMemPool::accept() : nonstandard transaction (%s)", strNonStd.c_str()); @@ -670,7 +668,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, if (fCheckInputs) { MapPrevTx mapInputs; - map mapUnused; + std::map mapUnused; bool fInvalid = false; if (!tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid)) { @@ -712,7 +710,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, { LOCK(cs); // Use an exponentially decaying ~10-minute window: - dFreeCount *= pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime)); + dFreeCount *= std::pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime)); nLastTime = nNow; // -limitfreerelay unit is thousand-bytes-per-minute // At default rate it would take over a month to fill 1GB @@ -804,7 +802,7 @@ void CTxMemPool::queryHashes(std::vector& vtxid) LOCK(cs); vtxid.reserve(mapTx.size()); - for (map::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) + for (auto mi = mapTx.begin(); mi != mapTx.end(); ++mi) vtxid.push_back((*mi).first); } @@ -817,7 +815,7 @@ int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const return 0; // Find the block it claims to be in - map::iterator mi = mapBlockIndex.find(hashBlock); + auto mi = mapBlockIndex.find(hashBlock); if (mi == mapBlockIndex.end()) return 0; CBlockIndex* pindex = (*mi).second; @@ -841,7 +839,7 @@ int CMerkleTx::GetBlocksToMaturity() const { if (!(IsCoinBase() || IsCoinStake())) return 0; - return max(0, (nCoinbaseMaturity+20) - GetDepthInMainChain()); + return std::max(0, (nCoinbaseMaturity+20) - GetDepthInMainChain()); } @@ -872,7 +870,7 @@ int CTxIndex::GetDepthInMainChain() const if (!block.ReadFromDisk(pos.nFile, pos.nBlockPos, false)) return 0; // Find the block in the index - map::iterator mi = mapBlockIndex.find(block.GetHash()); + auto mi = mapBlockIndex.find(block.GetHash()); if (mi == mapBlockIndex.end()) return 0; CBlockIndex* pindex = (*mi).second; @@ -1019,7 +1017,7 @@ int64_t GetProofOfWorkReward(unsigned int nBits) if (fDebug && GetBoolArg("-printcreation")) printf("GetProofOfWorkReward() : create=%s nBits=0x%08x nSubsidy=%" PRId64 "\n", FormatMoney(nSubsidy).c_str(), nBits, nSubsidy); - return min(nSubsidy, MAX_MINT_PROOF_OF_WORK); + return std::min(nSubsidy, MAX_MINT_PROOF_OF_WORK); } // miner's coin stake reward based on nBits and coin age spent (coin-days) @@ -1063,7 +1061,7 @@ int64_t GetProofOfStakeReward(int64_t nCoinAge, unsigned int nBits, int64_t nTim } nRewardCoinYear = bnUpperBound.getuint64(); - nRewardCoinYear = min((nRewardCoinYear / CENT) * CENT, MAX_MINT_PROOF_OF_STAKE); + nRewardCoinYear = std::min((nRewardCoinYear / CENT) * CENT, MAX_MINT_PROOF_OF_STAKE); if(bCoinYearOnly) return nRewardCoinYear; @@ -1077,7 +1075,7 @@ int64_t GetProofOfStakeReward(int64_t nCoinAge, unsigned int nBits, int64_t nTim if (fDebug && GetBoolArg("-printcreation") && nSubsidyLimit < nSubsidy) printf("GetProofOfStakeReward(): %s is greater than %s, coinstake reward will be truncated\n", FormatMoney(nSubsidy).c_str(), FormatMoney(nSubsidyLimit).c_str()); - nSubsidy = min(nSubsidy, nSubsidyLimit); + nSubsidy = std::min(nSubsidy, nSubsidyLimit); if (fDebug && GetBoolArg("-printcreation")) printf("GetProofOfStakeReward(): create=%s nCoinAge=%" PRId64 " nBits=%d\n", FormatMoney(nSubsidy).c_str(), nCoinAge, nBits); @@ -1165,7 +1163,7 @@ unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfS // ppcoin: retarget with exponential moving toward target spacing CBigNum bnNew; bnNew.SetCompact(pindexPrev->nBits); - int64_t nTargetSpacing = fProofOfStake? nStakeTargetSpacing : min(GetTargetSpacingWorkMax(pindexLast->nHeight, pindexLast->nTime), (int64_t) nStakeTargetSpacing * (1 + pindexLast->nHeight - pindexPrev->nHeight)); + int64_t nTargetSpacing = fProofOfStake? nStakeTargetSpacing : std::min(GetTargetSpacingWorkMax(pindexLast->nHeight, pindexLast->nTime), (int64_t) nStakeTargetSpacing * (1 + pindexLast->nHeight - pindexPrev->nHeight)); int64_t nInterval = nTargetTimespan / nTargetSpacing; bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing); bnNew /= ((nInterval + 1) * nTargetSpacing); @@ -1244,7 +1242,7 @@ uint256 CBlock::GetHash() const void CBlock::UpdateTime(const CBlockIndex* pindexPrev) { - nTime = max(GetBlockTime(), GetAdjustedTime()); + nTime = std::max(GetBlockTime(), GetAdjustedTime()); } @@ -1293,7 +1291,7 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb) } -bool CTransaction::FetchInputs(CTxDB& txdb, const map& mapTestPool, +bool CTransaction::FetchInputs(CTxDB& txdb, const std::map& mapTestPool, bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid) { // FetchInputs can return false either because we just haven't seen some inputs @@ -1422,7 +1420,7 @@ bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsig return CScriptCheck(txFrom, txTo, nIn, flags, nHashType)(); } -bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map& mapTestPool, const CDiskTxPos& posThisTx, +bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, std::map& mapTestPool, const CDiskTxPos& posThisTx, const CBlockIndex* pindexBlock, bool fBlock, bool fMiner, bool fScriptChecks, unsigned int flags, std::vector *pvChecks) { // Take over previous transactions' spent pointers @@ -1669,7 +1667,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) else nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK, CLIENT_VERSION) - (2 * GetSizeOfCompactSize(0)) + GetSizeOfCompactSize(vtx.size()); - map mapQueuedChanges; + std::map mapQueuedChanges; CCheckQueueControl control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL); int64_t nFees = 0; @@ -1768,7 +1766,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) return true; // Write queued txindex changes - for (map::iterator mi = mapQueuedChanges.begin(); mi != mapQueuedChanges.end(); ++mi) + for (auto mi = mapQueuedChanges.begin(); mi != mapQueuedChanges.end(); ++mi) { if (!txdb.UpdateTxIndex((*mi).first, (*mi).second)) return error("ConnectBlock() : UpdateTxIndex failed"); @@ -1811,12 +1809,12 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) } // List of what to disconnect - vector vDisconnect; + std::vector vDisconnect; for (CBlockIndex* pindex = pindexBest; pindex != pfork; pindex = pindex->pprev) vDisconnect.push_back(pindex); // List of what to connect - vector vConnect; + std::vector vConnect; for (CBlockIndex* pindex = pindexNew; pindex != pfork; pindex = pindex->pprev) vConnect.push_back(pindex); reverse(vConnect.begin(), vConnect.end()); @@ -1825,7 +1823,7 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) printf("REORGANIZE: Connect %" PRIszu " blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); // Disconnect shorter branch - vector vResurrect; + std::vector vResurrect; for (CBlockIndex* pindex : vDisconnect) { CBlock block; @@ -1841,7 +1839,7 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) } // Connect longer branch - vector vDelete; + std::vector vDelete; for (unsigned int i = 0; i < vConnect.size(); i++) { CBlockIndex* pindex = vConnect[i]; @@ -2107,11 +2105,11 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) return error("AddToBlockIndex() : %s already exists", hash.ToString().substr(0,20).c_str()); // Construct new block index object - CBlockIndex* pindexNew = new(nothrow) CBlockIndex(nFile, nBlockPos, *this); + CBlockIndex* pindexNew = new(std::nothrow) CBlockIndex(nFile, nBlockPos, *this); if (!pindexNew) return error("AddToBlockIndex() : new CBlockIndex failed"); pindexNew->phashBlock = &hash; - map::iterator miPrev = mapBlockIndex.find(hashPrevBlock); + auto miPrev = mapBlockIndex.find(hashPrevBlock); if (miPrev != mapBlockIndex.end()) { pindexNew->pprev = (*miPrev).second; @@ -2144,9 +2142,9 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) return error("AddToBlockIndex() : Rejected by stake modifier checkpoint height=%d, modifier=0x%016" PRIx64, pindexNew->nHeight, nStakeModifier); // Add to mapBlockIndex - map::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; + auto mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; if (pindexNew->IsProofOfStake()) - setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime)); + setStakeSeen.insert(std::make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime)); pindexNew->phashBlock = &((*mi).first); // Write to disk block index @@ -2184,7 +2182,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c // These are checks that are independent of context // that can be verified before saving an orphan block. - set uniqueTx; // tx hashes + std::set uniqueTx; // tx hashes unsigned int nSigOps = 0; // total sigops // Size limits @@ -2298,7 +2296,7 @@ bool CBlock::AcceptBlock() return error("AcceptBlock() : block already in mapBlockIndex"); // Get prev block index - map::iterator mi = mapBlockIndex.find(hashPrevBlock); + auto mi = mapBlockIndex.find(hashPrevBlock); if (mi == mapBlockIndex.end()) return DoS(10, error("AcceptBlock() : prev block not found")); CBlockIndex* pindexPrev = (*mi).second; @@ -2555,8 +2553,8 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) setStakeSeenOrphan.insert(pblock->GetProofOfStake()); } CBlock* pblock2 = new CBlock(*pblock); - mapOrphanBlocks.insert(make_pair(hash, pblock2)); - mapOrphanBlocksByPrev.insert(make_pair(pblock2->hashPrevBlock, pblock2)); + mapOrphanBlocks.insert(std::make_pair(hash, pblock2)); + mapOrphanBlocksByPrev.insert(std::make_pair(pblock2->hashPrevBlock, pblock2)); // Ask this guy to fill in what we're missing if (pfrom) @@ -2587,7 +2585,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) // Needed for AcceptBlock() if (!mapProofOfStake.count(hash)) - mapProofOfStake.insert(make_pair(hash, hashProofOfStake)); + mapProofOfStake.insert(std::make_pair(hash, hashProofOfStake)); } // Store to disk @@ -2595,12 +2593,12 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) return error("ProcessBlock() : AcceptBlock FAILED"); // Process any orphan blocks that depended on this one - vector vWorkQueue; + std::vector vWorkQueue; vWorkQueue.push_back(hash); for (unsigned int i = 0; i < vWorkQueue.size(); i++) { uint256 hashPrev = vWorkQueue[i]; - for (multimap::iterator mi = mapOrphanBlocksByPrev.lower_bound(hashPrev); + for (auto mi = mapOrphanBlocksByPrev.lower_bound(hashPrev); mi != mapOrphanBlocksByPrev.upper_bound(hashPrev); ++mi) { @@ -2617,7 +2615,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) { // Needed for AcceptBlock() if (!mapProofOfStake.count(hashOrphanBlock)) - mapProofOfStake.insert(make_pair(hashOrphanBlock, hashOrphanProofOfStake)); + mapProofOfStake.insert(std::make_pair(hashOrphanBlock, hashOrphanProofOfStake)); // Finally, we're ready to run AcceptBlock() if (pblockOrphan->AcceptBlock()) @@ -2654,7 +2652,7 @@ bool CBlock::CheckBlockSignature() const return false; txnouttype whichType; - vector vSolutions; + std::vector vSolutions; if (!Solver(vtx[1].vout[1].scriptPubKey, whichType, vSolutions)) return false; @@ -2678,7 +2676,7 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) { fShutdown = true; - string strMessage = _("Warning: Disk space is low!"); + std::string strMessage = _("Warning: Disk space is low!"); strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); uiInterface.ThreadSafeMessageBox(strMessage, "NovaCoin", CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL); @@ -2690,7 +2688,7 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes) static boost::filesystem::path BlockFilePath(unsigned int nFile) { - string strBlockFn = strprintf("blk%04u.dat", nFile); + std::string strBlockFn = strprintf("blk%04u.dat", nFile); return GetDataDir() / strBlockFn; } @@ -2796,12 +2794,12 @@ bool LoadBlockIndex(bool fAllowNew) // CTxOut(empty) // vMerkleTree: 4cb33b3b6a - const string strTimestamp = "https://bitcointalk.org/index.php?topic=134179.msg1502196#msg1502196"; + const std::string strTimestamp = "https://bitcointalk.org/index.php?topic=134179.msg1502196#msg1502196"; CTransaction txNew; txNew.nTime = 1360105017; txNew.vin.resize(1); txNew.vout.resize(1); - txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(9999) << vector(strTimestamp.begin(), strTimestamp.end()); + txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(9999) << std::vector(strTimestamp.begin(), strTimestamp.end()); txNew.vout[0].SetEmpty(); CBlock block; block.vtx.push_back(txNew); @@ -2840,7 +2838,7 @@ bool LoadBlockIndex(bool fAllowNew) { CTxDB txdb("r+"); - string strPubKey = ""; + std::string strPubKey = ""; if (!txdb.ReadCheckpointPubKey(strPubKey) || strPubKey != CSyncCheckpoint::strMasterPubKey) { // write checkpoint master key to db @@ -2878,8 +2876,8 @@ bool LoadBlockIndex(bool fAllowNew) void PrintBlockTree() { // pre-compute tree structure - map > mapNext; - for (map::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) + std::map > mapNext; + for (auto mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) { CBlockIndex* pindex = (*mi).second; mapNext[pindex->pprev].push_back(pindex); @@ -2888,8 +2886,8 @@ void PrintBlockTree() // mapNext[pindex->pprev].push_back(pindex); } - vector > vStack; - vStack.push_back(make_pair(0, pindexGenesisBlock)); + std::vector > vStack; + vStack.push_back(std::make_pair(0, pindexGenesisBlock)); int nPrevCol = 0; while (!vStack.empty()) @@ -2933,19 +2931,19 @@ void PrintBlockTree() PrintWallets(block); // put the main time-chain first - vector& vNext = mapNext[pindex]; + std::vector& vNext = mapNext[pindex]; for (unsigned int i = 0; i < vNext.size(); i++) { if (vNext[i]->pnext) { - swap(vNext[0], vNext[i]); + std::swap(vNext[0], vNext[i]); break; } } // iterate children for (unsigned int i = 0; i < vNext.size(); i++) - vStack.push_back(make_pair(nCol+i, vNext[i])); + vStack.push_back(std::make_pair(nCol+i, vNext[i])); } } @@ -3014,14 +3012,14 @@ bool LoadExternalBlockFile(FILE* fileIn) // CAlert // -extern map mapAlerts; +extern std::map mapAlerts; extern CCriticalSection cs_mapAlerts; -string GetWarnings(string strFor) +std::string GetWarnings(std::string strFor) { int nPriority = 0; - string strStatusBar; - string strRPC; + std::string strStatusBar; + std::string strRPC; if (GetBoolArg("-testsafemode")) strRPC = "test"; @@ -3117,7 +3115,7 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv) // a large 4-byte int at any alignment. unsigned char pchMessageStart[4] = { 0xe4, 0xe8, 0xe9, 0xe5 }; -bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) +bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vRecv) { RandAddSeedPerfmon(); if (fDebug) @@ -3195,7 +3193,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Change version pfrom->PushMessage("verack"); - pfrom->vSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); + pfrom->vSend.SetVersion(std::min(pfrom->nVersion, PROTOCOL_VERSION)); if (!pfrom->fInbound) { @@ -3270,13 +3268,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "verack") { - pfrom->vRecv.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); + pfrom->vRecv.SetVersion(std::min(pfrom->nVersion, PROTOCOL_VERSION)); } else if (strCommand == "addr") { - vector vAddr; + std::vector vAddr; vRecv >> vAddr; // Don't want addr from older versions unless seeding @@ -3289,7 +3287,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } // Store the new addresses - vector vAddrOk; + std::vector vAddrOk; int64_t nNow = GetAdjustedTime(); int64_t nSince = nNow - 10 * 60; for (CAddress& addr : vAddr) @@ -3313,7 +3311,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) uint64_t hashAddr = addr.GetHash(); uint256 hashRand = hashSalt ^ (hashAddr<<32) ^ ((GetTime()+hashAddr)/nOneDay); hashRand = Hash(BEGIN(hashRand), END(hashRand)); - multimap mapMix; + std::multimap mapMix; for (CNode* pnode : vNodes) { if (pnode->nVersion < CADDR_TIME_VERSION) @@ -3322,10 +3320,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) memcpy(&nPointer, &pnode, sizeof(nPointer)); uint256 hashKey = hashRand ^ nPointer; hashKey = Hash(BEGIN(hashKey), END(hashKey)); - mapMix.insert(make_pair(hashKey, pnode)); + mapMix.insert(std::make_pair(hashKey, pnode)); } int nRelayNodes = fReachable ? 2 : 1; // limited relaying of addresses outside our network(s) - for (multimap::iterator mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi) + for (auto mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi) ((*mi).second)->PushAddress(addr); } } @@ -3342,7 +3340,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "inv") { - vector vInv; + std::vector vInv; vRecv >> vInv; if (vInv.size() > MAX_INV_SZ) { @@ -3392,7 +3390,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "getdata") { - vector vInv; + std::vector vInv; vRecv >> vInv; if (vInv.size() > MAX_INV_SZ) { @@ -3413,7 +3411,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (inv.type == MSG_BLOCK) { // Send block from disk - map::iterator mi = mapBlockIndex.find(inv.hash); + auto mi = mapBlockIndex.find(inv.hash); if (mi != mapBlockIndex.end()) { CBlock block; @@ -3426,7 +3424,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // ppcoin: send latest proof-of-work block to allow the // download node to accept as orphan (proof-of-stake // block might be rejected by stake connection check) - vector vInv; + std::vector vInv; vInv.push_back(CInv(MSG_BLOCK, GetLastBlockIndex(pindexBest, false)->GetBlockHash())); pfrom->PushMessage("inv", vInv); pfrom->hashContinue = 0; @@ -3439,7 +3437,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) bool pushed = false; { LOCK(cs_mapRelay); - map::iterator mi = mapRelay.find(inv); + auto mi = mapRelay.find(inv); if (mi != mapRelay.end()) { pfrom->PushMessage(inv.GetCommand(), (*mi).second); pushed = true; @@ -3524,7 +3522,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (locator.IsNull()) { // If locator is null, return the hashStop block - map::iterator mi = mapBlockIndex.find(hashStop); + auto mi = mapBlockIndex.find(hashStop); if (mi == mapBlockIndex.end()) return true; pindex = (*mi).second; @@ -3537,7 +3535,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) pindex = pindex->pnext; } - vector vHeaders; + std::vector vHeaders; int nLimit = 2000; printf("getheaders %d to %s\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str()); for (; pindex; pindex = pindex->pnext) @@ -3552,8 +3550,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "tx") { - vector vWorkQueue; - vector vEraseQueue; + std::vector vWorkQueue; + std::vector vEraseQueue; CDataStream vMsg(vRecv); CTxDB txdb("r"); CTransaction tx; @@ -3575,7 +3573,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) for (unsigned int i = 0; i < vWorkQueue.size(); i++) { uint256 hashPrev = vWorkQueue[i]; - for (set::iterator mi = mapOrphanTransactionsByPrev[hashPrev].begin(); + for (auto mi = mapOrphanTransactionsByPrev[hashPrev].begin(); mi != mapOrphanTransactionsByPrev[hashPrev].end(); ++mi) { @@ -3645,7 +3643,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Don't return addresses older than nCutOff timestamp int64_t nCutOff = GetTime() - (nNodeLifespan * nOneDay); pfrom->vAddrToSend.clear(); - vector vAddr = addrman.GetAddr(); + std::vector vAddr = addrman.GetAddr(); for (const CAddress &addr : vAddr) if(addr.nTime > nCutOff) pfrom->PushAddress(addr); @@ -3656,7 +3654,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { std::vector vtxid; mempool.queryHashes(vtxid); - vector vInv; + std::vector vInv; for (unsigned int i = 0; i < vtxid.size(); i++) { CInv inv(MSG_TX, vtxid[i]); vInv.push_back(inv); @@ -3773,7 +3771,7 @@ bool ProcessMessages(CNode* pfrom) vRecv.erase(vRecv.begin(), pstart); // Read header - vector vHeaderSave(vRecv.begin(), vRecv.begin() + nHeaderSize); + std::vector vHeaderSave(vRecv.begin(), vRecv.begin() + nHeaderSize); CMessageHeader hdr; vRecv >> hdr; if (!hdr.IsValid()) @@ -3781,7 +3779,7 @@ bool ProcessMessages(CNode* pfrom) printf("\n\nPROCESSMESSAGE: ERRORS IN HEADER %s\n\n\n", hdr.GetCommand().c_str()); return false; } - string strCommand = hdr.GetCommand(); + std::string strCommand = hdr.GetCommand(); // Message size unsigned int nMessageSize = hdr.nMessageSize; @@ -3895,7 +3893,7 @@ bool SendMessages(CNode* pto) // if (pto->nNextAddrSend < nNow) { pto->nNextAddrSend = PoissonNextSend(nNow, 30); - vector vAddr; + std::vector vAddr; vAddr.reserve(pto->vAddrToSend.size()); for (const CAddress& addr : pto->vAddrToSend) { @@ -3918,8 +3916,8 @@ bool SendMessages(CNode* pto) // // Message: inventory // - vector vInv; - vector vInvWait; + std::vector vInv; + std::vector vInvWait; { bool fSendTrickle = false; if (pto->nNextInvSend < nNow) { @@ -3972,7 +3970,7 @@ bool SendMessages(CNode* pto) // // Message: getdata // - vector vGetData; + std::vector vGetData; CTxDB txdb("r"); while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) { diff --git a/src/net.cpp b/src/net.cpp index 93cbf41..f0c6bc6 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -18,7 +18,6 @@ #include #endif -using namespace std; static const int MAX_OUTBOUND_CONNECTIONS = 16; @@ -51,7 +50,7 @@ bool fClient = false; bool fDiscover = true; uint64_t nLocalServices = (fClient ? 0 : NODE_NETWORK); static CCriticalSection cs_mapLocalHost; -static map mapLocalHost; +static std::map mapLocalHost; static bool vfReachable[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {}; static CNode* pnodeLocalHost = NULL; @@ -62,20 +61,20 @@ std::array vnThreadsRunning; static std::vector vhListenSocket; CAddrMan addrman; -vector vNodes; +std::vector vNodes; CCriticalSection cs_vNodes; -map mapRelay; -deque > vRelayExpiration; +std::map mapRelay; +std::deque > vRelayExpiration; CCriticalSection cs_mapRelay; -map mapAlreadyAskedFor; +std::map mapAlreadyAskedFor; -static deque vOneShots; +static std::deque vOneShots; CCriticalSection cs_vOneShots; -set setservAddNodeAddresses; +std::set setservAddNodeAddresses; CCriticalSection cs_setservAddNodeAddresses; -vector vAddedNodes; +std::vector vAddedNodes; CCriticalSection cs_vAddedNodes; static CSemaphore *semOutbound = NULL; @@ -90,7 +89,7 @@ inline void RelayInventory(const CInv& inv) } } -void AddOneShot(string strDest) +void AddOneShot(std::string strDest) { LOCK(cs_vOneShots); vOneShots.push_back(strDest); @@ -122,7 +121,7 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer) int nBestReachability = -1; { LOCK(cs_mapLocalHost); - for (map::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) + for (auto it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) { int nScore = (*it).second.nScore; int nReachability = (*it).first.GetReachabilityFrom(paddrPeer); @@ -151,7 +150,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer) return ret; } -bool RecvLine(SOCKET hSocket, string& strLine) +bool RecvLine(SOCKET hSocket, std::string& strLine) { strLine.clear(); for ( ; ; ) @@ -575,7 +574,7 @@ void CNode::PushVersion() GetRandBytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); printf("send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString().c_str(), addrYou.ToString().c_str(), addr.ToString().c_str()); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, - nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector()), nBestHeight); + nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector()), nBestHeight); } @@ -681,7 +680,7 @@ void ThreadSocketHandler(void* parg) printf("ThreadSocketHandler exited\n"); } -static list vNodesDisconnected; +static std::list vNodesDisconnected; void ThreadSocketHandler2(void* parg) { @@ -695,7 +694,7 @@ void ThreadSocketHandler2(void* parg) { LOCK(cs_vNodes); // Disconnect unused nodes - vector vNodesCopy = vNodes; + std::vector vNodesCopy = vNodes; for (CNode* pnode : vNodesCopy) { if (pnode->fDisconnect || @@ -712,7 +711,7 @@ void ThreadSocketHandler2(void* parg) pnode->Cleanup(); // hold in disconnected pool until all refs are released - pnode->nReleaseTime = max(pnode->nReleaseTime, GetTime() + 15 * 60); + pnode->nReleaseTime = std::max(pnode->nReleaseTime, GetTime() + 15 * 60); if (pnode->fNetworkNode || pnode->fInbound) pnode->Release(); vNodesDisconnected.push_back(pnode); @@ -720,7 +719,7 @@ void ThreadSocketHandler2(void* parg) } // Delete disconnected nodes - list vNodesDisconnectedCopy = vNodesDisconnected; + std::list vNodesDisconnectedCopy = vNodesDisconnected; for (CNode* pnode : vNodesDisconnectedCopy) { // wait until threads are done using it @@ -773,7 +772,7 @@ void ThreadSocketHandler2(void* parg) for (SOCKET hListenSocket : vhListenSocket) { FD_SET(hListenSocket, &fdsetRecv); - hSocketMax = max(hSocketMax, hListenSocket); + hSocketMax = std::max(hSocketMax, hListenSocket); have_fds = true; } { @@ -784,7 +783,7 @@ void ThreadSocketHandler2(void* parg) continue; FD_SET(pnode->hSocket, &fdsetRecv); FD_SET(pnode->hSocket, &fdsetError); - hSocketMax = max(hSocketMax, pnode->hSocket); + hSocketMax = std::max(hSocketMax, pnode->hSocket); have_fds = true; { TRY_LOCK(pnode->cs_vSend, lockSend); @@ -877,7 +876,7 @@ void ThreadSocketHandler2(void* parg) // // Service each socket // - vector vNodesCopy; + std::vector vNodesCopy; { LOCK(cs_vNodes); vNodesCopy = vNodes; @@ -1054,8 +1053,8 @@ void ThreadDNSAddressSeed2(void* parg) if (HaveNameProxy()) { AddOneShot(strDNSSeed[seed_idx][1]); } else { - vector vaddr; - vector vAdd; + std::vector vaddr; + std::vector vAdd; if (LookupHost(strDNSSeed[seed_idx][1], vaddr)) { for (CNetAddr& ip : vaddr) @@ -1196,7 +1195,7 @@ void ThreadOpenConnections(void* parg) void static ProcessOneShot() { - string strDest; + std::string strDest; { LOCK(cs_vOneShots); if (vOneShots.empty()) @@ -1222,7 +1221,7 @@ void ThreadOpenConnections2(void* parg) for (int64_t nLoop = 0;; nLoop++) { ProcessOneShot(); - for (string strAddr : mapMultiArgs["-connect"]) + for (std::string strAddr : mapMultiArgs["-connect"]) { CAddress addr; OpenNetworkConnection(addr, NULL, strAddr.c_str()); @@ -1296,7 +1295,7 @@ void ThreadOpenConnections2(void* parg) // Only connect out to one peer per network group (/16 for IPv4). // Do this here so we don't have to critsect vNodes inside mapAddresses critsect. int nOutbound = 0; - set > setConnected; + std::set > setConnected; { LOCK(cs_vNodes); for (CNode* pnode : vNodes) { @@ -1313,7 +1312,7 @@ void ThreadOpenConnections2(void* parg) for ( ; ; ) { // use an nUnkBias between 10 (no outgoing connections) and 90 (8 outgoing connections) - CAddress addr = addrman.Select(10 + min(nOutbound,8)*10); + CAddress addr = addrman.Select(10 + std::min(nOutbound,8)*10); // if we selected an invalid address, restart if (!addr.IsValid() || setConnected.count(addr.GetGroup()) || IsLocal(addr)) @@ -1378,13 +1377,13 @@ void ThreadOpenAddedConnections2(void* parg) if (HaveNameProxy()) { while(!fShutdown) { - list lAddresses(0); + std::list lAddresses(0); { LOCK(cs_vAddedNodes); - for (string& strAddNode : vAddedNodes) + for (std::string& strAddNode : vAddedNodes) lAddresses.push_back(strAddNode); } - for (string& strAddNode : lAddresses) { + for (std::string& strAddNode : lAddresses) { CAddress addr; CSemaphoreGrant grant(*semOutbound); OpenNetworkConnection(addr, &grant, strAddNode.c_str()); @@ -1399,17 +1398,17 @@ void ThreadOpenAddedConnections2(void* parg) for (uint32_t i = 0; true; i++) { - list lAddresses(0); + std::list lAddresses(0); { LOCK(cs_vAddedNodes); - for (string& strAddNode : vAddedNodes) + for (std::string& strAddNode : vAddedNodes) lAddresses.push_back(strAddNode); } - list > lservAddressesToAdd(0); - for (string& strAddNode : lAddresses) + std::list > lservAddressesToAdd(0); + for (std::string& strAddNode : lAddresses) { - vector vservNode(0); + std::vector vservNode(0); if (Lookup(strAddNode.c_str(), vservNode, GetDefaultPort(), fNameLookup, 0)) { lservAddressesToAdd.push_back(vservNode); @@ -1425,7 +1424,7 @@ void ThreadOpenAddedConnections2(void* parg) { LOCK(cs_vNodes); for (CNode* pnode : vNodes) - for (list >::iterator it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++) + for (auto it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++) { for (CService& addrNode : *(it)) if (pnode->addr == addrNode) @@ -1439,7 +1438,7 @@ void ThreadOpenAddedConnections2(void* parg) break; } } - for (vector& vserv : lservAddressesToAdd) + for (std::vector& vserv : lservAddressesToAdd) { if (vserv.size() == 0) continue; @@ -1497,7 +1496,7 @@ static int64_t NodeSyncScore(const CNode *pnode) { return pnode->nLastRecv; } -void static StartSync(const vector &vNodes) { +void static StartSync(const std::vector &vNodes) { CNode *pnodeNewSync = NULL; int64_t nBestScore = 0; @@ -1551,7 +1550,7 @@ void ThreadMessageHandler2(void* parg) while (!fShutdown) { bool fHaveSyncNode = false; - vector vNodesCopy; + std::vector vNodesCopy; { LOCK(cs_vNodes); vNodesCopy = vNodes; @@ -1615,7 +1614,7 @@ void ThreadMessageHandler2(void* parg) -bool BindListenPort(const CService &addrBind, string& strError) +bool BindListenPort(const CService &addrBind, std::string& strError) { strError.clear(); int nOne = 1; @@ -1722,7 +1721,7 @@ void static Discover() char pszHostName[1000] = ""; if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR) { - vector vaddr; + std::vector vaddr; if (LookupHost(pszHostName, vaddr)) { for (const CNetAddr &addr : vaddr) @@ -1775,7 +1774,7 @@ void StartNode(void* parg) if (semOutbound == NULL) { // initialize semaphore - int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, GetArgInt("-maxconnections", 125)); + int nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, GetArgInt("-maxconnections", 125)); semOutbound = new CSemaphore(nMaxOutbound); } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index afef907..a5b5dd6 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -12,7 +12,6 @@ #include "base58.h" using namespace json_spirit; -using namespace std; int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; @@ -54,9 +53,9 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) entry.push_back(Pair(item.first, item.second)); } -string AccountFromValue(const Value& value) +std::string AccountFromValue(const Value& value) { - string strAccount = value.get_str(); + std::string strAccount = value.get_str(); if (strAccount == "*") throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name"); return strAccount; @@ -65,7 +64,7 @@ string AccountFromValue(const Value& value) Value getinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) - throw runtime_error( + throw std::runtime_error( "getinfo\n" "Returns an object containing various state info."); @@ -95,7 +94,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply))); obj.push_back(Pair("connections", (int)vNodes.size())); - obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); + obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : std::string()))); obj.push_back(Pair("ip", addrSeenByPeer.ToStringIP())); diff.push_back(Pair("proof-of-work", GetDifficulty())); @@ -116,14 +115,14 @@ Value getinfo(const Array& params, bool fHelp) Value getnewaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) - throw runtime_error( + throw std::runtime_error( "getnewaddress [account]\n" "Returns a new NovaCoin address for receiving payments. " "If [account] is specified (recommended), it is added to the address book " "so payments received with the address will be credited to [account]."); // Parse the account first so we don't generate a key if there's an error - string strAccount; + std::string strAccount; if (params.size() > 0) strAccount = AccountFromValue(params[0]); @@ -142,7 +141,7 @@ Value getnewaddress(const Array& params, bool fHelp) } -CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) +CBitcoinAddress GetAccountAddress(std::string strAccount, bool bForceNew=false) { CWalletDB walletdb(pwalletMain->strWalletFile); @@ -156,7 +155,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) { CScript scriptPubKey; scriptPubKey.SetDestination(account.vchPubKey.GetID()); - for (map::iterator it = pwalletMain->mapWallet.begin(); + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid(); ++it) { @@ -183,12 +182,12 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) Value getaccountaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error( + throw std::runtime_error( "getaccountaddress \n" "Returns the current NovaCoin address for receiving payments to this account."); // Parse the account first so we don't generate a key if there's an error - string strAccount = AccountFromValue(params[0]); + std::string strAccount = AccountFromValue(params[0]); Value ret; @@ -202,7 +201,7 @@ Value getaccountaddress(const Array& params, bool fHelp) Value setaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) - throw runtime_error( + throw std::runtime_error( "setaccount \n" "Sets the account associated with the given address."); @@ -211,14 +210,14 @@ Value setaccount(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address"); - string strAccount; + std::string strAccount; if (params.size() > 1) strAccount = AccountFromValue(params[1]); // Detect when changing the account of an address that is the 'unused current key' of another account: if (pwalletMain->mapAddressBook.count(address)) { - string strOldAccount = pwalletMain->mapAddressBook[address]; + std::string strOldAccount = pwalletMain->mapAddressBook[address]; if (address == GetAccountAddress(strOldAccount)) GetAccountAddress(strOldAccount, true); } @@ -232,7 +231,7 @@ Value setaccount(const Array& params, bool fHelp) Value getaccount(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error( + throw std::runtime_error( "getaccount \n" "Returns the account associated with the given address."); @@ -240,8 +239,8 @@ Value getaccount(const Array& params, bool fHelp) if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address"); - string strAccount; - map::iterator mi = pwalletMain->mapAddressBook.find(address); + std::string strAccount; + auto mi = pwalletMain->mapAddressBook.find(address); if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) strAccount = (*mi).second; return strAccount; @@ -251,18 +250,18 @@ Value getaccount(const Array& params, bool fHelp) Value getaddressesbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error( + throw std::runtime_error( "getaddressesbyaccount \n" "Returns the list of addresses for the given account."); - string strAccount = AccountFromValue(params[0]); + std::string strAccount = AccountFromValue(params[0]); // Find all addresses that have the given account Array ret; for (const auto& item : pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; - const string& strName = item.second; + const std::string& strName = item.second; if (strName == strAccount) ret.push_back(address.ToString()); } @@ -272,7 +271,7 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) Value mergecoins(const Array& params, bool fHelp) { if (fHelp || params.size() != 3) - throw runtime_error( + throw std::runtime_error( "mergecoins \n" " is resulting inputs sum\n" " is minimum value of inputs which are used in join process\n" @@ -304,7 +303,7 @@ Value mergecoins(const Array& params, bool fHelp) if (nOutputValue < nMinValue) throw JSONRPCError(-101, "Output value is lower than min value"); - list listMerged; + std::list listMerged; if (!pwalletMain->MergeCoins(nAmount, nMinValue, nOutputValue, listMerged)) return Value::null; @@ -318,14 +317,14 @@ Value mergecoins(const Array& params, bool fHelp) Value sendtoaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) - throw runtime_error( + throw std::runtime_error( "sendtoaddress [comment] [comment-to]\n" " is a real and is rounded to the nearest " + FormatMoney(nMinimumInputValue) + HelpRequiringPassphrase()); // Parse address CScript scriptPubKey; - string strAddress = params[0].get_str(); + std::string strAddress = params[0].get_str(); CBitcoinAddress address(strAddress); if (address.IsValid()) @@ -349,7 +348,7 @@ Value sendtoaddress(const Array& params, bool fHelp) if (pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); - string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); + std::string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); @@ -359,15 +358,15 @@ Value sendtoaddress(const Array& params, bool fHelp) Value listaddressgroupings(const Array& params, bool fHelp) { if (fHelp) - throw runtime_error( + throw std::runtime_error( "listaddressgroupings\n" "Lists groups of addresses which have had their common ownership\n" "made public by common use as inputs or as the resulting change\n" "in past transactions"); Array jsonGroupings; - map balances = pwalletMain->GetAddressBalances(); - for (set grouping : pwalletMain->GetAddressGroupings()) + auto balances = pwalletMain->GetAddressBalances(); + for (auto grouping : pwalletMain->GetAddressGroupings()) { Array jsonGrouping; for (CBitcoinAddress address : grouping) @@ -390,14 +389,14 @@ Value listaddressgroupings(const Array& params, bool fHelp) Value signmessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 2) - throw runtime_error( + throw std::runtime_error( "signmessage \n" "Sign a message with the private key of an address"); EnsureWalletIsUnlocked(); - string strAddress = params[0].get_str(); - string strMessage = params[1].get_str(); + std::string strAddress = params[0].get_str(); + std::string strMessage = params[1].get_str(); CBitcoinAddress addr(strAddress); if (!addr.IsValid()) @@ -415,7 +414,7 @@ Value signmessage(const Array& params, bool fHelp) ss << strMessageMagic; ss << strMessage; - vector vchSig; + std::vector vchSig; if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); @@ -425,13 +424,13 @@ Value signmessage(const Array& params, bool fHelp) Value verifymessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 3) - throw runtime_error( + throw std::runtime_error( "verifymessage \n" "Verify a signed message"); - string strAddress = params[0].get_str(); - string strSign = params[1].get_str(); - string strMessage = params[2].get_str(); + std::string strAddress = params[0].get_str(); + std::string strSign = params[1].get_str(); + std::string strMessage = params[2].get_str(); CBitcoinAddress addr(strAddress); if (!addr.IsValid()) @@ -442,7 +441,7 @@ Value verifymessage(const Array& params, bool fHelp) throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); bool fInvalid = false; - vector vchSig = DecodeBase64(strSign.c_str(), &fInvalid); + std::vector vchSig = DecodeBase64(strSign.c_str(), &fInvalid); if (fInvalid) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding"); @@ -462,7 +461,7 @@ Value verifymessage(const Array& params, bool fHelp) Value getreceivedbyaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) - throw runtime_error( + throw std::runtime_error( "getreceivedbyaddress [minconf=1]\n" "Returns the total amount received by in transactions with at least [minconf] confirmations."); @@ -479,7 +478,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) nMinDepth = params[1].get_int(); int64_t nAmount = 0; - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (wtx.IsCoinBase() || wtx.IsCoinStake() || !wtx.IsFinal()) @@ -498,12 +497,12 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) return ValueFromAmount(nAmount); } -void GetAccountAddresses(string strAccount, set& setAddress) +void GetAccountAddresses(std::string strAccount, std::set& setAddress) { for (const auto& item : pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; - const string& strName = item.second; + const std::string& strName = item.second; if (strName == strAccount) setAddress.insert(address); } @@ -512,7 +511,7 @@ void GetAccountAddresses(string strAccount, set& setAddress) Value getreceivedbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) - throw runtime_error( + throw std::runtime_error( "getreceivedbyaccount [minconf=1]\n" "Returns the total amount received by addresses with in transactions with at least [minconf] confirmations."); @@ -522,13 +521,13 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) nMinDepth = params[1].get_int(); // Get the set of pub keys assigned to account - string strAccount = AccountFromValue(params[0]); - set setAddress; + std::string strAccount = AccountFromValue(params[0]); + std::set setAddress; GetAccountAddresses(strAccount, setAddress); // Tally int64_t nAmount = 0; - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (wtx.IsCoinBase() || wtx.IsCoinStake() || !wtx.IsFinal()) @@ -547,12 +546,12 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) } -int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter) +int64_t GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter) { int64_t nBalance = 0; // Tally wallet transactions - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (!wtx.IsFinal()) @@ -572,7 +571,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi return nBalance; } -int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter) +int64_t GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter) { CWalletDB walletdb(pwalletMain->strWalletFile); return GetAccountBalance(walletdb, strAccount, nMinDepth, filter); @@ -582,7 +581,7 @@ int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminef Value getbalance(const Array& params, bool fHelp) { if (fHelp || params.size() > 3) - throw runtime_error( + throw std::runtime_error( "getbalance [account] [minconf=1] [watchonly=0]\n" "If [account] is not specified, returns the server's total available balance.\n" "If [account] is specified, returns the balance in the account.\n" @@ -604,7 +603,7 @@ Value getbalance(const Array& params, bool fHelp) // (GetBalance() sums up all unspent TxOuts) // getbalance and getbalance '*' 0 should return the same number. int64_t nBalance = 0; - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (!wtx.IsTrusted()) @@ -613,9 +612,9 @@ Value getbalance(const Array& params, bool fHelp) int64_t allGeneratedImmature, allGeneratedMature, allFee; allGeneratedImmature = allGeneratedMature = allFee = 0; - string strSentAccount; - list > listReceived; - list > listSent; + std::string strSentAccount; + std::list > listReceived; + std::list > listSent; wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter); if (wtx.GetDepthInMainChain() >= nMinDepth) { @@ -630,7 +629,7 @@ Value getbalance(const Array& params, bool fHelp) return ValueFromAmount(nBalance); } - string strAccount = AccountFromValue(params[0]); + std::string strAccount = AccountFromValue(params[0]); int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter); @@ -641,12 +640,12 @@ Value getbalance(const Array& params, bool fHelp) Value movecmd(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 5) - throw runtime_error( + throw std::runtime_error( "move [minconf=1] [comment]\n" "Move from one account in your wallet to another."); - string strFrom = AccountFromValue(params[0]); - string strTo = AccountFromValue(params[1]); + std::string strFrom = AccountFromValue(params[0]); + std::string strTo = AccountFromValue(params[1]); int64_t nAmount = AmountFromValue(params[2]); if (nAmount < nMinimumInputValue) @@ -655,7 +654,7 @@ Value movecmd(const Array& params, bool fHelp) if (params.size() > 3) // unused parameter, used to be nMinDepth, keep type-checking it though (void)params[3].get_int(); - string strComment; + std::string strComment; if (params.size() > 4) strComment = params[4].get_str(); @@ -695,16 +694,16 @@ Value movecmd(const Array& params, bool fHelp) Value sendfrom(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 6) - throw runtime_error( + throw std::runtime_error( "sendfrom [minconf=1] [comment] [comment-to]\n" " is a real and is rounded to the nearest " + FormatMoney(nMinimumInputValue) + HelpRequiringPassphrase()); - string strAccount = AccountFromValue(params[0]); + std::string strAccount = AccountFromValue(params[0]); // Parse address CScript scriptPubKey; - string strAddress = params[1].get_str(); + std::string strAddress = params[1].get_str(); CBitcoinAddress address(strAddress); if (address.IsValid()) @@ -737,7 +736,7 @@ Value sendfrom(const Array& params, bool fHelp) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); // Send - string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); + std::string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); @@ -748,12 +747,12 @@ Value sendfrom(const Array& params, bool fHelp) Value sendmany(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) - throw runtime_error( + throw std::runtime_error( "sendmany '{address:amount,...}' [minconf=1] [comment]\n" "amounts are double-precision floating point numbers" + HelpRequiringPassphrase()); - string strAccount = AccountFromValue(params[0]); + std::string strAccount = AccountFromValue(params[0]); Object sendTo = params[1].get_obj(); int nMinDepth = 1; if (params.size() > 2) @@ -764,20 +763,20 @@ Value sendmany(const Array& params, bool fHelp) if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) wtx.mapValue["comment"] = params[3].get_str(); - set setAddress; - vector > vecSend; + std::set setAddress; + std::vector > vecSend; int64_t totalAmount = 0; for (const Pair& s : sendTo) { CBitcoinAddress address(s.name_); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid NovaCoin address: ")+s.name_); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid NovaCoin address: ")+s.name_); if (!address.IsPair()) { if (setAddress.count(address)) - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_); + throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+s.name_); setAddress.insert(address); } @@ -821,28 +820,28 @@ Value addmultisigaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) { - string msg = "addmultisigaddress <'[\"key\",\"key\"]'> [account]\n" + std::string msg = "addmultisigaddress <'[\"key\",\"key\"]'> [account]\n" "Add a nrequired-to-sign multisignature address to the wallet\"\n" "each key is a NovaCoin address or hex-encoded public key\n" "If [account] is specified, assign address to [account]."; - throw runtime_error(msg); + throw std::runtime_error(msg); } int nRequired = params[0].get_int(); const Array& keys = params[1].get_array(); - string strAccount; + std::string strAccount; if (params.size() > 2) strAccount = AccountFromValue(params[2]); // Gather public keys if (nRequired < 1) - throw runtime_error("a multisignature address must require at least one key to redeem"); + throw std::runtime_error("a multisignature address must require at least one key to redeem"); if ((int)keys.size() < nRequired) - throw runtime_error( + throw std::runtime_error( strprintf("not enough keys supplied " "(got %" PRIszu " keys, but need at least %d to redeem)", keys.size(), nRequired)); if (keys.size() > 16) - throw runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number"); + throw std::runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number"); std::vector pubkeys; pubkeys.resize(keys.size()); for (unsigned int i = 0; i < keys.size(); i++) @@ -855,14 +854,14 @@ Value addmultisigaddress(const Array& params, bool fHelp) { CKeyID keyID; if (!address.GetKeyID(keyID)) - throw runtime_error( + throw std::runtime_error( strprintf("%s does not refer to a key",ks.c_str())); CPubKey vchPubKey; if (!pwalletMain->GetPubKey(keyID, vchPubKey)) - throw runtime_error( + throw std::runtime_error( strprintf("no full public key for address %s",ks.c_str())); if (!vchPubKey.IsValid()) - throw runtime_error(" Invalid public key: "+ks); + throw std::runtime_error(" Invalid public key: "+ks); pubkeys[i] = vchPubKey; } @@ -871,12 +870,12 @@ Value addmultisigaddress(const Array& params, bool fHelp) { CPubKey vchPubKey(ParseHex(ks)); if (!vchPubKey.IsValid()) - throw runtime_error(" Invalid public key: "+ks); + throw std::runtime_error(" Invalid public key: "+ks); pubkeys[i] = vchPubKey; } else { - throw runtime_error(" Invalid public key: "+ks); + throw std::runtime_error(" Invalid public key: "+ks); } } @@ -885,7 +884,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) inner.SetMultisig(nRequired, pubkeys); if (inner.size() > MAX_SCRIPT_ELEMENT_SIZE) - throw runtime_error( + throw std::runtime_error( strprintf("redeemScript exceeds size limit: %" PRIszu " > %d", inner.size(), MAX_SCRIPT_ELEMENT_SIZE)); pwalletMain->AddCScript(inner); @@ -899,18 +898,18 @@ Value addredeemscript(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) { - string msg = "addredeemscript [account]\n" + std::string msg = "addredeemscript [account]\n" "Add a P2SH address with a specified redeemScript to the wallet.\n" "If [account] is specified, assign address to [account]."; - throw runtime_error(msg); + throw std::runtime_error(msg); } - string strAccount; + std::string strAccount; if (params.size() > 1) strAccount = AccountFromValue(params[1]); // Construct using pay-to-script-hash: - vector innerData = ParseHexV(params[0], "redeemScript"); + auto innerData = ParseHexV(params[0], "redeemScript"); CScript inner(innerData.begin(), innerData.end()); pwalletMain->AddCScript(inner); CBitcoinAddress address(inner.GetID()); @@ -943,8 +942,8 @@ Value ListReceived(const Array& params, bool fByAccounts) fIncludeEmpty = params[1].get_bool(); // Tally - map mapTally; - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) + std::map mapTally; + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; @@ -963,18 +962,18 @@ Value ListReceived(const Array& params, bool fByAccounts) tallyitem& item = mapTally[address]; item.nAmount += txout.nValue; - item.nConf = min(item.nConf, nDepth); + item.nConf = std::min(item.nConf, nDepth); } } // Reply Array ret; - map mapAccountTally; + std::map mapAccountTally; for (const auto& item : pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; - const string& strAccount = item.second; - map::iterator it = mapTally.find(address); + const std::string& strAccount = item.second; + auto it = mapTally.find(address); if (it == mapTally.end() && !fIncludeEmpty) continue; @@ -990,7 +989,7 @@ Value ListReceived(const Array& params, bool fByAccounts) { tallyitem& item = mapAccountTally[strAccount]; item.nAmount += nAmount; - item.nConf = min(item.nConf, nConf); + item.nConf = std::min(item.nConf, nConf); } else { @@ -1005,7 +1004,7 @@ Value ListReceived(const Array& params, bool fByAccounts) if (fByAccounts) { - for (map::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it) + for (auto it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it) { int64_t nAmount = (*it).second.nAmount; int nConf = (*it).second.nConf; @@ -1023,7 +1022,7 @@ Value ListReceived(const Array& params, bool fByAccounts) Value listreceivedbyaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) - throw runtime_error( + throw std::runtime_error( "listreceivedbyaddress [minconf=1] [includeempty=false]\n" "[minconf] is the minimum number of confirmations before payments are included.\n" "[includeempty] whether to include addresses that haven't received any payments.\n" @@ -1039,7 +1038,7 @@ Value listreceivedbyaddress(const Array& params, bool fHelp) Value listreceivedbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) - throw runtime_error( + throw std::runtime_error( "listreceivedbyaccount [minconf=1] [includeempty=false]\n" "[minconf] is the minimum number of confirmations before payments are included.\n" "[includeempty] whether to include accounts that haven't received any payments.\n" @@ -1056,23 +1055,23 @@ static void MaybePushAddress(Object & entry, const CBitcoinAddress &dest) entry.push_back(Pair("address", dest.ToString())); } -void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter) +void ListTransactions(const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter) { int64_t nGeneratedImmature, nGeneratedMature, nFee; - string strSentAccount; - list > listReceived; - list > listSent; + std::string strSentAccount; + std::list > listReceived; + std::list > listSent; wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount, filter); - bool fAllAccounts = (strAccount == string("*")); + bool fAllAccounts = (strAccount == std::string("*")); bool involvesWatchonly = wtx.IsFromMe(MINE_WATCH_ONLY); // Generated blocks assigned to account "" if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount.empty())) { Object entry; - entry.push_back(Pair("account", string(""))); + entry.push_back(Pair("account", std::string(""))); if (nGeneratedImmature) { entry.push_back(Pair("category", wtx.GetDepthInMainChain() ? "immature" : "orphan")); @@ -1118,7 +1117,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe { for (const auto& r : listReceived) { - string account; + std::string account; if (pwalletMain->mapAddressBook.count(r.first)) account = pwalletMain->mapAddressBook[r.first]; if (fAllAccounts || (account == strAccount)) @@ -1148,9 +1147,9 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe } } -void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret) +void AcentryToJSON(const CAccountingEntry& acentry, const std::string& strAccount, Array& ret) { - bool fAllAccounts = (strAccount == string("*")); + bool fAllAccounts = (strAccount == std::string("*")); if (fAllAccounts || acentry.strAccount == strAccount) { @@ -1168,11 +1167,11 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Ar Value listtransactions(const Array& params, bool fHelp) { if (fHelp || params.size() > 3) - throw runtime_error( + throw std::runtime_error( "listtransactions [account] [count=10] [from=0]\n" "Returns up to [count] most recent transactions skipping the first [from] transactions for account [account]."); - string strAccount = "*"; + std::string strAccount = "*"; if (params.size() > 0) strAccount = params[0].get_str(); int nCount = 10; @@ -1231,7 +1230,7 @@ Value listtransactions(const Array& params, bool fHelp) Value listaccounts(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) - throw runtime_error( + throw std::runtime_error( "listaccounts [minconf=1]\n" "Returns Object that has account names as keys, account balances as values."); @@ -1245,19 +1244,19 @@ Value listaccounts(const Array& params, bool fHelp) includeWatchonly = includeWatchonly | MINE_WATCH_ONLY; - map mapAccountBalances; + std::map mapAccountBalances; for (const auto& entry : pwalletMain->mapAddressBook) { if (IsMine(*pwalletMain, entry.first)) // This address belongs to me mapAccountBalances[entry.second] = 0; } - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; int64_t nGeneratedImmature, nGeneratedMature, nFee; - string strSentAccount; - list > listReceived; - list > listSent; + std::string strSentAccount; + std::list > listReceived; + std::list > listSent; wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount, includeWatchonly); mapAccountBalances[strSentAccount] -= nFee; for (const auto& s : listSent) @@ -1273,7 +1272,7 @@ Value listaccounts(const Array& params, bool fHelp) } } - list acentries; + std::list acentries; CWalletDB(pwalletMain->strWalletFile).ListAccountCreditDebit("*", acentries); for (const CAccountingEntry& entry : acentries) mapAccountBalances[entry.strAccount] += entry.nCreditDebit; @@ -1288,7 +1287,7 @@ Value listaccounts(const Array& params, bool fHelp) Value listsinceblock(const Array& params, bool fHelp) { if (fHelp) - throw runtime_error( + throw std::runtime_error( "listsinceblock [blockhash] [target-confirmations]\n" "Get all transactions in blocks since block [blockhash], or all transactions if omitted"); @@ -1320,7 +1319,7 @@ Value listsinceblock(const Array& params, bool fHelp) Array transactions; - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++) + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++) { CWalletTx tx = (*it).second; @@ -1356,7 +1355,7 @@ Value listsinceblock(const Array& params, bool fHelp) Value gettransaction(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error( + throw std::runtime_error( "gettransaction \n" "Get detailed information about "); @@ -1403,7 +1402,7 @@ Value gettransaction(const Array& params, bool fHelp) else { entry.push_back(Pair("blockhash", hashBlock.GetHex())); - map::iterator mi = mapBlockIndex.find(hashBlock); + auto mi = mapBlockIndex.find(hashBlock); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; @@ -1425,11 +1424,11 @@ Value gettransaction(const Array& params, bool fHelp) Value backupwallet(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error( + throw std::runtime_error( "backupwallet \n" "Safely copies wallet.dat to destination, which can be a directory or a path with filename."); - string strDest = params[0].get_str(); + std::string strDest = params[0].get_str(); if (!BackupWallet(*pwalletMain, strDest)) throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); @@ -1440,14 +1439,14 @@ Value backupwallet(const Array& params, bool fHelp) Value keypoolrefill(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) - throw runtime_error( + throw std::runtime_error( "keypoolrefill [new-size]\n" "Fills the keypool.\n" "IMPORTANT: Any previous backups you have made of your wallet file " "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); + unsigned int nSize = std::max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1467,14 +1466,14 @@ Value keypoolrefill(const Array& params, bool fHelp) Value keypoolreset(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) - throw runtime_error( + throw std::runtime_error( "keypoolreset [new-size]\n" "Resets the keypool.\n" "IMPORTANT: Any previous backups you have made of your wallet file " "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); + unsigned int nSize = std::max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1547,7 +1546,7 @@ void ThreadCleanWalletPassphrase(void* parg) Value walletpassphrase(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3)) - throw runtime_error( + throw std::runtime_error( "walletpassphrase [mintonly]\n" "Stores the wallet decryption key in memory for seconds.\n" "mintonly is optional true/false allowing only block minting."); @@ -1571,7 +1570,7 @@ Value walletpassphrase(const Array& params, bool fHelp) throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); } else - throw runtime_error( + throw std::runtime_error( "walletpassphrase \n" "Stores the wallet decryption key in memory for seconds."); @@ -1592,7 +1591,7 @@ Value walletpassphrase(const Array& params, bool fHelp) Value walletpassphrasechange(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) - throw runtime_error( + throw std::runtime_error( "walletpassphrasechange \n" "Changes the wallet passphrase from to ."); if (fHelp) @@ -1611,7 +1610,7 @@ Value walletpassphrasechange(const Array& params, bool fHelp) strNewWalletPass = params[1].get_str().c_str(); if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1) - throw runtime_error( + throw std::runtime_error( "walletpassphrasechange \n" "Changes the wallet passphrase from to ."); @@ -1625,7 +1624,7 @@ Value walletpassphrasechange(const Array& params, bool fHelp) Value walletlock(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0)) - throw runtime_error( + throw std::runtime_error( "walletlock\n" "Removes the wallet encryption key from memory, locking the wallet.\n" "After calling this method, you will need to call walletpassphrase again\n" @@ -1648,7 +1647,7 @@ Value walletlock(const Array& params, bool fHelp) Value encryptwallet(const Array& params, bool fHelp) { if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1)) - throw runtime_error( + throw std::runtime_error( "encryptwallet \n" "Encrypts the wallet with ."); if (fHelp) @@ -1663,7 +1662,7 @@ Value encryptwallet(const Array& params, bool fHelp) strWalletPass = params[0].get_str().c_str(); if (strWalletPass.length() < 1) - throw runtime_error( + throw std::runtime_error( "encryptwallet \n" "Encrypts the wallet with ."); @@ -1724,7 +1723,7 @@ public: Value validateaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error( + throw std::runtime_error( "validateaddress \n" "Return information about ."); @@ -1751,7 +1750,7 @@ Value validateaddress(const Array& params, bool fHelp) } else { - string currentAddress = address.ToString(); + std::string currentAddress = address.ToString(); CTxDestination dest = address.Get(); ret.push_back(Pair("address", currentAddress)); isminetype mine = pwalletMain ? IsMine(*pwalletMain, address) : MINE_NO; @@ -1772,7 +1771,7 @@ Value validateaddress(const Array& params, bool fHelp) Value reservebalance(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) - throw runtime_error( + throw std::runtime_error( "reservebalance [ [amount]]\n" " is true or false to turn balance reserve on or off.\n" " is a real and rounded to cent.\n" @@ -1785,24 +1784,24 @@ Value reservebalance(const Array& params, bool fHelp) if (fReserve) { if (params.size() == 1) - throw runtime_error("must provide amount to reserve balance.\n"); + throw std::runtime_error("must provide amount to reserve balance.\n"); int64_t nAmount = AmountFromValue(params[1]); nAmount = (nAmount / CENT) * CENT; // round to cent if (nAmount < 0) - throw runtime_error("amount cannot be negative.\n"); + throw std::runtime_error("amount cannot be negative.\n"); mapArgs["-reservebalance"] = FormatMoney(nAmount); } else { if (params.size() > 1) - throw runtime_error("cannot specify amount to turn off reserve.\n"); + throw std::runtime_error("cannot specify amount to turn off reserve.\n"); mapArgs["-reservebalance"] = "0"; } } Object result; if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance)) - throw runtime_error("invalid reserve balance amount\n"); + throw std::runtime_error("invalid reserve balance amount\n"); result.push_back(Pair("reserve", (nReserveBalance > 0))); result.push_back(Pair("amount", ValueFromAmount(nReserveBalance))); return result; @@ -1813,7 +1812,7 @@ Value reservebalance(const Array& params, bool fHelp) Value checkwallet(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) - throw runtime_error( + throw std::runtime_error( "checkwallet\n" "Check wallet for integrity.\n"); @@ -1836,7 +1835,7 @@ Value checkwallet(const Array& params, bool fHelp) Value repairwallet(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) - throw runtime_error( + throw std::runtime_error( "repairwallet\n" "Repair wallet if checkwallet reports any problem.\n"); @@ -1858,7 +1857,7 @@ Value repairwallet(const Array& params, bool fHelp) Value resendtx(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) - throw runtime_error( + throw std::runtime_error( "resendtx\n" "Re-send unconfirmed transactions.\n" ); @@ -1871,7 +1870,7 @@ Value resendtx(const Array& params, bool fHelp) Value resendwallettransactions(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) - throw runtime_error( + throw std::runtime_error( "resendwallettransactions\n" "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n" "Intended only for testing; the wallet code periodically re-broadcasts\n" @@ -1895,11 +1894,11 @@ Value resendwallettransactions(const Array& params, bool fHelp) Value makekeypair(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) - throw runtime_error( + throw std::runtime_error( "makekeypair\n" "Make a public/private key pair.\n"); - string strPrefix = ""; + std::string strPrefix = ""; if (params.size() > 0) strPrefix = params[0].get_str(); @@ -1921,12 +1920,12 @@ Value makekeypair(const Array& params, bool fHelp) Value newmalleablekey(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) - throw runtime_error( + throw std::runtime_error( "newmalleablekey\n" "Make a malleable public/private key pair.\n"); // Parse the account first so we don't generate a key if there's an error - string strAccount; + std::string strAccount; if (params.size() > 0) strAccount = AccountFromValue(params[0]); @@ -1934,7 +1933,7 @@ Value newmalleablekey(const Array& params, bool fHelp) CMalleableKey mKey; if (!pwalletMain->GetMalleableKey(keyView, mKey)) - throw runtime_error("Unable to generate new malleable key"); + throw std::runtime_error("Unable to generate new malleable key"); CMalleablePubKey mPubKey = mKey.GetMalleablePubKey(); CBitcoinAddress address(mPubKey); @@ -1953,7 +1952,7 @@ Value newmalleablekey(const Array& params, bool fHelp) Value adjustmalleablekey(const Array& params, bool fHelp) { if (fHelp || params.size() != 3) - throw runtime_error( + throw std::runtime_error( "adjustmalleablekey \n" "Calculate new private key using provided malleable key, public key and R data.\n"); @@ -1966,7 +1965,7 @@ Value adjustmalleablekey(const Array& params, bool fHelp) CPubKey R(ParseHex(params[2].get_str())); if (!malleableKey.CheckKeyVariant(R,vchPubKeyVariant, privKeyVariant)) { - throw runtime_error("Unable to calculate the private key"); + throw std::runtime_error("Unable to calculate the private key"); } Object result; @@ -1981,11 +1980,11 @@ Value adjustmalleablekey(const Array& params, bool fHelp) Value adjustmalleablepubkey(const Array& params, bool fHelp) { if (fHelp || params.size() > 2 || params.size() == 0) - throw runtime_error( + throw std::runtime_error( "adjustmalleablepubkey \n" "Calculate new public key using provided data.\n"); - string strData = params[0].get_str(); + std::string strData = params[0].get_str(); CMalleablePubKey malleablePubKey; do @@ -2007,7 +2006,7 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp) if (malleablePubKey.SetString(strData)) break; // A valid public key pair - throw runtime_error("Though your data seems a valid Base58 string, we were unable to recognize it."); + throw std::runtime_error("Though your data seems a valid Base58 string, we were unable to recognize it."); } while(false); @@ -2025,7 +2024,7 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp) Value listmalleableviews(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) - throw runtime_error( + throw std::runtime_error( "listmalleableviews\n" "Get list of views for generated malleable keys.\n"); diff --git a/src/wallet.cpp b/src/wallet.cpp index 71a0988..83cb307 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -17,7 +17,7 @@ #include #include -using namespace std; + extern int64_t nReserveBalance; ////////////////////////////////////////////////////////////////////////////// @@ -27,8 +27,8 @@ extern int64_t nReserveBalance; struct CompareValueOnly { - bool operator()(const pair >& t1, - const pair >& t2) const + bool operator()(const std::pair >& t1, + const std::pair >& t2) const { return t1.first < t2.first; } @@ -137,7 +137,7 @@ bool CWallet::AddCryptedMalleableKey(const CMalleableKeyView& keyView, const std bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret) { SetMinVersion(FEATURE_WALLETCRYPT); return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } -bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector &vchCryptedSecret) +bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret) { if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; @@ -558,13 +558,13 @@ CWallet::TxItems CWallet::OrderedTxItems(std::list& acentries, for (auto & it : mapWallet) { CWalletTx* wtx = &(it.second); - txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)nullptr))); + txOrdered.insert(std::make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)nullptr))); } acentries.clear(); walletdb.ListAccountCreditDebit(strAccount, acentries); for (CAccountingEntry& entry : acentries) { - txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)nullptr, &entry))); + txOrdered.insert(std::make_pair(entry.nOrderPos, TxPair((CWalletTx*)nullptr, &entry))); } return txOrdered; @@ -579,7 +579,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) LOCK(cs_wallet); for (const CTxIn& txin : tx.vin) { - map::iterator mi = mapWallet.find(txin.prevout.hash); + auto mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { CWalletTx& wtx = (*mi).second; @@ -599,7 +599,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) if (fBlock) { uint256 hash = tx.GetHash(); - map::iterator mi = mapWallet.find(hash); + auto mi = mapWallet.find(hash); CWalletTx& wtx = (*mi).second; for (const CTxOut& txout : tx.vout) @@ -632,7 +632,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) { LOCK(cs_wallet); // Inserts only if not already there, returns tx inserted or tx found - pair::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn)); + auto ret = mapWallet.insert(std::make_pair(hash, wtxIn)); CWalletTx& wtx = (*ret.first).second; wtx.BindWallet(this); bool fInsertedNew = ret.second; @@ -793,7 +793,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const { { LOCK(cs_wallet); - map::const_iterator mi = mapWallet.find(txin.prevout.hash); + auto mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { const CWalletTx& prev = (*mi).second; @@ -876,7 +876,7 @@ int64_t CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const { { LOCK(cs_wallet); - map::const_iterator mi = mapWallet.find(txin.prevout.hash); + auto mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { const CWalletTx& prev = (*mi).second; @@ -994,7 +994,7 @@ int CWalletTx::GetRequestCount() const // Generated block if (hashBlock != 0) { - map::const_iterator mi = pwallet->mapRequestCount.find(hashBlock); + auto mi = pwallet->mapRequestCount.find(hashBlock); if (mi != pwallet->mapRequestCount.end()) nRequests = (*mi).second; } @@ -1002,7 +1002,7 @@ int CWalletTx::GetRequestCount() const else { // Did anyone request this transaction? - map::const_iterator mi = pwallet->mapRequestCount.find(GetHash()); + auto mi = pwallet->mapRequestCount.find(GetHash()); if (mi != pwallet->mapRequestCount.end()) { nRequests = (*mi).second; @@ -1010,7 +1010,7 @@ int CWalletTx::GetRequestCount() const // How about the block it's in? if (nRequests == 0 && hashBlock != 0) { - map::const_iterator mi = pwallet->mapRequestCount.find(hashBlock); + auto mi = pwallet->mapRequestCount.find(hashBlock); if (mi != pwallet->mapRequestCount.end()) nRequests = (*mi).second; else @@ -1222,8 +1222,8 @@ int64_t CWalletTx::GetChange() const return nChangeCached; } -void CWalletTx::GetAmounts(int64_t& nGeneratedImmature, int64_t& nGeneratedMature, list >& listReceived, - list >& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const +void CWalletTx::GetAmounts(int64_t& nGeneratedImmature, int64_t& nGeneratedMature, std::list >& listReceived, + std::list >& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const { nGeneratedImmature = nGeneratedMature = nFee = 0; listReceived.clear(); @@ -1274,25 +1274,25 @@ void CWalletTx::GetAmounts(int64_t& nGeneratedImmature, int64_t& nGeneratedMatur // If we are debited by the transaction, add the output as a "sent" entry if (nDebit > 0) - listSent.push_back(make_pair(address, txout.nValue)); + listSent.push_back(std::make_pair(address, txout.nValue)); // If we are receiving the output, add it as a "received" entry if (fIsMine & filter) - listReceived.push_back(make_pair(address, txout.nValue)); + listReceived.push_back(std::make_pair(address, txout.nValue)); } } -void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nGenerated, int64_t& nReceived, +void CWalletTx::GetAccountAmounts(const std::string& strAccount, int64_t& nGenerated, int64_t& nReceived, int64_t& nSent, int64_t& nFee, const isminefilter& filter) const { nGenerated = nReceived = nSent = nFee = 0; int64_t allGeneratedImmature, allGeneratedMature, allFee; allGeneratedImmature = allGeneratedMature = allFee = 0; - string strSentAccount; - list > listReceived; - list > listSent; + std::string strSentAccount; + std::list > listReceived; + std::list > listSent; GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter); if (strAccount.empty()) @@ -1309,7 +1309,7 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nGenerated, { if (pwallet->mapAddressBook.count(r.first)) { - map::const_iterator mi = pwallet->mapAddressBook.find(r.first); + auto mi = pwallet->mapAddressBook.find(r.first); if (mi != pwallet->mapAddressBook.end() && (*mi).second == strAccount) nReceived += r.second; } @@ -1333,15 +1333,15 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) const int COPY_DEPTH = 3; if (SetMerkleBranch() < COPY_DEPTH) { - vector vWorkQueue; + std::vector vWorkQueue; for (const CTxIn& txin : vin) vWorkQueue.push_back(txin.prevout.hash); // This critsect is OK because txdb is already open { LOCK(pwallet->cs_wallet); - map mapWalletPrev; - set setAlreadyDone; + std::map mapWalletPrev; + std::set setAlreadyDone; for (unsigned int i = 0; i < vWorkQueue.size(); i++) { uint256 hash = vWorkQueue[i]; @@ -1350,7 +1350,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) setAlreadyDone.insert(hash); CMerkleTx tx; - map::const_iterator mi = pwallet->mapWallet.find(hash); + auto mi = pwallet->mapWallet.find(hash); if (mi != pwallet->mapWallet.end()) { tx = (*mi).second; @@ -1459,7 +1459,7 @@ void CWallet::ReacceptWalletTransactions() { LOCK(cs_wallet); fRepeat = false; - vector vMissingTx; + std::vector vMissingTx; for (auto& item : mapWallet) { CWalletTx& wtx = item.second; @@ -1545,14 +1545,14 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) LOCK(cs_wallet); // Sort them in chronological order - map mapSorted; + std::map mapSorted; for (auto& item : mapWallet) { CWalletTx& wtx = item.second; // Don't rebroadcast if newer than nTime: if (wtx.nTimeReceived > nTime) continue; - mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx)); + mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx)); } for (auto& item : mapSorted) { @@ -1600,7 +1600,7 @@ int64_t CWallet::GetBalance() const int64_t nTotal = 0; { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsTrusted()) @@ -1616,7 +1616,7 @@ int64_t CWallet::GetWatchOnlyBalance() const int64_t nTotal = 0; { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsTrusted()) @@ -1632,7 +1632,7 @@ int64_t CWallet::GetUnconfirmedBalance() const int64_t nTotal = 0; { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (!pcoin->IsFinal() || !pcoin->IsTrusted()) @@ -1647,7 +1647,7 @@ int64_t CWallet::GetUnconfirmedWatchOnlyBalance() const int64_t nTotal = 0; { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (!pcoin->IsFinal() || !pcoin->IsTrusted()) @@ -1662,7 +1662,7 @@ int64_t CWallet::GetImmatureBalance() const int64_t nTotal = 0; { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; nTotal += pcoin->GetImmatureCredit(); @@ -1676,7 +1676,7 @@ int64_t CWallet::GetImmatureWatchOnlyBalance() const int64_t nTotal = 0; { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; nTotal += pcoin->GetImmatureWatchOnlyCredit(); @@ -1686,13 +1686,13 @@ int64_t CWallet::GetImmatureWatchOnlyBalance() const } // populate vCoins with vector of spendable COutputs -void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl) const +void CWallet::AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl) const { vCoins.clear(); { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; @@ -1721,13 +1721,13 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const } } -void CWallet::AvailableCoinsMinConf(vector& vCoins, int nConf, int64_t nMinValue, int64_t nMaxValue) const +void CWallet::AvailableCoinsMinConf(std::vector& vCoins, int nConf, int64_t nMinValue, int64_t nMaxValue) const { vCoins.clear(); { LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; @@ -1752,10 +1752,10 @@ void CWallet::AvailableCoinsMinConf(vector& vCoins, int nConf, int64_t } } -static void ApproximateBestSubset(vector > >vValue, int64_t nTotalLower, int64_t nTargetValue, - vector& vfBest, int64_t& nBest, int iterations = 1000) +static void ApproximateBestSubset(std::vector > >vValue, int64_t nTotalLower, int64_t nTargetValue, + std::vector& vfBest, int64_t& nBest, int iterations = 1000) { - vector vfIncluded; + std::vector vfIncluded; vfBest.assign(vValue.size(), true); nBest = nTotalLower; @@ -1794,7 +1794,7 @@ int64_t CWallet::GetStake() const { int64_t nTotal = 0; LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsCoinStake() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0) @@ -1807,7 +1807,7 @@ int64_t CWallet::GetWatchOnlyStake() const { int64_t nTotal = 0; LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsCoinStake() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0) @@ -1820,7 +1820,7 @@ int64_t CWallet::GetNewMint() const { int64_t nTotal = 0; LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0) @@ -1833,7 +1833,7 @@ int64_t CWallet::GetWatchOnlyNewMint() const { int64_t nTotal = 0; LOCK(cs_wallet); - for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0) @@ -1842,16 +1842,16 @@ int64_t CWallet::GetWatchOnlyNewMint() const return nTotal; } -bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, vector vCoins, set >& setCoinsRet, int64_t& nValueRet) const +bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const { setCoinsRet.clear(); nValueRet = 0; // List of values less than target - pair > coinLowestLarger; + std::pair > coinLowestLarger; coinLowestLarger.first = std::numeric_limits::max(); coinLowestLarger.second.first = NULL; - vector > > vValue; + std::vector > > vValue; int64_t nTotalLower = 0; std::random_device rd; @@ -1876,7 +1876,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int64_t n = pcoin->vout[i].nValue; - pair > coin = make_pair(n,make_pair(pcoin, i)); + auto coin = std::make_pair(n, std::make_pair(pcoin, i)); if (n == nTargetValue) { @@ -1917,7 +1917,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, // Solve subset sum by stochastic approximation std::sort(vValue.begin(), vValue.end(), CompareValueOnly()); std::reverse(vValue.begin(), vValue.end()); - vector vfBest; + std::vector vfBest; int64_t nBest; ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000); @@ -1954,9 +1954,9 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, return true; } -bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, set >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl) const +bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl) const { - vector vCoins; + std::vector vCoins; AvailableCoins(vCoins, true, coinControl); // coin control -> return all selected outputs (we want all selected to go into the transaction for sure) @@ -1967,7 +1967,7 @@ bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, setvout[out.i].nValue; - setCoinsRet.insert(make_pair(out.tx, out.i)); + setCoinsRet.insert(std::make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); } @@ -2007,9 +2007,9 @@ void CWallet::SetNull() } // Select some coins without random shuffle or best subset approximation -bool CWallet::SelectCoinsSimple(int64_t nTargetValue, int64_t nMinValue, int64_t nMaxValue, unsigned int nSpendTime, int nMinConf, set >& setCoinsRet, int64_t& nValueRet) const +bool CWallet::SelectCoinsSimple(int64_t nTargetValue, int64_t nMinValue, int64_t nMaxValue, unsigned int nSpendTime, int nMinConf, std::set >& setCoinsRet, int64_t& nValueRet) const { - vector vCoins; + std::vector vCoins; AvailableCoinsMinConf(vCoins, nMinConf, nMinValue, nMaxValue); setCoinsRet.clear(); @@ -2036,7 +2036,7 @@ bool CWallet::SelectCoinsSimple(int64_t nTargetValue, int64_t nMinValue, int64_t int64_t n = pcoin->vout[i].nValue; - pair > coin = make_pair(n,make_pair(pcoin, i)); + auto coin = std::make_pair(n, std::make_pair(pcoin, i)); if (n >= nTargetValue) { @@ -2056,7 +2056,7 @@ bool CWallet::SelectCoinsSimple(int64_t nTargetValue, int64_t nMinValue, int64_t return true; } -bool CWallet::CreateTransaction(const vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl) +bool CWallet::CreateTransaction(const std::vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl) { int64_t nValue = 0; for (const auto& s : vecSend) @@ -2089,7 +2089,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, wtxNew.vout.push_back(CTxOut(s.second, s.first)); // Choose coins to use - set > setCoins; + std::set > setCoins; int64_t nValueIn = 0; if (!SelectCoins(nTotalValue, wtxNew.nTime, setCoins, nValueIn, coinControl)) return false; @@ -2128,7 +2128,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, } // Insert change txn at random position: - vector::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size()); + auto position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size()); wtxNew.vout.insert(position, CTxOut(nChange, scriptChange)); } else @@ -2155,9 +2155,9 @@ bool CWallet::CreateTransaction(const vector >& vecSend, int64_t nPayFee = nTransactionFee * (1 + (int64_t)nBytes / 1000); int64_t nMinFee = wtxNew.GetMinFee(1, fAllowFree, GMF_SEND, nBytes); - if (nFeeRet < max(nPayFee, nMinFee)) + if (nFeeRet < std::max(nPayFee, nMinFee)) { - nFeeRet = max(nPayFee, nMinFee); + nFeeRet = std::max(nPayFee, nMinFee); continue; } @@ -2174,8 +2174,8 @@ bool CWallet::CreateTransaction(const vector >& vecSend, bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl) { - vector< pair > vecSend; - vecSend.push_back(make_pair(scriptPubKey, nValue)); + std::vector< std::pair > vecSend; + vecSend.push_back(std::make_pair(scriptPubKey, nValue)); return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, coinControl); } @@ -2194,7 +2194,7 @@ void CWallet::GetStakeWeightFromValue(const int64_t& nTime, const int64_t& nValu nWeight = bnCoinDayWeight.getuint64(); } -bool CWallet::MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const int64_t& nOutputValue, list& listMerged) +bool CWallet::MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const int64_t& nOutputValue, std::list& listMerged) { int64_t nBalance = GetBalance(); @@ -2203,7 +2203,7 @@ bool CWallet::MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const listMerged.clear(); int64_t nValueIn = 0; - set > setCoins; + std::set > setCoins; // Simple coins selection - no randomization if (!SelectCoinsSimple(nAmount, nMinValue, nOutputValue, GetTime(), 1, setCoins, nValueIn)) @@ -2213,7 +2213,7 @@ bool CWallet::MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const return false; CWalletTx wtxNew; - vector vwtxPrev; + std::vector vwtxPrev; // Reserve a new key pair from key pool CReserveKey reservekey(this); @@ -2323,7 +2323,7 @@ bool CWallet::CreateCoinStake(uint256 &hashTx, uint32_t nOut, uint32_t nGenerati if (!GetTransaction(hashTx, wtx)) return error("Transaction %s is not found\n", hashTx.GetHex().c_str()); - vector vSolutions; + std::vector vSolutions; txnouttype whichType; CScript scriptPubKeyOut; CScript scriptPubKeyKernel = wtx.vout[nOut].scriptPubKey; @@ -2365,7 +2365,7 @@ bool CWallet::CreateCoinStake(uint256 &hashTx, uint32_t nOut, uint32_t nGenerati txNew.vout.clear(); // List of constake dependencies - vector vwtxPrev; + std::vector vwtxPrev; vwtxPrev.push_back(&wtx); // Set generation time, and kernel input @@ -2561,7 +2561,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) -string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee) +std::string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee) { // Check amount if (nValue <= 0) @@ -2574,19 +2574,19 @@ string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNe if (IsLocked()) { - string strError = _("Error: Wallet locked, unable to create transaction "); + std::string strError = _("Error: Wallet locked, unable to create transaction "); printf("SendMoney() : %s", strError.c_str()); return strError; } if (fWalletUnlockMintOnly) { - string strError = _("Error: Wallet unlocked for block minting only, unable to create transaction."); + std::string strError = _("Error: Wallet unlocked for block minting only, unable to create transaction."); printf("SendMoney() : %s", strError.c_str()); return strError; } if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired)) { - string strError; + std::string strError; if (nValue + nFeeRequired > GetBalance()) strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds "), FormatMoney(nFeeRequired).c_str()); else @@ -2652,14 +2652,14 @@ DBErrors CWallet::ZapWalletTx() return DB_LOAD_OK; } -bool CWallet::SetAddressBookName(const CTxDestination& address, const string& strName) +bool CWallet::SetAddressBookName(const CTxDestination& address, const std::string& strName) { return SetAddressBookName(CBitcoinAddress(address), strName); } -bool CWallet::SetAddressBookName(const CBitcoinAddress& address, const string& strName) +bool CWallet::SetAddressBookName(const CBitcoinAddress& address, const std::string& strName) { - std::map::iterator mi = mapAddressBook.find(address); + auto mi = mapAddressBook.find(address); mapAddressBook[address] = strName; NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address) != MINE_NO, (mi == mapAddressBook.end()) ? CT_NEW : CT_UPDATED); if (!fFileBacked) @@ -2699,7 +2699,7 @@ void CWallet::Inventory(const uint256 &hash) { { LOCK(cs_wallet); - std::map::iterator mi = mapRequestCount.find(hash); + auto mi = mapRequestCount.find(hash); if (mi != mapRequestCount.end()) (*mi).second++; } @@ -2714,7 +2714,7 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx) { { LOCK(cs_wallet); - map::iterator mi = mapWallet.find(hashTx); + auto mi = mapWallet.find(hashTx); if (mi != mapWallet.end()) { wtx = (*mi).second; @@ -2735,7 +2735,7 @@ bool CWallet::SetDefaultKey(const CPubKey &vchPubKey) return true; } -bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut) +bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut) { if (!pwallet->fFileBacked) return false; @@ -2763,7 +2763,7 @@ bool CWallet::NewKeyPool(unsigned int nSize) if (nSize > 0) nKeys = nSize; else - nKeys = max(GetArg("-keypool", 100), 0); + nKeys = std::max(GetArg("-keypool", 100), 0); for (uint64_t i = 0; i < nKeys; i++) { @@ -2791,7 +2791,7 @@ bool CWallet::TopUpKeyPool(unsigned int nSize) if (nSize > 0) nTargetSize = nSize; else - nTargetSize = max(GetArg("-keypool", 100), 0); + nTargetSize = std::max(GetArg("-keypool", 100), 0); while (setKeyPool.size() < (nTargetSize + 1)) { @@ -2799,7 +2799,7 @@ bool CWallet::TopUpKeyPool(unsigned int nSize) if (!setKeyPool.empty()) nEnd = *(--setKeyPool.end()) + 1; if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) - throw runtime_error("TopUpKeyPool() : writing generated key failed"); + throw std::runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); printf("keypool added key %" PRIu64 ", size=%" PRIszu "\n", nEnd, setKeyPool.size()); } @@ -2826,9 +2826,9 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) nIndex = *(setKeyPool.begin()); setKeyPool.erase(setKeyPool.begin()); if (!walletdb.ReadPool(nIndex, keypool)) - throw runtime_error("ReserveKeyFromKeyPool() : read failed"); + throw std::runtime_error("ReserveKeyFromKeyPool() : read failed"); if (!HaveKey(keypool.vchPubKey.GetID())) - throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); + throw std::runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); if (fDebug && GetBoolArg("-printkeypool")) printf("keypool reserve %" PRId64 "\n", nIndex); @@ -2843,7 +2843,7 @@ int64_t CWallet::AddReserveKey(const CKeyPool& keypool) int64_t nIndex = 1 + *(--setKeyPool.end()); if (!walletdb.WritePool(nIndex, keypool)) - throw runtime_error("AddReserveKey() : writing added key failed"); + throw std::runtime_error("AddReserveKey() : writing added key failed"); setKeyPool.insert(nIndex); return nIndex; } @@ -2910,7 +2910,7 @@ int64_t CWallet::GetOldestKeyPoolTime() std::map CWallet::GetAddressBalances() { - map balances; + std::map balances; { LOCK(cs_wallet); @@ -2948,10 +2948,10 @@ std::map CWallet::GetAddressBalances() return balances; } -set< set > CWallet::GetAddressGroupings() +std::set< std::set > CWallet::GetAddressGroupings() { - set< set > groupings; - set grouping; + std::set< std::set > groupings; + std::set grouping; for (auto& walletEntry : mapWallet) { @@ -3004,20 +3004,20 @@ 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 - for (set grouping : groupings) + std::set< std::set* > uniqueGroupings; // a set of pointers to groups of addresses + std::map< CBitcoinAddress, std::set* > setmap; // map addresses to the unique group containing it + for (std::set grouping : groupings) { // make a set of all the groups hit by this new group - set< set* > hits; - map< CBitcoinAddress, set* >::iterator it; + std::set< std::set* > hits; + std::map< CBitcoinAddress, std::set* >::iterator it; 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); - for (set* hit : hits) + std::set* merged = new std::set(grouping); + for (std::set* hit : hits) { merged->insert(hit->begin(), hit->end()); uniqueGroupings.erase(hit); @@ -3030,8 +3030,8 @@ set< set > CWallet::GetAddressGroupings() setmap[element] = merged; } - set< set > ret; - for (set* uniqueGrouping : uniqueGroupings) + std::set< std::set > ret; + for (std::set* uniqueGrouping : uniqueGroupings) { ret.insert(*uniqueGrouping); delete uniqueGrouping; @@ -3048,9 +3048,9 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bo nBalanceInQuestion = 0; LOCK(cs_wallet); - vector vCoins; + std::vector vCoins; vCoins.reserve(mapWallet.size()); - for (map::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it) vCoins.push_back(&(*it).second); CTxDB txdb("r"); @@ -3109,7 +3109,7 @@ void CWallet::DisableTransaction(const CTransaction &tx) LOCK(cs_wallet); for (const CTxIn& txin : tx.vin) { - map::iterator mi = mapWallet.find(txin.prevout.hash); + auto mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { CWalletTx& prev = (*mi).second; @@ -3168,7 +3168,7 @@ void CReserveKey::ReturnKey() vchPubKey = CPubKey(); } -void CWallet::GetAllReserveKeys(set& setAddress) const +void CWallet::GetAllReserveKeys(std::set& setAddress) const { setAddress.clear(); @@ -3179,11 +3179,11 @@ void CWallet::GetAllReserveKeys(set& setAddress) const { CKeyPool keypool; if (!walletdb.ReadPool(id, keypool)) - throw runtime_error("GetAllReserveKeyHashes() : read failed"); + throw std::runtime_error("GetAllReserveKeyHashes() : read failed"); assert(keypool.vchPubKey.IsValid()); CKeyID keyID = keypool.vchPubKey.GetID(); if (!HaveKey(keyID)) - throw runtime_error("GetAllReserveKeyHashes() : unknown key in key pool"); + throw std::runtime_error("GetAllReserveKeyHashes() : unknown key in key pool"); setAddress.insert(keyID); } } @@ -3193,7 +3193,7 @@ void CWallet::UpdatedTransaction(const uint256 &hashTx) { LOCK(cs_wallet); // Only notify UI if this transaction is in this wallet - map::const_iterator mi = mapWallet.find(hashTx); + auto mi = mapWallet.find(hashTx); if (mi != mapWallet.end()) { NotifyTransactionChanged(this, hashTx, CT_UPDATED); @@ -3229,7 +3229,7 @@ void CWallet::GetAddresses(std::map &mapAddresses) con std::vector vAffected; ::ExtractAffectedKeys(*this, out.scriptPubKey, vAffected); - for(std::vector::const_iterator it3 = vAffected.begin(); it3 != vAffected.end(); it3++) { + for(auto it3 = vAffected.begin(); it3 != vAffected.end(); it3++) { CBitcoinAddress addrAffected(*it3); if (mapAddresses.find(addrAffected) != mapAddresses.end() && (mapAddresses[addrAffected] == 0 || mapAddresses[addrAffected] > wtx.nTime)) mapAddresses[addrAffected] = wtx.nTime; @@ -3242,10 +3242,10 @@ void CWallet::GetAddresses(std::map &mapAddresses) con void CWallet::ClearOrphans() { - list orphans; + std::list orphans; LOCK(cs_wallet); - for(map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + for(auto it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx *wtx = &(*it).second; if((wtx->IsCoinBase() || wtx->IsCoinStake()) && !wtx->IsInMainChain()) @@ -3254,7 +3254,7 @@ void CWallet::ClearOrphans() } } - for(list::const_iterator it = orphans.begin(); it != orphans.end(); ++it) + for(auto it = orphans.begin(); it != orphans.end(); ++it) EraseFromWallet(*it); } @@ -3317,7 +3317,7 @@ COutput::COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; } -string COutput::ToString() const +std::string COutput::ToString() const { return strprintf("COutput(%s, %d, %d, %d) [%s]", tx->GetHash().ToString().substr(0,10).c_str(), i, fSpendable, nDepth, FormatMoney(tx->vout[i].nValue).c_str()); } -- 1.7.1