@@ -527,15 +527,16 @@ UniValue getblock(const JSONRPCRequest& request)
527527{
528528 if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
529529 throw std::runtime_error (
530- " getblock \" blockhash\" ( verbose )\n "
531- " \n If verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n "
532- " If verbose is true, returns an Object with information about block <hash>.\n "
530+ " getblock \" blockhash\" ( verbosity )\n "
531+ " \n If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n "
532+ " If verbosity is 1, returns an Object with information about block <hash>.\n "
533+ " If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n "
533534
534535 " \n Arguments:\n "
535- " 1. \" blockhash\" (string, required) The block hash\n "
536- " 2. verbose (boolean , optional, default=true) True for a json object, false for the hex encoded data\n "
536+ " 1. \" blockhash\" (string, required) The block hash\n "
537+ " 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 "
537538
538- " \n Result (for verbose = true ):\n "
539+ " \n Result (for verbosity = 1 ):\n "
539540 " {\n "
540541 " \" hash\" : \" hash\" , (string) the block hash (same as provided)\n "
541542 " \" confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n "
@@ -571,9 +572,13 @@ UniValue getblock(const JSONRPCRequest& request)
571572
572573 uint256 hash (ParseHashV (request.params [0 ], " blockhash" ));
573574
574- bool fVerbose = true ;
575- if (request.params .size () > 1 )
576- fVerbose = request.params [1 ].get_bool ();
575+ int verbosity = 1 ;
576+ if (!request.params [1 ].isNull ()) {
577+ if (request.params [1 ].isNum ())
578+ verbosity = request.params [1 ].get_int ();
579+ else
580+ verbosity = request.params [1 ].get_bool () ? 1 : 0 ;
581+ }
577582
578583 CBlockIndex* pblockindex = LookupBlockIndex (hash);
579584 if (pblockindex == nullptr )
@@ -583,14 +588,14 @@ UniValue getblock(const JSONRPCRequest& request)
583588 if (!ReadBlockFromDisk (block, pblockindex))
584589 throw JSONRPCError (RPC_INTERNAL_ERROR, " Can't read block from disk" );
585590
586- if (! fVerbose ) {
591+ if (verbosity <= 0 ) {
587592 CDataStream ssBlock (SER_NETWORK, PROTOCOL_VERSION);
588593 ssBlock << block;
589594 std::string strHex = HexStr (ssBlock);
590595 return strHex;
591596 }
592597
593- return blockToJSON (block, chainActive.Tip (), pblockindex);
598+ return blockToJSON (block, chainActive.Tip (), pblockindex, verbosity >= 2 );
594599}
595600
596601UniValue getblockheader (const JSONRPCRequest& request)
@@ -1449,7 +1454,7 @@ static const CRPCCommand commands[] =
14491454 // --------------------- ------------------------ ----------------------- ------ --------
14501455 { " blockchain" , " getbestblockhash" , &getbestblockhash, true , {} },
14511456 { " blockchain" , " getbestsaplinganchor" , &getbestsaplinganchor, true , {} },
1452- { " blockchain" , " getblock" , &getblock, true , {" blockhash" ," verbose " } },
1457+ { " blockchain" , " getblock" , &getblock, true , {" blockhash" ," verbosity " } },
14531458 { " blockchain" , " getblockchaininfo" , &getblockchaininfo, true , {} },
14541459 { " blockchain" , " getblockcount" , &getblockcount, true , {} },
14551460 { " blockchain" , " getblockhash" , &getblockhash, true , {" height" } },
0 commit comments