]> Git Repo - VerusCoin.git/blame - src/rpcclient.cpp
Make some global variables less-global (static)
[VerusCoin.git] / src / rpcclient.cpp
CommitLineData
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
a10a6e2a 14#include <univalue.h>
23f71dc7 15
fb78cc23 16using namespace std;
fb78cc23 17
e35b37b1 18class CRPCConvertParam
fb78cc23 19{
e35b37b1 20public:
72fb3d29
MF
21 std::string methodName; //! method whose params want conversion
22 int paramIdx; //! 0-based idx of param to convert
e35b37b1
JG
23};
24
25static const CRPCConvertParam vRPCConvertParams[] =
26{
27 { "stop", 0 },
a8b2ce55 28 { "setmocktime", 0 },
e35b37b1
JG
29 { "getaddednodeinfo", 0 },
30 { "setgenerate", 0 },
31 { "setgenerate", 1 },
6b04508e 32 { "generate", 0 },
e35b37b1
JG
33 { "getnetworkhashps", 0 },
34 { "getnetworkhashps", 1 },
35 { "sendtoaddress", 1 },
292623ad 36 { "sendtoaddress", 4 },
e35b37b1
JG
37 { "settxfee", 0 },
38 { "getreceivedbyaddress", 1 },
39 { "getreceivedbyaccount", 1 },
40 { "listreceivedbyaddress", 0 },
41 { "listreceivedbyaddress", 1 },
0fa2f889 42 { "listreceivedbyaddress", 2 },
e35b37b1
JG
43 { "listreceivedbyaccount", 0 },
44 { "listreceivedbyaccount", 1 },
0fa2f889 45 { "listreceivedbyaccount", 2 },
e35b37b1 46 { "getbalance", 1 },
d4640d7d 47 { "getbalance", 2 },
e35b37b1
JG
48 { "getblockhash", 0 },
49 { "move", 2 },
50 { "move", 3 },
51 { "sendfrom", 2 },
52 { "sendfrom", 3 },
53 { "listtransactions", 1 },
54 { "listtransactions", 2 },
d7d5d23b 55 { "listtransactions", 3 },
e35b37b1 56 { "listaccounts", 0 },
83f3543f 57 { "listaccounts", 1 },
e35b37b1
JG
58 { "walletpassphrase", 1 },
59 { "getblocktemplate", 0 },
60 { "listsinceblock", 1 },
d7d5d23b 61 { "listsinceblock", 2 },
e35b37b1
JG
62 { "sendmany", 1 },
63 { "sendmany", 2 },
292623ad 64 { "sendmany", 4 },
e35b37b1
JG
65 { "addmultisigaddress", 0 },
66 { "addmultisigaddress", 1 },
67 { "createmultisig", 0 },
68 { "createmultisig", 1 },
69 { "listunspent", 0 },
70 { "listunspent", 1 },
71 { "listunspent", 2 },
72 { "getblock", 1 },
d3d5483e 73 { "getblockheader", 1 },
1a613963 74 { "gettransaction", 1 },
e35b37b1
JG
75 { "getrawtransaction", 1 },
76 { "createrawtransaction", 0 },
77 { "createrawtransaction", 1 },
78 { "signrawtransaction", 1 },
79 { "signrawtransaction", 2 },
80 { "sendrawtransaction", 1 },
3d8013a0 81 { "fundrawtransaction", 1 },
e35b37b1
JG
82 { "gettxout", 1 },
83 { "gettxout", 2 },
59ed61b3 84 { "gettxoutproof", 0 },
e35b37b1
JG
85 { "lockunspent", 0 },
86 { "lockunspent", 1 },
87 { "importprivkey", 2 },
c8988460 88 { "importaddress", 2 },
e35b37b1
JG
89 { "verifychain", 0 },
90 { "verifychain", 1 },
91 { "keypoolrefill", 0 },
92 { "getrawmempool", 0 },
93 { "estimatefee", 0 },
94 { "estimatepriority", 0 },
ebdcc360
CL
95 { "prioritisetransaction", 1 },
96 { "prioritisetransaction", 2 },
ed3f13a0 97 { "setban", 2 },
fcc8920f 98 { "setban", 3 },
22de1602
SB
99 { "zcrawjoinsplit", 1 },
100 { "zcrawjoinsplit", 2 },
101 { "zcrawjoinsplit", 3 },
102 { "zcrawjoinsplit", 4 },
1b114e54 103 { "zcbenchmark", 1 },
f7478de6 104 { "zcbenchmark", 2 },
c1c45943 105 { "getblocksubsidy", 0},
6c41028f 106 { "z_listreceivedbyaddress", 1},
a0a3334c
S
107 { "z_getbalance", 1},
108 { "z_gettotalbalance", 0},
fc72c078
S
109 { "z_sendmany", 1},
110 { "z_sendmany", 2},
af53da02 111 { "z_sendmany", 3},
34f0001c 112 { "z_getoperationstatus", 0},
c1eae280 113 { "z_getoperationresult", 0},
a31ba7a0 114 { "z_importkey", 2 },
e35b37b1
JG
115};
116
117class CRPCConvertTable
118{
119private:
120 std::set<std::pair<std::string, int> > members;
121
122public:
123 CRPCConvertTable();
124
125 bool convert(const std::string& method, int idx) {
126 return (members.count(std::make_pair(method, idx)) > 0);
fb78cc23 127 }
e35b37b1
JG
128};
129
130CRPCConvertTable::CRPCConvertTable()
131{
132 const unsigned int n_elem =
133 (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
134
135 for (unsigned int i = 0; i < n_elem; i++) {
136 members.insert(std::make_pair(vRPCConvertParams[i].methodName,
137 vRPCConvertParams[i].paramIdx));
fb78cc23
WL
138 }
139}
140
e35b37b1
JG
141static CRPCConvertTable rpcCvtTable;
142
ff67da37
WL
143/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
144 * as well as objects and arrays.
145 */
146UniValue ParseNonRFCJSONValue(const std::string& strVal)
147{
148 UniValue jVal;
149 if (!jVal.read(std::string("[")+strVal+std::string("]")) ||
150 !jVal.isArray() || jVal.size()!=1)
151 throw runtime_error(string("Error parsing JSON:")+strVal);
152 return jVal[0];
153}
154
72fb3d29 155/** Convert strings to command-specific RPC representation */
851f58f9 156UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
fb78cc23 157{
9756b7bd 158 UniValue params(UniValue::VARR);
e35b37b1
JG
159
160 for (unsigned int idx = 0; idx < strParams.size(); idx++) {
161 const std::string& strVal = strParams[idx];
162
e35b37b1 163 if (!rpcCvtTable.convert(strMethod, idx)) {
ff67da37 164 // insert string value directly
e35b37b1 165 params.push_back(strVal);
ff67da37
WL
166 } else {
167 // parse string as JSON, insert bool/number/object/etc. value
168 params.push_back(ParseNonRFCJSONValue(strVal));
e35b37b1 169 }
e35b37b1 170 }
fb78cc23
WL
171
172 return params;
173}
174
This page took 0.232318 seconds and 4 git commands to generate.