aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/util.cpp
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2019-04-04 00:39:04 -0700
committerBen Woosley <ben.woosley@gmail.com>2019-04-13 18:52:11 -0700
commit510c6532bae9abc5beda1c126c945923a64680cb (patch)
tree08817bc88ad774370833066ca14714a6f8a2d262 /src/rpc/util.cpp
parentba54342c9dd3f2e5cdeed9ac57f1924f0d885cc6 (diff)
downloadbitcoin-510c6532bae9abc5beda1c126c945923a64680cb.tar.xz
Extract ParseDescriptorRange
So as to be consistently informative when the checks fail, and to protect against unintentional divergence among the checks.
Diffstat (limited to 'src/rpc/util.cpp')
-rw-r--r--src/rpc/util.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index 10979b43b0..8f8488bc5f 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -8,6 +8,8 @@
#include <tinyformat.h>
#include <util/strencodings.h>
+#include <tuple>
+
InitInterfaces* g_rpc_interfaces = nullptr;
// Converts a hex string to a public key if possible
@@ -529,7 +531,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()};
@@ -542,3 +544,19 @@ 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};
+}