Skip to content

Commit 2b244ba

Browse files
tecnovertFuzzbawls
authored andcommitted
Fix missing help text and add backwards compatibility.
Github-Pull: #2779 Rebased-From: f4943e5
1 parent cce6951 commit 2b244ba

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

src/rpc/blockchain.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,15 @@ UniValue getblock(const JSONRPCRequest& request)
530530
"getblock \"blockhash\" ( verbosity )\n"
531531
"\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
532532
"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"
533+
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.\n"
534534

535535
"\nArguments:\n"
536536
"1. \"blockhash\" (string, required) The block hash\n"
537537
"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"
538538

539+
"\nResult (for verbosity = 0):\n"
540+
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
541+
539542
"\nResult (for verbosity = 1):\n"
540543
"{\n"
541544
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
@@ -561,8 +564,14 @@ UniValue getblock(const JSONRPCRequest& request)
561564
" }\n"
562565
"}\n"
563566

564-
"\nResult (for verbose=false):\n"
565-
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
567+
"\nResult (for verbosity = 2):\n"
568+
"{\n"
569+
" ..., Same output as verbosity = 1.\n"
570+
" \"tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result.\n"
571+
" ,...\n"
572+
" ],\n"
573+
" ,... Same output as verbosity = 1.\n"
574+
"}\n"
566575

567576
"\nExamples:\n" +
568577
HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") +
@@ -1454,7 +1463,7 @@ static const CRPCCommand commands[] =
14541463
// --------------------- ------------------------ ----------------------- ------ --------
14551464
{ "blockchain", "getbestblockhash", &getbestblockhash, true, {} },
14561465
{ "blockchain", "getbestsaplinganchor", &getbestsaplinganchor, true, {} },
1457-
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbosity"} },
1466+
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbose|verbosity"} },
14581467
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} },
14591468
{ "blockchain", "getblockcount", &getblockcount, true, {} },
14601469
{ "blockchain", "getblockhash", &getblockhash, true, {"height"} },

src/rpc/server.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include <boost/signals2/signal.hpp>
2424
#include <boost/thread.hpp>
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>
@@ -450,8 +452,16 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
450452
}
451453
// Process expected parameters.
452454
int hole = 0;
453-
for (const std::string &argName: argNames) {
454-
auto fr = argsIn.find(argName);
455+
for (const std::string &argNamePattern: argNames) {
456+
std::vector<std::string> vargNames;
457+
boost::algorithm::split(vargNames, argNamePattern, boost::algorithm::is_any_of("|"));
458+
auto fr = argsIn.end();
459+
for (const std::string & argName : vargNames) {
460+
fr = argsIn.find(argName);
461+
if (fr != argsIn.end()) {
462+
break;
463+
}
464+
}
455465
if (fr != argsIn.end()) {
456466
for (int i = 0; i < hole; ++i) {
457467
// Fill hole between specified parameters with JSON nulls,

test/functional/rpc_blockchain.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def run_test(self):
3737
self._test_getblockchaininfo()
3838
self._test_gettxoutsetinfo()
3939
self._test_getblockheader()
40+
self._test_getblock()
4041
#self._test_getdifficulty()
4142
self.nodes[0].verifychain(0)
4243

@@ -108,5 +109,17 @@ def _test_getdifficulty(self):
108109
# binary => decimal => binary math is why we do this check
109110
assert abs(difficulty * 2**31 - 1) < 0.0001
110111

112+
def _test_getblock(self):
113+
node = self.nodes[0]
114+
115+
# Test getblock verbosity
116+
besthash = node.getbestblockhash()
117+
assert(isinstance(node.getblock(blockhash=besthash, verbose=False), str))
118+
assert(isinstance(node.getblock(blockhash=besthash, verbosity=0), str))
119+
assert(isinstance(node.getblock(besthash, 1)['tx'][0], str))
120+
assert(isinstance(node.getblock(besthash, True)['tx'][0], str))
121+
assert('vin' in node.getblock(besthash, 2)['tx'][0])
122+
123+
111124
if __name__ == '__main__':
112125
BlockchainTest().main()

test/functional/rpc_named_arguments.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ def run_test(self):
3030
assert_equal(node.echo(arg9=None), [None]*10)
3131
assert_equal(node.echo(arg0=0,arg3=3,arg9=9), [0] + [None]*2 + [3] + [None]*5 + [9])
3232

33-
# Test getblock verbosity
34-
block = node.getblock(blockhash=h, verbosity=0)
35-
assert(isinstance(block, str))
36-
37-
block = node.getblock(blockhash=h, verbosity=1)
38-
assert(isinstance(block['tx'][0], str))
39-
40-
block = node.getblock(blockhash=h, verbosity=2)
41-
assert('vin' in block['tx'][0])
42-
4333

4434
if __name__ == '__main__':
4535
NamedArgumentTest().main()

0 commit comments

Comments
 (0)