2013-11-20 14:18:57 +01:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2014-12-17 02:47:57 +01:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
2014-11-20 03:19:29 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-20 14:18:57 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "rpcclient.h"
|
|
|
|
|
|
|
|
#include "rpcprotocol.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2014-09-14 12:43:56 +02:00
|
|
|
#include <set>
|
2013-11-20 14:18:57 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace json_spirit;
|
|
|
|
|
2014-06-27 04:12:36 +02:00
|
|
|
class CRPCConvertParam
|
2013-11-20 14:18:57 +01:00
|
|
|
{
|
2014-06-27 04:12:36 +02:00
|
|
|
public:
|
2014-11-20 03:19:29 +01:00
|
|
|
std::string methodName; //! method whose params want conversion
|
|
|
|
int paramIdx; //! 0-based idx of param to convert
|
2014-06-27 04:12:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const CRPCConvertParam vRPCConvertParams[] =
|
|
|
|
{
|
|
|
|
{ "stop", 0 },
|
2014-11-13 00:59:41 +01:00
|
|
|
{ "setmocktime", 0 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "getaddednodeinfo", 0 },
|
|
|
|
{ "setgenerate", 0 },
|
|
|
|
{ "setgenerate", 1 },
|
2015-04-01 05:28:28 +02:00
|
|
|
{ "generate", 0 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "getnetworkhashps", 0 },
|
|
|
|
{ "getnetworkhashps", 1 },
|
|
|
|
{ "sendtoaddress", 1 },
|
2014-07-23 14:34:36 +02:00
|
|
|
{ "sendtoaddress", 4 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "settxfee", 0 },
|
|
|
|
{ "getreceivedbyaddress", 1 },
|
|
|
|
{ "getreceivedbyaccount", 1 },
|
|
|
|
{ "listreceivedbyaddress", 0 },
|
|
|
|
{ "listreceivedbyaddress", 1 },
|
2014-05-31 16:57:26 +02:00
|
|
|
{ "listreceivedbyaddress", 2 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "listreceivedbyaccount", 0 },
|
|
|
|
{ "listreceivedbyaccount", 1 },
|
2014-05-31 16:57:26 +02:00
|
|
|
{ "listreceivedbyaccount", 2 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "getbalance", 1 },
|
2014-04-08 15:23:50 +02:00
|
|
|
{ "getbalance", 2 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "getblockhash", 0 },
|
|
|
|
{ "move", 2 },
|
|
|
|
{ "move", 3 },
|
|
|
|
{ "sendfrom", 2 },
|
|
|
|
{ "sendfrom", 3 },
|
|
|
|
{ "listtransactions", 1 },
|
|
|
|
{ "listtransactions", 2 },
|
2014-04-08 17:51:04 +02:00
|
|
|
{ "listtransactions", 3 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "listaccounts", 0 },
|
2014-04-08 16:13:15 +02:00
|
|
|
{ "listaccounts", 1 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "walletpassphrase", 1 },
|
|
|
|
{ "getblocktemplate", 0 },
|
|
|
|
{ "listsinceblock", 1 },
|
2014-04-08 17:51:04 +02:00
|
|
|
{ "listsinceblock", 2 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "sendmany", 1 },
|
|
|
|
{ "sendmany", 2 },
|
2014-07-23 14:34:36 +02:00
|
|
|
{ "sendmany", 4 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "addmultisigaddress", 0 },
|
|
|
|
{ "addmultisigaddress", 1 },
|
|
|
|
{ "createmultisig", 0 },
|
|
|
|
{ "createmultisig", 1 },
|
|
|
|
{ "listunspent", 0 },
|
|
|
|
{ "listunspent", 1 },
|
|
|
|
{ "listunspent", 2 },
|
|
|
|
{ "getblock", 1 },
|
2014-09-07 14:38:42 +02:00
|
|
|
{ "gettransaction", 1 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "getrawtransaction", 1 },
|
|
|
|
{ "createrawtransaction", 0 },
|
|
|
|
{ "createrawtransaction", 1 },
|
|
|
|
{ "signrawtransaction", 1 },
|
|
|
|
{ "signrawtransaction", 2 },
|
|
|
|
{ "sendrawtransaction", 1 },
|
|
|
|
{ "gettxout", 1 },
|
|
|
|
{ "gettxout", 2 },
|
2014-11-02 00:01:48 +01:00
|
|
|
{ "gettxoutproof", 0 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "lockunspent", 0 },
|
|
|
|
{ "lockunspent", 1 },
|
|
|
|
{ "importprivkey", 2 },
|
2013-07-26 01:06:01 +02:00
|
|
|
{ "importaddress", 2 },
|
2014-06-27 04:12:36 +02:00
|
|
|
{ "verifychain", 0 },
|
|
|
|
{ "verifychain", 1 },
|
|
|
|
{ "keypoolrefill", 0 },
|
|
|
|
{ "getrawmempool", 0 },
|
|
|
|
{ "estimatefee", 0 },
|
|
|
|
{ "estimatepriority", 0 },
|
2014-07-15 02:11:55 +02:00
|
|
|
{ "prioritisetransaction", 1 },
|
|
|
|
{ "prioritisetransaction", 2 },
|
2014-06-27 04:12:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CRPCConvertTable
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::set<std::pair<std::string, int> > members;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CRPCConvertTable();
|
|
|
|
|
|
|
|
bool convert(const std::string& method, int idx) {
|
|
|
|
return (members.count(std::make_pair(method, idx)) > 0);
|
2013-11-20 14:18:57 +01:00
|
|
|
}
|
2014-06-27 04:12:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
CRPCConvertTable::CRPCConvertTable()
|
|
|
|
{
|
|
|
|
const unsigned int n_elem =
|
|
|
|
(sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < n_elem; i++) {
|
|
|
|
members.insert(std::make_pair(vRPCConvertParams[i].methodName,
|
|
|
|
vRPCConvertParams[i].paramIdx));
|
2013-11-20 14:18:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 04:12:36 +02:00
|
|
|
static CRPCConvertTable rpcCvtTable;
|
|
|
|
|
2014-11-20 03:19:29 +01:00
|
|
|
/** Convert strings to command-specific RPC representation */
|
2013-11-20 14:18:57 +01:00
|
|
|
Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
|
|
|
|
{
|
|
|
|
Array params;
|
2014-06-27 04:12:36 +02:00
|
|
|
|
|
|
|
for (unsigned int idx = 0; idx < strParams.size(); idx++) {
|
|
|
|
const std::string& strVal = strParams[idx];
|
|
|
|
|
|
|
|
// insert string value directly
|
|
|
|
if (!rpcCvtTable.convert(strMethod, idx)) {
|
|
|
|
params.push_back(strVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse string as JSON, insert bool/number/object/etc. value
|
|
|
|
else {
|
|
|
|
Value jVal;
|
2014-08-20 21:15:16 +02:00
|
|
|
if (!jVal.read(strVal))
|
2014-06-27 04:12:36 +02:00
|
|
|
throw runtime_error(string("Error parsing JSON:")+strVal);
|
|
|
|
params.push_back(jVal);
|
|
|
|
}
|
|
|
|
}
|
2013-11-20 14:18:57 +01:00
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|