Skip to content

Commit ea347e6

Browse files
fanquakePastaPastaPasta
authored andcommitted
Merge bitcoin#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: bitcoin#21717 ACKs for top commit: instagibbs: utACK bitcoin@a411494 theStack: ACK a411494 promag: Code review ACK a411494. Tree-SHA512: 6e7d8290681e8ab375629f81669d0f8e0c21f9eb7ed9e2455cd19ea013e69b2d95fa7a9ee795315b2d5c60c96035c6cefc3d6e1039a06fd88c1dc7fe275ee6a1
1 parent df6d666 commit ea347e6

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

12431243
int verbosity = 1;
12441244
if (!request.params[1].isNull()) {
1245-
if(request.params[1].isNum())
1246-
verbosity = request.params[1].get_int();
1247-
else
1245+
if (request.params[1].isBool()) {
12481246
verbosity = request.params[1].get_bool() ? 1 : 0;
1247+
} else {
1248+
verbosity = request.params[1].get_int();
1249+
}
12491250
}
12501251

12511252
const NodeContext& node = EnsureAnyNodeContext(request.context);

test/functional/rpc_blockchain.py

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

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

0 commit comments

Comments
 (0)