mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Add ParseRange function to parse args of the form int/[int,int]
This commit is contained in:
@@ -523,3 +523,17 @@ std::string RPCArg::ToString(const bool oneline) const
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
std::pair<int64_t, int64_t> ParseRange(const UniValue& value)
|
||||
{
|
||||
if (value.isNum()) {
|
||||
return {0, value.get_int64()};
|
||||
}
|
||||
if (value.isArray() && value.size() == 2 && value[0].isNum() && value[1].isNum()) {
|
||||
int64_t low = value[0].get_int64();
|
||||
int64_t high = value[1].get_int64();
|
||||
if (low > high) throw JSONRPCError(RPC_INVALID_PARAMETER, "Range specified as [begin,end] must not have begin after end");
|
||||
return {low, high};
|
||||
}
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Range must be specified as end or as [begin,end]");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user