]> Git Repo - VerusCoin.git/blob - src/rpc/client.cpp
fix finalization on accepted notarization
[VerusCoin.git] / src / rpc / client.cpp
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.
5
6 #include "rpc/client.h"
7 #include "rpc/protocol.h"
8 #include "util.h"
9
10 #include <set>
11 #include <stdint.h>
12
13 #include <univalue.h>
14
15 using namespace std;
16
17 class CRPCConvertParam
18 {
19 public:
20     std::string methodName;            //! method whose params want conversion
21     int paramIdx;                      //! 0-based idx of param to convert
22 };
23
24 // dummy for linking - used only in server
25 UniValue RPCCall(const string& strMethod, const UniValue& params, const string credentials, int port, const string host, int timeout)
26 {assert(false);}
27 UniValue RPCCallRoot(const string& strMethod, const UniValue& params, int timeout)
28 {return NullUniValue;}
29 bool SetThisChain(UniValue &chainDefinition)
30 {}
31
32 static const CRPCConvertParam vRPCConvertParams[] =
33 {
34     { "stop", 0 },
35     { "setmocktime", 0 },
36     { "getaddednodeinfo", 0 },
37     { "setgenerate", 0 },
38     { "setgenerate", 1 },
39     { "generate", 0 },
40     { "getnetworkhashps", 0 },
41     { "getnetworkhashps", 1 },
42     { "getnetworksolps", 0 },
43     { "getnetworksolps", 1 },
44     { "sendtoaddress", 1 },
45     { "sendtoaddress", 4 },
46     { "settxfee", 0 },
47     { "getreceivedbyaddress", 1 },
48     { "getreceivedbyaccount", 1 },
49     { "listreceivedbyaddress", 0 },
50     { "listreceivedbyaddress", 1 },
51     { "listreceivedbyaddress", 2 },
52     { "listreceivedbyaccount", 0 },
53     { "listreceivedbyaccount", 1 },
54     { "listreceivedbyaccount", 2 },
55     { "getbalance", 1 },
56     { "getbalance", 2 },
57     { "getblockhash", 0 },
58     { "move", 2 },
59     { "move", 3 },
60     { "sendfrom", 2 },
61     { "sendfrom", 3 },
62     { "listtransactions", 1 },
63     { "listtransactions", 2 },
64     { "listtransactions", 3 },
65     { "listaccounts", 0 },
66     { "listaccounts", 1 },
67     { "walletpassphrase", 1 },
68     { "getblocktemplate", 0 },
69     { "listsinceblock", 1 },
70     { "listsinceblock", 2 },
71     { "sendmany", 1 },
72     { "sendmany", 2 },
73     { "sendmany", 4 },
74     { "addmultisigaddress", 0 },
75     { "addmultisigaddress", 1 },
76     { "createmultisig", 0 },
77     { "createmultisig", 1 },
78     { "listunspent", 0 },
79     { "listunspent", 1 },
80     { "listunspent", 2 },
81     { "getblock", 1 },
82     { "getblockheader", 1 },
83     { "gettransaction", 1 },
84     { "getrawtransaction", 1 },
85     { "createrawtransaction", 0 },
86     { "createrawtransaction", 1 },
87     { "createrawtransaction", 2 },
88     { "createrawtransaction", 3 },
89     { "signrawtransaction", 1 },
90     { "signrawtransaction", 2 },
91     { "sendrawtransaction", 1 },
92     { "fundrawtransaction", 1 },
93     { "gettxout", 1 },
94     { "gettxout", 2 },
95     { "gettxoutproof", 0 },
96     { "lockunspent", 0 },
97     { "lockunspent", 1 },
98     { "importprivkey", 2 },
99     { "importaddress", 2 },
100     { "verifychain", 0 },
101     { "verifychain", 1 },
102     { "keypoolrefill", 0 },
103     { "getrawmempool", 0 },
104     { "estimatefee", 0 },
105     { "estimatepriority", 0 },
106     { "prioritisetransaction", 1 },
107     { "prioritisetransaction", 2 },
108     { "setban", 2 },
109     { "setban", 3 },
110     { "getblockhashes", 0 },
111     { "getblockhashes", 1 },
112     { "getblockhashes", 2 },
113     { "getspentinfo", 0},
114     { "getaddresstxids", 0},
115     { "getaddressbalance", 0},
116     { "getaddressdeltas", 0},
117     { "getaddressutxos", 0},
118     { "getaddressmempool", 0},
119     { "zcrawjoinsplit", 1 },
120     { "zcrawjoinsplit", 2 },
121     { "zcrawjoinsplit", 3 },
122     { "zcrawjoinsplit", 4 },
123     { "zcbenchmark", 1 },
124     { "zcbenchmark", 2 },
125     { "getblocksubsidy", 0},
126     { "z_listaddresses", 0},
127     { "z_listreceivedbyaddress", 1},
128     { "z_listunspent", 0 },
129     { "z_listunspent", 1 },
130     { "z_listunspent", 2 },
131     { "z_listunspent", 3 },
132     { "z_getbalance", 1},
133     { "z_gettotalbalance", 0},
134     { "z_gettotalbalance", 1},
135     { "z_gettotalbalance", 2},
136     { "z_mergetoaddress", 0},
137     { "z_mergetoaddress", 2},
138     { "z_mergetoaddress", 3},
139     { "z_mergetoaddress", 4},
140     { "z_sendmany", 1},
141     { "z_sendmany", 2},
142     { "z_sendmany", 3},
143     { "z_shieldcoinbase", 2},
144     { "z_shieldcoinbase", 3},
145     { "z_getoperationstatus", 0},
146     { "z_getoperationresult", 0},
147     { "z_importkey", 1 },
148     { "paxprice", 4 },
149     { "paxprices", 3 },
150     { "paxpending", 0 },
151     { "notaries", 2 },
152     { "minerids", 1 },
153     { "kvsearch", 1 },
154     { "kvupdate", 4 },
155     { "z_importkey", 2 },
156     { "z_importviewingkey", 2 },
157     { "z_getpaymentdisclosure", 1},
158     { "z_getpaymentdisclosure", 2},
159     // crosschain
160     { "assetchainproof", 1},
161     { "crosschainproof", 1},
162     { "getproofroot", 2},
163     { "height_MoM", 1},
164     { "calc_MoM", 2},
165     // pbaas
166     { "definechain", 0},
167     { "getdefinedchains", 0},
168 };
169
170 class CRPCConvertTable
171 {
172 private:
173     std::set<std::pair<std::string, int> > members;
174
175 public:
176     CRPCConvertTable();
177
178     bool convert(const std::string& method, int idx) {
179         return (members.count(std::make_pair(method, idx)) > 0);
180     }
181 };
182
183 CRPCConvertTable::CRPCConvertTable()
184 {
185     const unsigned int n_elem =
186         (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
187
188     for (unsigned int i = 0; i < n_elem; i++) {
189         members.insert(std::make_pair(vRPCConvertParams[i].methodName,
190                                       vRPCConvertParams[i].paramIdx));
191     }
192 }
193
194 static CRPCConvertTable rpcCvtTable;
195
196 /** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
197  * as well as objects and arrays.
198  */
199 UniValue ParseNonRFCJSONValue(const std::string& strVal)
200 {
201     UniValue jVal;
202     if (!jVal.read(std::string("[")+strVal+std::string("]")) ||
203         !jVal.isArray() || jVal.size()!=1)
204         throw runtime_error(string("Error JSON:")+strVal);
205     return jVal[0];
206 }
207
208 /** Convert strings to command-specific RPC representation */
209 UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
210 {
211     UniValue params(UniValue::VARR);
212
213     for (unsigned int idx = 0; idx < strParams.size(); idx++) {
214         const std::string& strVal = strParams[idx];
215         if (!rpcCvtTable.convert(strMethod, idx)) {
216             // insert string value directly
217             params.push_back(strVal);
218         } else {
219             // parse string as JSON, insert bool/number/object/etc. value
220             params.push_back(ParseNonRFCJSONValue(strVal));
221         }
222     }
223
224     return params;
225 }
This page took 0.035962 seconds and 4 git commands to generate.