Skip to content

Commit a4258f6

Browse files
committed
rpc: move-only: consolidate blockchain scan args
For later reuse in `scanblocks`.
1 parent 2d8d9ae commit a4258f6

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

src/rpc/blockchain.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,40 @@ class CoinsViewScanReserver
20192019
}
20202020
};
20212021

2022+
static const auto scan_action_arg_desc = RPCArg{
2023+
"action", RPCArg::Type::STR, RPCArg::Optional::NO, "The action to execute\n"
2024+
"\"start\" for starting a scan\n"
2025+
"\"abort\" for aborting the current scan (returns true when abort was successful)\n"
2026+
"\"status\" for progress report (in %) of the current scan"
2027+
};
2028+
2029+
static const auto scan_objects_arg_desc = RPCArg{
2030+
"scanobjects", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "Array of scan objects. Required for \"start\" action\n"
2031+
"Every scan object is either a string descriptor or an object:",
2032+
{
2033+
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"},
2034+
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with output descriptor and metadata",
2035+
{
2036+
{"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"},
2037+
{"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "The range of HD chain indexes to explore (either end or [begin,end])"},
2038+
}},
2039+
},
2040+
RPCArgOptions{.oneline_description="[scanobjects,...]"},
2041+
};
2042+
2043+
static const auto scan_result_abort = RPCResult{
2044+
"when action=='abort'", RPCResult::Type::BOOL, "success",
2045+
"True if scan will be aborted (not necessarily before this RPC returns), or false if there is no scan to abort"
2046+
};
2047+
static const auto scan_result_status_none = RPCResult{
2048+
"when action=='status' and no scan is in progress - possibly already completed", RPCResult::Type::NONE, "", ""
2049+
};
2050+
static const auto scan_result_status_some = RPCResult{
2051+
"when action=='status' and a scan is currently in progress", RPCResult::Type::OBJ, "", "",
2052+
{{RPCResult::Type::NUM, "progress", "Approximate percent complete"},}
2053+
};
2054+
2055+
20222056
static RPCHelpMan scantxoutset()
20232057
{
20242058
// scriptPubKey corresponding to mainnet address 12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S
@@ -2038,21 +2072,8 @@ static RPCHelpMan scantxoutset()
20382072
"In the latter case, a range needs to be specified by below if different from 1000.\n"
20392073
"For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n",
20402074
{
2041-
{"action", RPCArg::Type::STR, RPCArg::Optional::NO, "The action to execute\n"
2042-
"\"start\" for starting a scan\n"
2043-
"\"abort\" for aborting the current scan (returns true when abort was successful)\n"
2044-
"\"status\" for progress report (in %) of the current scan"},
2045-
{"scanobjects", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "Array of scan objects. Required for \"start\" action\n"
2046-
"Every scan object is either a string descriptor or an object:",
2047-
{
2048-
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"},
2049-
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with output descriptor and metadata",
2050-
{
2051-
{"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"},
2052-
{"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "The range of HD chain indexes to explore (either end or [begin,end])"},
2053-
}},
2054-
},
2055-
RPCArgOptions{.oneline_description="[scanobjects,...]"}},
2075+
scan_action_arg_desc,
2076+
scan_objects_arg_desc,
20562077
},
20572078
{
20582079
RPCResult{"when action=='start'; only returns after scan completes", RPCResult::Type::OBJ, "", "", {
@@ -2074,12 +2095,9 @@ static RPCHelpMan scantxoutset()
20742095
}},
20752096
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount of all found unspent outputs in " + CURRENCY_UNIT},
20762097
}},
2077-
RPCResult{"when action=='abort'", RPCResult::Type::BOOL, "success", "True if scan will be aborted (not necessarily before this RPC returns), or false if there is no scan to abort"},
2078-
RPCResult{"when action=='status' and a scan is currently in progress", RPCResult::Type::OBJ, "", "",
2079-
{
2080-
{RPCResult::Type::NUM, "progress", "Approximate percent complete"},
2081-
}},
2082-
RPCResult{"when action=='status' and no scan is in progress - possibly already completed", RPCResult::Type::NONE, "", ""},
2098+
scan_result_abort,
2099+
scan_result_status_some,
2100+
scan_result_status_none,
20832101
},
20842102
RPCExamples{
20852103
HelpExampleCli("scantxoutset", "start \'[\"" + EXAMPLE_DESCRIPTOR_RAW + "\"]\'") +

0 commit comments

Comments
 (0)