Skip to content

Commit 96c850c

Browse files
committed
Merge #8704: [RPC] Transaction details in getblock
e3c9f2d Use a verbosity instead of two verbose parameters (Andrew Chow) c99ab3c RPC: Allow multiple names for parameters (Luke Dashjr) Tree-SHA512: 686b38f6b0106563738d51f55666fe6d49a5b121b30d4480c2bfb640a59ede8e6f7f3c05c3c5d80a5288e127991e191d19d1d4f9ace566fd39edeb27b31857ff
2 parents 41987aa + e3c9f2d commit 96c850c

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

src/rpc/blockchain.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,16 @@ UniValue getblock(const JSONRPCRequest& request)
688688
{
689689
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
690690
throw std::runtime_error(
691-
"getblock \"blockhash\" ( verbose )\n"
692-
"\nIf 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+
"\nIf 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"
694695
"\nArguments:\n"
695696
"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-
"\nResult (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+
"\nResult (for verbosity = 0):\n"
699+
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
700+
"\nResult (for verbosity = 1):\n"
698701
"{\n"
699702
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
700703
" \"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)
718721
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
719722
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
720723
"}\n"
721-
"\nResult (for verbose=false):\n"
722-
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
724+
"\nResult (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"
723732
"\nExamples:\n"
724733
+ HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
725734
+ HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
@@ -730,9 +739,13 @@ UniValue getblock(const JSONRPCRequest& request)
730739
std::string strHash = request.params[0].get_str();
731740
uint256 hash(uint256S(strHash));
732741

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+
}
736749

737750
if (mapBlockIndex.count(hash) == 0)
738751
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
@@ -751,15 +764,15 @@ UniValue getblock(const JSONRPCRequest& request)
751764
// block).
752765
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
753766

754-
if (!fVerbose)
767+
if (verbosity <= 0)
755768
{
756769
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
757770
ssBlock << block;
758771
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
759772
return strHex;
760773
}
761774

762-
return blockToJSON(block, pblockindex);
775+
return blockToJSON(block, pblockindex, verbosity >= 2);
763776
}
764777

765778
struct CCoinsStats
@@ -1489,7 +1502,7 @@ static const CRPCCommand commands[] =
14891502
{ "blockchain", "getchaintxstats", &getchaintxstats, true, {"nblocks", "blockhash"} },
14901503
{ "blockchain", "getbestblockhash", &getbestblockhash, true, {} },
14911504
{ "blockchain", "getblockcount", &getblockcount, true, {} },
1492-
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbose"} },
1505+
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbosity|verbose"} },
14931506
{ "blockchain", "getblockhash", &getblockhash, true, {"height"} },
14941507
{ "blockchain", "getblockheader", &getblockheader, true, {"blockhash","verbose"} },
14951508
{ "blockchain", "getchaintips", &getchaintips, true, {} },

src/rpc/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
7777
{ "listunspent", 0, "minconf" },
7878
{ "listunspent", 1, "maxconf" },
7979
{ "listunspent", 2, "addresses" },
80-
{ "getblock", 1, "verbose" },
80+
{ "getblock", 1, "verbosity" },
8181
{ "getblockheader", 1, "verbose" },
8282
{ "getchaintxstats", 0, "nblocks" },
8383
{ "gettransaction", 1, "include_watchonly" },

src/rpc/server.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <boost/signals2/signal.hpp>
2323
#include <boost/thread.hpp>
2424
#include <boost/algorithm/string/case_conv.hpp> // for to_upper()
25+
#include <boost/algorithm/string/classification.hpp>
26+
#include <boost/algorithm/string/split.hpp>
2527

2628
#include <memory> // for unique_ptr
2729
#include <unordered_map>
@@ -432,8 +434,16 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
432434
}
433435
// Process expected parameters.
434436
int hole = 0;
435-
for (const std::string &argName: argNames) {
436-
auto fr = argsIn.find(argName);
437+
for (const std::string &argNamePattern: argNames) {
438+
std::vector<std::string> vargNames;
439+
boost::algorithm::split(vargNames, argNamePattern, boost::algorithm::is_any_of("|"));
440+
auto fr = argsIn.end();
441+
for (const std::string & argName : vargNames) {
442+
fr = argsIn.find(argName);
443+
if (fr != argsIn.end()) {
444+
break;
445+
}
446+
}
437447
if (fr != argsIn.end()) {
438448
for (int i = 0; i < hole; ++i) {
439449
// Fill hole between specified parameters with JSON nulls,

0 commit comments

Comments
 (0)