#include <boost/asio/ip/v6_only.hpp>
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
-#include <boost/foreach.hpp>
+
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/algorithm/string.hpp>
void ThreadRPCServer3(void* parg);
-static inline unsigned short GetDefaultRPCPort()
+static inline uint16_t GetDefaultRPCPort()
{
return GetBoolArg("-testnet", false) ? 18344 : 8344;
}
bool fAllowNull)
{
unsigned int i = 0;
- BOOST_FOREACH(Value_type t, typesExpected)
+ for(Value_type t : typesExpected)
{
if (params.size() <= i)
break;
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);
}
const map<string, Value_type>& 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)
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).
+//
+uint256 ParseHashV(const Value& v, string strName)
+{
+ string strHex;
+ if (v.type() == str_type)
+ strHex = v.get_str();
+ if (!IsHex(strHex)) // Note: IsHex("") is false
+ throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
+ uint256 result;
+ result.SetHex(strHex);
+ return result;
+}
+
+uint256 ParseHashO(const Object& o, string strKey)
+{
+ return ParseHashV(find_value(o, strKey), strKey);
+}
+
+vector<unsigned char> ParseHexV(const Value& v, string strName)
+{
+ string strHex;
+ if (v.type() == str_type)
+ strHex = v.get_str();
+ if (!IsHex(strHex))
+ throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
+ return ParseHex(strHex);
+}
+
+vector<unsigned char> ParseHexO(const Object& o, string strKey)
+{
+ return ParseHexV(find_value(o, strKey), strKey);
+}
///
for (map<string, const CRPCCommand*>::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
{
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;
static const CRPCCommand vRPCCommands[] =
{ // name function safemd unlocked
// ------------------------ ----------------------- ------ --------
- { "help", &help, true, true },
- { "stop", &stop, true, true },
- { "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 },
- { "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 },
- { "importprivkey", &importprivkey, false, false },
- { "listunspent", &listunspent, false, false },
- { "getrawtransaction", &getrawtransaction, false, false },
- { "createrawtransaction", &createrawtransaction, false, false },
- { "decoderawtransaction", &decoderawtransaction, 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()
const CRPCCommand *CRPCTable::operator[](string name) const
{
- map<string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
+ auto it = mapCommands.find(name);
if (it == mapCommands.end())
return NULL;
return (*it).second;
<< "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;
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)
"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"
string str;
getline(stream, str);
vector<string> vWords;
- boost::split(vWords, str, boost::is_any_of(" "));
+ istringstream iss(str);
+ copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(vWords));
if (vWords.size() < 2)
return HTTP_INTERNAL_SERVER_ERROR;
proto = 0;
int ReadHTTPHeader(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet)
{
int nLen = 0;
- loop
+ for ( ; ; )
{
string str;
std::getline(stream, str);
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")
int ReadHTTP(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet, string& strMessageRet)
{
mapHeadersRet.clear();
- strMessageRet = "";
+ strMessageRet.clear();
// Read status
int nProto = 0;
strMessageRet = string(vch.begin(), vch.end());
}
- string sConHdr = mapHeadersRet["connection"];
+ auto sConHdr = mapHeadersRet["connection"];
if ((sConHdr != "close") && (sConHdr != "keep-alive"))
{
bool HTTPAuthorized(map<string, string>& 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);
}
//
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";
}
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;
}
const string strAddress = address.to_string();
const vector<string>& vAllow = mapMultiArgs["-rpcallowip"];
- BOOST_FOREACH(string strAllow, vAllow)
+ for(string strAllow : vAllow)
if (WildcardMatch(strAddress, strAllow))
return true;
return false;
private:
bool fNeedHandshake;
bool fUseSSL;
+ SSLIOStreamDevice& operator=(SSLIOStreamDevice const&);
asio::ssl::stream<typename Protocol::socket>& stream;
};
void ThreadRPCServer(void* parg)
{
// Make this thread recognisable as the RPC listener
- RenameThread("bitcoin-rpclist");
+ RenameThread("novacoin-rpclist");
try
{
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);
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"),
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());
}
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)
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)
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)
void ThreadRPCServer3(void* parg)
{
// Make this thread recognisable as the RPC handler
- RenameThread("bitcoin-rpchand");
+ RenameThread("novacoin-rpchand");
{
LOCK(cs_THREAD_RPCHANDLER);
AcceptedConnection *conn = (AcceptedConnection *) parg;
bool fRun = true;
- loop {
+ for ( ; ; )
+ {
if (fShutdown || !fRun)
{
conn->close();
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);
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);
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=<password> in the configuration file:\n%s\n"
"If the file does not exist, create it with owner-readable-only file permissions."),
asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);
iostreams::stream< SSLIOStreamDevice<asio::ip::tcp> > 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<string, string> 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
{
// 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<T>(value2, fAllowNull);
Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &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<bool>(params[0]);
+ if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
+ if (strMethod == "mergecoins" && n > 0) ConvertTo<double>(params[0]);
+ if (strMethod == "mergecoins" && n > 1) ConvertTo<double>(params[1]);
+ if (strMethod == "mergecoins" && n > 2) ConvertTo<double>(params[2]);
if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
- if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]);
- if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<boost::int64_t>(params[1]);
- if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);
+ if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<int64_t>(params[1]);
+ if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<int64_t>(params[1]);
+ if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo<bool>(params[1]);
- if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo<boost::int64_t>(params[0]);
+ if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo<bool>(params[1]);
- if (strMethod == "getbalance" && n > 1) ConvertTo<boost::int64_t>(params[1]);
+ if (strMethod == "getbalance" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "getblock" && n > 1) ConvertTo<bool>(params[1]);
- if (strMethod == "getblockbynumber" && n > 0) ConvertTo<boost::int64_t>(params[0]);
+ if (strMethod == "getblockbynumber" && n > 0) ConvertTo<int64_t>(params[0]);
+ if (strMethod == "dumpblockbynumber" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "getblockbynumber" && n > 1) ConvertTo<bool>(params[1]);
- if (strMethod == "getblockhash" && n > 0) ConvertTo<boost::int64_t>(params[0]);
+ if (strMethod == "getblockhash" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "move" && n > 2) ConvertTo<double>(params[2]);
- if (strMethod == "move" && n > 3) ConvertTo<boost::int64_t>(params[3]);
+ if (strMethod == "move" && n > 3) ConvertTo<int64_t>(params[3]);
if (strMethod == "sendfrom" && n > 2) ConvertTo<double>(params[2]);
- if (strMethod == "sendfrom" && n > 3) ConvertTo<boost::int64_t>(params[3]);
- if (strMethod == "listtransactions" && n > 1) ConvertTo<boost::int64_t>(params[1]);
- if (strMethod == "listtransactions" && n > 2) ConvertTo<boost::int64_t>(params[2]);
- if (strMethod == "listaccounts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
- if (strMethod == "walletpassphrase" && n > 1) ConvertTo<boost::int64_t>(params[1]);
+ if (strMethod == "sendfrom" && n > 3) ConvertTo<int64_t>(params[3]);
+ if (strMethod == "listtransactions" && n > 1) ConvertTo<int64_t>(params[1]);
+ if (strMethod == "listtransactions" && n > 2) ConvertTo<int64_t>(params[2]);
+ if (strMethod == "listaccounts" && n > 0) ConvertTo<int64_t>(params[0]);
+ if (strMethod == "walletpassphrase" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "walletpassphrase" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "getblocktemplate" && n > 0) ConvertTo<Object>(params[0]);
- if (strMethod == "listsinceblock" && n > 1) ConvertTo<boost::int64_t>(params[1]);
+ if (strMethod == "listsinceblock" && n > 1) ConvertTo<int64_t>(params[1]);
+
+ if (strMethod == "scaninput" && n > 0) ConvertTo<Object>(params[0]);
+
+ if (strMethod == "sendalert" && n > 2) ConvertTo<int64_t>(params[2]);
+ if (strMethod == "sendalert" && n > 3) ConvertTo<int64_t>(params[3]);
+ if (strMethod == "sendalert" && n > 4) ConvertTo<int64_t>(params[4]);
+ if (strMethod == "sendalert" && n > 5) ConvertTo<int64_t>(params[5]);
+ if (strMethod == "sendalert" && n > 6) ConvertTo<int64_t>(params[6]);
+
if (strMethod == "sendmany" && n > 1) ConvertTo<Object>(params[1]);
- if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
+ if (strMethod == "sendmany" && n > 2) ConvertTo<int64_t>(params[2]);
if (strMethod == "reservebalance" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "reservebalance" && n > 1) ConvertTo<double>(params[1]);
- if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);
+ if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "addmultisigaddress" && n > 1) ConvertTo<Array>(params[1]);
- if (strMethod == "listunspent" && n > 0) ConvertTo<boost::int64_t>(params[0]);
- if (strMethod == "listunspent" && n > 1) ConvertTo<boost::int64_t>(params[1]);
+ if (strMethod == "listunspent" && n > 0) ConvertTo<int64_t>(params[0]);
+ if (strMethod == "listunspent" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]);
- if (strMethod == "getrawtransaction" && n > 1) ConvertTo<boost::int64_t>(params[1]);
+ if (strMethod == "getrawtransaction" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "createrawtransaction" && n > 0) ConvertTo<Array>(params[0]);
if (strMethod == "createrawtransaction" && n > 1) ConvertTo<Object>(params[1]);
+ if (strMethod == "createmultisig" && n > 0) ConvertTo<int64_t>(params[0]);
+ if (strMethod == "createmultisig" && n > 1) ConvertTo<Array>(params[1]);
if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true);
if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true);
+ if (strMethod == "keypoolrefill" && n > 0) ConvertTo<int64_t>(params[0]);
+ if (strMethod == "keypoolreset" && n > 0) ConvertTo<int64_t>(params[0]);
+ if (strMethod == "importaddress" && n > 2) ConvertTo<bool>(params[2]);
+ if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
return params;
}
// Method
if (argc < 2)
throw runtime_error("too few parameters");
- string strMethod = argv[1];
+ auto strMethod = argv[1];
// Parameters default to strings
std::vector<std::string> 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)
{
{
// Result
if (result.type() == null_type)
- strPrint = "";
+ strPrint.clear();
else if (result.type() == str_type)
strPrint = result.get_str();
else
PrintException(NULL, "CommandLineRPC()");
}
- if (strPrint != "")
+ if (!strPrint.empty())
{
fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
}