Skip to content

Commit 90fd5ac

Browse files
rpc, test: Fix error message in getdescriptoractivity
Mark blockhashes and scanobjects arguments as required, so the user receives a clear help message when either is missing. Added a new functional test for this use case. Co-authored-by: stickies-v <[email protected]>
1 parent 39fef1d commit 90fd5ac

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/rpc/blockchain.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,16 +2193,20 @@ static const auto scan_action_arg_desc = RPCArg{
21932193
"\"status\" for progress report (in %) of the current scan"
21942194
};
21952195

2196+
static const auto output_descriptor_obj = RPCArg{
2197+
"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with output descriptor and metadata",
2198+
{
2199+
{"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"},
2200+
{"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "The range of HD chain indexes to explore (either end or [begin,end])"},
2201+
}
2202+
};
2203+
21962204
static const auto scan_objects_arg_desc = RPCArg{
21972205
"scanobjects", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "Array of scan objects. Required for \"start\" action\n"
21982206
"Every scan object is either a string descriptor or an object:",
21992207
{
22002208
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"},
2201-
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with output descriptor and metadata",
2202-
{
2203-
{"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"},
2204-
{"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "The range of HD chain indexes to explore (either end or [begin,end])"},
2205-
}},
2209+
output_descriptor_obj,
22062210
},
22072211
RPCArgOptions{.oneline_description="[scanobjects,...]"},
22082212
};
@@ -2632,10 +2636,16 @@ static RPCHelpMan getdescriptoractivity()
26322636
"This command pairs well with the `relevant_blocks` output of `scanblocks()`.\n"
26332637
"This call may take several minutes. If you encounter timeouts, try specifying no RPC timeout (bitcoin-cli -rpcclienttimeout=0)",
26342638
{
2635-
RPCArg{"blockhashes", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "The list of blockhashes to examine for activity. Order doesn't matter. Must be along main chain or an error is thrown.\n", {
2639+
RPCArg{"blockhashes", RPCArg::Type::ARR, RPCArg::Optional::NO, "The list of blockhashes to examine for activity. Order doesn't matter. Must be along main chain or an error is thrown.\n", {
26362640
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A valid blockhash"},
26372641
}},
2638-
scan_objects_arg_desc,
2642+
RPCArg{"scanobjects", RPCArg::Type::ARR, RPCArg::Optional::NO, "The list of descriptors (scan objects) to examine for activity. Every scan object is either a string descriptor or an object:",
2643+
{
2644+
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"},
2645+
output_descriptor_obj,
2646+
},
2647+
RPCArgOptions{.oneline_description="[scanobjects,...]"},
2648+
},
26392649
{"include_mempool", RPCArg::Type::BOOL, RPCArg::Default{true}, "Whether to include unconfirmed activity"},
26402650
},
26412651
RPCResult{

test/functional/rpc_getdescriptoractivity.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def run_test(self):
3131
self.test_confirmed_and_unconfirmed(node, wallet)
3232
self.test_receive_then_spend(node, wallet)
3333
self.test_no_address(node, wallet)
34+
self.test_required_args(node)
3435

3536
def test_no_activity(self, node):
3637
self.log.info("Test that no activity is found for an unused address")
@@ -231,6 +232,11 @@ def test_no_address(self, node, wallet):
231232
assert_equal(list(a2['output_spk'].keys()), ['asm', 'desc', 'hex', 'type'])
232233
assert a2['amount'] == Decimal(no_addr_tx["tx"].vout[0].nValue) / COIN
233234

235+
def test_required_args(self, node):
236+
self.log.info("Test that required arguments must be passed")
237+
assert_raises_rpc_error(-1, "getdescriptoractivity", node.getdescriptoractivity)
238+
assert_raises_rpc_error(-1, "getdescriptoractivity", node.getdescriptoractivity, [])
239+
234240

235241
if __name__ == '__main__':
236242
GetBlocksActivityTest(__file__).main()

0 commit comments

Comments
 (0)