]> Git Repo - VerusCoin.git/blob - src/rpcclient.cpp
Auto merge of #1104 - ebfull:libsnark-updates, r=ebfull
[VerusCoin.git] / src / rpcclient.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 "rpcclient.h"
7
8 #include "rpcprotocol.h"
9 #include "util.h"
10
11 #include <set>
12 #include <stdint.h>
13
14 using namespace std;
15 using namespace json_spirit;
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 static const CRPCConvertParam vRPCConvertParams[] =
25 {
26     { "stop", 0 },
27     { "setmocktime", 0 },
28     { "getaddednodeinfo", 0 },
29     { "setgenerate", 0 },
30     { "setgenerate", 1 },
31     { "generate", 0 },
32     { "getnetworkhashps", 0 },
33     { "getnetworkhashps", 1 },
34     { "sendtoaddress", 1 },
35     { "sendtoaddress", 4 },
36     { "settxfee", 0 },
37     { "getreceivedbyaddress", 1 },
38     { "getreceivedbyaccount", 1 },
39     { "listreceivedbyaddress", 0 },
40     { "listreceivedbyaddress", 1 },
41     { "listreceivedbyaddress", 2 },
42     { "listreceivedbyaccount", 0 },
43     { "listreceivedbyaccount", 1 },
44     { "listreceivedbyaccount", 2 },
45     { "getbalance", 1 },
46     { "getbalance", 2 },
47     { "getblockhash", 0 },
48     { "move", 2 },
49     { "move", 3 },
50     { "sendfrom", 2 },
51     { "sendfrom", 3 },
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 },
61     { "sendmany", 1 },
62     { "sendmany", 2 },
63     { "sendmany", 4 },
64     { "addmultisigaddress", 0 },
65     { "addmultisigaddress", 1 },
66     { "createmultisig", 0 },
67     { "createmultisig", 1 },
68     { "listunspent", 0 },
69     { "listunspent", 1 },
70     { "listunspent", 2 },
71     { "getblock", 1 },
72     { "gettransaction", 1 },
73     { "getrawtransaction", 1 },
74     { "createrawtransaction", 0 },
75     { "createrawtransaction", 1 },
76     { "signrawtransaction", 1 },
77     { "signrawtransaction", 2 },
78     { "sendrawtransaction", 1 },
79     { "gettxout", 1 },
80     { "gettxout", 2 },
81     { "gettxoutproof", 0 },
82     { "lockunspent", 0 },
83     { "lockunspent", 1 },
84     { "importprivkey", 2 },
85     { "importaddress", 2 },
86     { "verifychain", 0 },
87     { "verifychain", 1 },
88     { "keypoolrefill", 0 },
89     { "getrawmempool", 0 },
90     { "estimatefee", 0 },
91     { "estimatepriority", 0 },
92     { "prioritisetransaction", 1 },
93     { "prioritisetransaction", 2 },
94     { "zcrawpour", 1 },
95     { "zcrawpour", 2 },
96     { "zcrawpour", 3 },
97     { "zcrawpour", 4 },
98     { "zcbenchmark", 1 },
99     { "getblocksubsidy", 0}
100 };
101
102 class CRPCConvertTable
103 {
104 private:
105     std::set<std::pair<std::string, int> > members;
106
107 public:
108     CRPCConvertTable();
109
110     bool convert(const std::string& method, int idx) {
111         return (members.count(std::make_pair(method, idx)) > 0);
112     }
113 };
114
115 CRPCConvertTable::CRPCConvertTable()
116 {
117     const unsigned int n_elem =
118         (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
119
120     for (unsigned int i = 0; i < n_elem; i++) {
121         members.insert(std::make_pair(vRPCConvertParams[i].methodName,
122                                       vRPCConvertParams[i].paramIdx));
123     }
124 }
125
126 static CRPCConvertTable rpcCvtTable;
127
128 /** Convert strings to command-specific RPC representation */
129 Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
130 {
131     Array params;
132
133     for (unsigned int idx = 0; idx < strParams.size(); idx++) {
134         const std::string& strVal = strParams[idx];
135
136         // insert string value directly
137         if (!rpcCvtTable.convert(strMethod, idx)) {
138             params.push_back(strVal);
139         }
140
141         // parse string as JSON, insert bool/number/object/etc. value
142         else {
143             Value jVal;
144             if (!read_string(strVal, jVal))
145                 throw runtime_error(string("Error parsing JSON:")+strVal);
146             params.push_back(jVal);
147         }
148     }
149
150     return params;
151 }
152
This page took 0.03188 seconds and 4 git commands to generate.