|
24 | 24 | #include <boost/thread.hpp> |
25 | 25 | #include <boost/algorithm/string/case_conv.hpp> // for to_upper() |
26 | 26 |
|
| 27 | +#include <algorithm> |
27 | 28 | #include <memory> // for unique_ptr |
28 | 29 | #include <unordered_map> |
29 | 30 |
|
@@ -172,6 +173,53 @@ std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey) |
172 | 173 | return ParseHexV(find_value(o, strKey), strKey); |
173 | 174 | } |
174 | 175 |
|
| 176 | +int32_t ParseInt32V(const UniValue& v, const std::string &strName) |
| 177 | +{ |
| 178 | + std::string strNum = v.getValStr(); |
| 179 | + int32_t num; |
| 180 | + if (!ParseInt32(strNum, &num)) |
| 181 | + throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a 32bit integer (not '"+strNum+"')"); |
| 182 | + return num; |
| 183 | +} |
| 184 | + |
| 185 | +int64_t ParseInt64V(const UniValue& v, const std::string &strName) |
| 186 | +{ |
| 187 | + std::string strNum = v.getValStr(); |
| 188 | + int64_t num; |
| 189 | + if (!ParseInt64(strNum, &num)) |
| 190 | + throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a 64bit integer (not '"+strNum+"')"); |
| 191 | + return num; |
| 192 | +} |
| 193 | + |
| 194 | +double ParseDoubleV(const UniValue& v, const std::string &strName) |
| 195 | +{ |
| 196 | + std::string strNum = v.getValStr(); |
| 197 | + double num; |
| 198 | + if (!ParseDouble(strNum, &num)) |
| 199 | + throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a be number (not '"+strNum+"')"); |
| 200 | + return num; |
| 201 | +} |
| 202 | + |
| 203 | +bool ParseBoolV(const UniValue& v, const std::string &strName) |
| 204 | +{ |
| 205 | + std::string strBool; |
| 206 | + if (v.isBool()) |
| 207 | + return v.get_bool(); |
| 208 | + else if (v.isNum()) |
| 209 | + strBool = itostr(v.get_int()); |
| 210 | + else if (v.isStr()) |
| 211 | + strBool = v.get_str(); |
| 212 | + |
| 213 | + std::transform(strBool.begin(), strBool.end(), strBool.begin(), ::tolower); |
| 214 | + |
| 215 | + if (strBool == "true" || strBool == "yes" || strBool == "1") { |
| 216 | + return true; |
| 217 | + } else if (strBool == "false" || strBool == "no" || strBool == "0") { |
| 218 | + return false; |
| 219 | + } |
| 220 | + throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be true, false, yes, no, 1 or 0 (not '"+strBool+"')"); |
| 221 | +} |
| 222 | + |
175 | 223 | /** |
176 | 224 | * Note: This interface may still be subject to change. |
177 | 225 | */ |
|
0 commit comments