mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-01 03:01:09 +02:00
refactor: rpc: hide and rename ParseNonRFCJSONValue()
As per https://github.com/bitcoin/bitcoin/pull/26506#pullrequestreview-1211984059, this function is no longer necessary and we can use UniValue::read() directly. To avoid code duplication, we keep the function to throw on invalid input data but rename it to Parse() and remove it from the header.
This commit is contained in:
@ -222,6 +222,14 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
/** Parse string to UniValue or throw runtime_error if string contains invalid JSON */
|
||||||
|
static UniValue Parse(std::string_view raw)
|
||||||
|
{
|
||||||
|
UniValue parsed;
|
||||||
|
if (!parsed.read(raw)) throw std::runtime_error(tfm::format("Error parsing JSON: %s", raw));
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
class CRPCConvertTable
|
class CRPCConvertTable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -234,13 +242,13 @@ public:
|
|||||||
/** Return arg_value as UniValue, and first parse it if it is a non-string parameter */
|
/** Return arg_value as UniValue, and first parse it if it is a non-string parameter */
|
||||||
UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, int param_idx)
|
UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, int param_idx)
|
||||||
{
|
{
|
||||||
return members.count({method, param_idx}) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value;
|
return members.count({method, param_idx}) > 0 ? Parse(arg_value) : arg_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return arg_value as UniValue, and first parse it if it is a non-string parameter */
|
/** Return arg_value as UniValue, and first parse it if it is a non-string parameter */
|
||||||
UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, const std::string& param_name)
|
UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, const std::string& param_name)
|
||||||
{
|
{
|
||||||
return membersByName.count({method, param_name}) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value;
|
return membersByName.count({method, param_name}) > 0 ? Parse(arg_value) : arg_value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -254,16 +262,6 @@ CRPCConvertTable::CRPCConvertTable()
|
|||||||
|
|
||||||
static CRPCConvertTable rpcCvtTable;
|
static CRPCConvertTable rpcCvtTable;
|
||||||
|
|
||||||
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
|
|
||||||
* as well as objects and arrays.
|
|
||||||
*/
|
|
||||||
UniValue ParseNonRFCJSONValue(std::string_view raw)
|
|
||||||
{
|
|
||||||
UniValue parsed;
|
|
||||||
if (!parsed.read(raw)) throw std::runtime_error(tfm::format("Error parsing JSON: %s", raw));
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
|
UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
|
||||||
{
|
{
|
||||||
UniValue params(UniValue::VARR);
|
UniValue params(UniValue::VARR);
|
||||||
|
@ -17,9 +17,4 @@ UniValue RPCConvertValues(const std::string& strMethod, const std::vector<std::s
|
|||||||
/** Convert named arguments to command-specific RPC representation */
|
/** Convert named arguments to command-specific RPC representation */
|
||||||
UniValue RPCConvertNamedValues(const std::string& strMethod, const std::vector<std::string>& strParams);
|
UniValue RPCConvertNamedValues(const std::string& strMethod, const std::vector<std::string>& strParams);
|
||||||
|
|
||||||
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
|
|
||||||
* as well as objects and arrays.
|
|
||||||
*/
|
|
||||||
UniValue ParseNonRFCJSONValue(std::string_view raw);
|
|
||||||
|
|
||||||
#endif // BITCOIN_RPC_CLIENT_H
|
#endif // BITCOIN_RPC_CLIENT_H
|
||||||
|
Reference in New Issue
Block a user