Merge 14959753a4 into merged_master (Bitcoin PR #15744)

This commit is contained in:
Andrew Poelstra 2020-10-29 15:57:19 +00:00
commit 3fd900ce76
7 changed files with 48 additions and 23 deletions

View file

@ -11,6 +11,8 @@
#include <assetsdir.h>
#include <core_io.h>
#include <tuple>
InitInterfaces* g_rpc_interfaces = nullptr;
void RPCTypeCheck(const UniValue& params,
@ -665,7 +667,7 @@ std::string RPCArg::ToString(const bool oneline) const
assert(false);
}
std::pair<int64_t, int64_t> ParseRange(const UniValue& value)
static std::pair<int64_t, int64_t> ParseRange(const UniValue& value)
{
if (value.isNum()) {
return {0, value.get_int64()};
@ -679,6 +681,22 @@ std::pair<int64_t, int64_t> ParseRange(const UniValue& value)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Range must be specified as end or as [begin,end]");
}
std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value)
{
int64_t low, high;
std::tie(low, high) = ParseRange(value);
if (low < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Range should be greater or equal than 0");
}
if ((high >> 31) != 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "End of range is too high");
}
if (high >= low + 1000000) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Range is too large");
}
return {low, high};
}
//
// ELEMENTS