Skip to content

Commit a47ae61

Browse files
committed
Merge #21718: rpc: Improve error message for getblock invalid datatype.
a411494 rpc: Improve getblock error message for invalid data type. (klementtan) Pull request description: Improve error messages for getblock invalid datatype. fixes: #21717 ACKs for top commit: instagibbs: utACK bitcoin/bitcoin@a411494 theStack: ACK a411494 promag: Code review ACK a411494. Tree-SHA512: 6e7d8290681e8ab375629f81669d0f8e0c21f9eb7ed9e2455cd19ea013e69b2d95fa7a9ee795315b2d5c60c96035c6cefc3d6e1039a06fd88c1dc7fe275ee6a1
2 parents 0dd7b23 + a411494 commit a47ae61

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
@@ -955,10 +955,11 @@ static RPCHelpMan getblock()
955955

956956
int verbosity = 1;
957957
if (!request.params[1].isNull()) {
958-
if(request.params[1].isNum())
959-
verbosity = request.params[1].get_int();
960-
else
958+
if (request.params[1].isBool()) {
961959
verbosity = request.params[1].get_bool() ? 1 : 0;
960+
} else {
961+
verbosity = request.params[1].get_int();
962+
}
962963
}
963964

964965
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)