X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbitcoinrpc.cpp;h=0c7e2783fe3cade1e413818f5482af6bc3aed6ad;hb=f3a7ca84494552ea5ec6469cb0f5149217ce891c;hp=5c184520137de628f517af031a8dfd4bf9a03bf5;hpb=fc462f579d392011645c7fabcfc10ec45ca44bb5;p=novacoin.git diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 5c18452..0c7e278 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -16,7 +16,7 @@ #include #include #include -#include + #include #include #include @@ -41,7 +41,7 @@ const Object emptyobj; void ThreadRPCServer3(void* parg); -static inline unsigned short GetDefaultRPCPort() +static inline uint16_t GetDefaultRPCPort() { return GetBoolArg("-testnet", false) ? 18344 : 8344; } @@ -59,7 +59,7 @@ void RPCTypeCheck(const Array& params, bool fAllowNull) { unsigned int i = 0; - BOOST_FOREACH(Value_type t, typesExpected) + for(Value_type t : typesExpected) { if (params.size() <= i) break; @@ -67,7 +67,7 @@ void RPCTypeCheck(const Array& params, const Value& v = params[i]; if (!((v.type() == t) || (fAllowNull && (v.type() == null_type)))) { - string err = strprintf("Expected type %s, got %s", + auto err = strprintf("Expected type %s, got %s", Value_type_name[t], Value_type_name[v.type()]); throw JSONRPCError(RPC_TYPE_ERROR, err); } @@ -79,7 +79,7 @@ void RPCTypeCheck(const Object& o, const map& typesExpected, bool fAllowNull) { - BOOST_FOREACH(const PAIRTYPE(string, Value_type)& t, typesExpected) + for(const auto& t : typesExpected) { const Value& v = find_value(o, t.first); if (!fAllowNull && v.type() == null_type) @@ -87,40 +87,39 @@ void RPCTypeCheck(const Object& o, if (!((v.type() == t.second) || (fAllowNull && (v.type() == null_type)))) { - string err = strprintf("Expected type %s for %s, got %s", + auto err = strprintf("Expected type %s for %s, got %s", Value_type_name[t.second], t.first.c_str(), Value_type_name[v.type()]); throw JSONRPCError(RPC_TYPE_ERROR, err); } } } -int64 AmountFromValue(const Value& value) +int64_t AmountFromValue(const Value& value) { double dAmount = value.get_real(); if (dAmount <= 0.0 || dAmount > MAX_MONEY) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); - int64 nAmount = roundint64(dAmount * COIN); + auto nAmount = roundint64(dAmount * COIN); if (!MoneyRange(nAmount)) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); return nAmount; } -Value ValueFromAmount(int64 amount) +Value ValueFromAmount(int64_t amount) { return (double)amount / (double)COIN; } -std::string HexBits(unsigned int nBits) +string HexBits(uint32_t nBits) { union { - int32_t nBits; + uint32_t nBits; char cBits[4]; } uBits; - uBits.nBits = htonl((int32_t)nBits); + uBits.nBits = htonl(nBits); return HexStr(BEGIN(uBits.cBits), END(uBits.cBits)); } - // // Utilities: convert hex-encoded Values // (throws error if not hex). @@ -169,11 +168,11 @@ string CRPCTable::help(string strCommand) const for (map::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi) { const CRPCCommand *pcmd = mi->second; - string strMethod = mi->first; + auto strMethod = mi->first; // We already filter duplicates, but these deprecated screw up the sort order if (strMethod.find("label") != string::npos) continue; - if (strCommand != "" && strMethod != strCommand) + if (!strCommand.empty() && strMethod != strCommand) continue; try { @@ -185,14 +184,14 @@ string CRPCTable::help(string strCommand) const catch (std::exception& e) { // Help text is returned in an exception - string strHelp = string(e.what()); - if (strCommand == "") + auto strHelp = string(e.what()); + if (strCommand.empty()) if (strHelp.find('\n') != string::npos) strHelp = strHelp.substr(0, strHelp.find('\n')); strRet += strHelp + "\n"; } } - if (strRet == "") + if (strRet.empty()) strRet = strprintf("help: unknown command: %s\n", strCommand.c_str()); strRet = strRet.substr(0,strRet.size()-1); return strRet; @@ -237,74 +236,97 @@ Value stop(const Array& params, bool fHelp) static const CRPCCommand vRPCCommands[] = { // name function safemd unlocked // ------------------------ ----------------------- ------ -------- - { "help", &help, true, true }, - { "stop", &stop, true, true }, - { "getbestblockhash", &getbestblockhash, true, false }, - { "getblockcount", &getblockcount, true, false }, - { "getconnectioncount", &getconnectioncount, true, false }, - { "getpeerinfo", &getpeerinfo, true, false }, - { "getdifficulty", &getdifficulty, true, false }, - { "getinfo", &getinfo, true, false }, - { "getmininginfo", &getmininginfo, true, false }, - { "getnewaddress", &getnewaddress, true, false }, - { "getnewpubkey", &getnewpubkey, true, false }, - { "getaccountaddress", &getaccountaddress, true, false }, - { "setaccount", &setaccount, true, false }, - { "getaccount", &getaccount, false, false }, - { "getaddressesbyaccount", &getaddressesbyaccount, true, false }, - { "sendtoaddress", &sendtoaddress, false, false }, - { "getreceivedbyaddress", &getreceivedbyaddress, false, false }, - { "getreceivedbyaccount", &getreceivedbyaccount, false, false }, - { "listreceivedbyaddress", &listreceivedbyaddress, false, false }, - { "listreceivedbyaccount", &listreceivedbyaccount, false, false }, - { "backupwallet", &backupwallet, true, false }, - { "keypoolrefill", &keypoolrefill, true, false }, - { "walletpassphrase", &walletpassphrase, true, false }, - { "walletpassphrasechange", &walletpassphrasechange, false, false }, - { "walletlock", &walletlock, true, false }, - { "encryptwallet", &encryptwallet, false, false }, - { "validateaddress", &validateaddress, true, false }, - { "validatepubkey", &validatepubkey, true, false }, - { "getbalance", &getbalance, false, false }, - { "move", &movecmd, false, false }, - { "sendfrom", &sendfrom, false, false }, - { "sendmany", &sendmany, false, false }, - { "addmultisigaddress", &addmultisigaddress, false, false }, - { "addredeemscript", &addredeemscript, false, false }, - { "getrawmempool", &getrawmempool, true, false }, - { "getblock", &getblock, false, false }, - { "getblockbynumber", &getblockbynumber, false, false }, - { "getblockhash", &getblockhash, false, false }, - { "gettransaction", &gettransaction, false, false }, - { "listtransactions", &listtransactions, false, false }, - { "listaddressgroupings", &listaddressgroupings, false, false }, - { "signmessage", &signmessage, false, false }, - { "verifymessage", &verifymessage, false, false }, - { "getwork", &getwork, true, false }, - { "getworkex", &getworkex, true, false }, - { "listaccounts", &listaccounts, false, false }, - { "settxfee", &settxfee, false, false }, - { "getblocktemplate", &getblocktemplate, true, false }, - { "submitblock", &submitblock, false, false }, - { "listsinceblock", &listsinceblock, false, false }, - { "dumpprivkey", &dumpprivkey, false, false }, - { "dumpwallet", &dumpwallet, true, false }, - { "importwallet", &importwallet, false, false }, - { "importprivkey", &importprivkey, false, false }, - { "listunspent", &listunspent, false, false }, - { "getrawtransaction", &getrawtransaction, false, false }, - { "createrawtransaction", &createrawtransaction, false, false }, - { "decoderawtransaction", &decoderawtransaction, false, false }, - { "decodescript", &decodescript, false, false }, - { "signrawtransaction", &signrawtransaction, false, false }, - { "sendrawtransaction", &sendrawtransaction, false, false }, - { "getcheckpoint", &getcheckpoint, true, false }, - { "reservebalance", &reservebalance, false, true}, - { "checkwallet", &checkwallet, false, true}, - { "repairwallet", &repairwallet, false, true}, - { "resendtx", &resendtx, false, true}, - { "makekeypair", &makekeypair, false, true}, - { "sendalert", &sendalert, false, false}, + { "help", &help, true, true }, + { "stop", &stop, true, true }, + { "getbestblockhash", &getbestblockhash, true, false }, + { "getblockcount", &getblockcount, true, false }, + { "getconnectioncount", &getconnectioncount, true, false }, + { "getaddrmaninfo", &getaddrmaninfo, true, false }, + { "getpeerinfo", &getpeerinfo, true, false }, + { "addnode", &addnode, true, true }, + { "getaddednodeinfo", &getaddednodeinfo, true, true }, + { "getdifficulty", &getdifficulty, true, false }, + { "getinfo", &getinfo, true, false }, + { "getsubsidy", &getsubsidy, true, false }, + { "getmininginfo", &getmininginfo, true, false }, + { "scaninput", &scaninput, true, true }, + { "getnewaddress", &getnewaddress, true, false }, + { "getnettotals", &getnettotals, true, true }, + { "ntptime", &ntptime, true, true }, + { "getaccountaddress", &getaccountaddress, true, false }, + { "setaccount", &setaccount, true, false }, + { "getaccount", &getaccount, false, false }, + { "getaddressesbyaccount", &getaddressesbyaccount, true, false }, + { "sendtoaddress", &sendtoaddress, false, false }, + { "mergecoins", &mergecoins, false, false }, + { "getreceivedbyaddress", &getreceivedbyaddress, false, false }, + { "getreceivedbyaccount", &getreceivedbyaccount, false, false }, + { "listreceivedbyaddress", &listreceivedbyaddress, false, false }, + { "listreceivedbyaccount", &listreceivedbyaccount, false, false }, + { "backupwallet", &backupwallet, true, false }, + { "keypoolrefill", &keypoolrefill, true, false }, + { "keypoolreset", &keypoolreset, true, false }, + { "walletpassphrase", &walletpassphrase, true, false }, + { "walletpassphrasechange", &walletpassphrasechange, false, false }, + { "walletlock", &walletlock, true, false }, + { "encryptwallet", &encryptwallet, false, false }, + { "validateaddress", &validateaddress, true, false }, + { "getbalance", &getbalance, false, false }, + { "move", &movecmd, false, false }, + { "sendfrom", &sendfrom, false, false }, + { "sendmany", &sendmany, false, false }, + { "addmultisigaddress", &addmultisigaddress, false, false }, + { "addredeemscript", &addredeemscript, false, false }, + { "getrawmempool", &getrawmempool, true, false }, + { "getblock", &getblock, false, false }, + { "getblockbynumber", &getblockbynumber, false, false }, + { "dumpblock", &dumpblock, false, false }, + { "dumpblockbynumber", &dumpblockbynumber, false, false }, + { "getblockhash", &getblockhash, false, false }, + { "gettransaction", &gettransaction, false, false }, + { "listtransactions", &listtransactions, false, false }, + { "listaddressgroupings", &listaddressgroupings, false, false }, + { "signmessage", &signmessage, false, false }, + { "verifymessage", &verifymessage, false, false }, + { "getwork", &getwork, true, false }, + { "getworkex", &getworkex, true, false }, + { "listaccounts", &listaccounts, false, false }, + { "settxfee", &settxfee, false, false }, + { "getblocktemplate", &getblocktemplate, true, false }, + { "submitblock", &submitblock, false, false }, + { "listsinceblock", &listsinceblock, false, false }, + { "dumpprivkey", &dumpprivkey, false, false }, + { "dumppem", &dumppem, true, false }, + { "dumpwallet", &dumpwallet, true, false }, + { "importwallet", &importwallet, false, false }, + { "importprivkey", &importprivkey, false, false }, + { "importaddress", &importaddress, false, true }, + { "removeaddress", &removeaddress, false, true }, + { "listunspent", &listunspent, false, false }, + { "getrawtransaction", &getrawtransaction, false, false }, + { "createrawtransaction", &createrawtransaction, false, false }, + { "decoderawtransaction", &decoderawtransaction, false, false }, + { "createmultisig", &createmultisig, false, false }, + { "decodescript", &decodescript, false, false }, + { "signrawtransaction", &signrawtransaction, false, false }, + { "sendrawtransaction", &sendrawtransaction, false, false }, + { "getcheckpoint", &getcheckpoint, true, false }, + { "reservebalance", &reservebalance, false, true}, + { "checkwallet", &checkwallet, false, true}, + { "repairwallet", &repairwallet, false, true}, + { "resendwallettransactions", &resendwallettransactions, false, true}, + { "makekeypair", &makekeypair, false, true}, + { "newmalleablekey", &newmalleablekey, false, false}, + { "adjustmalleablekey", &adjustmalleablekey, false, false}, + { "adjustmalleablepubkey", &adjustmalleablepubkey, false, false}, + { "listmalleableviews", &listmalleableviews, false, false}, + { "dumpmalleablekey", &dumpmalleablekey, false, false}, + { "importmalleablekey", &importmalleablekey, true, false }, + { "encryptdata", &encryptdata, false, false }, + { "decryptdata", &decryptdata, false, false }, + { "encryptmessage", &encryptmessage, false, false }, + { "decryptmessage", &decryptmessage, false, false }, + { "sendalert", &sendalert, false, false}, }; CRPCTable::CRPCTable() @@ -321,7 +343,7 @@ CRPCTable::CRPCTable() const CRPCCommand *CRPCTable::operator[](string name) const { - map::const_iterator it = mapCommands.find(name); + auto it = mapCommands.find(name); if (it == mapCommands.end()) return NULL; return (*it).second; @@ -344,7 +366,7 @@ string HTTPPost(const string& strMsg, const map& mapRequestHeader << "Content-Length: " << strMsg.size() << "\r\n" << "Connection: close\r\n" << "Accept: application/json\r\n"; - BOOST_FOREACH(const PAIRTYPE(string, string)& item, mapRequestHeaders) + for(const auto& item : mapRequestHeaders) s << item.first << ": " << item.second << "\r\n"; s << "\r\n" << strMsg; @@ -353,15 +375,7 @@ string HTTPPost(const string& strMsg, const map& mapRequestHeader string rfc1123Time() { - char buffer[64]; - time_t now; - time(&now); - struct tm* now_gmt = gmtime(&now); - string locale(setlocale(LC_TIME, NULL)); - setlocale(LC_TIME, "C"); // we want POSIX (aka "C") weekday/month strings - strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S +0000", now_gmt); - setlocale(LC_TIME, locale.c_str()); - return string(buffer); + return DateTimeStrFormat("%a, %d %b %Y %H:%M:%S +0000", GetTime()); } static string HTTPReply(int nStatus, const string& strMsg, bool keepalive) @@ -394,7 +408,7 @@ static string HTTPReply(int nStatus, const string& strMsg, bool keepalive) "HTTP/1.1 %d %s\r\n" "Date: %s\r\n" "Connection: %s\r\n" - "Content-Length: %"PRIszu"\r\n" + "Content-Length: %" PRIszu "\r\n" "Content-Type: application/json\r\n" "Server: novacoin-json-rpc/%s\r\n" "\r\n" @@ -413,7 +427,8 @@ int ReadHTTPStatus(std::basic_istream& stream, int &proto) string str; getline(stream, str); vector vWords; - boost::split(vWords, str, boost::is_any_of(" ")); + istringstream iss(str); + copy(istream_iterator(iss), istream_iterator(), back_inserter(vWords)); if (vWords.size() < 2) return HTTP_INTERNAL_SERVER_ERROR; proto = 0; @@ -426,7 +441,7 @@ int ReadHTTPStatus(std::basic_istream& stream, int &proto) int ReadHTTPHeader(std::basic_istream& stream, map& mapHeadersRet) { int nLen = 0; - loop + for ( ; ; ) { string str; std::getline(stream, str); @@ -435,10 +450,10 @@ int ReadHTTPHeader(std::basic_istream& stream, map& mapHea string::size_type nColon = str.find(":"); if (nColon != string::npos) { - string strHeader = str.substr(0, nColon); + auto strHeader = str.substr(0, nColon); boost::trim(strHeader); - boost::to_lower(strHeader); - string strValue = str.substr(nColon+1); + transform(strHeader.begin(), strHeader.end(), strHeader.begin(), ::tolower); + auto strValue = str.substr(nColon+1); boost::trim(strValue); mapHeadersRet[strHeader] = strValue; if (strHeader == "content-length") @@ -451,7 +466,7 @@ int ReadHTTPHeader(std::basic_istream& stream, map& mapHea int ReadHTTP(std::basic_istream& stream, map& mapHeadersRet, string& strMessageRet) { mapHeadersRet.clear(); - strMessageRet = ""; + strMessageRet.clear(); // Read status int nProto = 0; @@ -470,7 +485,7 @@ int ReadHTTP(std::basic_istream& stream, map& mapHeadersRe strMessageRet = string(vch.begin(), vch.end()); } - string sConHdr = mapHeadersRet["connection"]; + auto sConHdr = mapHeadersRet["connection"]; if ((sConHdr != "close") && (sConHdr != "keep-alive")) { @@ -485,12 +500,12 @@ int ReadHTTP(std::basic_istream& stream, map& mapHeadersRe bool HTTPAuthorized(map& mapHeaders) { - string strAuth = mapHeaders["authorization"]; + auto strAuth = mapHeaders["authorization"]; if (strAuth.substr(0,6) != "Basic ") return false; - string strUserPass64 = strAuth.substr(6); boost::trim(strUserPass64); - string strUserPass = DecodeBase64(strUserPass64); - return strUserPass == strRPCUserColonPass; + auto strUserPass64 = strAuth.substr(6); boost::trim(strUserPass64); + auto strUserPass = DecodeBase64(strUserPass64); + return TimingResistantEqual(strUserPass, strRPCUserColonPass); } // @@ -526,7 +541,7 @@ Object JSONRPCReplyObj(const Value& result, const Value& error, const Value& id) string JSONRPCReply(const Value& result, const Value& error, const Value& id) { - Object reply = JSONRPCReplyObj(result, error, id); + auto reply = JSONRPCReplyObj(result, error, id); return write_string(Value(reply), false) + "\n"; } @@ -537,7 +552,7 @@ void ErrorReply(std::ostream& stream, const Object& objError, const Value& id) int code = find_value(objError, "code").get_int(); if (code == RPC_INVALID_REQUEST) nStatus = HTTP_BAD_REQUEST; else if (code == RPC_METHOD_NOT_FOUND) nStatus = HTTP_NOT_FOUND; - string strReply = JSONRPCReply(Value::null, objError, id); + auto strReply = JSONRPCReply(Value::null, objError, id); stream << HTTPReply(nStatus, strReply, false) << std::flush; } @@ -558,7 +573,7 @@ bool ClientAllowed(const boost::asio::ip::address& address) const string strAddress = address.to_string(); const vector& vAllow = mapMultiArgs["-rpcallowip"]; - BOOST_FOREACH(string strAllow, vAllow) + for(string strAllow : vAllow) if (WildcardMatch(strAddress, strAllow)) return true; return false; @@ -614,6 +629,7 @@ public: private: bool fNeedHandshake; bool fUseSSL; + SSLIOStreamDevice& operator=(SSLIOStreamDevice const&); asio::ssl::stream& stream; }; @@ -667,7 +683,7 @@ private: void ThreadRPCServer(void* parg) { // Make this thread recognisable as the RPC listener - RenameThread("bitcoin-rpclist"); + RenameThread("novacoin-rpclist"); try { @@ -766,7 +782,7 @@ void ThreadRPCServer2(void* parg) printf("ThreadRPCServer started\n"); strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; - if (mapArgs["-rpcpassword"] == "") + if (mapArgs["-rpcpassword"].empty()) { unsigned char rand_pwd[32]; RAND_bytes(rand_pwd, 32); @@ -778,7 +794,7 @@ void ThreadRPCServer2(void* parg) uiInterface.ThreadSafeMessageBox(strprintf( _("%s, you must set a rpcpassword in the configuration file:\n %s\n" "It is recommended you use the following random password:\n" - "rpcuser=bitcoinrpc\n" + "rpcuser=novacoinrpc\n" "rpcpassword=%s\n" "(you do not need to remember this password)\n" "If the file does not exist, create it with owner-readable-only file permissions.\n"), @@ -809,7 +825,7 @@ void ThreadRPCServer2(void* parg) if (filesystem::exists(pathPKFile)) context.use_private_key_file(pathPKFile.string(), ssl::context::pem); else printf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string().c_str()); - string strCiphers = GetArg("-rpcsslciphers", "TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH"); + auto strCiphers = GetArg("-rpcsslciphers", "TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH"); SSL_CTX_set_cipher_list(context.impl(), strCiphers.c_str()); } @@ -910,7 +926,7 @@ void JSONRequest::parse(const Value& valRequest) id = find_value(request, "id"); // Parse method - Value valMethod = find_value(request, "method"); + auto valMethod = find_value(request, "method"); if (valMethod.type() == null_type) throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method"); if (valMethod.type() != str_type) @@ -920,7 +936,7 @@ void JSONRequest::parse(const Value& valRequest) printf("ThreadRPCServer method=%s\n", strMethod.c_str()); // Parse params - Value valParams = find_value(request, "params"); + auto valParams = find_value(request, "params"); if (valParams.type() == array_type) params = valParams.get_array(); else if (valParams.type() == null_type) @@ -937,7 +953,7 @@ static Object JSONRPCExecOne(const Value& req) try { jreq.parse(req); - Value result = tableRPC.execute(jreq.strMethod, jreq.params); + auto result = tableRPC.execute(jreq.strMethod, jreq.params); rpc_result = JSONRPCReplyObj(result, Value::null, jreq.id); } catch (Object& objError) @@ -967,7 +983,7 @@ static CCriticalSection cs_THREAD_RPCHANDLER; void ThreadRPCServer3(void* parg) { // Make this thread recognisable as the RPC handler - RenameThread("bitcoin-rpchand"); + RenameThread("novacoin-rpchand"); { LOCK(cs_THREAD_RPCHANDLER); @@ -976,7 +992,8 @@ void ThreadRPCServer3(void* parg) AcceptedConnection *conn = (AcceptedConnection *) parg; bool fRun = true; - loop { + for ( ; ; ) + { if (fShutdown || !fRun) { conn->close(); @@ -1027,7 +1044,7 @@ void ThreadRPCServer3(void* parg) if (valRequest.type() == obj_type) { jreq.parse(valRequest); - Value result = tableRPC.execute(jreq.strMethod, jreq.params); + auto result = tableRPC.execute(jreq.strMethod, jreq.params); // Send reply strReply = JSONRPCReply(result, Value::null, jreq.id); @@ -1067,8 +1084,8 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); // Observe safe mode - string strWarning = GetWarnings("rpc"); - if (strWarning != "" && !GetBoolArg("-disablesafemode") && + auto strWarning = GetWarnings("rpc"); + if (!strWarning.empty() && !GetBoolArg("-disablesafemode") && !pcmd->okSafeMode) throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning); @@ -1095,7 +1112,7 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s Object CallRPC(const string& strMethod, const Array& params) { - if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") + if (mapArgs["-rpcuser"].empty() && mapArgs["-rpcpassword"].empty()) throw runtime_error(strprintf( _("You must set rpcpassword= in the configuration file:\n%s\n" "If the file does not exist, create it with owner-readable-only file permissions."), @@ -1109,17 +1126,17 @@ Object CallRPC(const string& strMethod, const Array& params) asio::ssl::stream sslStream(io_service, context); SSLIOStreamDevice d(sslStream, fUseSSL); iostreams::stream< SSLIOStreamDevice > stream(d); - if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(GetDefaultRPCPort())))) + if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", to_string(GetDefaultRPCPort())))) throw runtime_error("couldn't connect to server"); // HTTP basic authentication - string strUserPass64 = EncodeBase64(mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]); + auto strUserPass64 = EncodeBase64(mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]); map mapRequestHeaders; mapRequestHeaders["Authorization"] = string("Basic ") + strUserPass64; // Send request - string strRequest = JSONRPCRequest(strMethod, params, 1); - string strPost = HTTPPost(strRequest, mapRequestHeaders); + auto strRequest = JSONRPCRequest(strMethod, params, 1); + auto strPost = HTTPPost(strRequest, mapRequestHeaders); stream << strPost << std::flush; // Receive reply @@ -1156,7 +1173,7 @@ void ConvertTo(Value& value, bool fAllowNull=false) { // reinterpret string as unquoted json value Value value2; - string strJSON = value.get_str(); + auto strJSON = value.get_str(); if (!read_string(strJSON, value2)) throw runtime_error(string("Error parsing JSON:")+strJSON); ConvertTo(value2, fAllowNull); @@ -1172,53 +1189,73 @@ void ConvertTo(Value& value, bool fAllowNull=false) Array RPCConvertValues(const std::string &strMethod, const std::vector &strParams) { Array params; - BOOST_FOREACH(const std::string ¶m, strParams) + for(const auto ¶m : strParams) params.push_back(param); - int n = params.size(); + auto n = params.size(); // // Special case non-string parameter types // if (strMethod == "stop" && n > 0) ConvertTo(params[0]); + if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo(params[0]); if (strMethod == "sendtoaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "mergecoins" && n > 0) ConvertTo(params[0]); + if (strMethod == "mergecoins" && n > 1) ConvertTo(params[1]); + if (strMethod == "mergecoins" && n > 2) ConvertTo(params[2]); if (strMethod == "settxfee" && n > 0) ConvertTo(params[0]); - if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]); - if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo(params[0]); + if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]); + if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo(params[0]); if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo(params[0]); + if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo(params[0]); if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo(params[1]); - if (strMethod == "getbalance" && n > 1) ConvertTo(params[1]); + if (strMethod == "getbalance" && n > 1) ConvertTo(params[1]); if (strMethod == "getblock" && n > 1) ConvertTo(params[1]); - if (strMethod == "getblockbynumber" && n > 0) ConvertTo(params[0]); + if (strMethod == "getblockbynumber" && n > 0) ConvertTo(params[0]); + if (strMethod == "dumpblockbynumber" && n > 0) ConvertTo(params[0]); if (strMethod == "getblockbynumber" && n > 1) ConvertTo(params[1]); - if (strMethod == "getblockhash" && n > 0) ConvertTo(params[0]); + if (strMethod == "getblockhash" && n > 0) ConvertTo(params[0]); if (strMethod == "move" && n > 2) ConvertTo(params[2]); - if (strMethod == "move" && n > 3) ConvertTo(params[3]); + if (strMethod == "move" && n > 3) ConvertTo(params[3]); if (strMethod == "sendfrom" && n > 2) ConvertTo(params[2]); - if (strMethod == "sendfrom" && n > 3) ConvertTo(params[3]); - if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]); - if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); - if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); - if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); + if (strMethod == "sendfrom" && n > 3) ConvertTo(params[3]); + if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]); + if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); + if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); + if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); if (strMethod == "walletpassphrase" && n > 2) ConvertTo(params[2]); if (strMethod == "getblocktemplate" && n > 0) ConvertTo(params[0]); - if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); + if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); + + if (strMethod == "scaninput" && n > 0) ConvertTo(params[0]); + + if (strMethod == "sendalert" && n > 2) ConvertTo(params[2]); + if (strMethod == "sendalert" && n > 3) ConvertTo(params[3]); + if (strMethod == "sendalert" && n > 4) ConvertTo(params[4]); + if (strMethod == "sendalert" && n > 5) ConvertTo(params[5]); + if (strMethod == "sendalert" && n > 6) ConvertTo(params[6]); + if (strMethod == "sendmany" && n > 1) ConvertTo(params[1]); - if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); + if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); if (strMethod == "reservebalance" && n > 0) ConvertTo(params[0]); if (strMethod == "reservebalance" && n > 1) ConvertTo(params[1]); - if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); + if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); if (strMethod == "addmultisigaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "listunspent" && n > 0) ConvertTo(params[0]); - if (strMethod == "listunspent" && n > 1) ConvertTo(params[1]); + if (strMethod == "listunspent" && n > 0) ConvertTo(params[0]); + if (strMethod == "listunspent" && n > 1) ConvertTo(params[1]); if (strMethod == "listunspent" && n > 2) ConvertTo(params[2]); - if (strMethod == "getrawtransaction" && n > 1) ConvertTo(params[1]); + if (strMethod == "getrawtransaction" && n > 1) ConvertTo(params[1]); if (strMethod == "createrawtransaction" && n > 0) ConvertTo(params[0]); if (strMethod == "createrawtransaction" && n > 1) ConvertTo(params[1]); + if (strMethod == "createmultisig" && n > 0) ConvertTo(params[0]); + if (strMethod == "createmultisig" && n > 1) ConvertTo(params[1]); if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1], true); if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2], true); + if (strMethod == "keypoolrefill" && n > 0) ConvertTo(params[0]); + if (strMethod == "keypoolreset" && n > 0) ConvertTo(params[0]); + if (strMethod == "importaddress" && n > 2) ConvertTo(params[2]); + if (strMethod == "importprivkey" && n > 2) ConvertTo(params[2]); return params; } @@ -1239,18 +1276,18 @@ int CommandLineRPC(int argc, char *argv[]) // Method if (argc < 2) throw runtime_error("too few parameters"); - string strMethod = argv[1]; + auto strMethod = argv[1]; // Parameters default to strings std::vector strParams(&argv[2], &argv[argc]); - Array params = RPCConvertValues(strMethod, strParams); + auto params = RPCConvertValues(strMethod, strParams); // Execute - Object reply = CallRPC(strMethod, params); + auto reply = CallRPC(strMethod, params); // Parse reply - const Value& result = find_value(reply, "result"); - const Value& error = find_value(reply, "error"); + const auto& result = find_value(reply, "result"); + const auto& error = find_value(reply, "error"); if (error.type() != null_type) { @@ -1263,7 +1300,7 @@ int CommandLineRPC(int argc, char *argv[]) { // Result if (result.type() == null_type) - strPrint = ""; + strPrint.clear(); else if (result.type() == str_type) strPrint = result.get_str(); else @@ -1280,7 +1317,7 @@ int CommandLineRPC(int argc, char *argv[]) PrintException(NULL, "CommandLineRPC()"); } - if (strPrint != "") + if (!strPrint.empty()) { fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str()); }