diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -21,8 +21,6 @@ #include #include -using namespace std; - // // CDB // @@ -106,7 +104,7 @@ void CDBEnv::MakeMock() { if (fDbEnvInit) - throw runtime_error("CDBEnv::MakeMock: Already initialized"); + throw std::runtime_error("CDBEnv::MakeMock: Already initialized"); boost::this_thread::interruption_point(); @@ -124,7 +122,7 @@ DB_PRIVATE, S_IRUSR | S_IWUSR); if (ret > 0) - throw runtime_error(strprintf( + throw std::runtime_error(strprintf( "CDBEnv::MakeMock: Error %d opening database environment.", ret)); fDbEnvInit = true; @@ -162,7 +160,7 @@ u_int32_t flags = DB_SALVAGE; if (fAggressive) flags |= DB_AGGRESSIVE; - stringstream strDump; + std::stringstream strDump; Db db(dbenv, 0); int result = db.verify(strFile.c_str(), nullptr, &strDump, flags); @@ -189,7 +187,7 @@ // ... repeated // DATA=END - string strLine; + std::string strLine; while (!strDump.eof() && strLine != HEADER_END) { // Skip past header getline(strDump, strLine); @@ -228,7 +226,6 @@ CDB::CDB(const std::string &strFilename, const char *pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr) { - int ret; fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); fFlushOnClose = fFlushOnCloseIn; if (strFilename.empty()) return; @@ -238,9 +235,10 @@ if (fCreate) nFlags |= DB_CREATE; { + int ret; LOCK(bitdb.cs_db); if (!bitdb.Open(GetDataDir())) - throw runtime_error("CDB: Failed to open database environment."); + throw std::runtime_error("CDB: Failed to open database environment."); strFile = strFilename; ++bitdb.mapFileUseCount[strFile]; @@ -253,7 +251,7 @@ DbMpoolFile *mpf = pdb->get_mpf(); ret = mpf->set_flags(DB_MPOOL_NOFILE, 1); if (ret != 0) - throw runtime_error( + throw std::runtime_error( strprintf("CDB: Failed to configure for no temp file " "backing for database %s", strFile)); @@ -272,11 +270,11 @@ pdb = nullptr; --bitdb.mapFileUseCount[strFile]; strFile = ""; - throw runtime_error(strprintf( + throw std::runtime_error(strprintf( "CDB: Error %d, can't open database %s", ret, strFilename)); } - if (fCreate && !Exists(string("version"))) { + if (fCreate && !Exists(std::string("version"))) { bool fTmp = fReadOnly; fReadOnly = false; WriteVersion(CLIENT_VERSION); @@ -314,7 +312,7 @@ } } -void CDBEnv::CloseDb(const string &strFile) { +void CDBEnv::CloseDb(const std::string &strFile) { LOCK(cs_db); if (mapDb[strFile] != nullptr) { // Close the database handle @@ -325,7 +323,7 @@ } } -bool CDBEnv::RemoveDb(const string &strFile) { +bool CDBEnv::RemoveDb(const std::string &strFile) { this->CloseDb(strFile); LOCK(cs_db); @@ -333,7 +331,7 @@ return (rc == 0); } -bool CDB::Rewrite(const string &strFile, const char *pszSkip) { +bool CDB::Rewrite(const std::string &strFile, const char *pszSkip) { while (true) { { LOCK(bitdb.cs_db); @@ -346,7 +344,7 @@ bool fSuccess = true; LogPrintf("CDB::Rewrite: Rewriting %s...\n", strFile); - string strFileRes = strFile + ".rewrite"; + std::string strFileRes = strFile + ".rewrite"; { // surround usage of db with extra {} CDB db(strFile.c_str(), "r"); Db *pdbCopy = new Db(bitdb.dbenv, 0); @@ -430,9 +428,9 @@ if (!fDbEnvInit) return; { LOCK(cs_db); - map::iterator mi = mapFileUseCount.begin(); + std::map::iterator mi = mapFileUseCount.begin(); while (mi != mapFileUseCount.end()) { - string strFile = (*mi).first; + std::string strFile = (*mi).first; int nRefCount = (*mi).second; LogPrint("db", "CDBEnv::Flush: Flushing %s (refcount = %d)...\n", strFile, nRefCount); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -26,8 +26,6 @@ #include -using namespace std; - void EnsureWalletIsUnlocked(); bool EnsureWalletIsAvailable(bool avoidException); @@ -79,7 +77,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) - throw runtime_error( + throw std::runtime_error( "importprivkey \"bitcoinprivkey\" ( \"label\" ) ( rescan )\n" "\nAdds a private key (as returned by dumpprivkey) to your " "wallet.\n" @@ -108,8 +106,8 @@ EnsureWalletIsUnlocked(); - string strSecret = request.params[0].get_str(); - string strLabel = ""; + std::string strSecret = request.params[0].get_str(); + std::string strLabel = ""; if (request.params.size() > 1) strLabel = request.params[1].get_str(); // Whether to perform rescan after import @@ -158,8 +156,8 @@ return NullUniValue; } -void ImportAddress(const CBitcoinAddress &address, const string &strLabel); -void ImportScript(const CScript &script, const string &strLabel, +void ImportAddress(const CBitcoinAddress &address, const std::string &strLabel); +void ImportScript(const CScript &script, const std::string &strLabel, bool isRedeemScript) { if (!isRedeemScript && ::IsMine(*pwalletMain, script) == ISMINE_SPENDABLE) throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the " @@ -186,7 +184,7 @@ } } -void ImportAddress(const CBitcoinAddress &address, const string &strLabel) { +void ImportAddress(const CBitcoinAddress &address, const std::string &strLabel) { CScript script = GetScriptForDestination(address.Get()); ImportScript(script, strLabel, false); // add to address book or update label @@ -198,7 +196,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) - throw runtime_error( + throw std::runtime_error( "importaddress \"address\" ( \"label\" rescan p2sh )\n" "\nAdds a script (in hex) or address that can be watched as if it " "were in your wallet but cannot be used to spend.\n" @@ -227,7 +225,7 @@ HelpExampleRpc("importaddress", "\"myscript\", \"testing\", false")); - string strLabel = ""; + std::string strLabel = ""; if (request.params.size() > 1) strLabel = request.params[1].get_str(); // Whether to perform rescan after import @@ -272,7 +270,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 2) - throw runtime_error( + throw std::runtime_error( "importprunedfunds\n" "\nImports funds without rescan. Corresponding address or script " "must previously be included in wallet. Aimed towards pruned " @@ -299,8 +297,8 @@ // Search partial merkle tree in proof for our transaction and index in // valid block - vector vMatch; - vector vIndex; + std::vector vMatch; + std::vector vIndex; unsigned int txnIndex = 0; if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == merkleBlock.header.hashMerkleRoot) { @@ -312,7 +310,7 @@ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain"); - vector::const_iterator it; + std::vector::const_iterator it; if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == vMatch.end()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, @@ -345,7 +343,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "removeprunedfunds \"txid\"\n" "\nDeletes the specified transaction from the wallet. Meant for " "use with pruned wallets and as a companion to importprunedfunds. " @@ -366,9 +364,9 @@ uint256 hash; hash.SetHex(request.params[0].get_str()); - vector vHash; + std::vector vHash; vHash.push_back(hash); - vector vHashOut; + std::vector vHashOut; if (pwalletMain->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) { throw JSONRPCError(RPC_INTERNAL_ERROR, @@ -387,7 +385,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) - throw runtime_error( + throw std::runtime_error( "importpubkey \"pubkey\" ( \"label\" rescan )\n" "\nAdds a public key (in hex) that can be watched as if it were in " "your wallet but cannot be used to spend.\n" @@ -408,7 +406,7 @@ "\nAs a JSON-RPC call\n" + HelpExampleRpc("importpubkey", "\"mypubkey\", \"testing\", false")); - string strLabel = ""; + std::string strLabel = ""; if (request.params.size() > 1) strLabel = request.params[1].get_str(); // Whether to perform rescan after import @@ -445,7 +443,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "importwallet \"filename\"\n" "\nImports keys from a wallet dump file (see dumpwallet).\n" "\nArguments:\n" @@ -465,7 +463,7 @@ EnsureWalletIsUnlocked(); - ifstream file; + std::ifstream file; file.open(request.params[0].get_str().c_str(), std::ios::in | std::ios::ate); if (!file.is_open()) @@ -551,7 +549,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "dumpprivkey \"address\"\n" "\nReveals the private key corresponding to 'address'.\n" "Then the importprivkey can be used with this output\n" @@ -569,7 +567,7 @@ EnsureWalletIsUnlocked(); - string strAddress = request.params[0].get_str(); + std::string strAddress = request.params[0].get_str(); CBitcoinAddress address; if (!address.SetString(strAddress)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, @@ -588,7 +586,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "dumpwallet \"filename\"\n" "\nDumps all wallet keys in a human-readable format.\n" "\nArguments:\n" @@ -601,7 +599,7 @@ EnsureWalletIsUnlocked(); - ofstream file; + std::ofstream file; file.open(request.params[0].get_str().c_str()); if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, @@ -700,7 +698,7 @@ } // Optional fields. - const string &strRedeemScript = + const std::string &strRedeemScript = data.exists("redeemscript") ? data["redeemscript"].get_str() : ""; const UniValue &pubKeys = data.exists("pubkeys") ? data["pubkeys"].get_array() : UniValue(); @@ -710,12 +708,12 @@ data.exists("internal") ? data["internal"].get_bool() : false; const bool &watchOnly = data.exists("watchonly") ? data["watchonly"].get_bool() : false; - const string &label = + const std::string &label = data.exists("label") && !internal ? data["label"].get_str() : ""; bool isScript = scriptPubKey.getType() == UniValue::VSTR; bool isP2SH = strRedeemScript.length() > 0; - const string &output = isScript ? scriptPubKey.get_str() + const std::string &output = isScript ? scriptPubKey.get_str() : scriptPubKey["address"].get_str(); // Parse the output. @@ -827,7 +825,7 @@ // Import private keys. if (keys.size()) { for (size_t i = 0; i < keys.size(); i++) { - const string &privkey = keys[i].get_str(); + const std::string &privkey = keys[i].get_str(); CBitcoinSecret vchSecret; bool fGood = vchSecret.SetString(privkey); @@ -872,7 +870,7 @@ } else { // Import public keys. if (pubKeys.size() && keys.size() == 0) { - const string &strPubKey = pubKeys[0].get_str(); + const std::string &strPubKey = pubKeys[0].get_str(); if (!IsHex(strPubKey)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, @@ -957,7 +955,7 @@ // Import private keys. if (keys.size()) { - const string &strPrivkey = keys[0].get_str(); + const std::string &strPrivkey = keys[0].get_str(); // Checks. CBitcoinSecret vchSecret; @@ -1085,7 +1083,7 @@ UniValue importmulti(const Config &config, const JSONRPCRequest &mainRequest) { // clang-format off if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "importmulti \"requests\" \"options\"\n\n" "Import addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options).\n\n" "Arguments:\n" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -27,8 +27,6 @@ #include -using namespace std; - int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; @@ -79,13 +77,13 @@ entry.push_back(Pair("time", wtx.GetTxTime())); entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); - for (const std::pair &item : wtx.mapValue) { + for (const std::pair &item : wtx.mapValue) { entry.push_back(Pair(item.first, item.second)); } } -string AccountFromValue(const UniValue &value) { - string strAccount = value.get_str(); +std::string AccountFromValue(const UniValue &value) { + std::string strAccount = value.get_str(); if (strAccount == "*") throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name"); @@ -97,7 +95,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 1) - throw runtime_error( + throw std::runtime_error( "getnewaddress ( \"account\" )\n" "\nReturns a new Bitcoin address for receiving payments.\n" "If 'account' is specified (DEPRECATED), it is added to the " @@ -120,7 +118,7 @@ LOCK2(cs_main, pwalletMain->cs_wallet); // Parse the account first so we don't generate a key if there's an error - string strAccount; + std::string strAccount; if (request.params.size() > 0) strAccount = AccountFromValue(request.params[0]); @@ -139,7 +137,7 @@ return CBitcoinAddress(keyID).ToString(); } -CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew = false) { +CBitcoinAddress GetAccountAddress(std::string strAccount, bool bForceNew = false) { CPubKey pubKey; if (!pwalletMain->GetAccountPubkey(pubKey, strAccount, bForceNew)) { throw JSONRPCError( @@ -155,7 +153,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "getaccountaddress \"account\"\n" "\nDEPRECATED. Returns the current Bitcoin address for receiving " "payments to this account.\n" @@ -176,7 +174,7 @@ LOCK2(cs_main, pwalletMain->cs_wallet); // Parse the account first so we don't generate a key if there's an error - string strAccount = AccountFromValue(request.params[0]); + std::string strAccount = AccountFromValue(request.params[0]); UniValue ret(UniValue::VSTR); @@ -189,7 +187,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 1) - throw runtime_error( + throw std::runtime_error( "getrawchangeaddress\n" "\nReturns a new Bitcoin address, for receiving change.\n" "This is for use with raw transactions, NOT normal use.\n" @@ -222,7 +220,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "setaccount \"address\" \"account\"\n" "\nDEPRECATED. Sets the account associated with the given " "address.\n" @@ -245,7 +243,7 @@ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); - string strAccount; + std::string strAccount; if (request.params.size() > 1) strAccount = AccountFromValue(request.params[1]); @@ -254,7 +252,7 @@ // Detect when changing the account of an address that is the 'unused // current key' of another account: if (pwalletMain->mapAddressBook.count(address.Get())) { - string strOldAccount = + std::string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name; if (address == GetAccountAddress(strOldAccount)) GetAccountAddress(strOldAccount, true); @@ -272,7 +270,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "getaccount \"address\"\n" "\nDEPRECATED. Returns the account associated with the given " "address.\n" @@ -294,8 +292,8 @@ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); - string strAccount; - map::iterator mi = + std::string strAccount; + std::map::iterator mi = pwalletMain->mapAddressBook.find(address.Get()); if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty()) strAccount = (*mi).second.name; @@ -307,7 +305,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "getaddressesbyaccount \"account\"\n" "\nDEPRECATED. Returns the list of addresses for the given " "account.\n" @@ -325,14 +323,14 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - string strAccount = AccountFromValue(request.params[0]); + std::string strAccount = AccountFromValue(request.params[0]); // Find all addresses that have the given account UniValue ret(UniValue::VARR); for (const std::pair &item : pwalletMain->mapAddressBook) { const CBitcoinAddress &address = item.first; - const string &strName = item.second.name; + const std::string &strName = item.second.name; if (strName == strAccount) ret.push_back(address.ToString()); } return ret; @@ -361,7 +359,7 @@ CReserveKey reservekey(pwalletMain); CAmount nFeeRequired; std::string strError; - vector vecSend; + std::vector vecSend; int nChangePosRet = -1; CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; vecSend.push_back(recipient); @@ -389,7 +387,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) - throw runtime_error( + throw std::runtime_error( "sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" " "subtractfeefromamount )\n" "\nSend an amount to a given address.\n" + @@ -467,7 +465,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp) - throw runtime_error( + throw std::runtime_error( "listaddressgroupings\n" "\nLists groups of addresses which have had their common " "ownership\n" @@ -494,8 +492,8 @@ LOCK2(cs_main, pwalletMain->cs_wallet); UniValue jsonGroupings(UniValue::VARR); - map balances = pwalletMain->GetAddressBalances(); - for (set grouping : pwalletMain->GetAddressGroupings()) { + std::map balances = pwalletMain->GetAddressBalances(); + for (std::set grouping : pwalletMain->GetAddressGroupings()) { UniValue jsonGrouping(UniValue::VARR); for (CTxDestination address : grouping) { UniValue addressInfo(UniValue::VARR); @@ -522,7 +520,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 2) - throw runtime_error( + throw std::runtime_error( "signmessage \"address\" \"message\"\n" "\nSign a message with the private key of an address" + HelpRequiringPassphrase() + @@ -555,8 +553,8 @@ EnsureWalletIsUnlocked(); - string strAddress = request.params[0].get_str(); - string strMessage = request.params[1].get_str(); + std::string strAddress = request.params[0].get_str(); + std::string strMessage = request.params[1].get_str(); CBitcoinAddress addr(strAddress); if (!addr.IsValid()) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); @@ -573,7 +571,7 @@ ss << strMessageMagic; ss << strMessage; - vector vchSig; + std::vector vchSig; if (!key.SignCompact(ss.GetHash(), vchSig)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); @@ -585,7 +583,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "getreceivedbyaddress \"address\" ( minconf )\n" "\nReturns the total amount received by the given address in " "transactions with at least minconf confirmations.\n" @@ -629,7 +627,7 @@ // Tally CAmount nAmount = 0; - for (map::iterator it = pwalletMain->mapWallet.begin(); + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -656,7 +654,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "getreceivedbyaccount \"account\" ( minconf )\n" "\nDEPRECATED. Returns the total amount received by addresses with " " in transactions with at least [minconf] confirmations.\n" @@ -687,13 +685,13 @@ if (request.params.size() > 1) nMinDepth = request.params[1].get_int(); // Get the set of pub keys assigned to account - string strAccount = AccountFromValue(request.params[0]); - set setAddress = + std::string strAccount = AccountFromValue(request.params[0]); + std::set setAddress = pwalletMain->GetAccountAddresses(strAccount); // Tally CAmount nAmount = 0; - for (map::iterator it = pwalletMain->mapWallet.begin(); + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; CValidationState state; @@ -721,7 +719,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 3) - throw runtime_error( + throw std::runtime_error( "getbalance ( \"account\" minconf include_watchonly )\n" "\nIf account is not specified, returns the server's total " "available balance.\n" @@ -787,7 +785,7 @@ // TxIns spending from the wallet. This also has fewer restrictions on // which unconfirmed transactions are considered trusted. CAmount nBalance = 0; - for (map::iterator it = + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -801,9 +799,9 @@ } CAmount allFee; - string strSentAccount; - list listReceived; - list listSent; + std::string strSentAccount; + std::list listReceived; + std::list listSent; wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); if (wtx.GetDepthInMainChain() >= nMinDepth) { @@ -819,7 +817,7 @@ return ValueFromAmount(nBalance); } - string strAccount = AccountFromValue(request.params[0]); + std::string strAccount = AccountFromValue(request.params[0]); CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, filter); @@ -832,7 +830,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 0) - throw runtime_error("getunconfirmedbalance\n" + throw std::runtime_error("getunconfirmedbalance\n" "Returns the server's total unconfirmed balance\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -844,7 +842,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 3 || request.params.size() > 5) - throw runtime_error( + throw std::runtime_error( "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" " ")\n" "\nDEPRECATED. Move a specified amount from one account in your " @@ -879,15 +877,15 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - string strFrom = AccountFromValue(request.params[0]); - string strTo = AccountFromValue(request.params[1]); + std::string strFrom = AccountFromValue(request.params[0]); + std::string strTo = AccountFromValue(request.params[1]); CAmount nAmount = AmountFromValue(request.params[2]); if (nAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); if (request.params.size() > 3) // unused parameter, used to be nMinDepth, keep type-checking it though (void)request.params[3].get_int(); - string strComment; + std::string strComment; if (request.params.size() > 4) strComment = request.params[4].get_str(); if (!pwalletMain->AccountMove(strFrom, strTo, nAmount, strComment)) @@ -900,7 +898,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 3 || request.params.size() > 6) - throw runtime_error( + throw std::runtime_error( "sendfrom \"fromaccount\" \"toaddress\" amount ( minconf " "\"comment\" \"comment_to\" )\n" "\nDEPRECATED (use sendtoaddress). Sent an amount from an account " @@ -955,7 +953,7 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - string strAccount = AccountFromValue(request.params[0]); + std::string strAccount = AccountFromValue(request.params[0]); CBitcoinAddress address(request.params[1].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, @@ -993,7 +991,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) - throw runtime_error( + throw std::runtime_error( "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf " "\"comment\" [\"address\",...] )\n" "\nSend multiple times. Amounts are double-precision floating " @@ -1070,7 +1068,7 @@ RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - string strAccount = AccountFromValue(request.params[0]); + std::string strAccount = AccountFromValue(request.params[0]); UniValue sendTo = request.params[1].get_obj(); int nMinDepth = 1; if (request.params.size() > 2) nMinDepth = request.params[2].get_int(); @@ -1085,21 +1083,21 @@ if (request.params.size() > 4) subtractFeeFromAmount = request.params[4].get_array(); - set setAddress; - vector vecSend; + std::set setAddress; + std::vector vecSend; CAmount totalAmount = 0; - vector keys = sendTo.getKeys(); - for (const string &name_ : keys) { + std::vector keys = sendTo.getKeys(); + for (const std::string &name_ : keys) { CBitcoinAddress address(name_); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, - string("Invalid Bitcoin address: ") + name_); + std::string("Invalid Bitcoin address: ") + name_); if (setAddress.count(address)) throw JSONRPCError( RPC_INVALID_PARAMETER, - string("Invalid parameter, duplicated address: ") + name_); + std::string("Invalid parameter, duplicated address: ") + name_); setAddress.insert(address); CScript scriptPubKey = GetScriptForDestination(address.Get()); @@ -1131,7 +1129,7 @@ CReserveKey keyChange(pwalletMain); CAmount nFeeRequired = 0; int nChangePosRet = -1; - string strFailReason; + std::string strFailReason; bool fCreated = pwalletMain->CreateTransaction( vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason); if (!fCreated) @@ -1153,7 +1151,7 @@ if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) { - string msg = + std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n" "\nAdd a nrequired-to-sign multisignature address to the wallet.\n" "Each key is a Bitcoin address or hex-encoded public key.\n" @@ -1188,12 +1186,12 @@ "2, " "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); - throw runtime_error(msg); + throw std::runtime_error(msg); } LOCK2(cs_main, pwalletMain->cs_wallet); - string strAccount; + std::string strAccount; if (request.params.size() > 2) strAccount = AccountFromValue(request.params[2]); @@ -1209,7 +1207,7 @@ struct tallyitem { CAmount nAmount; int nConf; - vector txids; + std::vector txids; bool fIsWatchonly; tallyitem() { nAmount = 0; @@ -1233,8 +1231,8 @@ if (params[2].get_bool()) filter = filter | ISMINE_WATCH_ONLY; // Tally - map mapTally; - for (map::iterator it = pwalletMain->mapWallet.begin(); + std::map mapTally; + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -1258,7 +1256,7 @@ tallyitem &item = mapTally[address]; item.nAmount += txout.nValue; - item.nConf = min(item.nConf, nDepth); + item.nConf = std::min(item.nConf, nDepth); item.txids.push_back(wtx.GetId()); if (mine & ISMINE_WATCH_ONLY) item.fIsWatchonly = true; } @@ -1266,12 +1264,12 @@ // Reply UniValue ret(UniValue::VARR); - map mapAccountTally; + std::map mapAccountTally; for (const std::pair &item : pwalletMain->mapAddressBook) { const CBitcoinAddress &address = item.first; - const string &strAccount = item.second.name; - map::iterator it = mapTally.find(address); + const std::string &strAccount = item.second.name; + std::map::iterator it = mapTally.find(address); if (it == mapTally.end() && !fIncludeEmpty) continue; CAmount nAmount = 0; @@ -1286,7 +1284,7 @@ if (fByAccounts) { tallyitem &_item = mapAccountTally[strAccount]; _item.nAmount += nAmount; - _item.nConf = min(_item.nConf, nConf); + _item.nConf = std::min(_item.nConf, nConf); _item.fIsWatchonly = fIsWatchonly; } else { UniValue obj(UniValue::VOBJ); @@ -1310,7 +1308,7 @@ } if (fByAccounts) { - for (map::iterator it = mapAccountTally.begin(); + for (std::map::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it) { CAmount nAmount = (*it).second.nAmount; int nConf = (*it).second.nConf; @@ -1334,7 +1332,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 3) - throw runtime_error( + throw std::runtime_error( "listreceivedbyaddress ( minconf include_empty include_watchonly)\n" "\nList balances by receiving address.\n" "\nArguments:\n" @@ -1386,7 +1384,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 3) - throw runtime_error( + throw std::runtime_error( "listreceivedbyaccount ( minconf include_empty include_watchonly)\n" "\nDEPRECATED. List balances by account.\n" "\nArguments:\n" @@ -1429,17 +1427,17 @@ if (addr.Set(dest)) entry.push_back(Pair("address", addr.ToString())); } -void ListTransactions(const CWalletTx &wtx, const string &strAccount, +void ListTransactions(const CWalletTx &wtx, const std::string &strAccount, int nMinDepth, bool fLong, UniValue &ret, const isminefilter &filter) { CAmount nFee; - string strSentAccount; - list listReceived; - list listSent; + std::string strSentAccount; + std::list listReceived; + std::list listSent; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); - bool fAllAccounts = (strAccount == string("*")); + bool fAllAccounts = (strAccount == std::string("*")); bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY); // Sent @@ -1468,7 +1466,7 @@ // Received if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { for (const COutputEntry &r : listReceived) { - string account; + std::string account; if (pwalletMain->mapAddressBook.count(r.destination)) account = pwalletMain->mapAddressBook[r.destination].name; if (fAllAccounts || (account == strAccount)) { @@ -1499,9 +1497,9 @@ } } -void AcentryToJSON(const CAccountingEntry &acentry, const string &strAccount, +void AcentryToJSON(const CAccountingEntry &acentry, const std::string &strAccount, UniValue &ret) { - bool fAllAccounts = (strAccount == string("*")); + bool fAllAccounts = (strAccount == std::string("*")); if (fAllAccounts || acentry.strAccount == strAccount) { UniValue entry(UniValue::VOBJ); @@ -1520,7 +1518,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 4) - throw runtime_error( + throw std::runtime_error( "listtransactions ( \"account\" count skip include_watchonly)\n" "\nReturns up to 'count' most recent transactions skipping the " "first 'from' transactions for account 'account'.\n" @@ -1620,7 +1618,7 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - string strAccount = "*"; + std::string strAccount = "*"; if (request.params.size() > 0) strAccount = request.params[0].get_str(); int nCount = 10; if (request.params.size() > 1) nCount = request.params[1].get_int(); @@ -1653,11 +1651,11 @@ if (nFrom > (int)ret.size()) nFrom = ret.size(); if ((nFrom + nCount) > (int)ret.size()) nCount = ret.size() - nFrom; - vector arrTmp = ret.getValues(); + std::vector arrTmp = ret.getValues(); - vector::iterator first = arrTmp.begin(); + std::vector::iterator first = arrTmp.begin(); std::advance(first, nFrom); - vector::iterator last = arrTmp.begin(); + std::vector::iterator last = arrTmp.begin(); std::advance(last, nFrom + nCount); if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end()); @@ -1677,7 +1675,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "listaccounts ( minconf include_watchonly)\n" "\nDEPRECATED. Returns Object that has account names as keys, " "account balances as values.\n" @@ -1712,7 +1710,7 @@ if (request.params[1].get_bool()) includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY; - map mapAccountBalances; + std::map mapAccountBalances; for (const std::pair &entry : pwalletMain->mapAddressBook) { // This address belongs to me @@ -1720,13 +1718,13 @@ mapAccountBalances[entry.second.name] = 0; } - for (map::iterator it = pwalletMain->mapWallet.begin(); + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; CAmount nFee; - string strSentAccount; - list listReceived; - list listSent; + std::string strSentAccount; + std::list listReceived; + std::list listSent; int nDepth = wtx.GetDepthInMainChain(); if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) continue; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, @@ -1747,13 +1745,13 @@ } } - const list &acentries = pwalletMain->laccentries; + const std::list &acentries = pwalletMain->laccentries; for (const CAccountingEntry &entry : acentries) { mapAccountBalances[entry.strAccount] += entry.nCreditDebit; } UniValue ret(UniValue::VOBJ); - for (const std::pair &accountBalance : + for (const std::pair &accountBalance : mapAccountBalances) { ret.push_back( Pair(accountBalance.first, ValueFromAmount(accountBalance.second))); @@ -1766,7 +1764,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp) - throw runtime_error( + throw std::runtime_error( "listsinceblock ( \"blockhash\" target_confirmations " "include_watchonly)\n" "\nGet all transactions in blocks since block [blockhash], or all " @@ -1882,7 +1880,7 @@ UniValue transactions(UniValue::VARR); - for (map::iterator it = pwalletMain->mapWallet.begin(); + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++) { CWalletTx tx = (*it).second; @@ -1906,7 +1904,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "gettransaction \"txid\" ( include_watchonly )\n" "\nGet detailed information about in-wallet transaction \n" "\nArguments:\n" @@ -2017,7 +2015,7 @@ ListTransactions(wtx, "*", 0, false, details, filter); entry.push_back(Pair("details", details)); - string strHex = + std::string strHex = EncodeHexTx(static_cast(wtx), RPCSerializationFlags()); entry.push_back(Pair("hex", strHex)); @@ -2029,7 +2027,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "abandontransaction \"txid\"\n" "\nMark in-wallet transaction as abandoned\n" "This will mark this transaction and all its in-wallet descendants " @@ -2071,7 +2069,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "backupwallet \"destination\"\n" "\nSafely copies current wallet file to destination, which can be " "a directory or a path with filename.\n" @@ -2083,7 +2081,7 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - string strDest = request.params[0].get_str(); + std::string strDest = request.params[0].get_str(); if (!pwalletMain->BackupWallet(strDest)) throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); @@ -2095,7 +2093,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 1) - throw runtime_error("keypoolrefill ( newsize )\n" + throw std::runtime_error("keypoolrefill ( newsize )\n" "\nFills the keypool." + HelpRequiringPassphrase() + "\n" @@ -2139,7 +2137,7 @@ if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 2)) - throw runtime_error( + throw std::runtime_error( "walletpassphrase \"passphrase\" timeout\n" "\nStores the wallet decryption key in memory for 'timeout' " "seconds.\n" @@ -2184,7 +2182,7 @@ RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); } else - throw runtime_error("walletpassphrase \n" + throw std::runtime_error("walletpassphrase \n" "Stores the wallet decryption key in memory for " " seconds."); @@ -2204,7 +2202,7 @@ if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 2)) - throw runtime_error( + throw std::runtime_error( "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n" "\nChanges the wallet passphrase from 'oldpassphrase' to " "'newpassphrase'.\n" @@ -2238,7 +2236,7 @@ strNewWalletPass = request.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 " "."); @@ -2258,7 +2256,7 @@ if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 0)) - throw runtime_error( + throw std::runtime_error( "walletlock\n" "\nRemoves the wallet encryption key from memory, locking the " "wallet.\n" @@ -2300,7 +2298,7 @@ if (!pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 1)) - throw runtime_error( + throw std::runtime_error( "encryptwallet \"passphrase\"\n" "\nEncrypts the wallet with 'passphrase'. This is for first time " "encryption.\n" @@ -2346,7 +2344,7 @@ strWalletPass = request.params[0].get_str().c_str(); if (strWalletPass.length() < 1) - throw runtime_error("encryptwallet \n" + throw std::runtime_error("encryptwallet \n" "Encrypts the wallet with ."); if (!pwalletMain->EncryptWallet(strWalletPass)) @@ -2368,7 +2366,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "lockunspent unlock ([{\"txid\":\"txid\",\"vout\":n},...])\n" "\nUpdates list of temporarily unspendable outputs.\n" "Temporarily lock (unlock=false) or unlock (unlock=true) specified " @@ -2451,7 +2449,7 @@ {"vout", UniValueType(UniValue::VNUM)}, }); - string txid = find_value(o, "txid").get_str(); + std::string txid = find_value(o, "txid").get_str(); if (!IsHex(txid)) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid"); @@ -2477,7 +2475,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 0) - throw runtime_error( + throw std::runtime_error( "listlockunspent\n" "\nReturns list of temporarily unspendable outputs.\n" "See the lockunspent call to lock and unlock transactions for " @@ -2512,7 +2510,7 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - vector vOutpts; + std::vector vOutpts; pwalletMain->ListLockedCoins(vOutpts); UniValue ret(UniValue::VARR); @@ -2532,7 +2530,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) - throw runtime_error( + throw std::runtime_error( "settxfee amount\n" "\nSet the transaction fee per kB. Overwrites the paytxfee " "parameter.\n" @@ -2561,7 +2559,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "getwalletinfo\n" "Returns an object containing various wallet state info.\n" "\nResult:\n" @@ -2623,7 +2621,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "resendwallettransactions\n" "Immediately re-broadcast unconfirmed wallet transactions to all " "peers.\n" @@ -2653,7 +2651,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() > 4) - throw runtime_error( + throw std::runtime_error( "listunspent ( minconf maxconf [\"addresses\",...] " "[include_unsafe] )\n" "\nReturns array of unspent transaction outputs\n" @@ -2726,7 +2724,7 @@ nMaxDepth = request.params[1].get_int(); } - set setAddress; + std::set setAddress; if (request.params.size() > 2 && !request.params[2].isNull()) { RPCTypeCheckArgument(request.params[2], UniValue::VARR); UniValue inputs = request.params[2].get_array(); @@ -2735,12 +2733,12 @@ CBitcoinAddress address(input.get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, - string("Invalid Bitcoin address: ") + + std::string("Invalid Bitcoin address: ") + input.get_str()); if (setAddress.count(address)) throw JSONRPCError( RPC_INVALID_PARAMETER, - string("Invalid parameter, duplicated address: ") + + std::string("Invalid parameter, duplicated address: ") + input.get_str()); setAddress.insert(address); } @@ -2753,7 +2751,7 @@ } UniValue results(UniValue::VARR); - vector vecOutputs; + std::vector vecOutputs; assert(pwalletMain != nullptr); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, !include_unsafe, nullptr, true); @@ -2807,7 +2805,7 @@ if (!EnsureWalletIsAvailable(request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw runtime_error( + throw std::runtime_error( "fundrawtransaction \"hexstring\" ( options )\n" "\nAdd inputs to a transaction until it has enough in value to " "meet its out value.\n" @@ -2893,7 +2891,7 @@ CFeeRate feeRate = CFeeRate(0); bool overrideEstimatedFeerate = false; UniValue subtractFeeFromOutputs; - set setSubtractFeeFromOutputs; + std::set setSubtractFeeFromOutputs; if (request.params.size() > 1) { if (request.params[1].type() == UniValue::VBOOL) { @@ -2984,7 +2982,7 @@ } CAmount nFeeOut; - string strFailReason; + std::string strFailReason; if (!pwalletMain->FundTransaction( tx, nFeeOut, overrideEstimatedFeerate, feeRate, changePosition,