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.
This commit is contained in:
Andrew Chow 2017-04-10 09:28:56 -04:00
parent c99ab3ca4b
commit e3c9f2ddb1
2 changed files with 27 additions and 14 deletions

View File

@ -686,13 +686,16 @@ UniValue getblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error( throw std::runtime_error(
"getblock \"blockhash\" ( verbose )\n" "getblock \"blockhash\" ( verbosity ) \n"
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n" "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
"If verbose is true, returns an Object with information about block <hash>.\n" "If verbosity is 1, returns an Object with information about block <hash>.\n"
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n"
"\nArguments:\n" "\nArguments:\n"
"1. \"blockhash\" (string, required) The block hash\n" "1. \"blockhash\" (string, required) The block hash\n"
"2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n" "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"
"\nResult (for verbose = true):\n" "\nResult (for verbosity = 0):\n"
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
"\nResult (for verbosity = 1):\n"
"{\n" "{\n"
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n" " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" " \"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)
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n" " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
"}\n" "}\n"
"\nResult (for verbose=false):\n" "\nResult (for verbosity = 2):\n"
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" "{\n"
" ..., Same output as verbosity = 1.\n"
" \"tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result.\n"
" ,...\n"
" ],\n"
" ,... Same output as verbosity = 1.\n"
"}\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
+ HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
@ -728,9 +737,13 @@ UniValue getblock(const JSONRPCRequest& request)
std::string strHash = request.params[0].get_str(); std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash)); uint256 hash(uint256S(strHash));
bool fVerbose = true; int verbosity = 1;
if (request.params.size() > 1) if (request.params.size() > 1) {
fVerbose = request.params[1].get_bool(); if(request.params[1].isNum())
verbosity = request.params[1].get_int();
else
verbosity = request.params[1].get_bool() ? 1 : 0;
}
if (mapBlockIndex.count(hash) == 0) if (mapBlockIndex.count(hash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
@ -749,7 +762,7 @@ UniValue getblock(const JSONRPCRequest& request)
// block). // block).
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk"); throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
if (!fVerbose) if (verbosity <= 0)
{ {
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
ssBlock << block; ssBlock << block;
@ -757,7 +770,7 @@ UniValue getblock(const JSONRPCRequest& request)
return strHex; return strHex;
} }
return blockToJSON(block, pblockindex); return blockToJSON(block, pblockindex, verbosity >= 2);
} }
struct CCoinsStats struct CCoinsStats
@ -1421,7 +1434,7 @@ static const CRPCCommand commands[] =
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} }, { "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} },
{ "blockchain", "getbestblockhash", &getbestblockhash, true, {} }, { "blockchain", "getbestblockhash", &getbestblockhash, true, {} },
{ "blockchain", "getblockcount", &getblockcount, true, {} }, { "blockchain", "getblockcount", &getblockcount, true, {} },
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbose"} }, { "blockchain", "getblock", &getblock, true, {"blockhash","verbosity|verbose"} },
{ "blockchain", "getblockhash", &getblockhash, true, {"height"} }, { "blockchain", "getblockhash", &getblockhash, true, {"height"} },
{ "blockchain", "getblockheader", &getblockheader, true, {"blockhash","verbose"} }, { "blockchain", "getblockheader", &getblockheader, true, {"blockhash","verbose"} },
{ "blockchain", "getchaintips", &getchaintips, true, {} }, { "blockchain", "getchaintips", &getchaintips, true, {} },

View File

@ -77,7 +77,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listunspent", 0, "minconf" }, { "listunspent", 0, "minconf" },
{ "listunspent", 1, "maxconf" }, { "listunspent", 1, "maxconf" },
{ "listunspent", 2, "addresses" }, { "listunspent", 2, "addresses" },
{ "getblock", 1, "verbose" }, { "getblock", 1, "verbosity" },
{ "getblockheader", 1, "verbose" }, { "getblockheader", 1, "verbose" },
{ "gettransaction", 1, "include_watchonly" }, { "gettransaction", 1, "include_watchonly" },
{ "getrawtransaction", 1, "verbose" }, { "getrawtransaction", 1, "verbose" },