Skip to content

Commit e3c9f2d

Browse files
committed
Use a verbosity instead of two verbose parameters
Verbose is changed to an int. This can have values from 0-2 for each level of verbosity. Verbosity level 2 has transaction details displayed in the results.
1 parent c99ab3c commit e3c9f2d

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/rpc/blockchain.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,16 @@ UniValue getblock(const JSONRPCRequest& request)
686686
{
687687
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
688688
throw std::runtime_error(
689-
"getblock \"blockhash\" ( verbose )\n"
690-
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
691-
"If verbose is true, returns an Object with information about block <hash>.\n"
689+
"getblock \"blockhash\" ( verbosity ) \n"
690+
"\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
691+
"If verbosity is 1, returns an Object with information about block <hash>.\n"
692+
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n"
692693
"\nArguments:\n"
693694
"1. \"blockhash\" (string, required) The block hash\n"
694-
"2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
695-
"\nResult (for verbose = true):\n"
695+
"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"
696+
"\nResult (for verbosity = 0):\n"
697+
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
698+
"\nResult (for verbosity = 1):\n"
696699
"{\n"
697700
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
698701
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
@@ -716,8 +719,14 @@ UniValue getblock(const JSONRPCRequest& request)
716719
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
717720
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
718721
"}\n"
719-
"\nResult (for verbose=false):\n"
720-
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
722+
"\nResult (for verbosity = 2):\n"
723+
"{\n"
724+
" ..., Same output as verbosity = 1.\n"
725+
" \"tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result.\n"
726+
" ,...\n"
727+
" ],\n"
728+
" ,... Same output as verbosity = 1.\n"
729+
"}\n"
721730
"\nExamples:\n"
722731
+ HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
723732
+ HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
@@ -728,9 +737,13 @@ UniValue getblock(const JSONRPCRequest& request)
728737
std::string strHash = request.params[0].get_str();
729738
uint256 hash(uint256S(strHash));
730739

731-
bool fVerbose = true;
732-
if (request.params.size() > 1)
733-
fVerbose = request.params[1].get_bool();
740+
int verbosity = 1;
741+
if (request.params.size() > 1) {
742+
if(request.params[1].isNum())
743+
verbosity = request.params[1].get_int();
744+
else
745+
verbosity = request.params[1].get_bool() ? 1 : 0;
746+
}
734747

735748
if (mapBlockIndex.count(hash) == 0)
736749
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
@@ -749,15 +762,15 @@ UniValue getblock(const JSONRPCRequest& request)
749762
// block).
750763
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
751764

752-
if (!fVerbose)
765+
if (verbosity <= 0)
753766
{
754767
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
755768
ssBlock << block;
756769
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
757770
return strHex;
758771
}
759772

760-
return blockToJSON(block, pblockindex);
773+
return blockToJSON(block, pblockindex, verbosity >= 2);
761774
}
762775

763776
struct CCoinsStats
@@ -1421,7 +1434,7 @@ static const CRPCCommand commands[] =
14211434
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} },
14221435
{ "blockchain", "getbestblockhash", &getbestblockhash, true, {} },
14231436
{ "blockchain", "getblockcount", &getblockcount, true, {} },
1424-
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbose"} },
1437+
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbosity|verbose"} },
14251438
{ "blockchain", "getblockhash", &getblockhash, true, {"height"} },
14261439
{ "blockchain", "getblockheader", &getblockheader, true, {"blockhash","verbose"} },
14271440
{ "blockchain", "getchaintips", &getchaintips, true, {} },

src/rpc/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
7777
{ "listunspent", 0, "minconf" },
7878
{ "listunspent", 1, "maxconf" },
7979
{ "listunspent", 2, "addresses" },
80-
{ "getblock", 1, "verbose" },
80+
{ "getblock", 1, "verbosity" },
8181
{ "getblockheader", 1, "verbose" },
8282
{ "gettransaction", 1, "include_watchonly" },
8383
{ "getrawtransaction", 1, "verbose" },

0 commit comments

Comments
 (0)