Bitcoin ABC 0.32.4
P2P Digital Currency
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
RPCHelpMan Class Reference

#include <util.h>

Collaboration diagram for RPCHelpMan:
[legend]

Public Types

using RPCMethodImpl = std::function< UniValue(const RPCHelpMan &, const Config &config, const JSONRPCRequest &)>
 

Public Member Functions

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

Public Attributes

const std::string m_name
 

Private Member Functions

template<typename 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. More...
 

Private Attributes

const RPCMethodImpl m_fun
 
const std::string m_description
 
const std::vector< RPCArgm_args
 
const RPCResults m_results
 
const RPCExamples m_examples
 
const JSONRPCRequestm_req {nullptr}
 A pointer to the request for the duration of m_fun() More...
 

Detailed Description

Definition at line 372 of file util.h.

Member Typedef Documentation

◆ RPCMethodImpl

using RPCHelpMan::RPCMethodImpl = std::function<UniValue( const RPCHelpMan &, const Config &config, const JSONRPCRequest &)>

Definition at line 377 of file util.h.

Constructor & Destructor Documentation

◆ RPCHelpMan() [1/2]

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

Definition at line 490 of file util.cpp.

◆ RPCHelpMan() [2/2]

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

Definition at line 496 of file util.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Arg() [1/2]

template<typename R >
auto RPCHelpMan::Arg ( size_t  i) 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.

There are two overloads of this function:

  • Use Arg<Type>(size_t i) to get the argument (or the default value) by index.
  • Use Arg<Type>(const std::string& key) to get the argument (or the default value) by key.

The Type passed to this helper must match the corresponding RPCArg::Type.

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

Definition at line 410 of file util.h.

Here is the caller graph for this function:

◆ Arg() [2/2]

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

Definition at line 420 of file util.h.

Here is the call graph for this function:

◆ ArgValue()

template<typename R >
R RPCHelpMan::ArgValue ( size_t  i) const
private

◆ GetArgMap()

UniValue RPCHelpMan::GetArgMap ( ) const

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

Definition at line 821 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 > > RPCHelpMan::GetArgNames ( ) const

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

Definition at line 714 of file util.cpp.

◆ GetParamIndex()

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

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

Definition at line 728 of file util.cpp.

Here is the caller graph for this function:

◆ HandleRequest()

UniValue RPCHelpMan::HandleRequest ( const Config config,
const JSONRPCRequest request 
) const

Definition at line 590 of file util.cpp.

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

◆ IsValidNumArgs()

bool RPCHelpMan::IsValidNumArgs ( size_t  num_args) const

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

Definition at line 703 of file util.cpp.

Here is the caller graph for this function:

◆ MaybeArg() [1/2]

template<typename R >
auto RPCHelpMan::MaybeArg ( size_t  i) 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.

There are two overloads of this function:

  • Use MaybeArg<Type>(size_t i) to get the optional argument by index.
  • Use MaybeArg<Type>(const std::string& key) to get the optional argument by key.

The Type passed to this helper must match the corresponding RPCArg::Type.

Returns
For integral and floating-point types, a std::optional<Type> is returned. For other types, a Type* 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 450 of file util.h.

Here is the caller graph for this function:

◆ MaybeArg() [2/2]

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

Definition at line 460 of file util.h.

Here is the call graph for this function:

◆ ToString()

std::string RPCHelpMan::ToString ( ) const

Definition at line 738 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> RPCHelpMan::m_args
private

Definition at line 479 of file util.h.

◆ m_description

const std::string RPCHelpMan::m_description
private

Definition at line 478 of file util.h.

◆ m_examples

const RPCExamples RPCHelpMan::m_examples
private

Definition at line 481 of file util.h.

◆ m_fun

const RPCMethodImpl RPCHelpMan::m_fun
private

Definition at line 477 of file util.h.

◆ m_name

const std::string RPCHelpMan::m_name

Definition at line 474 of file util.h.

◆ m_req

const JSONRPCRequest* RPCHelpMan::m_req {nullptr}
mutableprivate

A pointer to the request for the duration of m_fun()

Definition at line 483 of file util.h.

◆ m_results

const RPCResults RPCHelpMan::m_results
private

Definition at line 480 of file util.h.


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