Browse Source

[RPC] Give RPC commands more information about the RPC request

pull/1/head
Jonas Schnelli 6 years ago
parent
commit
69d1c25768
No known key found for this signature in database
GPG Key ID: 29D4BCB6416F53EC
  1. 7
      src/httprpc.cpp
  2. 5
      src/qt/rpcconsole.cpp
  3. 6
      src/rest.cpp
  4. 158
      src/rpc/blockchain.cpp
  5. 90
      src/rpc/mining.cpp
  6. 42
      src/rpc/misc.cpp
  7. 72
      src/rpc/net.cpp
  8. 90
      src/rpc/rawtransaction.cpp
  9. 29
      src/rpc/server.cpp
  10. 13
      src/rpc/server.h
  11. 7
      src/test/rpc_tests.cpp
  12. 100
      src/wallet/rpcdump.cpp
  13. 486
      src/wallet/rpcwallet.cpp

7
src/httprpc.cpp

@ -172,19 +172,22 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &) @@ -172,19 +172,22 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
return false;
}
JSONRequest jreq;
JSONRPCRequest 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);

5
src/qt/rpcconsole.cpp

@ -246,7 +246,10 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string @@ -246,7 +246,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();

6
src/rest.cpp

@ -274,7 +274,7 @@ static bool rest_block_notxdetails(HTTPRequest* req, const std::string& strURIPa @@ -274,7 +274,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)
{
@ -285,8 +285,8 @@ static bool rest_chaininfo(HTTPRequest* req, const std::string& strURIPart) @@ -285,8 +285,8 @@ 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;
UniValue chainInfoObject = getblockchaininfo(jsonRequest);
string strJSON = chainInfoObject.write() + "\n";
req->WriteHeader("Content-Type", "application/json");
req->WriteReply(HTTP_OK, strJSON);

158
src/rpc/blockchain.cpp

@ -146,9 +146,9 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -603,9 +603,9 @@ UniValue getmempoolentry(const UniValue& params, bool fHelp)
return info;
}
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"
@ -620,7 +620,7 @@ UniValue getblockhash(const UniValue& params, bool fHelp) @@ -620,7 +620,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");
@ -628,9 +628,9 @@ UniValue getblockhash(const UniValue& params, bool fHelp) @@ -628,9 +628,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"
@ -664,12 +664,12 @@ UniValue getblockheader(const UniValue& params, bool fHelp) @@ -664,12 +664,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");
@ -687,9 +687,9 @@ UniValue getblockheader(const UniValue& params, bool fHelp) @@ -687,9 +687,9 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
return blockheaderToJSON(pblockindex);
}
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"
@ -730,12 +730,12 @@ UniValue getblock(const UniValue& params, bool fHelp) @@ -730,12 +730,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");
@ -814,9 +814,9 @@ static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats) @@ -814,9 +814,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"
@ -854,9 +854,9 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) @@ -854,9 +854,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"
@ -896,12 +896,12 @@ UniValue gettxout(const UniValue& params, bool fHelp) @@ -896,12 +896,12 @@ 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();
bool fMempool = true;
if (params.size() > 2)
fMempool = params[2].get_bool();
if (request.params.size() > 2)
fMempool = request.params[2].get_bool();
CCoins coins;
if (fMempool) {
@ -934,11 +934,11 @@ UniValue gettxout(const UniValue& params, bool fHelp) @@ -934,11 +934,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"
@ -954,10 +954,10 @@ UniValue verifychain(const UniValue& params, bool fHelp) @@ -954,10 +954,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);
}
@ -1021,9 +1021,9 @@ void BIP9SoftForkDescPushBack(UniValue& bip9_softforks, const std::string &name, @@ -1021,9 +1021,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"
@ -1113,9 +1113,9 @@ struct CompareBlocksByHeight @@ -1113,9 +1113,9 @@ struct CompareBlocksByHeight
}
};
UniValue getchaintips(const UniValue& params, bool fHelp)
UniValue getchaintips(const JSONRPCRequest& request)
{
if (fHelp || params.size() != 0)
if (request.fHelp || request.params.size() != 0)
throw runtime_error(
"getchaintips\n"
"Return information about all known tips in the block tree,"
@ -1229,9 +1229,9 @@ UniValue mempoolInfoToJSON() @@ -1229,9 +1229,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"
@ -1251,9 +1251,9 @@ UniValue getmempoolinfo(const UniValue& params, bool fHelp) @@ -1251,9 +1251,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"
@ -1267,7 +1267,7 @@ UniValue preciousblock(const UniValue& params, bool fHelp) @@ -1267,7 +1267,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;
@ -1289,9 +1289,9 @@ UniValue preciousblock(const UniValue& params, bool fHelp) @@ -1289,9 +1289,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"
@ -1303,7 +1303,7 @@ UniValue invalidateblock(const UniValue& params, bool fHelp) @@ -1303,7 +1303,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;
@ -1327,9 +1327,9 @@ UniValue invalidateblock(const UniValue& params, bool fHelp) @@ -1327,9 +1327,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"
@ -1342,7 +1342,7 @@ UniValue reconsiderblock(const UniValue& params, bool fHelp) @@ -1342,7 +1342,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));
{

90
src/rpc/mining.cpp

@ -74,9 +74,9 @@ UniValue GetNetworkHashPS(int lookup, int height) { @@ -74,9 +74,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"
@ -93,7 +93,7 @@ UniValue getnetworkhashps(const UniValue& params, bool fHelp) @@ -93,7 +93,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)
@ -146,9 +146,9 @@ UniValue generateBlocks(boost::shared_ptr<CReserveScript> coinbaseScript, int nG @@ -146,9 +146,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"
@ -162,10 +162,10 @@ UniValue generate(const UniValue& params, bool fHelp) @@ -162,10 +162,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;
@ -182,9 +182,9 @@ UniValue generate(const UniValue& params, bool fHelp) @@ -182,9 +182,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"
@ -199,13 +199,13 @@ UniValue generatetoaddress(const UniValue& params, bool fHelp) @@ -199,13 +199,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");
@ -215,9 +215,9 @@ UniValue generatetoaddress(const UniValue& params, bool fHelp) @@ -215,9 +215,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."
@ -248,7 +248,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp) @@ -248,7 +248,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;
@ -256,9 +256,9 @@ UniValue getmininginfo(const UniValue& params, bool fHelp) @@ -256,9 +256,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"
@ -279,10 +279,10 @@ UniValue prioritisetransaction(const UniValue& params, bool fHelp) @@ -279,10 +279,10 @@ UniValue prioritisetransaction(const UniValue& params, bool fHelp)
LOCK(cs_main);
uint256 hash = ParseHashStr(params[0].get_str(), "txid");
CAmount nAmount = params[2].get_int64();
uint256 hash = ParseHashStr(request.params[0].get_str(), "txid");
CAmount nAmount = request.params[2].get_int64();
mempool.PrioritiseTransaction(hash, params[0].get_str(), params[1].get_real(), nAmount);
mempool.PrioritiseTransaction(hash, request.params[0].get_str(), request.params[1].get_real(), nAmount);
return true;
}
@ -315,9 +315,9 @@ std::string gbt_vb_name(const Consensus::DeploymentPos pos) { @@ -315,9 +315,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"
@ -400,9 +400,9 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) @@ -400,9 +400,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();
@ -705,9 +705,9 @@ protected: @@ -705,9 +705,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"
@ -727,7 +727,7 @@ UniValue submitblock(const UniValue& params, bool fHelp) @@ -727,7 +727,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();
@ -774,9 +774,9 @@ UniValue submitblock(const UniValue& params, bool fHelp) @@ -774,9 +774,9 @@ UniValue submitblock(const UniValue& params, bool fHelp)
return BIP22ValidationResult(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"
@ -792,9 +792,9 @@ UniValue estimatefee(const UniValue& params, bool fHelp) @@ -792,9 +792,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;
@ -805,9 +805,9 @@ UniValue estimatefee(const UniValue& params, bool fHelp) @@ -805,9 +805,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"
@ -823,18 +823,18 @@ UniValue estimatepriority(const UniValue& params, bool fHelp) @@ -823,18 +823,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"
@ -856,9 +856,9 @@ UniValue estimatesmartfee(const UniValue& params, bool fHelp) @@ -856,9 +856,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;
@ -868,9 +868,9 @@ UniValue estimatesmartfee(const UniValue& params, bool fHelp) @@ -868,9 +868,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"
@ -892,9 +892,9 @@ UniValue estimatesmartpriority(const UniValue& params, bool fHelp) @@ -892,9 +892,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;

42
src/rpc/misc.cpp

@ -39,9 +39,9 @@ using namespace std; @@ -39,9 +39,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"
@ -148,9 +148,9 @@ public: @@ -148,9 +148,9 @@ public:
};
#endif
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 \"bitcoinaddress\"\n"
"\nReturn information about the given bitcoin address.\n"
@ -181,7 +181,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp) @@ -181,7 +181,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);
@ -278,9 +278,9 @@ CScript _createmultisig_redeemScript(const UniValue& params) @@ -278,9 +278,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"
@ -310,7 +310,7 @@ UniValue createmultisig(const UniValue& params, bool fHelp) @@ -310,7 +310,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);
@ -321,9 +321,9 @@ UniValue createmultisig(const UniValue& params, bool fHelp) @@ -321,9 +321,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 \"bitcoinaddress\" \"signature\" \"message\"\n"
"\nVerify a signed message\n"
@ -346,9 +346,9 @@ UniValue verifymessage(const UniValue& params, bool fHelp) @@ -346,9 +346,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())
@ -375,9 +375,9 @@ UniValue verifymessage(const UniValue& params, bool fHelp) @@ -375,9 +375,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"
@ -395,8 +395,8 @@ UniValue signmessagewithprivkey(const UniValue& params, bool fHelp) @@ -395,8 +395,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);
@ -417,9 +417,9 @@ UniValue signmessagewithprivkey(const UniValue& params, bool fHelp) @@ -417,9 +417,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"
@ -437,8 +437,8 @@ UniValue setmocktime(const UniValue& params, bool fHelp) @@ -437,8 +437,8 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
// in a long time.
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());
uint64_t t = GetTime();
if(g_connman) {

72
src/rpc/net.cpp

@ -23,9 +23,9 @@ @@ -23,9 +23,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"
@ -42,9 +42,9 @@ UniValue getconnectioncount(const UniValue& params, bool fHelp) @@ -42,9 +42,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"
@ -65,9 +65,9 @@ UniValue ping(const UniValue& params, bool fHelp) @@ -65,9 +65,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"
@ -184,12 +184,12 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp) @@ -184,12 +184,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"
@ -206,7 +206,7 @@ UniValue addnode(const UniValue& params, bool fHelp) @@ -206,7 +206,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")
{
@ -229,9 +229,9 @@ UniValue addnode(const UniValue& params, bool fHelp) @@ -229,9 +229,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"
@ -245,16 +245,16 @@ UniValue disconnectnode(const UniValue& params, bool fHelp) @@ -245,16 +245,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"
@ -286,10 +286,10 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp) @@ -286,10 +286,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;
@ -320,9 +320,9 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp) @@ -320,9 +320,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"
@ -386,9 +386,9 @@ static UniValue GetNetworksInfo() @@ -386,9 +386,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"
@ -456,12 +456,12 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp) @@ -456,12 +456,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"
@ -483,16 +483,16 @@ UniValue setban(const UniValue& params, bool fHelp) @@ -483,16 +483,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");
@ -503,11 +503,11 @@ UniValue setban(const UniValue& params, bool fHelp) @@ -503,11 +503,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);
@ -520,9 +520,9 @@ UniValue setban(const UniValue& params, bool fHelp) @@ -520,9 +520,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"
@ -553,9 +553,9 @@ UniValue listbanned(const UniValue& params, bool fHelp) @@ -553,9 +553,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"

90
src/rpc/rawtransaction.cpp

@ -126,9 +126,9 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) @@ -126,9 +126,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"
@ -198,11 +198,11 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp) @@ -198,11 +198,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;
@ -220,9 +220,9 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp) @@ -220,9 +220,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"
@ -244,7 +244,7 @@ UniValue gettxoutproof(const UniValue& params, bool fHelp) @@ -244,7 +244,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()))
@ -261,9 +261,9 @@ UniValue gettxoutproof(const UniValue& params, bool fHelp) @@ -261,9 +261,9 @@ UniValue gettxoutproof(const UniValue& params, bool fHelp)
CBlockIndex* pbl