@@ -688,13 +688,16 @@ UniValue getblock(const JSONRPCRequest& request)
688
688
{
689
689
if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
690
690
throw std::runtime_error (
691
- " getblock \" blockhash\" ( verbose )\n "
692
- " \n If verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n "
693
- " If verbose is true, returns an Object with information about block <hash>.\n "
691
+ " getblock \" blockhash\" ( verbosity ) \n "
692
+ " \n If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n "
693
+ " If verbosity is 1, returns an Object with information about block <hash>.\n "
694
+ " If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n "
694
695
" \n Arguments:\n "
695
696
" 1. \" blockhash\" (string, required) The block hash\n "
696
- " 2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n "
697
- " \n Result (for verbose = true):\n "
697
+ " 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 "
698
+ " \n Result (for verbosity = 0):\n "
699
+ " \" data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n "
700
+ " \n Result (for verbosity = 1):\n "
698
701
" {\n "
699
702
" \" hash\" : \" hash\" , (string) the block hash (same as provided)\n "
700
703
" \" confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n "
@@ -718,8 +721,14 @@ UniValue getblock(const JSONRPCRequest& request)
718
721
" \" previousblockhash\" : \" hash\" , (string) The hash of the previous block\n "
719
722
" \" nextblockhash\" : \" hash\" (string) The hash of the next block\n "
720
723
" }\n "
721
- " \n Result (for verbose=false):\n "
722
- " \" data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n "
724
+ " \n Result (for verbosity = 2):\n "
725
+ " {\n "
726
+ " ..., Same output as verbosity = 1.\n "
727
+ " \" tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \" tx\" result.\n "
728
+ " ,...\n "
729
+ " ],\n "
730
+ " ,... Same output as verbosity = 1.\n "
731
+ " }\n "
723
732
" \n Examples:\n "
724
733
+ HelpExampleCli (" getblock" , " \" 00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" " )
725
734
+ HelpExampleRpc (" getblock" , " \" 00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" " )
@@ -730,9 +739,13 @@ UniValue getblock(const JSONRPCRequest& request)
730
739
std::string strHash = request.params [0 ].get_str ();
731
740
uint256 hash (uint256S (strHash));
732
741
733
- bool fVerbose = true ;
734
- if (request.params .size () > 1 )
735
- fVerbose = request.params [1 ].get_bool ();
742
+ int verbosity = 1 ;
743
+ if (request.params .size () > 1 ) {
744
+ if (request.params [1 ].isNum ())
745
+ verbosity = request.params [1 ].get_int ();
746
+ else
747
+ verbosity = request.params [1 ].get_bool () ? 1 : 0 ;
748
+ }
736
749
737
750
if (mapBlockIndex.count (hash) == 0 )
738
751
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
@@ -751,15 +764,15 @@ UniValue getblock(const JSONRPCRequest& request)
751
764
// block).
752
765
throw JSONRPCError (RPC_MISC_ERROR, " Block not found on disk" );
753
766
754
- if (! fVerbose )
767
+ if (verbosity <= 0 )
755
768
{
756
769
CDataStream ssBlock (SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags ());
757
770
ssBlock << block;
758
771
std::string strHex = HexStr (ssBlock.begin (), ssBlock.end ());
759
772
return strHex;
760
773
}
761
774
762
- return blockToJSON (block, pblockindex);
775
+ return blockToJSON (block, pblockindex, verbosity >= 2 );
763
776
}
764
777
765
778
struct CCoinsStats
@@ -1489,7 +1502,7 @@ static const CRPCCommand commands[] =
1489
1502
{ " blockchain" , " getchaintxstats" , &getchaintxstats, true , {" nblocks" , " blockhash" } },
1490
1503
{ " blockchain" , " getbestblockhash" , &getbestblockhash, true , {} },
1491
1504
{ " blockchain" , " getblockcount" , &getblockcount, true , {} },
1492
- { " blockchain" , " getblock" , &getblock, true , {" blockhash" ," verbose" } },
1505
+ { " blockchain" , " getblock" , &getblock, true , {" blockhash" ," verbosity| verbose" } },
1493
1506
{ " blockchain" , " getblockhash" , &getblockhash, true , {" height" } },
1494
1507
{ " blockchain" , " getblockheader" , &getblockheader, true , {" blockhash" ," verbose" } },
1495
1508
{ " blockchain" , " getchaintips" , &getchaintips, true , {} },
0 commit comments