Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
RPCMethod Class Reference

#include <util.h>

Collaboration diagram for RPCMethod:
[legend]

Public Types

using RPCMethodImpl = std::function<UniValue(const RPCMethod&, const JSONRPCRequest&)>

Public Member Functions

 RPCMethod (std::string name, std::string description, std::vector< RPCArg > args, RPCResults results, RPCExamples examples)
 RPCMethod (std::string name, std::string description, std::vector< RPCArg > args, RPCResults results, RPCExamples examples, RPCMethodImpl fun)
UniValue HandleRequest (const JSONRPCRequest &request) const
template<typename R>
auto Arg (std::string_view key) const
 Helper to get a required or default-valued request argument.
template<typename R>
auto MaybeArg (std::string_view key) const
 Helper to get an optional request argument.
std::string ToString () const
UniValue GetArgMap () const
 Return the named args that need to be converted from string to another JSON type.
bool IsValidNumArgs (size_t num_args) const
 If the supplied number of args is neither too small nor too high.
std::vector< std::pair< std::string, bool > > GetArgNames () const
 Return list of arguments and whether they are named-only.
const std::string & GetDescription () const
const std::vector< RPCArg > & GetArgs () const
const RPCResults & GetResults () const

Public Attributes

const std::string m_name

Private Member Functions

template<typename R>
R ArgValue (size_t i) const
size_t GetParamIndex (std::string_view key) const
 Return positional index of a parameter using its name as key.

Private Attributes

const RPCMethodImpl m_fun
const std::string m_description
const std::vector< RPCArg > m_args
const RPCResults m_results
const RPCExamples m_examples
const JSONRPCRequest * m_req {nullptr}

Detailed Description

Definition at line 444 of file util.h.

Member Typedef Documentation

◆ RPCMethodImpl

using RPCMethod::RPCMethodImpl = std::function<UniValue(const RPCMethod&, const JSONRPCRequest&)>

Definition at line 448 of file util.h.

Constructor & Destructor Documentation

◆ RPCMethod() [1/2]

RPCMethod::RPCMethod ( std::string name,
std::string description,
std::vector< RPCArg > args,
RPCResults results,
RPCExamples examples )

Definition at line 552 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPCMethod() [2/2]

RPCMethod::RPCMethod ( std::string name,
std::string description,
std::vector< RPCArg > args,
RPCResults results,
RPCExamples examples,
RPCMethodImpl fun )

Definition at line 555 of file util.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Arg()

template<typename R>
auto RPCMethod::Arg ( std::string_view key) const
inline

Helper to get a required or default-valued request argument.

Use this function when the argument is required or when it has a default value. If the argument is optional and may not be provided, use MaybeArg instead.

This function only works during m_fun(), i.e., it should only be used in RPC method implementations. It internally checks whether the user-passed argument isNull() and parses (from JSON) and returns the user-passed argument, or the default value derived from the RPCArg documentation.

The instantiation of this helper for type R must match the corresponding RPCArg::Type.

Returns
The value of the RPC argument (or the default value) cast to type R.
See also
MaybeArg for handling optional arguments without default values.

Definition at line 470 of file util.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ArgValue()

template<typename R>
R RPCMethod::ArgValue ( size_t i) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetArgMap()

UniValue RPCMethod::GetArgMap ( ) const

Return the named args that need to be converted from string to another JSON type.

Definition at line 842 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetArgNames()

std::vector< std::pair< std::string, bool > > RPCMethod::GetArgNames ( ) const

Return list of arguments and whether they are named-only.

Definition at line 754 of file util.cpp.

◆ GetArgs()

const std::vector< RPCArg > & RPCMethod::GetArgs ( ) const
inline

Definition at line 522 of file util.h.

Here is the caller graph for this function:

◆ GetDescription()

const std::string & RPCMethod::GetDescription ( ) const
inline

Definition at line 521 of file util.h.

Here is the caller graph for this function:

◆ GetParamIndex()

size_t RPCMethod::GetParamIndex ( std::string_view key) const
private

Return positional index of a parameter using its name as key.

Definition at line 769 of file util.cpp.

Here is the caller graph for this function:

◆ GetResults()

const RPCResults & RPCMethod::GetResults ( ) const
inline

Definition at line 523 of file util.h.

Here is the caller graph for this function:

◆ HandleRequest()

UniValue RPCMethod::HandleRequest ( const JSONRPCRequest & request) const

Definition at line 644 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsValidNumArgs()

bool RPCMethod::IsValidNumArgs ( size_t num_args) const

If the supplied number of args is neither too small nor too high.

Definition at line 742 of file util.cpp.

Here is the caller graph for this function:

◆ MaybeArg()

template<typename R>
auto RPCMethod::MaybeArg ( std::string_view key) const
inline

Helper to get an optional request argument.

Use this function when the argument is optional and does not have a default value. If the argument is required or has a default value, use Arg instead.

This function only works during m_fun(), i.e., it should only be used in RPC method implementations. It internally checks whether the user-passed argument isNull() and parses (from JSON) and returns the user-passed argument, or a falsy value if no argument was passed.

The instantiation of this helper for type R must match the corresponding RPCArg::Type.

Returns
For trivially copyable types, a std::optional<R> is returned. For other types, a R* pointer to the argument is returned. If the argument is not provided, std::nullopt or a null pointer is returned.
See also
Arg for handling arguments that are required or have a default value.

Definition at line 502 of file util.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToString()

std::string RPCMethod::ToString ( ) const

Definition at line 779 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_args

const std::vector<RPCArg> RPCMethod::m_args
private

Definition at line 530 of file util.h.

◆ m_description

const std::string RPCMethod::m_description
private

Definition at line 529 of file util.h.

◆ m_examples

const RPCExamples RPCMethod::m_examples
private

Definition at line 532 of file util.h.

◆ m_fun

const RPCMethodImpl RPCMethod::m_fun
private

Definition at line 528 of file util.h.

◆ m_name

const std::string RPCMethod::m_name

Definition at line 525 of file util.h.

◆ m_req

const JSONRPCRequest* RPCMethod::m_req {nullptr}
mutableprivate

Definition at line 533 of file util.h.

◆ m_results

const RPCResults RPCMethod::m_results
private

Definition at line 531 of file util.h.


The documentation for this class was generated from the following files: