Repository: bitcoin/bitcoin
File: src/rpc/client.cpp (C++)

Code before:
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/args.h>
#include <rpc/client.h>
#include <tinyformat.h>

#include <cstdint>
#include <set>
#include <string>
#include <string_view>

enum ParamFormat { JSON, STRING };

class CRPCConvertParam
{
public:
    std::string methodName; //!< method whose params want conversion
    int paramIdx;           //!< 0-based idx of param to convert
    std::string paramName;  //!< parameter name
    ParamFormat format{ParamFormat::JSON}; //!< parameter format
};

// clang-format off
/**
 * Specify a (method, idx, name, format) here if the argument is a non-string RPC
 * argument and needs to be converted from JSON, or if it is a string argument
 * passed to a method that accepts '=' characters in string arguments.
 *
 * JSON parameters need to be listed here to make bitcoin-cli treat command line
 * arguments as JSON values instead of strings.
 *
 * String parameters need to be listed here for methods accepting string
 * arguments with '=' characters, to make bitcoin-cli treat these command line
 * arguments as positional parameters instead of named parameters when -named is
 * used. For example, passing "key=store" as a parameter for some method would split
 * "key" as a param name and "store" as a param value rather than passing "key=store"
 * as a whole positional parameter when -named is used. This is useful when we want to pass the

Review comment (suggestion):
In commit "rpc: Handle -named argument parsing where '=' character is used" (fbeacfabe802c24b427bee2cd82da1f12ef9899d)

Note: with #33230 this could have JSON_OR_STRING added as well

Code after:
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/args.h>
#include <rpc/client.h>
#include <tinyformat.h>

#include <cstdint>
#include <set>
#include <string>
#include <string_view>

//! Specify whether parameter should be parsed by bitcoin-cli as a JSON value,
//! or passed unchanged as a string, or a combination of both.
enum ParamFormat { JSON, STRING, JSON_OR_STRING };

class CRPCConvertParam
{
public:
    std::string methodName; //!< method whose params want conversion
    int paramIdx;           //!< 0-based idx of param to convert
    std::string paramName;  //!< parameter name
    ParamFormat format{ParamFormat::JSON}; //!< parameter format
};

// clang-format off
/**
 * Specify a (method, idx, name, format) here if the argument is a non-string RPC
 * argument and needs to be converted from JSON, or if it is a string argument
 * passed to a method that accepts '=' characters in any string arguments.
 *
 * JSON parameters need to be listed here to make bitcoin-cli parse command line
 * arguments as JSON, instead of passing them as raw strings. `JSON` and
 * `JSON_OR_STRING` formats both make `bitcoin-cli` attempt to parse the
 * argument as JSON. But if parsing fails, the former triggers an error while
 * the latter falls back to passing the argument as a raw string. This is
 * useful for arguments like hash_or_height, allowing invocations such as
 * `bitcoin-cli getblockstats <hash>` without needing to quote the hash string