123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- // Copyright (c) 2010 Satoshi Nakamoto
- // Copyright (c) 2009-2014 The Bitcoin Core developers
- // Distributed under the MIT software license, see the accompanying
- // file COPYING or http://www.opensource.org/licenses/mit-license.php.
- #include "rpcclient.h"
- #include "rpcprotocol.h"
- #include "util.h"
- #include <set>
- #include <stdint.h>
- using namespace std;
- using namespace json_spirit;
- class CRPCConvertParam
- {
- public:
- std::string methodName; //! method whose params want conversion
- int paramIdx; //! 0-based idx of param to convert
- };
- static const CRPCConvertParam vRPCConvertParams[] =
- {
- { "stop", 0 },
- { "setmocktime", 0 },
- { "getaddednodeinfo", 0 },
- { "setgenerate", 0 },
- { "setgenerate", 1 },
- { "generate", 0 },
- { "getnetworkhashps", 0 },
- { "getnetworkhashps", 1 },
- { "sendtoaddress", 1 },
- { "sendtoaddress", 4 },
- { "settxfee", 0 },
- { "getreceivedbyaddress", 1 },
- { "getreceivedbyaccount", 1 },
- { "listreceivedbyaddress", 0 },
- { "listreceivedbyaddress", 1 },
- { "listreceivedbyaddress", 2 },
- { "listreceivedbyaccount", 0 },
- { "listreceivedbyaccount", 1 },
- { "listreceivedbyaccount", 2 },
- { "getbalance", 1 },
- { "getbalance", 2 },
- { "getblockhash", 0 },
- { "move", 2 },
- { "move", 3 },
- { "sendfrom", 2 },
- { "sendfrom", 3 },
- { "listtransactions", 1 },
- { "listtransactions", 2 },
- { "listtransactions", 3 },
- { "listaccounts", 0 },
- { "listaccounts", 1 },
- { "walletpassphrase", 1 },
- { "getblocktemplate", 0 },
- { "listsinceblock", 1 },
- { "listsinceblock", 2 },
- { "sendmany", 1 },
- { "sendmany", 2 },
- { "sendmany", 4 },
- { "addmultisigaddress", 0 },
- { "addmultisigaddress", 1 },
- { "createmultisig", 0 },
- { "createmultisig", 1 },
- { "listunspent", 0 },
- { "listunspent", 1 },
- { "listunspent", 2 },
- { "getblock", 1 },
- { "gettransaction", 1 },
- { "getrawtransaction", 1 },
- { "createrawtransaction", 0 },
- { "createrawtransaction", 1 },
- { "signrawtransaction", 1 },
- { "signrawtransaction", 2 },
- { "sendrawtransaction", 1 },
- { "gettxout", 1 },
- { "gettxout", 2 },
- { "gettxoutproof", 0 },
- { "lockunspent", 0 },
- { "lockunspent", 1 },
- { "importprivkey", 2 },
- { "importaddress", 2 },
- { "verifychain", 0 },
- { "verifychain", 1 },
- { "keypoolrefill", 0 },
- { "getrawmempool", 0 },
- { "estimatefee", 0 },
- { "estimatepriority", 0 },
- { "prioritisetransaction", 1 },
- { "prioritisetransaction", 2 },
- { "zcrawjoinsplit", 1 },
- { "zcrawjoinsplit", 2 },
- { "zcrawjoinsplit", 3 },
- { "zcrawjoinsplit", 4 },
- { "zcbenchmark", 1 },
- { "zcbenchmark", 2 },
- { "getblocksubsidy", 0},
- { "z_listreceivedbyaddress", 1},
- { "z_getbalance", 1},
- { "z_gettotalbalance", 0},
- { "z_sendmany", 1},
- { "z_sendmany", 2},
- { "z_getoperationstatus", 0},
- { "z_getoperationresult", 0},
- { "z_importkey", 1 }
- };
- class CRPCConvertTable
- {
- private:
- std::set<std::pair<std::string, int> > members;
- public:
- CRPCConvertTable();
- bool convert(const std::string& method, int idx) {
- return (members.count(std::make_pair(method, idx)) > 0);
- }
- };
- CRPCConvertTable::CRPCConvertTable()
- {
- const unsigned int n_elem =
- (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
- for (unsigned int i = 0; i < n_elem; i++) {
- members.insert(std::make_pair(vRPCConvertParams[i].methodName,
- vRPCConvertParams[i].paramIdx));
- }
- }
- static CRPCConvertTable rpcCvtTable;
- /** Convert strings to command-specific RPC representation */
- Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
- {
- Array params;
- for (unsigned int idx = 0; idx < strParams.size(); idx++) {
- const std::string& strVal = strParams[idx];
- // insert string value directly
- if (!rpcCvtTable.convert(strMethod, idx)) {
- params.push_back(strVal);
- }
- // parse string as JSON, insert bool/number/object/etc. value
- else {
- Value jVal;
- if (!read_string(strVal, jVal))
- throw runtime_error(string("Error parsing JSON:")+strVal);
- params.push_back(jVal);
- }
- }
- return params;
- }
|