src/bitcoinrpc.cpp
/**
 * Process named arguments into a vector of positional arguments, based on the
 * passed-in specification for the RPC call's arguments.
 */
Process named arguments into a vector of positional arguments, based on the
passed-in specification for the RPC call's arguments.
Process named arguments into a vector of positional arguments based on the passed - in specification for the RPC call ' s arguments .
static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, const std::vector<std::string>& argNames)
{
    JSONRPCRequest out = in;
    out.params = UniValue(UniValue::VARR);
    const std::vector<std::string>& keys = in.params.getKeys();
    const std::vector<UniValue>& values = in.params.getValues();
    std::unordered_map<std::string, const UniValue*> argsIn;
    for (size_t i=0; i<keys.size(); ++i)
        argsIn[keys[i]] = &values[i];
    int hole = 0;
    for (const std::string &argName: argNames)
    {
        auto fr = argsIn.find(argName);
        if (fr != argsIn.end())
        {
            for (int i = 0; i < hole; ++i)
            {
                out.params.push_back(UniValue());
            }
            hole = 0;
            out.params.push_back(*fr->second);
            argsIn.erase(fr);
        }
        else
            hole += 1;
    }
    if (!argsIn.empty())
        throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown named parameter " + argsIn.begin()->first);
    return out;
}
static inline JSONRPCRequest transformNamedArguments ( const JSONRPCRequest & in , const std :: vector < std :: string > & argNames ) { JSONRPCRequest out = in ; out . params = UniValue ( UniValue :: VARR ) ; const std :: vector < std :: string > & keys = in . params . getKeys ( ) ; const std :: vector < UniValue > & values = in . params . getValues ( ) ; std :: unordered_map < std :: string , const UniValue * > argsIn ; for ( size_t i = 0 ; i < keys . size ( ) ; ++ i ) argsIn [ keys [ i ] ] = & values [ i ] ; int hole = 0 ; for ( const std :: string & argName : argNames ) { auto fr = argsIn . find ( argName ) ; if ( fr != argsIn . end ( ) ) { for ( int i = 0 ; i < hole ; ++ i ) { out . params . push_back ( UniValue ( ) ) ; } hole = 0 ; out . params . push_back ( * fr -> second ) ; argsIn . erase ( fr ) ; } else hole += 1 ; } if ( ! argsIn . empty ( ) ) throw JSONRPCError ( RPC_INVALID_PARAMETER , " " + argsIn . begin ( ) -> first ) ; return out ; }
Process named arguments into a vector of positional arguments, based on the
 passed-in specification for the RPC call's arguments.
Process named arguments into a vector of positional arguments based on the passed - in specification for the RPC call ' s arguments .
// Build a map of parameters, and remove ones that have been processed, so that we can throw a focused error if // there is an unknown one. // Fill hole between specified parameters with JSON nulls, // but not at the end (for backwards compatibility with calls // that act based on number of specified parameters). // If there are still arguments in the argsIn map, this is an error. // Return request with named arguments transformed to positional arguments