mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-25 16:31:29 +02:00
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:
parent
1d02e59901
commit
7727603e44
@ -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)
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user