2013-11-20 14:18:57 +01:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
|
|
|
// Copyright (c) 2009-2013 The Bitcoin developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "rpcclient.h"
|
|
|
|
|
|
|
|
#include "rpcprotocol.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "ui_interface.h"
|
|
|
|
#include "chainparams.h" // for Params().RPCPort()
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace json_spirit;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void ConvertTo(Value& value, bool fAllowNull=false)
|
|
|
|
{
|
|
|
|
if (fAllowNull && value.type() == null_type)
|
|
|
|
return;
|
|
|
|
if (value.type() == str_type)
|
|
|
|
{
|
|
|
|
// reinterpret string as unquoted json value
|
|
|
|
Value value2;
|
|
|
|
string strJSON = value.get_str();
|
|
|
|
if (!read_string(strJSON, value2))
|
|
|
|
throw runtime_error(string("Error parsing JSON:")+strJSON);
|
|
|
|
ConvertTo<T>(value2, fAllowNull);
|
|
|
|
value = value2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = value.get_value<T>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert strings to command-specific RPC representation
|
|
|
|
Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
|
|
|
|
{
|
|
|
|
Array params;
|
|
|
|
BOOST_FOREACH(const std::string ¶m, strParams)
|
|
|
|
params.push_back(param);
|
|
|
|
|
|
|
|
int 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 == "setgenerate" && n > 0) ConvertTo<bool>(params[0]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "setgenerate" && n > 1) ConvertTo<int64_t>(params[1]);
|
|
|
|
if (strMethod == "getnetworkhashps" && n > 0) ConvertTo<int64_t>(params[0]);
|
|
|
|
if (strMethod == "getnetworkhashps" && n > 1) ConvertTo<int64_t>(params[1]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
|
|
|
|
if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
|
2014-05-05 20:08:13 +02:00
|
|
|
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]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo<bool>(params[1]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo<int64_t>(params[0]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo<bool>(params[1]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "getbalance" && n > 1) ConvertTo<int64_t>(params[1]);
|
|
|
|
if (strMethod == "getblockhash" && n > 0) ConvertTo<int64_t>(params[0]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "move" && n > 2) ConvertTo<double>(params[2]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "move" && n > 3) ConvertTo<int64_t>(params[3]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "sendfrom" && n > 2) ConvertTo<double>(params[2]);
|
2014-05-05 20:08:13 +02:00
|
|
|
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]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "getblocktemplate" && n > 0) ConvertTo<Object>(params[0]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "listsinceblock" && n > 1) ConvertTo<int64_t>(params[1]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "sendmany" && n > 1) ConvertTo<Object>(params[1]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "sendmany" && n > 2) ConvertTo<int64_t>(params[2]);
|
|
|
|
if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<int64_t>(params[0]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "addmultisigaddress" && n > 1) ConvertTo<Array>(params[1]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "createmultisig" && n > 0) ConvertTo<int64_t>(params[0]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "createmultisig" && n > 1) ConvertTo<Array>(params[1]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "listunspent" && n > 0) ConvertTo<int64_t>(params[0]);
|
|
|
|
if (strMethod == "listunspent" && n > 1) ConvertTo<int64_t>(params[1]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]);
|
|
|
|
if (strMethod == "getblock" && n > 1) ConvertTo<bool>(params[1]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "getrawtransaction" && n > 1) ConvertTo<int64_t>(params[1]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "createrawtransaction" && n > 0) ConvertTo<Array>(params[0]);
|
|
|
|
if (strMethod == "createrawtransaction" && n > 1) ConvertTo<Object>(params[1]);
|
|
|
|
if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true);
|
|
|
|
if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true);
|
|
|
|
if (strMethod == "sendrawtransaction" && n > 1) ConvertTo<bool>(params[1], true);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "gettxout" && n > 1) ConvertTo<int64_t>(params[1]);
|
2013-11-20 14:18:57 +01:00
|
|
|
if (strMethod == "gettxout" && n > 2) ConvertTo<bool>(params[2]);
|
|
|
|
if (strMethod == "lockunspent" && n > 0) ConvertTo<bool>(params[0]);
|
|
|
|
if (strMethod == "lockunspent" && n > 1) ConvertTo<Array>(params[1]);
|
|
|
|
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
|
2014-05-05 20:08:13 +02:00
|
|
|
if (strMethod == "verifychain" && n > 0) ConvertTo<int64_t>(params[0]);
|
|
|
|
if (strMethod == "verifychain" && n > 1) ConvertTo<int64_t>(params[1]);
|
|
|
|
if (strMethod == "keypoolrefill" && n > 0) ConvertTo<int64_t>(params[0]);
|
2013-11-11 08:35:14 +01:00
|
|
|
if (strMethod == "getrawmempool" && n > 0) ConvertTo<bool>(params[0]);
|
2014-03-17 13:19:54 +01:00
|
|
|
if (strMethod == "estimatefee" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
|
|
|
if (strMethod == "estimatepriority" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
2013-11-20 14:18:57 +01:00
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|