Extract ParseDescriptorRange

So as to be consistently informative when the checks fail, and
to protect against unintentional divergence among the checks.
This commit is contained in:
Ben Woosley
2019-04-04 00:39:04 -07:00
parent ba54342c9d
commit 510c6532ba
7 changed files with 48 additions and 23 deletions

View File

@@ -22,6 +22,7 @@
#include <wallet/rpcwallet.h>
#include <stdint.h>
#include <tuple>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -1144,12 +1145,7 @@ static UniValue ProcessImportDescriptor(ImportData& import_data, std::map<CKeyID
if (!data.exists("range")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Descriptor is ranged, please specify the range");
}
auto range = ParseRange(data["range"]);
range_start = range.first;
range_end = range.second;
if (range_start < 0 || (range_end >> 31) != 0 || range_end - range_start >= 1000000) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid descriptor range specified");
}
std::tie(range_start, range_end) = ParseDescriptorRange(data["range"]);
}
const UniValue& priv_keys = data.exists("keys") ? data["keys"].get_array() : UniValue();