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 2022-11-30 16:27:13 +00:00
parent 1d02e59901
commit 7727603e44
No known key found for this signature in database
GPG Key ID: 5CB1CE6E5E66A757
2 changed files with 5 additions and 7 deletions

View File

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

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)
* as well as objects and arrays.
*/
UniValue ParseNonRFCJSONValue(const std::string& strVal);
UniValue ParseNonRFCJSONValue(const std::string& raw);
#endif // BITCOIN_RPC_CLIENT_H