@@ -686,13 +686,16 @@ UniValue getblock(const JSONRPCRequest& request)
686
686
{
687
687
if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
688
688
throw std::runtime_error (
689
- " getblock \" blockhash\" ( verbose )\n "
690
- " \n If 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
+ " \n If 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 "
692
693
" \n Arguments:\n "
693
694
" 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
- " \n Result (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
+ " \n Result (for verbosity = 0):\n "
697
+ " \" data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n "
698
+ " \n Result (for verbosity = 1):\n "
696
699
" {\n "
697
700
" \" hash\" : \" hash\" , (string) the block hash (same as provided)\n "
698
701
" \" 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)
716
719
" \" previousblockhash\" : \" hash\" , (string) The hash of the previous block\n "
717
720
" \" nextblockhash\" : \" hash\" (string) The hash of the next block\n "
718
721
" }\n "
719
- " \n Result (for verbose=false):\n "
720
- " \" data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n "
722
+ " \n Result (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 "
721
730
" \n Examples:\n "
722
731
+ HelpExampleCli (" getblock" , " \" 00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" " )
723
732
+ HelpExampleRpc (" getblock" , " \" 00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" " )
@@ -728,9 +737,13 @@ UniValue getblock(const JSONRPCRequest& request)
728
737
std::string strHash = request.params [0 ].get_str ();
729
738
uint256 hash (uint256S (strHash));
730
739
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
+ }
734
747
735
748
if (mapBlockIndex.count (hash) == 0 )
736
749
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
@@ -749,15 +762,15 @@ UniValue getblock(const JSONRPCRequest& request)
749
762
// block).
750
763
throw JSONRPCError (RPC_MISC_ERROR, " Block not found on disk" );
751
764
752
- if (! fVerbose )
765
+ if (verbosity <= 0 )
753
766
{
754
767
CDataStream ssBlock (SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags ());
755
768
ssBlock << block;
756
769
std::string strHex = HexStr (ssBlock.begin (), ssBlock.end ());
757
770
return strHex;
758
771
}
759
772
760
- return blockToJSON (block, pblockindex);
773
+ return blockToJSON (block, pblockindex, verbosity >= 2 );
761
774
}
762
775
763
776
struct CCoinsStats
@@ -1421,7 +1434,7 @@ static const CRPCCommand commands[] =
1421
1434
{ " blockchain" , " getblockchaininfo" , &getblockchaininfo, true , {} },
1422
1435
{ " blockchain" , " getbestblockhash" , &getbestblockhash, true , {} },
1423
1436
{ " blockchain" , " getblockcount" , &getblockcount, true , {} },
1424
- { " blockchain" , " getblock" , &getblock, true , {" blockhash" ," verbose" } },
1437
+ { " blockchain" , " getblock" , &getblock, true , {" blockhash" ," verbosity| verbose" } },
1425
1438
{ " blockchain" , " getblockhash" , &getblockhash, true , {" height" } },
1426
1439
{ " blockchain" , " getblockheader" , &getblockheader, true , {" blockhash" ," verbose" } },
1427
1440
{ " blockchain" , " getchaintips" , &getchaintips, true , {} },
0 commit comments