mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05: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:
parent
6c8bde6d54
commit
cfbc8a623b
2 changed files with 10 additions and 17 deletions
|
@ -222,6 +222,14 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||
};
|
||||
// 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
|
||||
{
|
||||
private:
|
||||
|
@ -234,13 +242,13 @@ public:
|
|||
/** 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)
|
||||
{
|
||||
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 */
|
||||
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;
|
||||
|
||||
/** 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 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 */
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue