refactor: reduce unnecessary complexity in ParseNonRFCJSONValue

Since https://github.com/jgarzik/univalue/pull/31, UniValue::read() can now
parse raw literals directly, so there is no more need to wrap them into an
array first.
This commit is contained in:
stickies-v committed 2023-01-18 17:01:21 +00:00
1 parent 1d02e59901
commit 7727603e44
2 files changed
+5 -7

No files matched your search

+4 -6
View File
@@ -253,13 +253,11 @@ static CRPCConvertTable rpcCvtTable;
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) /** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
* as well as objects and arrays. * as well as objects and arrays.
*/ */
UniValue ParseNonRFCJSONValue(const std::string& strVal) UniValue ParseNonRFCJSONValue(const std::string& raw)
{ {
UniValue jVal; UniValue parsed;
if (!jVal.read(std::string("[")+strVal+std::string("]")) || if (!parsed.read(raw)) throw std::runtime_error(std::string("Error parsing JSON: ") + raw);
!jVal.isArray() || jVal.size()!=1) return parsed;
throw std::runtime_error(std::string("Error parsing JSON: ") + strVal);
return jVal[0];
} }
UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams) UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
+1 -1
View File
@@ -17,6 +17,6 @@ UniValue RPCConvertNamedValues(const std::string& strMethod, const std::vector<s
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) /** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
* as well as objects and arrays. * as well as objects and arrays.
*/ */
UniValue ParseNonRFCJSONValue(const std::string& strVal); UniValue ParseNonRFCJSONValue(const std::string& raw);
#endif // BITCOIN_RPC_CLIENT_H #endif // BITCOIN_RPC_CLIENT_H