Merge #8788: [RPC] Give RPC commands more information about the RPC request

e7156ad [RPC] pass HTTP basic authentication username to the JSONRequest object (Jonas Schnelli)
69d1c25 [RPC] Give RPC commands more information about the RPC request (Jonas Schnelli)
23c32a9 rpc: Change JSONRPCRequest to JSONRPCRequestObj (Wladimir J. van der Laan)
This commit is contained in:
Wladimir J. van der Laan 2016-10-19 15:01:33 +02:00 committed by Alexander Block
parent b5b7cd7b7b
commit dd6b9ad20f
18 changed files with 777 additions and 760 deletions

View File

@ -238,7 +238,7 @@ UniValue CallRPC(const string& strMethod, const UniValue& params)
evhttp_add_header(output_headers, "Authorization", (std::string("Basic ") + EncodeBase64(strRPCUserColonPass)).c_str());
// Attach request data
std::string strRequest = JSONRPCRequest(strMethod, params, 1);
std::string strRequest = JSONRPCRequestObj(strMethod, params, 1).write() + "\n";
struct evbuffer * output_buffer = evhttp_request_get_output_buffer(req);
assert(output_buffer);
evbuffer_add(output_buffer, strRequest.data(), strRequest.size());

View File

@ -127,7 +127,7 @@ static bool multiUserAuthorized(std::string strUserPass)
return false;
}
static bool RPCAuthorized(const std::string& strAuth)
static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut)
{
if (strRPCUserColonPass.empty()) // Belt-and-suspenders measure if InitRPCAuthentication was not called
return false;
@ -136,7 +136,10 @@ static bool RPCAuthorized(const std::string& strAuth)
std::string strUserPass64 = strAuth.substr(6);
boost::trim(strUserPass64);
std::string strUserPass = DecodeBase64(strUserPass64);
if (strUserPass.find(":") != std::string::npos)
strAuthUsernameOut = strUserPass.substr(0, strUserPass.find(":"));
//Check if authorized under single-user field
if (TimingResistantEqual(strUserPass, strRPCUserColonPass)) {
return true;
@ -159,7 +162,8 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
return false;
}
if (!RPCAuthorized(authHeader.second)) {
JSONRPCRequest jreq;
if (!RPCAuthorized(authHeader.second, jreq.authUser)) {
LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", req->GetPeer().ToString());
/* Deter brute-forcing
@ -172,19 +176,21 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
return false;
}
JSONRequest jreq;
try {
// Parse request
UniValue valRequest;
if (!valRequest.read(req->ReadBody()))
throw JSONRPCError(RPC_PARSE_ERROR, "Parse error");
// Set the URI
jreq.URI = req->GetURI();
std::string strReply;
// singleton request
if (valRequest.isObject()) {
jreq.parse(valRequest);
UniValue result = tableRPC.execute(jreq.strMethod, jreq.params);
UniValue result = tableRPC.execute(jreq);
// Send reply
strReply = JSONRPCReply(result, NullUniValue, jreq.id);

View File

@ -256,7 +256,10 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
std::string strPrint;
// Convert argument list to JSON objects in method-dependent way,
// and pass it along with the method name to the dispatcher.
lastResult = tableRPC.execute(stack.back()[0], RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end())));
JSONRPCRequest req;
req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
req.strMethod = stack.back()[0];
lastResult = tableRPC.execute(req);
state = STATE_COMMAND_EXECUTED;
curarg.clear();

View File

@ -277,7 +277,7 @@ static bool rest_block_notxdetails(HTTPRequest* req, const std::string& strURIPa
}
// A bit of a hack - dependency on a function defined in rpc/blockchain.cpp
UniValue getblockchaininfo(const UniValue& params, bool fHelp);
UniValue getblockchaininfo(const JSONRPCRequest& request);
static bool rest_chaininfo(HTTPRequest* req, const std::string& strURIPart)
{
@ -288,8 +288,9 @@ static bool rest_chaininfo(HTTPRequest* req, const std::string& strURIPart)
switch (rf) {
case RF_JSON: {
UniValue rpcParams(UniValue::VARR);
UniValue chainInfoObject = getblockchaininfo(rpcParams, false);
JSONRPCRequest jsonRequest;
jsonRequest.params = UniValue(UniValue::VARR);
UniValue chainInfoObject = getblockchaininfo(jsonRequest);
string strJSON = chainInfoObject.write() + "\n";
req->WriteHeader("Content-Type", "application/json");
req->WriteReply(HTTP_OK, strJSON);

View File

@ -146,9 +146,9 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
return result;
}
UniValue getblockcount(const UniValue& params, bool fHelp)
UniValue getblockcount(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getblockcount\n"
"\nReturns the number of blocks in the longest block chain.\n"
@ -163,9 +163,9 @@ UniValue getblockcount(const UniValue& params, bool fHelp)
return chainActive.Height();
}
UniValue getbestblockhash(const UniValue& params, bool fHelp)
UniValue getbestblockhash(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getbestblockhash\n"
"\nReturns the hash of the best (tip) block in the longest block chain.\n"
@ -190,9 +190,9 @@ void RPCNotifyBlockChange(bool ibd, const CBlockIndex * pindex)
cond_blockchange.notify_all();
}
UniValue waitfornewblock(const UniValue& params, bool fHelp)
UniValue waitfornewblock(const JSONRPCRequest& request)
{
if (fHelp || params.size() > 1)
if (request.fHelp || request.params.size() > 1)
throw runtime_error(
"waitfornewblock\n"
"\nWaits for a specific new block and returns useful info about it.\n"
@ -209,8 +209,8 @@ UniValue waitfornewblock(const UniValue& params, bool fHelp)
+ HelpExampleRpc("waitfornewblock", "1000")
);
int timeout = 0;
if (params.size() > 0)
timeout = params[0].get_int();
if (request.params.size() > 0)
timeout = request.params[0].get_int();
CUpdatedBlock block;
{
@ -228,9 +228,9 @@ UniValue waitfornewblock(const UniValue& params, bool fHelp)
return ret;
}
UniValue waitforblock(const UniValue& params, bool fHelp)
UniValue waitforblock(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"waitforblock\n"
"\nWaits for a specific new block and returns useful info about it.\n"
@ -249,10 +249,10 @@ UniValue waitforblock(const UniValue& params, bool fHelp)
);
int timeout = 0;
uint256 hash = uint256S(params[0].get_str());
uint256 hash = uint256S(request.params[0].get_str());
if (params.size() > 1)
timeout = params[1].get_int();
if (request.params.size() > 1)
timeout = request.params[1].get_int();
CUpdatedBlock block;
{
@ -270,9 +270,9 @@ UniValue waitforblock(const UniValue& params, bool fHelp)
return ret;
}
UniValue waitforblockheight(const UniValue& params, bool fHelp)
UniValue waitforblockheight(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"waitforblock\n"
"\nWaits for (at least) block height and returns the height and hash\n"
@ -292,10 +292,10 @@ UniValue waitforblockheight(const UniValue& params, bool fHelp)
);
int timeout = 0;
int height = params[0].get_int();
int height = request.params[0].get_int();
if (params.size() > 1)
timeout = params[1].get_int();
if (request.params.size() > 1)
timeout = request.params[1].get_int();
CUpdatedBlock block;
{
@ -312,9 +312,9 @@ UniValue waitforblockheight(const UniValue& params, bool fHelp)
return ret;
}
UniValue getdifficulty(const UniValue& params, bool fHelp)
UniValue getdifficulty(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getdifficulty\n"
"\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
@ -411,9 +411,9 @@ UniValue mempoolToJSON(bool fVerbose = false)
}
}
UniValue getrawmempool(const UniValue& params, bool fHelp)
UniValue getrawmempool(const JSONRPCRequest& request)
{
if (fHelp || params.size() > 1)
if (request.fHelp || request.params.size() > 1)
throw runtime_error(
"getrawmempool ( verbose )\n"
"\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
@ -436,15 +436,15 @@ UniValue getrawmempool(const UniValue& params, bool fHelp)
);
bool fVerbose = false;
if (params.size() > 0)
fVerbose = params[0].get_bool();
if (request.params.size() > 0)
fVerbose = request.params[0].get_bool();
return mempoolToJSON(fVerbose);
}
UniValue getmempoolancestors(const UniValue& params, bool fHelp)
UniValue getmempoolancestors(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2) {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
throw runtime_error(
"getmempoolancestors txid (verbose)\n"
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n"
@ -469,10 +469,10 @@ UniValue getmempoolancestors(const UniValue& params, bool fHelp)
}
bool fVerbose = false;
if (params.size() > 1)
fVerbose = params[1].get_bool();
if (request.params.size() > 1)
fVerbose = request.params[1].get_bool();
uint256 hash = ParseHashV(params[0], "parameter 1");
uint256 hash = ParseHashV(request.params[0], "parameter 1");
LOCK(mempool.cs);
@ -506,9 +506,9 @@ UniValue getmempoolancestors(const UniValue& params, bool fHelp)
}
}
UniValue getmempooldescendants(const UniValue& params, bool fHelp)
UniValue getmempooldescendants(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2) {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
throw runtime_error(
"getmempooldescendants txid (verbose)\n"
"\nIf txid is in the mempool, returns all in-mempool descendants.\n"
@ -533,10 +533,10 @@ UniValue getmempooldescendants(const UniValue& params, bool fHelp)
}
bool fVerbose = false;
if (params.size() > 1)
fVerbose = params[1].get_bool();
if (request.params.size() > 1)
fVerbose = request.params[1].get_bool();
uint256 hash = ParseHashV(params[0], "parameter 1");
uint256 hash = ParseHashV(request.params[0], "parameter 1");
LOCK(mempool.cs);
@ -570,9 +570,9 @@ UniValue getmempooldescendants(const UniValue& params, bool fHelp)
}
}
UniValue getmempoolentry(const UniValue& params, bool fHelp)
UniValue getmempoolentry(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1) {
if (request.fHelp || request.params.size() != 1) {
throw runtime_error(
"getmempoolentry txid\n"
"\nReturns mempool data for given transaction\n"
@ -588,7 +588,7 @@ UniValue getmempoolentry(const UniValue& params, bool fHelp)
);
}
uint256 hash = ParseHashV(params[0], "parameter 1");
uint256 hash = ParseHashV(request.params[0], "parameter 1");
LOCK(mempool.cs);
@ -603,9 +603,9 @@ UniValue getmempoolentry(const UniValue& params, bool fHelp)
return info;
}
UniValue getblockhashes(const UniValue& params, bool fHelp)
UniValue getblockhashes(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 2)
if (request.fHelp || request.params.size() != 2)
throw runtime_error(
"getblockhashes timestamp\n"
"\nReturns array of hashes of blocks within the timestamp range provided.\n"
@ -621,8 +621,8 @@ UniValue getblockhashes(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getblockhashes", "1231614698, 1231024505")
);
unsigned int high = params[0].get_int();
unsigned int low = params[1].get_int();
unsigned int high = request.params[0].get_int();
unsigned int low = request.params[1].get_int();
std::vector<uint256> blockHashes;
if (!GetTimestampIndex(high, low, blockHashes)) {
@ -637,9 +637,9 @@ UniValue getblockhashes(const UniValue& params, bool fHelp)
return result;
}
UniValue getblockhash(const UniValue& params, bool fHelp)
UniValue getblockhash(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"getblockhash index\n"
"\nReturns hash of block in best-block-chain at index provided.\n"
@ -654,7 +654,7 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
LOCK(cs_main);
int nHeight = params[0].get_int();
int nHeight = request.params[0].get_int();
if (nHeight < 0 || nHeight > chainActive.Height())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
@ -662,9 +662,9 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
return pblockindex->GetBlockHash().GetHex();
}
UniValue getblockheader(const UniValue& params, bool fHelp)
UniValue getblockheader(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"getblockheader \"hash\" ( verbose )\n"
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n"
@ -698,12 +698,12 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
LOCK(cs_main);
std::string strHash = params[0].get_str();
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
bool fVerbose = true;
if (params.size() > 1)
fVerbose = params[1].get_bool();
if (request.params.size() > 1)
fVerbose = request.params[1].get_bool();
if (mapBlockIndex.count(hash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
@ -721,9 +721,9 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
return blockheaderToJSON(pblockindex);
}
UniValue getblockheaders(const UniValue& params, bool fHelp)
UniValue getblockheaders(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 3)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw runtime_error(
"getblockheaders \"hash\" ( count verbose )\n"
"\nReturns an array of items with information about <count> blockheaders starting from <hash>.\n"
@ -765,22 +765,22 @@ UniValue getblockheaders(const UniValue& params, bool fHelp)
LOCK(cs_main);
std::string strHash = params[0].get_str();
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
if (mapBlockIndex.count(hash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
int nCount = MAX_HEADERS_RESULTS;
if (params.size() > 1)
nCount = params[1].get_int();
if (request.params.size() > 1)
nCount = request.params[1].get_int();
if (nCount <= 0 || nCount > (int)MAX_HEADERS_RESULTS)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range");
bool fVerbose = true;
if (params.size() > 2)
fVerbose = params[2].get_bool();
if (request.params.size() > 2)
fVerbose = request.params[2].get_bool();
CBlockIndex* pblockindex = mapBlockIndex[hash];
@ -810,9 +810,9 @@ UniValue getblockheaders(const UniValue& params, bool fHelp)
return arrHeaders;
}
UniValue getblock(const UniValue& params, bool fHelp)
UniValue getblock(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"getblock \"hash\" ( verbose )\n"
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
@ -851,12 +851,12 @@ UniValue getblock(const UniValue& params, bool fHelp)
LOCK(cs_main);
std::string strHash = params[0].get_str();
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
bool fVerbose = true;
if (params.size() > 1)
fVerbose = params[1].get_bool();
if (request.params.size() > 1)
fVerbose = request.params[1].get_bool();
if (mapBlockIndex.count(hash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
@ -948,9 +948,9 @@ static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
return true;
}
UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
UniValue gettxoutsetinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"gettxoutsetinfo\n"
"\nReturns statistics about the unspent transaction output set.\n"
@ -988,9 +988,9 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
return ret;
}
UniValue gettxout(const UniValue& params, bool fHelp)
UniValue gettxout(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 2 || params.size() > 3)
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw runtime_error(
"gettxout \"txid\" n ( includemempool )\n"
"\nReturns details about an unspent transaction output.\n"
@ -1030,13 +1030,13 @@ UniValue gettxout(const UniValue& params, bool fHelp)
UniValue ret(UniValue::VOBJ);
std::string strHash = params[0].get_str();
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
int n = params[1].get_int();
int n = request.params[1].get_int();
COutPoint out(hash, n);
bool fMempool = true;
if (params.size() > 2)
fMempool = params[2].get_bool();
if (request.params.size() > 2)
fMempool = request.params[2].get_bool();
Coin coin;
if (fMempool) {
@ -1068,11 +1068,11 @@ UniValue gettxout(const UniValue& params, bool fHelp)
return ret;
}
UniValue verifychain(const UniValue& params, bool fHelp)
UniValue verifychain(const JSONRPCRequest& request)
{
int nCheckLevel = GetArg("-checklevel", DEFAULT_CHECKLEVEL);
int nCheckDepth = GetArg("-checkblocks", DEFAULT_CHECKBLOCKS);
if (fHelp || params.size() > 2)
if (request.fHelp || request.params.size() > 2)
throw runtime_error(
"verifychain ( checklevel numblocks )\n"
"\nVerifies blockchain database.\n"
@ -1088,10 +1088,10 @@ UniValue verifychain(const UniValue& params, bool fHelp)
LOCK(cs_main);
if (params.size() > 0)
nCheckLevel = params[0].get_int();
if (params.size() > 1)
nCheckDepth = params[1].get_int();
if (request.params.size() > 0)
nCheckLevel = request.params[0].get_int();
if (request.params.size() > 1)
nCheckDepth = request.params[1].get_int();
return CVerifyDB().VerifyDB(Params(), pcoinsTip, nCheckLevel, nCheckDepth);
}
@ -1155,9 +1155,9 @@ void BIP9SoftForkDescPushBack(UniValue& bip9_softforks, const std::string &name,
bip9_softforks.push_back(Pair(name, BIP9SoftForkDesc(consensusParams, id)));
}
UniValue getblockchaininfo(const UniValue& params, bool fHelp)
UniValue getblockchaininfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getblockchaininfo\n"
"Returns an object containing various state info regarding block chain processing.\n"
@ -1251,9 +1251,9 @@ struct CompareBlocksByHeight
}
};
UniValue getchaintips(const UniValue& params, bool fHelp)
UniValue getchaintips(const JSONRPCRequest& request)
{
if (fHelp || params.size() > 2)
if (request.fHelp || request.params.size() > 2)
throw runtime_error(
"getchaintips ( count branchlen )\n"
"Return information about all known tips in the block tree,"
@ -1325,11 +1325,11 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
int nBranchMin = -1;
int nCountMax = INT_MAX;
if(params.size() >= 1)
nCountMax = params[0].get_int();
if(request.params.size() >= 1)
nCountMax = request.params[0].get_int();
if(params.size() == 2)
nBranchMin = params[1].get_int();
if(request.params.size() == 2)
nBranchMin = request.params[1].get_int();
/* Construct the output array. */
UniValue res(UniValue::VARR);
@ -1388,9 +1388,9 @@ UniValue mempoolInfoToJSON()
return ret;
}
UniValue getmempoolinfo(const UniValue& params, bool fHelp)
UniValue getmempoolinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getmempoolinfo\n"
"\nReturns details on the active state of the TX memory pool.\n"
@ -1410,9 +1410,9 @@ UniValue getmempoolinfo(const UniValue& params, bool fHelp)
return mempoolInfoToJSON();
}
UniValue preciousblock(const UniValue& params, bool fHelp)
UniValue preciousblock(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"preciousblock \"hash\"\n"
"\nTreats a block as if it were received before others with the same work.\n"
@ -1426,7 +1426,7 @@ UniValue preciousblock(const UniValue& params, bool fHelp)
+ HelpExampleRpc("preciousblock", "\"blockhash\"")
);
std::string strHash = params[0].get_str();
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
CBlockIndex* pblockindex;
@ -1448,9 +1448,9 @@ UniValue preciousblock(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue invalidateblock(const UniValue& params, bool fHelp)
UniValue invalidateblock(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"invalidateblock \"hash\"\n"
"\nPermanently marks a block as invalid, as if it violated a consensus rule.\n"
@ -1462,7 +1462,7 @@ UniValue invalidateblock(const UniValue& params, bool fHelp)
+ HelpExampleRpc("invalidateblock", "\"blockhash\"")
);
std::string strHash = params[0].get_str();
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
CValidationState state;
@ -1486,9 +1486,9 @@ UniValue invalidateblock(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue reconsiderblock(const UniValue& params, bool fHelp)
UniValue reconsiderblock(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"reconsiderblock \"hash\"\n"
"\nRemoves invalidity status of a block and its descendants, reconsider them for activation.\n"
@ -1501,7 +1501,7 @@ UniValue reconsiderblock(const UniValue& params, bool fHelp)
+ HelpExampleRpc("reconsiderblock", "\"blockhash\"")
);
std::string strHash = params[0].get_str();
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
{

View File

@ -25,13 +25,13 @@
#include <boost/lexical_cast.hpp>
UniValue gobject(const UniValue& params, bool fHelp)
UniValue gobject(const JSONRPCRequest& request)
{
std::string strCommand;
if (params.size() >= 1)
strCommand = params[0].get_str();
if (request.params.size() >= 1)
strCommand = request.params[0].get_str();
if (fHelp ||
if (request.fHelp ||
(
#ifdef ENABLE_WALLET
strCommand != "prepare" &&
@ -72,11 +72,11 @@ UniValue gobject(const UniValue& params, bool fHelp)
// DEBUG : TEST DESERIALIZATION OF GOVERNANCE META DATA
if(strCommand == "deserialize")
{
if (params.size() != 2) {
if (request.params.size() != 2) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject deserialize <data-hex>'");
}
std::string strHex = params[1].get_str();
std::string strHex = request.params[1].get_str();
std::vector<unsigned char> v = ParseHex(strHex);
std::string s(v.begin(), v.end());
@ -90,7 +90,7 @@ UniValue gobject(const UniValue& params, bool fHelp)
// VALIDATE A GOVERNANCE OBJECT PRIOR TO SUBMISSION
if(strCommand == "check")
{
if (params.size() != 2) {
if (request.params.size() != 2) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject check <data-hex>'");
}
@ -101,7 +101,7 @@ UniValue gobject(const UniValue& params, bool fHelp)
int nRevision = 1;
int64_t nTime = GetAdjustedTime();
std::string strData = params[1].get_str();
std::string strData = request.params[1].get_str();
CGovernanceObject govobj(hashParent, nRevision, nTime, uint256(), strData);
@ -126,7 +126,7 @@ UniValue gobject(const UniValue& params, bool fHelp)
// PREPARE THE GOVERNANCE OBJECT BY CREATING A COLLATERAL TRANSACTION
if(strCommand == "prepare")
{
if (params.size() != 5) {
if (request.params.size() != 5) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject prepare <parent-hash> <revision> <time> <data-hex>'");
}
@ -135,17 +135,17 @@ UniValue gobject(const UniValue& params, bool fHelp)
uint256 hashParent;
// -- attach to root node (root node doesn't really exist, but has a hash of zero)
if(params[1].get_str() == "0") {
if(request.params[1].get_str() == "0") {
hashParent = uint256();
} else {
hashParent = ParseHashV(params[1], "fee-txid, parameter 1");
hashParent = ParseHashV(request.params[1], "fee-txid, parameter 1");
}
std::string strRevision = params[2].get_str();
std::string strTime = params[3].get_str();
std::string strRevision = request.params[2].get_str();
std::string strTime = request.params[3].get_str();
int nRevision = boost::lexical_cast<int>(strRevision);
int nTime = boost::lexical_cast<int>(strTime);
std::string strData = params[4].get_str();
std::string strData = request.params[4].get_str();
// CREATE A NEW COLLATERAL TRANSACTION FOR THIS SPECIFIC OBJECT
@ -193,7 +193,7 @@ UniValue gobject(const UniValue& params, bool fHelp)
// AFTER COLLATERAL TRANSACTION HAS MATURED USER CAN SUBMIT GOVERNANCE OBJECT TO PROPAGATE NETWORK
if(strCommand == "submit")
{
if ((params.size() < 5) || (params.size() > 6)) {
if ((request.params.size() < 5) || (request.params.size() > 6)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject submit <parent-hash> <revision> <time> <data-hex> <fee-txid>'");
}
@ -205,30 +205,30 @@ UniValue gobject(const UniValue& params, bool fHelp)
DBG( cout << "gobject: submit activeMasternode.pubKeyMasternode = " << activeMasternode.pubKeyMasternode.GetHash().ToString()
<< ", outpoint = " << activeMasternode.outpoint.ToStringShort()
<< ", params.size() = " << params.size()
<< ", params.size() = " << request.params.size()
<< ", fMnFound = " << fMnFound << endl; );
// ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS
uint256 txidFee;
if(params.size() == 6) {
txidFee = ParseHashV(params[5], "fee-txid, parameter 6");
if(request.params.size() == 6) {
txidFee = ParseHashV(request.params[5], "fee-txid, parameter 6");
}
uint256 hashParent;
if(params[1].get_str() == "0") { // attach to root node (root node doesn't really exist, but has a hash of zero)
if(request.params[1].get_str() == "0") { // attach to root node (root node doesn't really exist, but has a hash of zero)
hashParent = uint256();
} else {
hashParent = ParseHashV(params[1], "parent object hash, parameter 2");
hashParent = ParseHashV(request.params[1], "parent object hash, parameter 2");
}
// GET THE PARAMETERS FROM USER
std::string strRevision = params[2].get_str();
std::string strTime = params[3].get_str();
std::string strRevision = request.params[2].get_str();
std::string strTime = request.params[3].get_str();
int nRevision = boost::lexical_cast<int>(strRevision);
int nTime = boost::lexical_cast<int>(strTime);
std::string strData = params[4].get_str();
std::string strData = request.params[4].get_str();
CGovernanceObject govobj(hashParent, nRevision, nTime, txidFee, strData);
@ -258,7 +258,7 @@ UniValue gobject(const UniValue& params, bool fHelp)
}
}
else {
if(params.size() != 6) {
if(request.params.size() != 6) {
LogPrintf("gobject(submit) -- Object submission rejected because fee tx not provided\n");
throw JSONRPCError(RPC_INVALID_PARAMETER, "The fee-txid parameter must be included to submit this type of object");
}
@ -298,15 +298,15 @@ UniValue gobject(const UniValue& params, bool fHelp)
if(strCommand == "vote-conf")
{
if(params.size() != 4)
if(request.params.size() != 4)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject vote-conf <governance-hash> [funding|valid|delete] [yes|no|abstain]'");
uint256 hash;
std::string strVote;
hash = ParseHashV(params[1], "Object hash");
std::string strVoteSignal = params[2].get_str();
std::string strVoteOutcome = params[3].get_str();
hash = ParseHashV(request.params[1], "Object hash");
std::string strVoteSignal = request.params[2].get_str();
std::string strVoteOutcome = request.params[3].get_str();
vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal);
if(eVoteSignal == VOTE_SIGNAL_NONE) {
@ -376,15 +376,15 @@ UniValue gobject(const UniValue& params, bool fHelp)
if(strCommand == "vote-many")
{
if(params.size() != 4)
if(request.params.size() != 4)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject vote-many <governance-hash> [funding|valid|delete] [yes|no|abstain]'");
uint256 hash;
std::string strVote;
hash = ParseHashV(params[1], "Object hash");
std::string strVoteSignal = params[2].get_str();
std::string strVoteOutcome = params[3].get_str();
hash = ParseHashV(request.params[1], "Object hash");
std::string strVoteSignal = request.params[2].get_str();
std::string strVoteOutcome = request.params[3].get_str();
vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal);
@ -482,7 +482,7 @@ UniValue gobject(const UniValue& params, bool fHelp)
// MASTERNODES CAN VOTE ON GOVERNANCE OBJECTS ON THE NETWORK FOR VARIOUS SIGNALS AND OUTCOMES
if(strCommand == "vote-alias")
{
if(params.size() != 5)
if(request.params.size() != 5)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject vote-alias <governance-hash> [funding|valid|delete] [yes|no|abstain] <alias-name>'");
uint256 hash;
@ -490,10 +490,10 @@ UniValue gobject(const UniValue& params, bool fHelp)
// COLLECT NEEDED PARAMETRS FROM USER
hash = ParseHashV(params[1], "Object hash");
std::string strVoteSignal = params[2].get_str();
std::string strVoteOutcome = params[3].get_str();
std::string strAlias = params[4].get_str();
hash = ParseHashV(request.params[1], "Object hash");
std::string strVoteSignal = request.params[2].get_str();
std::string strVoteOutcome = request.params[3].get_str();
std::string strAlias = request.params[4].get_str();
// CONVERT NAMED SIGNAL/ACTION AND CONVERT
@ -608,18 +608,18 @@ UniValue gobject(const UniValue& params, bool fHelp)
// USERS CAN QUERY THE SYSTEM FOR A LIST OF VARIOUS GOVERNANCE ITEMS
if(strCommand == "list" || strCommand == "diff")
{
if (params.size() > 3)
if (request.params.size() > 3)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject [list|diff] ( signal type )'");
// GET MAIN PARAMETER FOR THIS MODE, VALID OR ALL?
std::string strCachedSignal = "valid";
if (params.size() >= 2) strCachedSignal = params[1].get_str();
if (request.params.size() >= 2) strCachedSignal = request.params[1].get_str();
if (strCachedSignal != "valid" && strCachedSignal != "funding" && strCachedSignal != "delete" && strCachedSignal != "endorsed" && strCachedSignal != "all")
return "Invalid signal, should be 'valid', 'funding', 'delete', 'endorsed' or 'all'";
std::string strType = "all";
if (params.size() == 3) strType = params[2].get_str();
if (request.params.size() == 3) strType = request.params[2].get_str();
if (strType != "proposals" && strType != "triggers" && strType != "watchdogs" && strType != "all")
return "Invalid type, should be 'proposals', 'triggers', 'watchdogs' or 'all'";
@ -688,11 +688,11 @@ UniValue gobject(const UniValue& params, bool fHelp)
// GET SPECIFIC GOVERNANCE ENTRY
if(strCommand == "get")
{
if (params.size() != 2)
if (request.params.size() != 2)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject get <governance-hash>'");
// COLLECT VARIABLES FROM OUR USER
uint256 hash = ParseHashV(params[1], "GovObj hash");
uint256 hash = ParseHashV(request.params[1], "GovObj hash");
LOCK2(cs_main, governance.cs);
@ -764,14 +764,14 @@ UniValue gobject(const UniValue& params, bool fHelp)
// GETVOTES FOR SPECIFIC GOVERNANCE OBJECT
if(strCommand == "getvotes")
{
if (params.size() != 2)
if (request.params.size() != 2)
throw std::runtime_error(
"Correct usage is 'gobject getvotes <governance-hash>'"
);
// COLLECT PARAMETERS FROM USER
uint256 hash = ParseHashV(params[1], "Governance hash");
uint256 hash = ParseHashV(request.params[1], "Governance hash");
// FIND OBJECT USER IS LOOKING FOR
@ -800,19 +800,19 @@ UniValue gobject(const UniValue& params, bool fHelp)
// GETVOTES FOR SPECIFIC GOVERNANCE OBJECT
if(strCommand == "getcurrentvotes")
{
if (params.size() != 2 && params.size() != 4)
if (request.params.size() != 2 && request.params.size() != 4)
throw std::runtime_error(
"Correct usage is 'gobject getcurrentvotes <governance-hash> [txid vout_index]'"
);
// COLLECT PARAMETERS FROM USER
uint256 hash = ParseHashV(params[1], "Governance hash");
uint256 hash = ParseHashV(request.params[1], "Governance hash");
COutPoint mnCollateralOutpoint;
if (params.size() == 4) {
uint256 txid = ParseHashV(params[2], "Masternode Collateral hash");
std::string strVout = params[3].get_str();
if (request.params.size() == 4) {
uint256 txid = ParseHashV(request.params[2], "Masternode Collateral hash");
std::string strVout = request.params[3].get_str();
uint32_t vout = boost::lexical_cast<uint32_t>(strVout);
mnCollateralOutpoint = COutPoint(txid, vout);
}
@ -844,21 +844,21 @@ UniValue gobject(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue voteraw(const UniValue& params, bool fHelp)
UniValue voteraw(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 7)
if (request.fHelp || request.params.size() != 7)
throw std::runtime_error(
"voteraw <masternode-tx-hash> <masternode-tx-index> <governance-hash> <vote-signal> [yes|no|abstain] <time> <vote-sig>\n"
"Compile and relay a governance vote with provided external signature instead of signing vote internally\n"
);
uint256 hashMnTx = ParseHashV(params[0], "mn tx hash");
int nMnTxIndex = params[1].get_int();
uint256 hashMnTx = ParseHashV(request.params[0], "mn tx hash");
int nMnTxIndex = request.params[1].get_int();
COutPoint outpoint = COutPoint(hashMnTx, nMnTxIndex);
uint256 hashGovObj = ParseHashV(params[2], "Governance hash");
std::string strVoteSignal = params[3].get_str();
std::string strVoteOutcome = params[4].get_str();
uint256 hashGovObj = ParseHashV(request.params[2], "Governance hash");
std::string strVoteSignal = request.params[3].get_str();
std::string strVoteOutcome = request.params[4].get_str();
vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal);
if(eVoteSignal == VOTE_SIGNAL_NONE) {
@ -872,8 +872,8 @@ UniValue voteraw(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
}
int64_t nTime = params[5].get_int64();
std::string strSig = params[6].get_str();
int64_t nTime = request.params[5].get_int64();
std::string strSig = request.params[6].get_str();
bool fInvalid = false;
std::vector<unsigned char> vchSig = DecodeBase64(strSig.c_str(), &fInvalid);
@ -905,9 +905,9 @@ UniValue voteraw(const UniValue& params, bool fHelp)
}
}
UniValue getgovernanceinfo(const UniValue& params, bool fHelp)
UniValue getgovernanceinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0) {
if (request.fHelp || request.params.size() != 0) {
throw std::runtime_error(
"getgovernanceinfo\n"
"Returns an object containing governance parameters.\n"
@ -965,9 +965,9 @@ UniValue getgovernanceinfo(const UniValue& params, bool fHelp)
return obj;
}
UniValue getsuperblockbudget(const UniValue& params, bool fHelp)
UniValue getsuperblockbudget(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1) {
if (request.fHelp || request.params.size() != 1) {
throw std::runtime_error(
"getsuperblockbudget index\n"
"\nReturns the absolute maximum sum of superblock payments allowed.\n"
@ -981,7 +981,7 @@ UniValue getsuperblockbudget(const UniValue& params, bool fHelp)
);
}
int nBlockHeight = params[0].get_int();
int nBlockHeight = request.params[0].get_int();
if (nBlockHeight < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
}

View File

@ -23,14 +23,14 @@
#include <iomanip>
#include <univalue.h>
UniValue masternodelist(const UniValue& params, bool fHelp);
UniValue masternodelist(const JSONRPCRequest& request);
#ifdef ENABLE_WALLET
void EnsureWalletIsUnlocked();
UniValue privatesend(const UniValue& params, bool fHelp)
UniValue privatesend(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"privatesend \"command\"\n"
"\nArguments:\n"
@ -41,7 +41,7 @@ UniValue privatesend(const UniValue& params, bool fHelp)
" reset - Reset mixing\n"
);
if(params[0].get_str() == "start") {
if(request.params[0].get_str() == "start") {
{
LOCK(pwalletMain->cs_wallet);
EnsureWalletIsUnlocked();
@ -55,12 +55,12 @@ UniValue privatesend(const UniValue& params, bool fHelp)
return "Mixing " + (result ? "started successfully" : ("start failed: " + privateSendClient.GetStatus() + ", will retry"));
}
if(params[0].get_str() == "stop") {
if(request.params[0].get_str() == "stop") {
privateSendClient.fEnablePrivateSend = false;
return "Mixing was stopped";
}
if(params[0].get_str() == "reset") {
if(request.params[0].get_str() == "reset") {
privateSendClient.ResetPool();
return "Mixing was reset";
}
@ -69,9 +69,9 @@ UniValue privatesend(const UniValue& params, bool fHelp)
}
#endif // ENABLE_WALLET
UniValue getpoolinfo(const UniValue& params, bool fHelp)
UniValue getpoolinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
"getpoolinfo\n"
"Returns an object containing mixing pool related information.\n");
@ -108,11 +108,11 @@ UniValue getpoolinfo(const UniValue& params, bool fHelp)
}
UniValue masternode(const UniValue& params, bool fHelp)
UniValue masternode(const JSONRPCRequest& request)
{
std::string strCommand;
if (params.size() >= 1) {
strCommand = params[0].get_str();
if (request.params.size() >= 1) {
strCommand = request.params[0].get_str();
}
#ifdef ENABLE_WALLET
@ -120,7 +120,7 @@ UniValue masternode(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_PARAMETER, "DEPRECATED, please use start-all instead");
#endif // ENABLE_WALLET
if (fHelp ||
if (request.fHelp ||
(
#ifdef ENABLE_WALLET
strCommand != "start-alias" && strCommand != "start-all" && strCommand != "start-missing" &&
@ -152,20 +152,21 @@ UniValue masternode(const UniValue& params, bool fHelp)
if (strCommand == "list")
{
UniValue newParams(UniValue::VARR);
JSONRPCRequest newRequest = request;
newRequest.params.clear();
// forward params but skip "list"
for (unsigned int i = 1; i < params.size(); i++) {
newParams.push_back(params[i]);
for (unsigned int i = 1; i < request.params.size(); i++) {
newRequest.params.push_back(request.params[i]);
}
return masternodelist(newParams, fHelp);
return masternodelist(newRequest);
}
if(strCommand == "connect")
{
if (params.size() < 2)
if (request.params.size() < 2)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Masternode address required");
std::string strAddress = params[1].get_str();
std::string strAddress = request.params[1].get_str();
CService addr;
if (!Lookup(strAddress.c_str(), addr, 0, false))
@ -181,13 +182,13 @@ UniValue masternode(const UniValue& params, bool fHelp)
if (strCommand == "count")
{
if (params.size() > 2)
if (request.params.size() > 2)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Too many parameters");
if (params.size() == 1)
if (request.params.size() == 1)
return mnodeman.size();
std::string strMode = params[1].get_str();
std::string strMode = request.params[1].get_str();
if (strMode == "ps")
return mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION);
@ -239,7 +240,7 @@ UniValue masternode(const UniValue& params, bool fHelp)
#ifdef ENABLE_WALLET
if (strCommand == "start-alias")
{
if (params.size() < 2)
if (request.params.size() < 2)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Please specify an alias");
{
@ -247,7 +248,7 @@ UniValue masternode(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
}
std::string strAlias = params[1].get_str();
std::string strAlias = request.params[1].get_str();
bool fFound = false;
@ -417,15 +418,15 @@ UniValue masternode(const UniValue& params, bool fHelp)
int nLast = 10;
std::string strFilter = "";
if (params.size() >= 2) {
nLast = atoi(params[1].get_str());
if (request.params.size() >= 2) {
nLast = atoi(request.params[1].get_str());
}
if (params.size() == 3) {
strFilter = params[2].get_str();
if (request.params.size() == 3) {
strFilter = request.params[2].get_str();
}
if (params.size() > 3)
if (request.params.size() > 3)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'masternode winners ( \"count\" \"filter\" )'");
UniValue obj(UniValue::VOBJ);
@ -442,15 +443,15 @@ UniValue masternode(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue masternodelist(const UniValue& params, bool fHelp)
UniValue masternodelist(const JSONRPCRequest& request)
{
std::string strMode = "status";
std::string strFilter = "";
if (params.size() >= 1) strMode = params[0].get_str();
if (params.size() == 2) strFilter = params[1].get_str();
if (request.params.size() >= 1) strMode = request.params[0].get_str();
if (request.params.size() == 2) strFilter = request.params[1].get_str();
if (fHelp || (
if (request.fHelp || (
strMode != "activeseconds" && strMode != "addr" && strMode != "full" && strMode != "info" &&
strMode != "lastseen" && strMode != "lastpaidtime" && strMode != "lastpaidblock" &&
strMode != "protocol" && strMode != "payee" && strMode != "pubkey" &&
@ -595,13 +596,13 @@ bool DecodeHexVecMnb(std::vector<CMasternodeBroadcast>& vecMnb, std::string strH
return true;
}
UniValue masternodebroadcast(const UniValue& params, bool fHelp)
UniValue masternodebroadcast(const JSONRPCRequest& request)
{
std::string strCommand;
if (params.size() >= 1)
strCommand = params[0].get_str();
if (request.params.size() >= 1)
strCommand = request.params[0].get_str();
if (fHelp ||
if (request.fHelp ||
(
#ifdef ENABLE_WALLET
strCommand != "create-alias" && strCommand != "create-all" &&
@ -628,7 +629,7 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
if (fImporting || fReindex)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wait for reindex and/or import to finish");
if (params.size() < 2)
if (request.params.size() < 2)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Please specify an alias");
{
@ -637,7 +638,7 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
}
bool fFound = false;
std::string strAlias = params[1].get_str();
std::string strAlias = request.params[1].get_str();
UniValue statusObj(UniValue::VOBJ);
std::vector<CMasternodeBroadcast> vecMnb;
@ -728,12 +729,12 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
if (strCommand == "decode")
{
if (params.size() != 2)
if (request.params.size() != 2)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'masternodebroadcast decode \"hexstring\"'");
std::vector<CMasternodeBroadcast> vecMnb;
if (!DecodeHexVecMnb(vecMnb, params[1].get_str()))
if (!DecodeHexVecMnb(vecMnb, request.params[1].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Masternode broadcast message decode failed");
int nSuccessful = 0;
@ -777,7 +778,7 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
if (strCommand == "relay")
{
if (params.size() < 2 || params.size() > 3)
if (request.params.size() < 2 || request.params.size() > 3)
throw JSONRPCError(RPC_INVALID_PARAMETER, "masternodebroadcast relay \"hexstring\" ( fast )\n"
"\nArguments:\n"
"1. \"hex\" (string, required) Broadcast messages hex string\n"
@ -785,12 +786,12 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
std::vector<CMasternodeBroadcast> vecMnb;
if (!DecodeHexVecMnb(vecMnb, params[1].get_str()))
if (!DecodeHexVecMnb(vecMnb, request.params[1].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Masternode broadcast message decode failed");
int nSuccessful = 0;
int nFailed = 0;
bool fSafe = params.size() == 2;
bool fSafe = request.params.size() == 2;
UniValue returnObj(UniValue::VOBJ);
// verify all signatures first, bailout if any of them broken
@ -832,9 +833,9 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue sentinelping(const UniValue& params, bool fHelp)
UniValue sentinelping(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1) {
if (request.fHelp || request.params.size() != 1) {
throw std::runtime_error(
"sentinelping version\n"
"\nSentinel ping.\n"
@ -848,7 +849,7 @@ UniValue sentinelping(const UniValue& params, bool fHelp)
);
}
activeMasternode.UpdateSentinelPing(StringVersionToInt(params[0].get_str()));
activeMasternode.UpdateSentinelPing(StringVersionToInt(request.params[0].get_str()));
return true;
}

View File

@ -80,9 +80,9 @@ UniValue GetNetworkHashPS(int lookup, int height) {
return workDiff.getdouble() / timeDiff;
}
UniValue getnetworkhashps(const UniValue& params, bool fHelp)
UniValue getnetworkhashps(const JSONRPCRequest& request)
{
if (fHelp || params.size() > 2)
if (request.fHelp || request.params.size() > 2)
throw runtime_error(
"getnetworkhashps ( blocks height )\n"
"\nReturns the estimated network hashes per second based on the last n blocks.\n"
@ -99,7 +99,7 @@ UniValue getnetworkhashps(const UniValue& params, bool fHelp)
);
LOCK(cs_main);
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
return GetNetworkHashPS(request.params.size() > 0 ? request.params[0].get_int() : 120, request.params.size() > 1 ? request.params[1].get_int() : -1);
}
UniValue generateBlocks(boost::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
@ -151,9 +151,9 @@ UniValue generateBlocks(boost::shared_ptr<CReserveScript> coinbaseScript, int nG
return blockHashes;
}
UniValue generate(const UniValue& params, bool fHelp)
UniValue generate(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"generate numblocks ( maxtries )\n"
"\nMine up to numblocks blocks immediately (before the RPC call returns)\n"
@ -167,10 +167,10 @@ UniValue generate(const UniValue& params, bool fHelp)
+ HelpExampleCli("generate", "11")
);
int nGenerate = params[0].get_int();
int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
if (params.size() > 1) {
nMaxTries = params[1].get_int();
if (request.params.size() > 1) {
nMaxTries = request.params[1].get_int();
}
boost::shared_ptr<CReserveScript> coinbaseScript;
@ -187,9 +187,9 @@ UniValue generate(const UniValue& params, bool fHelp)
return generateBlocks(coinbaseScript, nGenerate, nMaxTries, true);
}
UniValue generatetoaddress(const UniValue& params, bool fHelp)
UniValue generatetoaddress(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 2 || params.size() > 3)
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw runtime_error(
"generatetoaddress numblocks address (maxtries)\n"
"\nMine blocks immediately to a specified address (before the RPC call returns)\n"
@ -204,13 +204,13 @@ UniValue generatetoaddress(const UniValue& params, bool fHelp)
+ HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
);
int nGenerate = params[0].get_int();
int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
if (params.size() > 2) {
nMaxTries = params[2].get_int();
if (request.params.size() > 2) {
nMaxTries = request.params[2].get_int();
}
CBitcoinAddress address(params[1].get_str());
CBitcoinAddress address(request.params[1].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
@ -220,9 +220,9 @@ UniValue generatetoaddress(const UniValue& params, bool fHelp)
return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false);
}
UniValue getmininginfo(const UniValue& params, bool fHelp)
UniValue getmininginfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getmininginfo\n"
"\nReturns a json object containing mining-related information."
@ -251,7 +251,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
obj.push_back(Pair("networkhashps", getnetworkhashps(request)));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("chain", Params().NetworkIDString()));
return obj;
@ -259,9 +259,9 @@ UniValue getmininginfo(const UniValue& params, bool fHelp)
// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
UniValue prioritisetransaction(const UniValue& params, bool fHelp)
UniValue prioritisetransaction(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 3)
if (request.fHelp || request.params.size() != 3)
throw runtime_error(
"prioritisetransaction <txid> <priority delta> <fee delta>\n"
"Accepts the transaction into mined blocks at a higher (or lower) priority\n"
@ -281,10 +281,11 @@ UniValue prioritisetransaction(const UniValue& params, bool fHelp)
);
LOCK(cs_main);
uint256 hash = ParseHashStr(params[0].get_str(), "txid");
CAmount nAmount = params[2].get_int64();
mempool.PrioritiseTransaction(hash, params[0].get_str(), params[1].get_real(), nAmount);
uint256 hash = ParseHashStr(request.params[0].get_str(), "txid");
CAmount nAmount = request.params[2].get_int64();
mempool.PrioritiseTransaction(hash, request.params[0].get_str(), request.params[1].get_real(), nAmount);
return true;
}
@ -317,9 +318,9 @@ std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
return s;
}
UniValue getblocktemplate(const UniValue& params, bool fHelp)
UniValue getblocktemplate(const JSONRPCRequest& request)
{
if (fHelp || params.size() > 1)
if (request.fHelp || request.params.size() > 1)
throw runtime_error(
"getblocktemplate ( TemplateRequest )\n"
"\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
@ -416,9 +417,9 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
UniValue lpval = NullUniValue;
std::set<std::string> setClientRules;
int64_t nMaxVersionPreVB = -1;
if (params.size() > 0)
if (request.params.size() > 0)
{
const UniValue& oparam = params[0].get_obj();
const UniValue& oparam = request.params[0].get_obj();
const UniValue& modeval = find_value(oparam, "mode");
if (modeval.isStr())
strMode = modeval.get_str();
@ -748,9 +749,9 @@ protected:
};
};
UniValue submitblock(const UniValue& params, bool fHelp)
UniValue submitblock(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"submitblock \"hexdata\" ( \"jsonparametersobject\" )\n"
"\nAttempts to submit new block to network.\n"
@ -770,7 +771,7 @@ UniValue submitblock(const UniValue& params, bool fHelp)
);
CBlock block;
if (!DecodeHexBlk(block, params[0].get_str()))
if (!DecodeHexBlk(block, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
uint256 hash = block.GetHash();
@ -804,9 +805,9 @@ UniValue submitblock(const UniValue& params, bool fHelp)
return BIP22ValidationResult(sc.state);
}
UniValue estimatefee(const UniValue& params, bool fHelp)
UniValue estimatefee(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"estimatefee nblocks\n"
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
@ -822,9 +823,9 @@ UniValue estimatefee(const UniValue& params, bool fHelp)
+ HelpExampleCli("estimatefee", "6")
);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VNUM));
int nBlocks = params[0].get_int();
int nBlocks = request.params[0].get_int();
if (nBlocks < 1)
nBlocks = 1;
@ -835,9 +836,9 @@ UniValue estimatefee(const UniValue& params, bool fHelp)
return ValueFromAmount(feeRate.GetFeePerK());
}
UniValue estimatepriority(const UniValue& params, bool fHelp)
UniValue estimatepriority(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"estimatepriority nblocks\n"
"\nEstimates the approximate priority a zero-fee transaction needs to begin\n"
@ -853,18 +854,18 @@ UniValue estimatepriority(const UniValue& params, bool fHelp)
+ HelpExampleCli("estimatepriority", "6")
);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VNUM));
int nBlocks = params[0].get_int();
int nBlocks = request.params[0].get_int();
if (nBlocks < 1)
nBlocks = 1;
return mempool.estimatePriority(nBlocks);
}
UniValue estimatesmartfee(const UniValue& params, bool fHelp)
UniValue estimatesmartfee(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"estimatesmartfee nblocks\n"
"\nWARNING: This interface is unstable and may disappear or change!\n"
@ -886,9 +887,9 @@ UniValue estimatesmartfee(const UniValue& params, bool fHelp)
+ HelpExampleCli("estimatesmartfee", "6")
);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VNUM));
int nBlocks = params[0].get_int();
int nBlocks = request.params[0].get_int();
UniValue result(UniValue::VOBJ);
int answerFound;
@ -898,9 +899,9 @@ UniValue estimatesmartfee(const UniValue& params, bool fHelp)
return result;
}
UniValue estimatesmartpriority(const UniValue& params, bool fHelp)
UniValue estimatesmartpriority(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"estimatesmartpriority nblocks\n"
"\nWARNING: This interface is unstable and may disappear or change!\n"
@ -922,9 +923,9 @@ UniValue estimatesmartpriority(const UniValue& params, bool fHelp)
+ HelpExampleCli("estimatesmartpriority", "6")
);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VNUM));
int nBlocks = params[0].get_int();
int nBlocks = request.params[0].get_int();
UniValue result(UniValue::VOBJ);
int answerFound;

View File

@ -45,9 +45,9 @@ using namespace std;
*
* Or alternatively, create a specific query method for the information.
**/
UniValue getinfo(const UniValue& params, bool fHelp)
UniValue getinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getinfo\n"
"\nDEPRECATED. Returns an object containing various state info.\n"
@ -117,9 +117,9 @@ UniValue getinfo(const UniValue& params, bool fHelp)
return obj;
}
UniValue debug(const UniValue& params, bool fHelp)
UniValue debug(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"debug ( 0|1|addrman|alert|bench|coindb|db|lock|rand|rpc|selectcoins|mempool"
"|mempoolrej|net|proxy|prune|http|libevent|tor|zmq|"
@ -130,7 +130,7 @@ UniValue debug(const UniValue& params, bool fHelp)
+ HelpExampleRpc("debug", "dash,net")
);
std::string strMode = params[0].get_str();
std::string strMode = request.params[0].get_str();
mapMultiArgs["-debug"].clear();
boost::split(mapMultiArgs["-debug"], strMode, boost::is_any_of(","));
@ -141,15 +141,15 @@ UniValue debug(const UniValue& params, bool fHelp)
return "Debug mode: " + (fDebug ? strMode : "off");
}
UniValue mnsync(const UniValue& params, bool fHelp)
UniValue mnsync(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"mnsync [status|next|reset]\n"
"Returns the sync status, updates to the next step or resets it entirely.\n"
);
std::string strMode = params[0].get_str();
std::string strMode = request.params[0].get_str();
if(strMode == "status") {
UniValue objStatus(UniValue::VOBJ);
@ -223,16 +223,16 @@ public:
/*
Used for updating/reading spork settings on the network
*/
UniValue spork(const UniValue& params, bool fHelp)
UniValue spork(const JSONRPCRequest& request)
{
if(params.size() == 1 && params[0].get_str() == "show"){
if(request.params.size() == 1 && request.params[0].get_str() == "show"){
UniValue ret(UniValue::VOBJ);
for(int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++){
if(sporkManager.GetSporkNameByID(nSporkID) != "Unknown")
ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), sporkManager.GetSporkValue(nSporkID)));
}
return ret;
} else if(params.size() == 1 && params[0].get_str() == "active"){
} else if(request.params.size() == 1 && request.params[0].get_str() == "active"){
UniValue ret(UniValue::VOBJ);
for(int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++){
if(sporkManager.GetSporkNameByID(nSporkID) != "Unknown")
@ -241,8 +241,8 @@ UniValue spork(const UniValue& params, bool fHelp)
return ret;
}
#ifdef ENABLE_WALLET
else if (params.size() == 2){
int nSporkID = sporkManager.GetSporkIDByName(params[0].get_str());
else if (request.params.size() == 2){
int nSporkID = sporkManager.GetSporkIDByName(request.params[0].get_str());
if(nSporkID == -1){
return "Invalid spork name";
}
@ -251,7 +251,7 @@ UniValue spork(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
// SPORK VALUE
int64_t nValue = params[1].get_int64();
int64_t nValue = request.params[1].get_int64();
//broadcast new spork
if(sporkManager.UpdateSpork(nSporkID, nValue, *g_connman)){
@ -276,9 +276,9 @@ UniValue spork(const UniValue& params, bool fHelp)
}
UniValue validateaddress(const UniValue& params, bool fHelp)
UniValue validateaddress(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"validateaddress \"dashaddress\"\n"
"\nReturn information about the given dash address.\n"
@ -309,7 +309,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp)
LOCK(cs_main);
#endif
CBitcoinAddress address(params[0].get_str());
CBitcoinAddress address(request.params[0].get_str());
bool isValid = address.IsValid();
UniValue ret(UniValue::VOBJ);
@ -407,9 +407,9 @@ CScript _createmultisig_redeemScript(const UniValue& params)
return result;
}
UniValue createmultisig(const UniValue& params, bool fHelp)
UniValue createmultisig(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 2 || params.size() > 2)
if (request.fHelp || request.params.size() < 2 || request.params.size() > 2)
{
string msg = "createmultisig nrequired [\"key\",...]\n"
"\nCreates a multi-signature address with n signature of m keys required.\n"
@ -439,7 +439,7 @@ UniValue createmultisig(const UniValue& params, bool fHelp)
}
// Construct using pay-to-script-hash:
CScript inner = _createmultisig_redeemScript(params);
CScript inner = _createmultisig_redeemScript(request.params);
CScriptID innerID(inner);
CBitcoinAddress address(innerID);
@ -450,9 +450,9 @@ UniValue createmultisig(const UniValue& params, bool fHelp)
return result;
}
UniValue verifymessage(const UniValue& params, bool fHelp)
UniValue verifymessage(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 3)
if (request.fHelp || request.params.size() != 3)
throw runtime_error(
"verifymessage \"dashaddress\" \"signature\" \"message\"\n"
"\nVerify a signed message\n"
@ -475,9 +475,9 @@ UniValue verifymessage(const UniValue& params, bool fHelp)
LOCK(cs_main);
string strAddress = params[0].get_str();
string strSign = params[1].get_str();
string strMessage = params[2].get_str();
string strAddress = request.params[0].get_str();
string strSign = request.params[1].get_str();
string strMessage = request.params[2].get_str();
CBitcoinAddress addr(strAddress);
if (!addr.IsValid())
@ -504,9 +504,9 @@ UniValue verifymessage(const UniValue& params, bool fHelp)
return (pubkey.GetID() == keyID);
}
UniValue signmessagewithprivkey(const UniValue& params, bool fHelp)
UniValue signmessagewithprivkey(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 2)
if (request.fHelp || request.params.size() != 2)
throw runtime_error(
"signmessagewithprivkey \"privkey\" \"message\"\n"
"\nSign a message with the private key of an address\n"
@ -524,8 +524,8 @@ UniValue signmessagewithprivkey(const UniValue& params, bool fHelp)
+ HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\"")
);
string strPrivkey = params[0].get_str();
string strMessage = params[1].get_str();
string strPrivkey = request.params[0].get_str();
string strMessage = request.params[1].get_str();
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strPrivkey);
@ -546,9 +546,9 @@ UniValue signmessagewithprivkey(const UniValue& params, bool fHelp)
return EncodeBase64(&vchSig[0], vchSig.size());
}
UniValue setmocktime(const UniValue& params, bool fHelp)
UniValue setmocktime(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"setmocktime timestamp\n"
"\nSet the local time to given timestamp (-regtest only)\n"
@ -567,8 +567,8 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
// ensure all callsites of GetTime() are accessing this safely.
LOCK(cs_main);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
SetMockTime(params[0].get_int64());
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VNUM));
SetMockTime(request.params[0].get_int64());
return NullUniValue;
}
@ -631,9 +631,9 @@ bool timestampSort(std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> a,
return a.second.time < b.second.time;
}
UniValue getaddressmempool(const UniValue& params, bool fHelp)
UniValue getaddressmempool(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"getaddressmempool\n"
"\nReturns all mempool deltas for an address (requires addressindex to be enabled).\n"
@ -664,7 +664,7 @@ UniValue getaddressmempool(const UniValue& params, bool fHelp)
std::vector<std::pair<uint160, int> > addresses;
if (!getAddressesFromParams(params, addresses)) {
if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
@ -702,9 +702,9 @@ UniValue getaddressmempool(const UniValue& params, bool fHelp)
return result;
}
UniValue getaddressutxos(const UniValue& params, bool fHelp)
UniValue getaddressutxos(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"getaddressutxos\n"
"\nReturns all unspent outputs for an address (requires addressindex to be enabled).\n"
@ -734,7 +734,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
std::vector<std::pair<uint160, int> > addresses;
if (!getAddressesFromParams(params, addresses)) {
if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
@ -769,9 +769,9 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
return result;
}
UniValue getaddressdeltas(const UniValue& params, bool fHelp)
UniValue getaddressdeltas(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1 || !params[0].isObject())
if (request.fHelp || request.params.size() != 1 || !request.params[0].isObject())
throw runtime_error(
"getaddressdeltas\n"
"\nReturns all changes for an address (requires addressindex to be enabled).\n"
@ -802,8 +802,8 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
);
UniValue startValue = find_value(params[0].get_obj(), "start");
UniValue endValue = find_value(params[0].get_obj(), "end");
UniValue startValue = find_value(request.params[0].get_obj(), "start");
UniValue endValue = find_value(request.params[0].get_obj(), "end");
int start = 0;
int end = 0;
@ -818,7 +818,7 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
std::vector<std::pair<uint160, int> > addresses;
if (!getAddressesFromParams(params, addresses)) {
if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
@ -857,9 +857,9 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
return result;
}
UniValue getaddressbalance(const UniValue& params, bool fHelp)
UniValue getaddressbalance(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"getaddressbalance\n"
"\nReturns the balance for an address(es) (requires addressindex to be enabled).\n"
@ -883,7 +883,7 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp)
std::vector<std::pair<uint160, int> > addresses;
if (!getAddressesFromParams(params, addresses)) {
if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
@ -913,9 +913,9 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp)
}
UniValue getaddresstxids(const UniValue& params, bool fHelp)
UniValue getaddresstxids(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"getaddresstxids\n"
"\nReturns the txids for an address(es) (requires addressindex to be enabled).\n"
@ -941,15 +941,15 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp)
std::vector<std::pair<uint160, int> > addresses;
if (!getAddressesFromParams(params, addresses)) {
if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
int start = 0;
int end = 0;
if (params[0].isObject()) {
UniValue startValue = find_value(params[0].get_obj(), "start");
UniValue endValue = find_value(params[0].get_obj(), "end");
if (request.params[0].isObject()) {
UniValue startValue = find_value(request.params[0].get_obj(), "start");
UniValue endValue = find_value(request.params[0].get_obj(), "end");
if (startValue.isNum() && endValue.isNum()) {
start = startValue.get_int();
end = endValue.get_int();
@ -996,10 +996,9 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp)
}
UniValue getspentinfo(const UniValue& params, bool fHelp)
UniValue getspentinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1 || !params[0].isObject())
if (request.fHelp || request.params.size() != 1 || !request.params[0].isObject())
throw runtime_error(
"getspentinfo\n"
"\nReturns the txid and index where an output is spent.\n"
@ -1019,8 +1018,8 @@ UniValue getspentinfo(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getspentinfo", "{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}")
);
UniValue txidValue = find_value(params[0].get_obj(), "txid");
UniValue indexValue = find_value(params[0].get_obj(), "index");
UniValue txidValue = find_value(request.params[0].get_obj(), "txid");
UniValue indexValue = find_value(request.params[0].get_obj(), "index");
if (!txidValue.isStr() || !indexValue.isNum()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid txid or index");

View File

@ -25,9 +25,9 @@
using namespace std;
UniValue getconnectioncount(const UniValue& params, bool fHelp)
UniValue getconnectioncount(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getconnectioncount\n"
"\nReturns the number of connections to other nodes.\n"
@ -44,9 +44,9 @@ UniValue getconnectioncount(const UniValue& params, bool fHelp)
return (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL);
}
UniValue ping(const UniValue& params, bool fHelp)
UniValue ping(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"ping\n"
"\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
@ -67,9 +67,9 @@ UniValue ping(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue getpeerinfo(const UniValue& params, bool fHelp)
UniValue getpeerinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getpeerinfo\n"
"\nReturns data about each connected network node as a json array of objects.\n"
@ -186,12 +186,12 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp)
return ret;
}
UniValue addnode(const UniValue& params, bool fHelp)
UniValue addnode(const JSONRPCRequest& request)
{
string strCommand;
if (params.size() == 2)
strCommand = params[1].get_str();
if (fHelp || params.size() != 2 ||
if (request.params.size() == 2)
strCommand = request.params[1].get_str();
if (request.fHelp || request.params.size() != 2 ||
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
throw runtime_error(
"addnode \"node\" \"add|remove|onetry\"\n"
@ -208,7 +208,7 @@ UniValue addnode(const UniValue& params, bool fHelp)
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
string strNode = params[0].get_str();
string strNode = request.params[0].get_str();
if (strCommand == "onetry")
{
@ -231,9 +231,9 @@ UniValue addnode(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue disconnectnode(const UniValue& params, bool fHelp)
UniValue disconnectnode(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"disconnectnode \"node\" \n"
"\nImmediately disconnects from the specified node.\n"
@ -247,16 +247,16 @@ UniValue disconnectnode(const UniValue& params, bool fHelp)
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
bool ret = g_connman->DisconnectNode(params[0].get_str());
bool ret = g_connman->DisconnectNode(request.params[0].get_str());
if (!ret)
throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes");
return NullUniValue;
}
UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
UniValue getaddednodeinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() > 1)
if (request.fHelp || request.params.size() > 1)
throw runtime_error(
"getaddednodeinfo ( \"node\" )\n"
"\nReturns information about the given added node, or all added nodes\n"
@ -288,10 +288,10 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo();
if (params.size() == 1) {
if (request.params.size() == 1) {
bool found = false;
for (const AddedNodeInfo& info : vInfo) {
if (info.strAddedNode == params[0].get_str()) {
if (info.strAddedNode == request.params[0].get_str()) {
vInfo.assign(1, info);
found = true;
break;
@ -322,9 +322,9 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
return ret;
}
UniValue getnettotals(const UniValue& params, bool fHelp)
UniValue getnettotals(const JSONRPCRequest& request)
{
if (fHelp || params.size() > 0)
if (request.fHelp || request.params.size() > 0)
throw runtime_error(
"getnettotals\n"
"\nReturns information about network traffic, including bytes in, bytes out,\n"
@ -388,9 +388,9 @@ static UniValue GetNetworksInfo()
return networks;
}
UniValue getnetworkinfo(const UniValue& params, bool fHelp)
UniValue getnetworkinfo(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getnetworkinfo\n"
"Returns an object containing various state info regarding P2P networking.\n"
@ -461,12 +461,12 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp)
return obj;
}
UniValue setban(const UniValue& params, bool fHelp)
UniValue setban(const JSONRPCRequest& request)
{
string strCommand;
if (params.size() >= 2)
strCommand = params[1].get_str();
if (fHelp || params.size() < 2 ||
if (request.params.size() >= 2)
strCommand = request.params[1].get_str();
if (request.fHelp || request.params.size() < 2 ||
(strCommand != "add" && strCommand != "remove"))
throw runtime_error(
"setban \"ip(/netmask)\" \"add|remove\" (bantime) (absolute)\n"
@ -488,16 +488,16 @@ UniValue setban(const UniValue& params, bool fHelp)
CNetAddr netAddr;
bool isSubnet = false;
if (params[0].get_str().find("/") != string::npos)
if (request.params[0].get_str().find("/") != string::npos)
isSubnet = true;
if (!isSubnet) {
CNetAddr resolved;
LookupHost(params[0].get_str().c_str(), resolved, false);
LookupHost(request.params[0].get_str().c_str(), resolved, false);
netAddr = resolved;
}
else
LookupSubNet(params[0].get_str().c_str(), subNet);
LookupSubNet(request.params[0].get_str().c_str(), subNet);
if (! (isSubnet ? subNet.IsValid() : netAddr.IsValid()) )
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Invalid IP/Subnet");
@ -508,11 +508,11 @@ UniValue setban(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
int64_t banTime = 0; //use standard bantime if not specified
if (params.size() >= 3 && !params[2].isNull())
banTime = params[2].get_int64();
if (request.params.size() >= 3 && !request.params[2].isNull())
banTime = request.params[2].get_int64();
bool absolute = false;
if (params.size() == 4 && params[3].isTrue())
if (request.params.size() == 4 && request.params[3].isTrue())
absolute = true;
isSubnet ? g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
@ -525,9 +525,9 @@ UniValue setban(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue listbanned(const UniValue& params, bool fHelp)
UniValue listbanned(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"listbanned\n"
"\nList all banned IPs/Subnets.\n"
@ -558,9 +558,9 @@ UniValue listbanned(const UniValue& params, bool fHelp)
return bannedAddresses;
}
UniValue clearbanned(const UniValue& params, bool fHelp)
UniValue clearbanned(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"clearbanned\n"
"\nClear all banned IPs.\n"
@ -576,9 +576,9 @@ UniValue clearbanned(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue setnetworkactive(const UniValue& params, bool fHelp)
UniValue setnetworkactive(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1) {
if (request.fHelp || request.params.size() != 1) {
throw runtime_error(
"setnetworkactive true|false\n"
"Disable/enable all p2p network activity."
@ -589,7 +589,7 @@ UniValue setnetworkactive(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
}
g_connman->SetNetworkActive(params[0].get_bool());
g_connman->SetNetworkActive(request.params[0].get_bool());
return g_connman->GetNetworkActive();
}

View File

@ -27,13 +27,13 @@ using namespace std;
* 1.2 spec: http://jsonrpc.org/historical/json-rpc-over-http.html
*/
string JSONRPCRequest(const string& strMethod, const UniValue& params, const UniValue& id)
UniValue JSONRPCRequestObj(const string& strMethod, const UniValue& params, const UniValue& id)
{
UniValue request(UniValue::VOBJ);
request.push_back(Pair("method", strMethod));
request.push_back(Pair("params", params));
request.push_back(Pair("id", id));
return request.write() + "\n";
return request;
}
UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id)

View File

@ -77,7 +77,7 @@ enum RPCErrorCode
RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked
};
std::string JSONRPCRequest(const std::string& strMethod, const UniValue& params, const UniValue& id);
UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id);
std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id);
UniValue JSONRPCError(int code, const std::string& message);

View File

@ -141,9 +141,9 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
}
}
UniValue getrawtransaction(const UniValue& params, bool fHelp)
UniValue getrawtransaction(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"getrawtransaction \"txid\" ( verbose )\n"
"\nNOTE: By default this function only works sometimes. This is when the tx is in the mempool\n"
@ -210,11 +210,11 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
LOCK(cs_main);
uint256 hash = ParseHashV(params[0], "parameter 1");
uint256 hash = ParseHashV(request.params[0], "parameter 1");
bool fVerbose = false;
if (params.size() > 1)
fVerbose = (params[1].get_int() != 0);
if (request.params.size() > 1)
fVerbose = (request.params[1].get_int() != 0);
CTransaction tx;
uint256 hashBlock;
@ -232,9 +232,9 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
return result;
}
UniValue gettxoutproof(const UniValue& params, bool fHelp)
UniValue gettxoutproof(const JSONRPCRequest& request)
{
if (fHelp || (params.size() != 1 && params.size() != 2))
if (request.fHelp || (request.params.size() != 1 && request.params.size() != 2))
throw runtime_error(
"gettxoutproof [\"txid\",...] ( blockhash )\n"
"\nReturns a hex-encoded proof that \"txid\" was included in a block.\n"
@ -261,7 +261,7 @@ UniValue gettxoutproof(const UniValue& params, bool fHelp)
set<uint256> setTxids;
uint256 oneTxid;
UniValue txids = params[0].get_array();
UniValue txids = request.params[0].get_array();
for (unsigned int idx = 0; idx < txids.size(); idx++) {
const UniValue& txid = txids[idx];
if (txid.get_str().length() != 64 || !IsHex(txid.get_str()))
@ -278,9 +278,9 @@ UniValue gettxoutproof(const UniValue& params, bool fHelp)
CBlockIndex* pblockindex = NULL;
uint256 hashBlock;
if (params.size() > 1)
if (request.params.size() > 1)
{
hashBlock = uint256S(params[1].get_str());
hashBlock = uint256S(request.params[1].get_str());
if (!mapBlockIndex.count(hashBlock))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
pblockindex = mapBlockIndex[hashBlock];
@ -319,9 +319,9 @@ UniValue gettxoutproof(const UniValue& params, bool fHelp)
return strHex;
}
UniValue verifytxoutproof(const UniValue& params, bool fHelp)
UniValue verifytxoutproof(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"verifytxoutproof \"proof\"\n"
"\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n"
@ -336,7 +336,7 @@ UniValue verifytxoutproof(const UniValue& params, bool fHelp)
+ HelpExampleRpc("gettxoutproof", "\"proof\"")
);
CDataStream ssMB(ParseHexV(params[0], "proof"), SER_NETWORK, PROTOCOL_VERSION);
CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK, PROTOCOL_VERSION);
CMerkleBlock merkleBlock;
ssMB >> merkleBlock;
@ -357,9 +357,9 @@ UniValue verifytxoutproof(const UniValue& params, bool fHelp)
return res;
}
UniValue createrawtransaction(const UniValue& params, bool fHelp)
UniValue createrawtransaction(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 2 || params.size() > 3)
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw runtime_error(
"createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime )\n"
"\nCreate a transaction spending the given inputs and creating new outputs.\n"
@ -395,17 +395,17 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"}\"")
);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM), true);
if (params[0].isNull() || params[1].isNull())
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM), true);
if (request.params[0].isNull() || request.params[1].isNull())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
UniValue inputs = params[0].get_array();
UniValue sendTo = params[1].get_obj();
UniValue inputs = request.params[0].get_array();
UniValue sendTo = request.params[1].get_obj();
CMutableTransaction rawTx;
if (params.size() > 2 && !params[2].isNull()) {
int64_t nLockTime = params[2].get_int64();
if (request.params.size() > 2 && !request.params[2].isNull()) {
int64_t nLockTime = request.params[2].get_int64();
if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
rawTx.nLockTime = nLockTime;
@ -470,9 +470,9 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
return EncodeHexTx(rawTx);
}
UniValue decoderawtransaction(const UniValue& params, bool fHelp)
UniValue decoderawtransaction(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"decoderawtransaction \"hexstring\"\n"
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"
@ -523,11 +523,11 @@ UniValue decoderawtransaction(const UniValue& params, bool fHelp)
);
LOCK(cs_main);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR));
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR));
CTransaction tx;
if (!DecodeHexTx(tx, params[0].get_str()))
if (!DecodeHexTx(tx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
UniValue result(UniValue::VOBJ);
@ -536,9 +536,9 @@ UniValue decoderawtransaction(const UniValue& params, bool fHelp)
return result;
}
UniValue decodescript(const UniValue& params, bool fHelp)
UniValue decodescript(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"decodescript \"hex\"\n"
"\nDecode a hex-encoded script.\n"
@ -561,12 +561,12 @@ UniValue decodescript(const UniValue& params, bool fHelp)
+ HelpExampleRpc("decodescript", "\"hexstring\"")
);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR));
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR));
UniValue r(UniValue::VOBJ);
CScript script;
if (params[0].get_str().size() > 0){
vector<unsigned char> scriptData(ParseHexV(params[0], "argument"));
if (request.params[0].get_str().size() > 0){
vector<unsigned char> scriptData(ParseHexV(request.params[0], "argument"));
script = CScript(scriptData.begin(), scriptData.end());
} else {
// Empty scripts are valid
@ -598,9 +598,9 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::
vErrorsRet.push_back(entry);
}
UniValue signrawtransaction(const UniValue& params, bool fHelp)
UniValue signrawtransaction(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 4)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
throw runtime_error(
"signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
"\nSign inputs for raw transaction (serialized, hex-encoded).\n"
@ -663,9 +663,9 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
#else
LOCK(cs_main);
#endif
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true);
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true);
vector<unsigned char> txData(ParseHexV(params[0], "argument 1"));
vector<unsigned char> txData(ParseHexV(request.params[0], "argument 1"));
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
vector<CMutableTransaction> txVariants;
while (!ssData.empty()) {
@ -704,9 +704,9 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
bool fGivenKeys = false;
CBasicKeyStore tempKeystore;
if (params.size() > 2 && !params[2].isNull()) {
if (request.params.size() > 2 && !request.params[2].isNull()) {
fGivenKeys = true;
UniValue keys = params[2].get_array();
UniValue keys = request.params[2].get_array();
for (unsigned int idx = 0; idx < keys.size(); idx++) {
UniValue k = keys[idx];
CBitcoinSecret vchSecret;
@ -725,8 +725,8 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
#endif
// Add previous txouts given in the RPC call:
if (params.size() > 1 && !params[1].isNull()) {
UniValue prevTxs = params[1].get_array();
if (request.params.size() > 1 && !request.params[1].isNull()) {
UniValue prevTxs = request.params[1].get_array();
for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
const UniValue& p = prevTxs[idx];
if (!p.isObject())
@ -793,7 +793,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
#endif
int nHashType = SIGHASH_ALL;
if (params.size() > 3 && !params[3].isNull()) {
if (request.params.size() > 3 && !request.params[3].isNull()) {
static map<string, int> mapSigHashValues =
boost::assign::map_list_of
(string("ALL"), int(SIGHASH_ALL))
@ -803,7 +803,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
(string("SINGLE"), int(SIGHASH_SINGLE))
(string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY))
;
string strHashType = params[3].get_str();
string strHashType = request.params[3].get_str();
if (mapSigHashValues.count(strHashType))
nHashType = mapSigHashValues[strHashType];
else
@ -854,9 +854,9 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
return result;
}
UniValue sendrawtransaction(const UniValue& params, bool fHelp)
UniValue sendrawtransaction(const JSONRPCRequest& request)
{
if (fHelp || params.size() < 1 || params.size() > 3)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw runtime_error(
"sendrawtransaction \"hexstring\" ( allowhighfees instantsend )\n"
"\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
@ -879,22 +879,22 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
);
LOCK(cs_main);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL)(UniValue::VBOOL));
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL)(UniValue::VBOOL));
// parse hex string from parameter
CTransaction tx;
if (!DecodeHexTx(tx, params[0].get_str()))
if (!DecodeHexTx(tx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
uint256 hashTx = tx.GetHash();
bool fLimitFree = false;
CAmount nMaxRawTxFee = maxTxFee;
if (params.size() > 1 && params[1].get_bool())
if (request.params.size() > 1 && request.params[1].get_bool())
nMaxRawTxFee = 0;
bool fInstantSend = false;
if (params.size() > 2)
fInstantSend = params[2].get_bool();
if (request.params.size() > 2)
fInstantSend = request.params[2].get_bool();
CCoinsViewCache &view = *pcoinsTip;
bool fHaveChain = false;

View File

@ -196,10 +196,11 @@ std::string CRPCTable::help(const std::string& strCommand) const
continue;
try
{
UniValue params;
JSONRPCRequest jreq;
jreq.fHelp = true;
rpcfn_type pfn = pcmd->actor;
if (setDone.insert(pfn).second)
(*pfn)(params, true);
(*pfn)(jreq);
}
catch (const std::exception& e)
{
@ -229,9 +230,9 @@ std::string CRPCTable::help(const std::string& strCommand) const
return strRet;
}
UniValue help(const UniValue& params, bool fHelp)
UniValue help(const JSONRPCRequest& jsonRequest)
{
if (fHelp || params.size() > 1)
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
throw runtime_error(
"help ( \"command\" )\n"
"\nList all commands, or get help for a specified command.\n"
@ -242,17 +243,17 @@ UniValue help(const UniValue& params, bool fHelp)
);
string strCommand;
if (params.size() > 0)
strCommand = params[0].get_str();
if (jsonRequest.params.size() > 0)
strCommand = jsonRequest.params[0].get_str();
return tableRPC.help(strCommand);
}
UniValue stop(const UniValue& params, bool fHelp)
UniValue stop(const JSONRPCRequest& jsonRequest)
{
// Accept the deprecated and ignored 'detach' boolean argument
if (fHelp || params.size() > 1)
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
throw runtime_error(
"stop\n"
"\nStop Dash Core server.");
@ -355,7 +356,7 @@ bool RPCIsInWarmup(std::string *outStatus)
return fRPCInWarmup;
}
void JSONRequest::parse(const UniValue& valRequest)
void JSONRPCRequest::parse(const UniValue& valRequest)
{
// Parse request
if (!valRequest.isObject())
@ -389,11 +390,11 @@ static UniValue JSONRPCExecOne(const UniValue& req)
{
UniValue rpc_result(UniValue::VOBJ);
JSONRequest jreq;
JSONRPCRequest jreq;
try {
jreq.parse(req);
UniValue result = tableRPC.execute(jreq.strMethod, jreq.params);
UniValue result = tableRPC.execute(jreq);
rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
}
catch (const UniValue& objError)
@ -418,7 +419,7 @@ std::string JSONRPCExecBatch(const UniValue& vReq)
return ret.write() + "\n";
}
UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params) const
UniValue CRPCTable::execute(const JSONRPCRequest &request) const
{
// Return immediately if in warmup
{
@ -428,7 +429,7 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params
}
// Find method
const CRPCCommand *pcmd = tableRPC[strMethod];
const CRPCCommand *pcmd = tableRPC[request.strMethod];
if (!pcmd)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
@ -437,7 +438,7 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params
try
{
// Execute
return pcmd->actor(params, false);
return pcmd->actor(request);
}
catch (const std::exception& e)
{

View File

@ -41,14 +41,17 @@ struct UniValueType {
UniValue::VType type;
};
class JSONRequest
class JSONRPCRequest
{
public:
UniValue id;
std::string strMethod;
UniValue params;
bool fHelp;
std::string URI;
std::string authUser;
JSONRequest() { id = NullUniValue; }
JSONRPCRequest() { id = NullUniValue; params = NullUniValue; fHelp = false; }
void parse(const UniValue& valRequest);
};
@ -122,7 +125,7 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface);
*/
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
typedef UniValue(*rpcfn_type)(const UniValue& params, bool fHelp);
typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest);
class CRPCCommand
{
@ -147,12 +150,11 @@ public:
/**
* Execute a method.
* @param method Method to execute
* @param params UniValue Array of arguments (JSON objects)
* @param request The JSONRPCRequest to execute
* @returns Result of the call.
* @throws an exception (UniValue) when an error happens.
*/
UniValue execute(const std::string &method, const UniValue &params) const;
UniValue execute(const JSONRPCRequest &request) const;
/**
* Returns a list of registered commands

View File

@ -24,11 +24,14 @@ UniValue CallRPC(string args)
boost::split(vArgs, args, boost::is_any_of(" \t"));
string strMethod = vArgs[0];
vArgs.erase(vArgs.begin());
UniValue params = RPCConvertValues(strMethod, vArgs);
JSONRPCRequest request;
request.strMethod = strMethod;
request.params = RPCConvertValues(strMethod, vArgs);
request.fHelp = false;
BOOST_CHECK(tableRPC[strMethod]);
rpcfn_type method = tableRPC[strMethod]->actor;
try {
UniValue result = (*method)(params, false);
UniValue result = (*method)(request);
return result;
}
catch (const UniValue& objError) {

View File

@ -75,12 +75,12 @@ std::string DecodeDumpString(const std::string &str) {
return ret.str();
}
UniValue importprivkey(const UniValue& params, bool fHelp)
UniValue importprivkey(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 3)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw runtime_error(
"importprivkey \"dashprivkey\" ( \"label\" rescan )\n"
"\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
@ -105,15 +105,15 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
string strSecret = params[0].get_str();
string strSecret = request.params[0].get_str();
string strLabel = "";
if (params.size() > 1)
strLabel = params[1].get_str();
if (request.params.size() > 1)
strLabel = request.params[1].get_str();
// Whether to perform rescan after import
bool fRescan = true;
if (params.size() > 2)
fRescan = params[2].get_bool();
if (request.params.size() > 2)
fRescan = request.params[2].get_bool();
if (fRescan && fPruneMode)
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan is disabled in pruned mode");
@ -185,12 +185,12 @@ void ImportAddress(const CBitcoinAddress& address, const string& strLabel)
pwalletMain->SetAddressBook(address.Get(), strLabel, "receive");
}
UniValue importaddress(const UniValue& params, bool fHelp)
UniValue importaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 4)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
throw runtime_error(
"importaddress \"address\" ( \"label\" rescan p2sh )\n"
"\nAdds a script (in hex) or address that can be watched as if it were in your wallet but cannot be used to spend.\n"
@ -214,31 +214,31 @@ UniValue importaddress(const UniValue& params, bool fHelp)
string strLabel = "";
if (params.size() > 1)
strLabel = params[1].get_str();
if (request.params.size() > 1)
strLabel = request.params[1].get_str();
// Whether to perform rescan after import
bool fRescan = true;
if (params.size() > 2)
fRescan = params[2].get_bool();
if (request.params.size() > 2)
fRescan = request.params[2].get_bool();
if (fRescan && fPruneMode)
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan is disabled in pruned mode");
// Whether to import a p2sh version, too
bool fP2SH = false;
if (params.size() > 3)
fP2SH = params[3].get_bool();
if (request.params.size() > 3)
fP2SH = request.params[3].get_bool();
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(params[0].get_str());
CBitcoinAddress address(request.params[0].get_str());
if (address.IsValid()) {
if (fP2SH)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Cannot use the p2sh flag with an address - use a script instead");
ImportAddress(address, strLabel);
} else if (IsHex(params[0].get_str())) {
std::vector<unsigned char> data(ParseHex(params[0].get_str()));
} else if (IsHex(request.params[0].get_str())) {
std::vector<unsigned char> data(ParseHex(request.params[0].get_str()));
ImportScript(CScript(data.begin(), data.end()), strLabel, fP2SH);
} else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address or script");
@ -253,12 +253,12 @@ UniValue importaddress(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue importprunedfunds(const UniValue& params, bool fHelp)
UniValue importprunedfunds(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() != 2)
if (request.fHelp || request.params.size() != 2)
throw runtime_error(
"importprunedfunds\n"
"\nImports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n"
@ -268,12 +268,12 @@ UniValue importprunedfunds(const UniValue& params, bool fHelp)
);
CTransaction tx;
if (!DecodeHexTx(tx, params[0].get_str()))
if (!DecodeHexTx(tx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
uint256 hashTx = tx.GetHash();
CWalletTx wtx(pwalletMain,tx);
CDataStream ssMB(ParseHexV(params[1], "proof"), SER_NETWORK, PROTOCOL_VERSION);
CDataStream ssMB(ParseHexV(request.params[1], "proof"), SER_NETWORK, PROTOCOL_VERSION);
CMerkleBlock merkleBlock;
ssMB >> merkleBlock;
@ -312,12 +312,12 @@ UniValue importprunedfunds(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No addresses in wallet correspond to included transaction");
}
UniValue removeprunedfunds(const UniValue& params, bool fHelp)
UniValue removeprunedfunds(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"removeprunedfunds \"txid\"\n"
"\nDeletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will effect wallet balances.\n"
@ -332,7 +332,7 @@ UniValue removeprunedfunds(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet);
uint256 hash;
hash.SetHex(params[0].get_str());
hash.SetHex(request.params[0].get_str());
vector<uint256> vHash;
vHash.push_back(hash);
vector<uint256> vHashOut;
@ -348,12 +348,12 @@ UniValue removeprunedfunds(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue importpubkey(const UniValue& params, bool fHelp)
UniValue importpubkey(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 4)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
throw runtime_error(
"importpubkey \"pubkey\" ( \"label\" rescan )\n"
"\nAdds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend.\n"
@ -373,20 +373,20 @@ UniValue importpubkey(const UniValue& params, bool fHelp)
string strLabel = "";
if (params.size() > 1)
strLabel = params[1].get_str();
if (request.params.size() > 1)
strLabel = request.params[1].get_str();
// Whether to perform rescan after import
bool fRescan = true;
if (params.size() > 2)
fRescan = params[2].get_bool();
if (request.params.size() > 2)
fRescan = request.params[2].get_bool();
if (fRescan && fPruneMode)
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan is disabled in pruned mode");
if (!IsHex(params[0].get_str()))
if (!IsHex(request.params[0].get_str()))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey must be a hex string");
std::vector<unsigned char> data(ParseHex(params[0].get_str()));
std::vector<unsigned char> data(ParseHex(request.params[0].get_str()));
CPubKey pubKey(data.begin(), data.end());
if (!pubKey.IsFullyValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key");
@ -406,12 +406,12 @@ UniValue importpubkey(const UniValue& params, bool fHelp)
}
UniValue importwallet(const UniValue& params, bool fHelp)
UniValue importwallet(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"importwallet \"filename\"\n"
"\nImports keys from a wallet dump file (see dumpwallet).\n"
@ -434,7 +434,7 @@ UniValue importwallet(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
ifstream file;
file.open(params[0].get_str().c_str(), std::ios::in | std::ios::ate);
file.open(request.params[0].get_str().c_str(), std::ios::in | std::ios::ate);
if (!file.is_open())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
@ -513,12 +513,12 @@ UniValue importwallet(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue importelectrumwallet(const UniValue& params, bool fHelp)
UniValue importelectrumwallet(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"importelectrumwallet \"filename\" index\n"
"\nImports keys from an Electrum wallet export file (.csv or .json)\n"
@ -542,7 +542,7 @@ UniValue importelectrumwallet(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
ifstream file;
std::string strFileName = params[0].get_str();
std::string strFileName = request.params[0].get_str();
size_t nDotPos = strFileName.find_last_of(".");
if(nDotPos == string::npos)
throw JSONRPCError(RPC_INVALID_PARAMETER, "File has no extension, should be .json or .csv");
@ -628,8 +628,8 @@ UniValue importelectrumwallet(const UniValue& params, bool fHelp)
// Whether to perform rescan after import
int nStartHeight = 0;
if (params.size() > 1)
nStartHeight = params[1].get_int();
if (request.params.size() > 1)
nStartHeight = request.params[1].get_int();
if (chainActive.Height() < nStartHeight)
nStartHeight = chainActive.Height();
@ -647,12 +647,12 @@ UniValue importelectrumwallet(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue dumpprivkey(const UniValue& params, bool fHelp)
UniValue dumpprivkey(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"dumpprivkey \"dashaddress\"\n"
"\nReveals the private key corresponding to 'dashaddress'.\n"
@ -671,7 +671,7 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
string strAddress = params[0].get_str();
string strAddress = request.params[0].get_str();
CBitcoinAddress address;
if (!address.SetString(strAddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
@ -684,12 +684,12 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp)
return CBitcoinSecret(vchSecret).ToString();
}
UniValue dumphdinfo(const UniValue& params, bool fHelp)
UniValue dumphdinfo(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"dumphdinfo\n"
"Returns an object containing sensitive private info about this HD wallet.\n"
@ -730,12 +730,12 @@ UniValue dumphdinfo(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue dumpwallet(const UniValue& params, bool fHelp)
UniValue dumpwallet(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(fHelp))
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
if (request.fHelp || request.params.size() != 1)
throw runtime_error(
"dumpwallet \"filename\"\n"
"\nDumps all wallet keys in a human-readable format.\n"
@ -751,7 +751,7 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
ofstream file;
file.open(params[0].get_str().c_str());
file.open(request.params[0].get_str().c_str());
if (!file.is_open())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");

File diff suppressed because it is too large Load Diff