Skip to content

Commit 7727603

Browse files
committed
refactor: reduce unnecessary complexity in ParseNonRFCJSONValue
Since jgarzik/univalue#31, UniValue::read() can now parse raw literals directly, so there is no more need to wrap them into an array first.
1 parent 1d02e59 commit 7727603

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/rpc/client.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,11 @@ static CRPCConvertTable rpcCvtTable;
253253
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
254254
* as well as objects and arrays.
255255
*/
256-
UniValue ParseNonRFCJSONValue(const std::string& strVal)
256+
UniValue ParseNonRFCJSONValue(const std::string& raw)
257257
{
258-
UniValue jVal;
259-
if (!jVal.read(std::string("[")+strVal+std::string("]")) ||
260-
!jVal.isArray() || jVal.size()!=1)
261-
throw std::runtime_error(std::string("Error parsing JSON: ") + strVal);
262-
return jVal[0];
258+
UniValue parsed;
259+
if (!parsed.read(raw)) throw std::runtime_error(std::string("Error parsing JSON: ") + raw);
260+
return parsed;
263261
}
264262

265263
UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)

src/rpc/client.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ UniValue RPCConvertNamedValues(const std::string& strMethod, const std::vector<s
1717
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
1818
* as well as objects and arrays.
1919
*/
20-
UniValue ParseNonRFCJSONValue(const std::string& strVal);
20+
UniValue ParseNonRFCJSONValue(const std::string& raw);
2121

2222
#endif // BITCOIN_RPC_CLIENT_H

0 commit comments

Comments
 (0)