@@ -225,11 +225,16 @@ class CRPCConvertTable
225
225
public:
226
226
CRPCConvertTable ();
227
227
228
- bool convert (const std::string& method, int idx) {
229
- return (members.count (std::make_pair (method, idx)) > 0 );
228
+ /* * Return arg_value as UniValue, and first parse it if it is a non-string parameter */
229
+ UniValue ArgToUniValue (const std::string& arg_value, const std::string& method, int param_idx)
230
+ {
231
+ return members.count (std::make_pair (method, param_idx)) > 0 ? ParseNonRFCJSONValue (arg_value) : arg_value;
230
232
}
231
- bool convert (const std::string& method, const std::string& name) {
232
- return (membersByName.count (std::make_pair (method, name)) > 0 );
233
+
234
+ /* * Return arg_value as UniValue, and first parse it if it is a non-string parameter */
235
+ UniValue ArgToUniValue (const std::string& arg_value, const std::string& method, const std::string& param_name)
236
+ {
237
+ return membersByName.count (std::make_pair (method, param_name)) > 0 ? ParseNonRFCJSONValue (arg_value) : arg_value;
233
238
}
234
239
};
235
240
@@ -261,14 +266,7 @@ UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::s
261
266
262
267
for (unsigned int idx = 0 ; idx < strParams.size (); idx++) {
263
268
const std::string& strVal = strParams[idx];
264
-
265
- if (!rpcCvtTable.convert (strMethod, idx)) {
266
- // insert string value directly
267
- params.push_back (strVal);
268
- } else {
269
- // parse string as JSON, insert bool/number/object/etc. value
270
- params.push_back (ParseNonRFCJSONValue (strVal));
271
- }
269
+ params.push_back (rpcCvtTable.ArgToUniValue (strVal, strMethod, idx));
272
270
}
273
271
274
272
return params;
@@ -282,7 +280,7 @@ UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector<s
282
280
for (const std::string &s: strParams) {
283
281
size_t pos = s.find (' =' );
284
282
if (pos == std::string::npos) {
285
- positional_args.push_back (rpcCvtTable.convert ( strMethod, positional_args.size ()) ? ParseNonRFCJSONValue (s) : s );
283
+ positional_args.push_back (rpcCvtTable.ArgToUniValue (s, strMethod, positional_args.size ()));
286
284
continue ;
287
285
}
288
286
@@ -292,13 +290,7 @@ UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector<s
292
290
// Intentionally overwrite earlier named values with later ones as a
293
291
// convenience for scripts and command line users that want to merge
294
292
// options.
295
- if (!rpcCvtTable.convert (strMethod, name)) {
296
- // insert string value directly
297
- params.pushKV (name, value);
298
- } else {
299
- // parse string as JSON, insert bool/number/object/etc. value
300
- params.pushKV (name, ParseNonRFCJSONValue (value));
301
- }
293
+ params.pushKV (name, rpcCvtTable.ArgToUniValue (value, strMethod, name));
302
294
}
303
295
304
296
if (!positional_args.empty ()) {
0 commit comments