]> Git Repo - VerusCoin.git/blob - src/rpcclient.cpp
test
[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     { "zcrawjoinsplit", 1 },
95     { "zcrawjoinsplit", 2 },
96     { "zcrawjoinsplit", 3 },
97     { "zcrawjoinsplit", 4 },
98     { "zcbenchmark", 1 },
99     { "zcbenchmark", 2 },
100     { "getblocksubsidy", 0},
101     { "z_listreceivedbyaddress", 1},    
102     { "z_getbalance", 1},
103     { "z_gettotalbalance", 0},
104     { "z_sendmany", 1},
105     { "z_sendmany", 2},
106     { "z_getoperationstatus", 0},
107     { "z_getoperationresult", 0},
108     { "z_importkey", 1 },
109     { "paxprice", 4 },
110     { "paxprices", 3 },
111     { "notaries", 1 },
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);
124     }
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));
135     }
136 }
137
138 static CRPCConvertTable rpcCvtTable;
139
140 /** Convert strings to command-specific RPC representation */
141 Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
142 {
143     Array params;
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         }
160     }
161
162     return params;
163 }
164
This page took 0.030086 seconds and 4 git commands to generate.