]>
Commit | Line | Data |
---|---|---|
fb78cc23 | 1 | // Copyright (c) 2010 Satoshi Nakamoto |
f914f1a7 | 2 | // Copyright (c) 2009-2014 The Bitcoin Core developers |
72fb3d29 | 3 | // Distributed under the MIT software license, see the accompanying |
fb78cc23 WL |
4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | ||
6 | #include "rpcclient.h" | |
7 | ||
8 | #include "rpcprotocol.h" | |
9 | #include "util.h" | |
fb78cc23 | 10 | |
611116d4 | 11 | #include <set> |
fb78cc23 WL |
12 | #include <stdint.h> |
13 | ||
fb78cc23 | 14 | using namespace std; |
fb78cc23 WL |
15 | using namespace json_spirit; |
16 | ||
e35b37b1 | 17 | class CRPCConvertParam |
fb78cc23 | 18 | { |
e35b37b1 | 19 | public: |
72fb3d29 MF |
20 | std::string methodName; //! method whose params want conversion |
21 | int paramIdx; //! 0-based idx of param to convert | |
e35b37b1 JG |
22 | }; |
23 | ||
24 | static const CRPCConvertParam vRPCConvertParams[] = | |
25 | { | |
26 | { "stop", 0 }, | |
a8b2ce55 | 27 | { "setmocktime", 0 }, |
e35b37b1 JG |
28 | { "getaddednodeinfo", 0 }, |
29 | { "setgenerate", 0 }, | |
30 | { "setgenerate", 1 }, | |
6b04508e | 31 | { "generate", 0 }, |
e35b37b1 JG |
32 | { "getnetworkhashps", 0 }, |
33 | { "getnetworkhashps", 1 }, | |
34 | { "sendtoaddress", 1 }, | |
292623ad | 35 | { "sendtoaddress", 4 }, |
e35b37b1 JG |
36 | { "settxfee", 0 }, |
37 | { "getreceivedbyaddress", 1 }, | |
38 | { "getreceivedbyaccount", 1 }, | |
39 | { "listreceivedbyaddress", 0 }, | |
40 | { "listreceivedbyaddress", 1 }, | |
0fa2f889 | 41 | { "listreceivedbyaddress", 2 }, |
e35b37b1 JG |
42 | { "listreceivedbyaccount", 0 }, |
43 | { "listreceivedbyaccount", 1 }, | |
0fa2f889 | 44 | { "listreceivedbyaccount", 2 }, |
e35b37b1 | 45 | { "getbalance", 1 }, |
d4640d7d | 46 | { "getbalance", 2 }, |
e35b37b1 JG |
47 | { "getblockhash", 0 }, |
48 | { "move", 2 }, | |
49 | { "move", 3 }, | |
50 | { "sendfrom", 2 }, | |
51 | { "sendfrom", 3 }, | |
52 | { "listtransactions", 1 }, | |
53 | { "listtransactions", 2 }, | |
d7d5d23b | 54 | { "listtransactions", 3 }, |
e35b37b1 | 55 | { "listaccounts", 0 }, |
83f3543f | 56 | { "listaccounts", 1 }, |
e35b37b1 JG |
57 | { "walletpassphrase", 1 }, |
58 | { "getblocktemplate", 0 }, | |
59 | { "listsinceblock", 1 }, | |
d7d5d23b | 60 | { "listsinceblock", 2 }, |
e35b37b1 JG |
61 | { "sendmany", 1 }, |
62 | { "sendmany", 2 }, | |
292623ad | 63 | { "sendmany", 4 }, |
e35b37b1 JG |
64 | { "addmultisigaddress", 0 }, |
65 | { "addmultisigaddress", 1 }, | |
66 | { "createmultisig", 0 }, | |
67 | { "createmultisig", 1 }, | |
68 | { "listunspent", 0 }, | |
69 | { "listunspent", 1 }, | |
70 | { "listunspent", 2 }, | |
71 | { "getblock", 1 }, | |
1a613963 | 72 | { "gettransaction", 1 }, |
e35b37b1 JG |
73 | { "getrawtransaction", 1 }, |
74 | { "createrawtransaction", 0 }, | |
75 | { "createrawtransaction", 1 }, | |
76 | { "signrawtransaction", 1 }, | |
77 | { "signrawtransaction", 2 }, | |
78 | { "sendrawtransaction", 1 }, | |
79 | { "gettxout", 1 }, | |
80 | { "gettxout", 2 }, | |
59ed61b3 | 81 | { "gettxoutproof", 0 }, |
e35b37b1 JG |
82 | { "lockunspent", 0 }, |
83 | { "lockunspent", 1 }, | |
84 | { "importprivkey", 2 }, | |
c8988460 | 85 | { "importaddress", 2 }, |
e35b37b1 JG |
86 | { "verifychain", 0 }, |
87 | { "verifychain", 1 }, | |
88 | { "keypoolrefill", 0 }, | |
89 | { "getrawmempool", 0 }, | |
90 | { "estimatefee", 0 }, | |
91 | { "estimatepriority", 0 }, | |
ebdcc360 CL |
92 | { "prioritisetransaction", 1 }, |
93 | { "prioritisetransaction", 2 }, | |
22de1602 SB |
94 | { "zcrawjoinsplit", 1 }, |
95 | { "zcrawjoinsplit", 2 }, | |
96 | { "zcrawjoinsplit", 3 }, | |
97 | { "zcrawjoinsplit", 4 }, | |
1b114e54 | 98 | { "zcbenchmark", 1 }, |
f7478de6 | 99 | { "zcbenchmark", 2 }, |
c1c45943 | 100 | { "getblocksubsidy", 0}, |
6c41028f | 101 | { "z_listreceivedbyaddress", 1}, |
a0a3334c S |
102 | { "z_getbalance", 1}, |
103 | { "z_gettotalbalance", 0}, | |
fc72c078 S |
104 | { "z_sendmany", 1}, |
105 | { "z_sendmany", 2}, | |
34f0001c | 106 | { "z_getoperationstatus", 0}, |
c1eae280 | 107 | { "z_getoperationresult", 0}, |
a9869d0d | 108 | { "z_importkey", 1 }, |
83a7f513 | 109 | { "paxprice", 4 }, |
336ab141 | 110 | { "paxprices", 3 }, |
111 | { "notaries", 1 }, | |
e35b37b1 JG |
112 | }; |
113 | ||
114 | class CRPCConvertTable | |
115 | { | |
116 | private: | |
117 | std::set<std::pair<std::string, int> > members; | |
118 | ||
119 | public: | |
120 | CRPCConvertTable(); | |
121 | ||
122 | bool convert(const std::string& method, int idx) { | |
123 | return (members.count(std::make_pair(method, idx)) > 0); | |
fb78cc23 | 124 | } |
e35b37b1 JG |
125 | }; |
126 | ||
127 | CRPCConvertTable::CRPCConvertTable() | |
128 | { | |
129 | const unsigned int n_elem = | |
130 | (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0])); | |
131 | ||
132 | for (unsigned int i = 0; i < n_elem; i++) { | |
133 | members.insert(std::make_pair(vRPCConvertParams[i].methodName, | |
134 | vRPCConvertParams[i].paramIdx)); | |
fb78cc23 WL |
135 | } |
136 | } | |
137 | ||
e35b37b1 JG |
138 | static CRPCConvertTable rpcCvtTable; |
139 | ||
72fb3d29 | 140 | /** Convert strings to command-specific RPC representation */ |
fb78cc23 WL |
141 | Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams) |
142 | { | |
143 | Array params; | |
e35b37b1 JG |
144 | |
145 | for (unsigned int idx = 0; idx < strParams.size(); idx++) { | |
146 | const std::string& strVal = strParams[idx]; | |
147 | ||
148 | // insert string value directly | |
149 | if (!rpcCvtTable.convert(strMethod, idx)) { | |
150 | params.push_back(strVal); | |
151 | } | |
152 | ||
153 | // parse string as JSON, insert bool/number/object/etc. value | |
154 | else { | |
155 | Value jVal; | |
156 | if (!read_string(strVal, jVal)) | |
157 | throw runtime_error(string("Error parsing JSON:")+strVal); | |
158 | params.push_back(jVal); | |
159 | } | |
e35b37b1 | 160 | } |
fb78cc23 WL |
161 | |
162 | return params; | |
163 | } | |
164 |