Skip to content

Commit a411494

Browse files
author
klementtan
committed
rpc: Improve getblock error message for invalid data type.
1 parent f5e8bcf commit a411494

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/rpc/blockchain.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,11 @@ static RPCHelpMan getblock()
936936

937937
int verbosity = 1;
938938
if (!request.params[1].isNull()) {
939-
if(request.params[1].isNum())
940-
verbosity = request.params[1].get_int();
941-
else
939+
if (request.params[1].isBool()) {
942940
verbosity = request.params[1].get_bool() ? 1 : 0;
941+
} else {
942+
verbosity = request.params[1].get_int();
943+
}
943944
}
944945

945946
CBlock block;

test/functional/rpc_blockchain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ def _test_getblock(self):
410410
self.log.info("Test that getblock with verbosity 2 still works with pruned Undo data")
411411
datadir = get_datadir_path(self.options.tmpdir, 0)
412412

413+
self.log.info("Test that getblock with invalid verbosity type returns proper error message")
414+
assert_raises_rpc_error(-1, "JSON value is not an integer as expected", node.getblock, blockhash, "2")
415+
413416
def move_block_file(old, new):
414417
old_path = os.path.join(datadir, self.chain, 'blocks', old)
415418
new_path = os.path.join(datadir, self.chain, 'blocks', new)

0 commit comments

Comments
 (0)