1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 #include "rpcprotocol.h"
15 using namespace json_spirit;
17 class CRPCConvertParam
20 std::string methodName; //! method whose params want conversion
21 int paramIdx; //! 0-based idx of param to convert
24 static const CRPCConvertParam vRPCConvertParams[] =
28 { "getaddednodeinfo", 0 },
32 { "getnetworkhashps", 0 },
33 { "getnetworkhashps", 1 },
34 { "sendtoaddress", 1 },
35 { "sendtoaddress", 4 },
37 { "getreceivedbyaddress", 1 },
38 { "getreceivedbyaccount", 1 },
39 { "listreceivedbyaddress", 0 },
40 { "listreceivedbyaddress", 1 },
41 { "listreceivedbyaddress", 2 },
42 { "listreceivedbyaccount", 0 },
43 { "listreceivedbyaccount", 1 },
44 { "listreceivedbyaccount", 2 },
47 { "getblockhash", 0 },
52 { "listtransactions", 1 },
53 { "listtransactions", 2 },
54 { "listtransactions", 3 },
55 { "listaccounts", 0 },
56 { "listaccounts", 1 },
57 { "walletpassphrase", 1 },
58 { "getblocktemplate", 0 },
59 { "listsinceblock", 1 },
60 { "listsinceblock", 2 },
64 { "addmultisigaddress", 0 },
65 { "addmultisigaddress", 1 },
66 { "createmultisig", 0 },
67 { "createmultisig", 1 },
72 { "gettransaction", 1 },
73 { "getrawtransaction", 1 },
74 { "createrawtransaction", 0 },
75 { "createrawtransaction", 1 },
76 { "signrawtransaction", 1 },
77 { "signrawtransaction", 2 },
78 { "sendrawtransaction", 1 },
81 { "gettxoutproof", 0 },
84 { "importprivkey", 2 },
85 { "importaddress", 2 },
88 { "keypoolrefill", 0 },
89 { "getrawmempool", 0 },
91 { "estimatepriority", 0 },
92 { "prioritisetransaction", 1 },
93 { "prioritisetransaction", 2 },
94 { "zcrawjoinsplit", 1 },
95 { "zcrawjoinsplit", 2 },
96 { "zcrawjoinsplit", 3 },
97 { "zcrawjoinsplit", 4 },
100 { "getblocksubsidy", 0},
101 { "z_listreceivedbyaddress", 1},
102 { "z_getbalance", 1},
103 { "z_gettotalbalance", 0},
106 { "z_getoperationstatus", 0},
107 { "z_getoperationresult", 0},
108 { "z_importkey", 1 },
114 class CRPCConvertTable
117 std::set<std::pair<std::string, int> > members;
122 bool convert(const std::string& method, int idx) {
123 return (members.count(std::make_pair(method, idx)) > 0);
127 CRPCConvertTable::CRPCConvertTable()
129 const unsigned int n_elem =
130 (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
132 for (unsigned int i = 0; i < n_elem; i++) {
133 members.insert(std::make_pair(vRPCConvertParams[i].methodName,
134 vRPCConvertParams[i].paramIdx));
138 static CRPCConvertTable rpcCvtTable;
140 /** Convert strings to command-specific RPC representation */
141 Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
145 for (unsigned int idx = 0; idx < strParams.size(); idx++) {
146 const std::string& strVal = strParams[idx];
148 // insert string value directly
149 if (!rpcCvtTable.convert(strMethod, idx)) {
150 params.push_back(strVal);
153 // parse string as JSON, insert bool/number/object/etc. value
156 if (!read_string(strVal, jVal))
157 throw runtime_error(string("Error parsing JSON:")+strVal);
158 params.push_back(jVal);