@@ -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- " \n If 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+ " \n If 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 " \n Arguments:\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- " \n Result (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+ " \n Result (for verbosity = 0):\n "
841+ " \" data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n "
842+ " \n Result (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- " \n Result (for verbose=false):\n "
862- " \" data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n "
864+ " \n Result (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 " \n Examples:\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
900913struct 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" } },
0 commit comments