Skip to content

Commit 1270b71

Browse files
salisbury-espinosacodablock
authored andcommitted
Use a verbosity instead of two verbose parameters (#2506)
1 parent 22dcec7 commit 1270b71

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

src/rpc/blockchain.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -830,13 +830,16 @@ UniValue getblock(const JSONRPCRequest& request)
830830
{
831831
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
832832
throw std::runtime_error(
833-
"getblock \"blockhash\" ( verbose )\n"
834-
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
835-
"If verbose is true, returns an Object with information about block <hash>.\n"
833+
"getblock \"blockhash\" ( verbosity ) \n"
834+
"\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
835+
"If verbosity is 1, returns an Object with information about block <hash>.\n"
836+
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n"
836837
"\nArguments:\n"
837838
"1. \"blockhash\" (string, required) The block hash\n"
838-
"2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
839-
"\nResult (for verbose = true):\n"
839+
"2. verbosity (numeric, optional, default=1) 0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data\n"
840+
"\nResult (for verbosity = 0):\n"
841+
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
842+
"\nResult (for verbose = 1):\n"
840843
"{\n"
841844
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
842845
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
@@ -858,8 +861,14 @@ UniValue getblock(const JSONRPCRequest& request)
858861
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
859862
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
860863
"}\n"
861-
"\nResult (for verbose=false):\n"
862-
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
864+
"\nResult (for verbosity = 2):\n"
865+
"{\n"
866+
" ..., Same output as verbosity = 1.\n"
867+
" \"tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result.\n"
868+
" ,...\n"
869+
" ],\n"
870+
" ,... Same output as verbosity = 1.\n"
871+
"}\n"
863872
"\nExamples:\n"
864873
+ HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")
865874
+ HelpExampleRpc("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")
@@ -870,9 +879,13 @@ UniValue getblock(const JSONRPCRequest& request)
870879
std::string strHash = request.params[0].get_str();
871880
uint256 hash(uint256S(strHash));
872881

873-
bool fVerbose = true;
874-
if (request.params.size() > 1)
875-
fVerbose = request.params[1].get_bool();
882+
int verbosity = 1;
883+
if (request.params.size() > 1) {
884+
if(request.params[1].isNum())
885+
verbosity = request.params[1].get_int();
886+
else
887+
verbosity = request.params[1].get_bool() ? 1 : 0;
888+
}
876889

877890
if (mapBlockIndex.count(hash) == 0)
878891
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
@@ -886,15 +899,15 @@ UniValue getblock(const JSONRPCRequest& request)
886899
if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
887900
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
888901

889-
if (!fVerbose)
902+
if (verbosity <= 0)
890903
{
891904
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
892905
ssBlock << block;
893906
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
894907
return strHex;
895908
}
896909

897-
return blockToJSON(block, pblockindex);
910+
return blockToJSON(block, pblockindex, verbosity >= 2);
898911
}
899912

900913
struct CCoinsStats
@@ -1613,7 +1626,7 @@ static const CRPCCommand commands[] =
16131626
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} },
16141627
{ "blockchain", "getbestblockhash", &getbestblockhash, true, {} },
16151628
{ "blockchain", "getblockcount", &getblockcount, true, {} },
1616-
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbose"} },
1629+
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbosity|verbose"} },
16171630
{ "blockchain", "getblockhashes", &getblockhashes, true, {"high","low"} },
16181631
{ "blockchain", "getblockhash", &getblockhash, true, {"height"} },
16191632
{ "blockchain", "getblockheader", &getblockheader, true, {"blockhash","verbose"} },

src/rpc/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
9797
{ "listunspent", 1, "maxconf" },
9898
{ "listunspent", 2, "addresses" },
9999
{ "listunspent", 3, "include_unsafe" },
100-
{ "getblock", 1, "verbose" },
100+
{ "getblock", 1, "verbosity" },
101101
{ "getblockheader", 1, "verbose" },
102102
{ "getblockheaders", 1, "count" },
103103
{ "getblockheaders", 2, "verbose" },

src/rpc/server.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <boost/signals2/signal.hpp>
2424
#include <boost/thread.hpp>
2525
#include <boost/algorithm/string/case_conv.hpp> // for to_upper()
26+
#include <boost/algorithm/string/classification.hpp>
27+
#include <boost/algorithm/string/split.hpp>
2628

2729
#include <algorithm>
2830
#include <memory> // for unique_ptr
@@ -495,8 +497,16 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
495497
}
496498
// Process expected parameters.
497499
int hole = 0;
498-
for (const std::string &argName: argNames) {
499-
auto fr = argsIn.find(argName);
500+
for (const std::string &argNamePattern: argNames) {
501+
std::vector<std::string> vargNames;
502+
boost::algorithm::split(vargNames, argNamePattern, boost::algorithm::is_any_of("|"));
503+
auto fr = argsIn.end();
504+
for (const std::string & argName : vargNames) {
505+
fr = argsIn.find(argName);
506+
if (fr != argsIn.end()) {
507+
break;
508+
}
509+
}
500510
if (fr != argsIn.end()) {
501511
for (int i = 0; i < hole; ++i) {
502512
// Fill hole between specified parameters with JSON nulls,

0 commit comments

Comments
 (0)