diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -13,8 +13,6 @@ #include // for to_lower() #include -using namespace std; - class CRPCConvertParam { public: std::string methodName; //!< method whose params want conversion @@ -166,7 +164,7 @@ UniValue jVal; if (!jVal.read(std::string("[") + strVal + std::string("]")) || !jVal.isArray() || jVal.size() != 1) - throw runtime_error(string("Error parsing JSON:") + strVal); + throw std::runtime_error(std::string("Error parsing JSON:") + strVal); return jVal[0]; } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -27,8 +27,6 @@ #include -using namespace std; - /** * @note Do not add or change anything in the information returned by this * method. `getinfo` exists for backwards-compatibility only. It combines @@ -44,7 +42,7 @@ **/ static UniValue getinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "getinfo\n" "\nDEPRECATED. Returns an object containing various state info.\n" "\nResult:\n" @@ -108,8 +106,8 @@ if (g_connman) obj.push_back(Pair("connections", (int)g_connman->GetNodeCount( CConnman::CONNECTIONS_ALL))); - obj.push_back(Pair( - "proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); + obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() + : std::string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("testnet", Params().NetworkIDString() == CBaseChainParams::TESTNET)); @@ -175,7 +173,7 @@ static UniValue validateaddress(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "validateaddress \"address\"\n" "\nReturn information about the given bitcoin address.\n" "\nArguments:\n" @@ -228,7 +226,7 @@ ret.push_back(Pair("isvalid", isValid)); if (isValid) { CTxDestination dest = address.Get(); - string currentAddress = address.ToString(); + std::string currentAddress = address.ToString(); ret.push_back(Pair("address", currentAddress)); CScript scriptPubKey = GetScriptForDestination(dest); @@ -275,17 +273,18 @@ // Gather public keys if (nRequired < 1) - throw runtime_error( + 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 %u 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++) { @@ -296,14 +295,14 @@ if (pwalletMain && address.IsValid()) { CKeyID keyID; if (!address.GetKeyID(keyID)) - throw runtime_error( + throw std::runtime_error( strprintf("%s does not refer to a key", ks)); CPubKey vchPubKey; if (!pwalletMain->GetPubKey(keyID, vchPubKey)) - throw runtime_error( + throw std::runtime_error( strprintf("no full public key for address %s", ks)); if (!vchPubKey.IsFullyValid()) - throw runtime_error(" Invalid public key: " + ks); + throw std::runtime_error(" Invalid public key: " + ks); pubkeys[i] = vchPubKey; } @@ -313,16 +312,16 @@ if (IsHex(ks)) { CPubKey vchPubKey(ParseHex(ks)); if (!vchPubKey.IsFullyValid()) - 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); } } CScript result = GetScriptForMultisig(nRequired, pubkeys); if (result.size() > MAX_SCRIPT_ELEMENT_SIZE) - throw runtime_error( + throw std::runtime_error( strprintf("redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE)); @@ -333,7 +332,7 @@ const JSONRPCRequest &request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 2) { - string msg = + std::string msg = "createmultisig nrequired [\"key\",...]\n" "\nCreates a multi-signature address with n signature of m keys " "required.\n" @@ -369,7 +368,7 @@ "2, " "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); - throw runtime_error(msg); + throw std::runtime_error(msg); } // Construct using pay-to-script-hash: @@ -387,7 +386,7 @@ static UniValue verifymessage(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 3) - throw runtime_error( + throw std::runtime_error( "verifymessage \"address\" \"signature\" \"message\"\n" "\nVerify a signed message\n" "\nArguments:\n" @@ -417,9 +416,9 @@ LOCK(cs_main); - string strAddress = request.params[0].get_str(); - string strSign = request.params[1].get_str(); - string strMessage = request.params[2].get_str(); + std::string strAddress = request.params[0].get_str(); + std::string strSign = request.params[1].get_str(); + std::string strMessage = request.params[2].get_str(); CBitcoinAddress addr(strAddress); if (!addr.IsValid()) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); @@ -429,7 +428,8 @@ 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, @@ -448,7 +448,7 @@ static UniValue signmessagewithprivkey(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 2) - throw runtime_error( + throw std::runtime_error( "signmessagewithprivkey \"privkey\" \"message\"\n" "\nSign a message with the private key of an address\n" "\nArguments:\n" @@ -470,8 +470,8 @@ "\nAs json rpc\n" + HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\"")); - string strPrivkey = request.params[0].get_str(); - string strMessage = request.params[1].get_str(); + std::string strPrivkey = request.params[0].get_str(); + std::string strMessage = request.params[1].get_str(); CBitcoinSecret vchSecret; bool fGood = vchSecret.SetString(strPrivkey); @@ -486,7 +486,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"); @@ -496,7 +496,7 @@ static UniValue setmocktime(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) - throw runtime_error( + throw std::runtime_error( "setmocktime timestamp\n" "\nSet the local time to given timestamp (-regtest only)\n" "\nArguments:\n" @@ -505,7 +505,7 @@ " Pass 0 to go back to using the system time."); if (!Params().MineBlocksOnDemand()) - throw runtime_error( + throw std::runtime_error( "setmocktime for regression testing (-regtest mode) only"); // For now, don't change mocktime if we're in the middle of validation, as @@ -539,7 +539,7 @@ * as users will undoubtedly confuse it with the other "memory pool" */ if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "getmemoryinfo\n" "Returns an object containing information about memory usage.\n" "\nResult:\n" @@ -569,7 +569,7 @@ static UniValue echo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp) - throw runtime_error( + throw std::runtime_error( "echo|echojson \"message\" ...\n" "\nSimply echo back the input arguments. This command is for " "testing.\n" diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -22,12 +22,10 @@ #include -using namespace std; - static UniValue getconnectioncount(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "getconnectioncount\n" "\nReturns the number of connections to other nodes.\n" "\nResult:\n" @@ -46,7 +44,7 @@ static UniValue ping(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "ping\n" "\nRequests that a ping be sent to all other nodes, to measure " "ping time.\n" @@ -70,7 +68,7 @@ static UniValue getpeerinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "getpeerinfo\n" "\nReturns data about each connected network node as a json array " "of objects.\n" @@ -146,7 +144,7 @@ RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - vector vstats; + std::vector vstats; g_connman->GetNodeStats(vstats); UniValue ret(UniValue::VARR); @@ -212,12 +210,12 @@ } static UniValue addnode(const Config &config, const JSONRPCRequest &request) { - string strCommand; + std::string strCommand; if (request.params.size() == 2) strCommand = request.params[1].get_str(); if (request.fHelp || request.params.size() != 2 || (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) - throw runtime_error( + throw std::runtime_error( "addnode \"node\" \"add|remove|onetry\"\n" "\nAttempts add or remove a node from the addnode list.\n" "Or try a connection to a node once.\n" @@ -236,7 +234,7 @@ RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - string strNode = request.params[0].get_str(); + std::string strNode = request.params[0].get_str(); if (strCommand == "onetry") { CAddress addr; @@ -286,7 +284,7 @@ static UniValue getaddednodeinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 1) - throw runtime_error( + throw std::runtime_error( "getaddednodeinfo ( \"node\" )\n" "\nReturns information about the given added node, or all added " "nodes\n" @@ -363,7 +361,7 @@ static UniValue getnettotals(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() > 0) - throw runtime_error( + throw std::runtime_error( "getnettotals\n" "\nReturns information about network traffic, including bytes in, " "bytes out,\n" @@ -432,7 +430,7 @@ obj.push_back(Pair("reachable", IsReachable(network))); obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() - : string())); + : std::string())); obj.push_back( Pair("proxy_randomize_credentials", proxy.randomize_credentials)); networks.push_back(obj); @@ -443,7 +441,7 @@ static UniValue getnetworkinfo(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) - throw runtime_error( + throw std::runtime_error( "getnetworkinfo\n" "Returns an object containing various state info regarding P2P " "networking.\n" @@ -544,11 +542,11 @@ } static UniValue setban(const Config &config, const JSONRPCRequest &request) { - string strCommand; + std::string strCommand; if (request.params.size() >= 2) strCommand = request.params[1].get_str(); if (request.fHelp || request.params.size() < 2 || (strCommand != "add" && strCommand != "remove")) - throw runtime_error( + throw std::runtime_error( "setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" "\nAttempts add or remove a IP/Subnet from the banned list.\n" "\nArguments:\n" @@ -576,7 +574,8 @@ CNetAddr netAddr; bool isSubnet = false; - if (request.params[0].get_str().find("/") != string::npos) isSubnet = true; + if (request.params[0].get_str().find("/") != std::string::npos) + isSubnet = true; if (!isSubnet) { CNetAddr resolved; @@ -617,11 +616,11 @@ static UniValue listbanned(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) - throw runtime_error("listbanned\n" - "\nList all banned IPs/Subnets.\n" - "\nExamples:\n" + - HelpExampleCli("listbanned", "") + - HelpExampleRpc("listbanned", "")); + throw std::runtime_error("listbanned\n" + "\nList all banned IPs/Subnets.\n" + "\nExamples:\n" + + HelpExampleCli("listbanned", "") + + HelpExampleRpc("listbanned", "")); if (!g_connman) throw JSONRPCError( @@ -649,11 +648,11 @@ static UniValue clearbanned(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 0) - throw runtime_error("clearbanned\n" - "\nClear all banned IPs.\n" - "\nExamples:\n" + - HelpExampleCli("clearbanned", "") + - HelpExampleRpc("clearbanned", "")); + throw std::runtime_error("clearbanned\n" + "\nClear all banned IPs.\n" + "\nExamples:\n" + + HelpExampleCli("clearbanned", "") + + HelpExampleRpc("clearbanned", "")); if (!g_connman) throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -667,11 +666,12 @@ static UniValue setnetworkactive(const Config &config, const JSONRPCRequest &request) { if (request.fHelp || request.params.size() != 1) { - throw runtime_error("setnetworkactive true|false\n" - "\nDisable/enable all p2p network activity.\n" - "\nArguments:\n" - "1. \"state\" (boolean, required) true to " - "enable networking, false to disable\n"); + throw std::runtime_error( + "setnetworkactive true|false\n" + "\nDisable/enable all p2p network activity.\n" + "\nArguments:\n" + "1. \"state\" (boolean, required) true to " + "enable networking, false to disable\n"); } if (!g_connman) { diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -15,8 +15,6 @@ #include #include -using namespace std; - /** * JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility, but * uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were @@ -26,7 +24,7 @@ * 1.2 spec: http://jsonrpc.org/historical/json-rpc-over-http.html */ -UniValue JSONRPCRequestObj(const string &strMethod, const UniValue ¶ms, +UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue ¶ms, const UniValue &id) { UniValue request(UniValue::VOBJ); request.push_back(Pair("method", strMethod)); @@ -47,13 +45,13 @@ return reply; } -string JSONRPCReply(const UniValue &result, const UniValue &error, - const UniValue &id) { +std::string JSONRPCReply(const UniValue &result, const UniValue &error, + const UniValue &id) { UniValue reply = JSONRPCReplyObj(result, error, id); return reply.write() + "\n"; } -UniValue JSONRPCError(int code, const string &message) { +UniValue JSONRPCError(int code, const std::string &message) { UniValue error(UniValue::VOBJ); error.push_back(Pair("code", code)); error.push_back(Pair("message", message)); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -28,7 +28,6 @@ #include using namespace RPCServer; -using namespace std; static bool fRPCRunning = false; static bool fRPCInWarmup = true; @@ -63,7 +62,8 @@ } void RPCTypeCheck(const UniValue ¶ms, - const list &typesExpected, bool fAllowNull) { + const std::list &typesExpected, + bool fAllowNull) { unsigned int i = 0; for (UniValue::VType t : typesExpected) { if (params.size() <= i) break; @@ -85,7 +85,7 @@ } void RPCTypeCheckObj(const UniValue &o, - const map &typesExpected, + const std::map &typesExpected, bool fAllowNull, bool fStrict) { for (const auto &t : typesExpected) { const UniValue &v = find_value(o, t.first); @@ -95,17 +95,17 @@ if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) { - string err = strprintf("Expected type %s for %s, got %s", - uvTypeName(t.second.type), t.first, - uvTypeName(v.type())); + std::string err = strprintf("Expected type %s for %s, got %s", + uvTypeName(t.second.type), t.first, + uvTypeName(v.type())); throw JSONRPCError(RPC_TYPE_ERROR, err); } } if (fStrict) { - for (const string &k : o.getKeys()) { + for (const std::string &k : o.getKeys()) { if (typesExpected.count(k) == 0) { - string err = strprintf("Unexpected key %s", k); + std::string err = strprintf("Unexpected key %s", k); throw JSONRPCError(RPC_TYPE_ERROR, err); } } @@ -132,8 +132,8 @@ quotient, remainder)); } -uint256 ParseHashV(const UniValue &v, string strName) { - string strHex; +uint256 ParseHashV(const UniValue &v, std::string strName) { + std::string strHex; if (v.isStr()) strHex = v.get_str(); // Note: IsHex("") is false if (!IsHex(strHex)) @@ -148,11 +148,11 @@ result.SetHex(strHex); return result; } -uint256 ParseHashO(const UniValue &o, string strKey) { +uint256 ParseHashO(const UniValue &o, std::string strKey) { return ParseHashV(find_value(o, strKey), strKey); } -vector ParseHexV(const UniValue &v, string strName) { - string strHex; +std::vector ParseHexV(const UniValue &v, std::string strName) { + std::string strHex; if (v.isStr()) strHex = v.get_str(); if (!IsHex(strHex)) throw JSONRPCError(RPC_INVALID_PARAMETER, @@ -160,7 +160,7 @@ strHex + "')"); return ParseHex(strHex); } -vector ParseHexO(const UniValue &o, string strKey) { +std::vector ParseHexO(const UniValue &o, std::string strKey) { return ParseHexV(find_value(o, strKey), strKey); } @@ -169,24 +169,25 @@ */ std::string CRPCTable::help(Config &config, const std::string &strCommand) const { - string strRet; - string category; + std::string strRet; + std::string category; std::set setDone; - vector> vCommands; + std::vector> vCommands; - for (map::const_iterator mi = + for (std::map::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi) vCommands.push_back( - make_pair(mi->second->category + mi->first, mi->second)); + std::make_pair(mi->second->category + mi->first, mi->second)); sort(vCommands.begin(), vCommands.end()); - for (const std::pair &command : vCommands) { + for (const std::pair &command : + vCommands) { const CRPCCommand *pcmd = command.second; - string strMethod = pcmd->name; + std::string strMethod = pcmd->name; // We already filter duplicates, but these deprecated screw up the sort // order - if (strMethod.find("label") != string::npos) continue; + if (strMethod.find("label") != std::string::npos) continue; if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand) continue; @@ -197,15 +198,15 @@ if (setDone.insert(pfn).second) pfn(config, jreq); } catch (const std::exception &e) { // Help text is returned in an exception - string strHelp = string(e.what()); + std::string strHelp = std::string(e.what()); if (strCommand == "") { - if (strHelp.find('\n') != string::npos) + if (strHelp.find('\n') != std::string::npos) strHelp = strHelp.substr(0, strHelp.find('\n')); if (category != pcmd->category) { if (!category.empty()) strRet += "\n"; category = pcmd->category; - string firstLetter = category.substr(0, 1); + std::string firstLetter = category.substr(0, 1); boost::to_upper(firstLetter); strRet += "== " + firstLetter + category.substr(1) + " ==\n"; @@ -222,7 +223,7 @@ static UniValue help(Config &config, const JSONRPCRequest &jsonRequest) { if (jsonRequest.fHelp || jsonRequest.params.size() > 1) - throw runtime_error( + throw std::runtime_error( "help ( \"command\" )\n" "\nList all commands, or get help for a specified command.\n" "\nArguments:\n" @@ -230,7 +231,7 @@ "\nResult:\n" "\"text\" (string) The help text\n"); - string strCommand; + std::string strCommand; if (jsonRequest.params.size() > 0) strCommand = jsonRequest.params[0].get_str(); @@ -240,8 +241,8 @@ static UniValue stop(const Config &config, const JSONRPCRequest &jsonRequest) { // Accept the deprecated and ignored 'detach' boolean argument if (jsonRequest.fHelp || jsonRequest.params.size() > 1) - throw runtime_error("stop\n" - "\nStop Bitcoin server."); + throw std::runtime_error("stop\n" + "\nStop Bitcoin server."); // Event loop will exit after current HTTP requests have been handled, so // this reply will get back to the client. StartShutdown(); @@ -273,7 +274,7 @@ } const CRPCCommand *CRPCTable::operator[](const std::string &name) const { - map::const_iterator it = + std::map::const_iterator it = mapCommands.find(name); if (it == mapCommands.end()) return nullptr; return (*it).second; @@ -284,7 +285,7 @@ if (IsRPCRunning()) return false; // don't allow overwriting for now - map::const_iterator it = + std::map::const_iterator it = mapCommands.find(name); if (it != mapCommands.end()) return false;