Page MenuHomePhabricator

D6610.id21490.diff
No OneTemporary

D6610.id21490.diff

diff --git a/src/rpc/util.h b/src/rpc/util.h
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -87,6 +87,9 @@
UniValue JSONRPCTransactionError(TransactionError terr,
const std::string &err_string = "");
+//! Parse a JSON range specified as int64, or [int64, int64]
+std::pair<int64_t, int64_t> ParseRange(const UniValue &value);
+
struct RPCArg {
enum class Type {
OBJ,
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -683,3 +683,21 @@
}
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]");
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 09:09 (48 m, 9 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5185557
Default Alt Text
D6610.id21490.diff (1 KB)

Event Timeline