Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13114997
D6610.id21490.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D6610.id21490.diff
View Options
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
Details
Attached
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)
Attached To
D6610: [backport#15497] Add ParseRange function to parse args of the form int/[int,int]
Event Timeline
Log In to Comment