Bitcoin ABC 0.32.12
P2P Digital Currency
Classes | Macros | Typedefs | Functions | Variables
util.cpp File Reference
#include <rpc/util.h>
#include <clientversion.h>
#include <common/args.h>
#include <common/messages.h>
#include <common/types.h>
#include <consensus/amount.h>
#include <key_io.h>
#include <node/types.h>
#include <script/descriptor.h>
#include <script/signingprovider.h>
#include <tinyformat.h>
#include <util/check.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/translation.h>
#include <algorithm>
#include <iterator>
#include <string_view>
#include <tuple>
#include <variant>
Include dependency graph for util.cpp:

Go to the source code of this file.

Classes

class  DescribeAddressVisitor
 
struct  Section
 A pair of strings that can be aligned (through padding) with other Sections later on. More...
 
struct  Sections
 Keeps track of RPCArgs by transforming them into sections for the purpose of serializing everything to a single string. More...
 

Macros

#define TMPL_INST(check_param, ret_type, return_code)
 

Typedefs

using CheckFn = void(const RPCArg &)
 

Functions

void RPCTypeCheckObj (const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
 Check for expected keys/value types in an Object. More...
 
Amount AmountFromValue (const UniValue &value)
 
uint256 ParseHashV (const UniValue &v, std::string strName)
 Utilities: convert hex-encoded values (throws error if not hex). More...
 
uint256 ParseHashO (const UniValue &o, std::string strKey)
 
std::vector< uint8_t > ParseHexV (const UniValue &v, std::string strName)
 
std::vector< uint8_t > ParseHexO (const UniValue &o, std::string strKey)
 
std::string HelpExampleCli (const std::string &methodname, const std::string &args)
 
std::string HelpExampleCliNamed (const std::string &methodname, const RPCArgList &args)
 
std::string HelpExampleRpc (const std::string &methodname, const std::string &args)
 
std::string HelpExampleRpcNamed (const std::string &methodname, const RPCArgList &args)
 
CPubKey HexToPubKey (const std::string &hex_in)
 
CPubKey AddrToPubKey (const CChainParams &chainparams, const FillableSigningProvider &keystore, const std::string &addr_in)
 
CTxDestination AddAndGetMultisigDestination (const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
 
UniValue DescribeAddress (const CTxDestination &dest)
 
std::string GetAllOutputTypes ()
 
RPCErrorCode RPCErrorFromPSBTError (PSBTError err)
 
RPCErrorCode RPCErrorFromTransactionError (TransactionError terr)
 
UniValue JSONRPCPSBTError (PSBTError err)
 
UniValue JSONRPCTransactionError (TransactionError terr, const std::string &err_string)
 
static const UniValueDetailMaybeArg (CheckFn *check, const std::vector< RPCArg > &params, const JSONRPCRequest *req, size_t i)
 
static void CheckRequiredOrDefault (const RPCArg &param)
 
 TMPL_INST (nullptr, std::optional< double >, maybe_arg ? std::optional{maybe_arg->get_real()} :std::nullopt;)
 
 TMPL_INST (nullptr, std::optional< bool >, maybe_arg ? std::optional{maybe_arg->get_bool()} :std::nullopt;)
 
 TMPL_INST (nullptr, const std::string *, maybe_arg ? &maybe_arg->get_str() :nullptr;)
 
 TMPL_INST (CheckRequiredOrDefault, bool, CHECK_NONFATAL(maybe_arg) ->get_bool();)
 
 TMPL_INST (CheckRequiredOrDefault, int, CHECK_NONFATAL(maybe_arg) ->getInt< int >();)
 
 TMPL_INST (CheckRequiredOrDefault, uint64_t, CHECK_NONFATAL(maybe_arg) ->getInt< uint64_t >();)
 
 TMPL_INST (CheckRequiredOrDefault, const std::string &, CHECK_NONFATAL(maybe_arg) ->get_str();)
 
static std::optional< UniValue::VTypeExpectedType (RPCArg::Type type)
 
static std::optional< UniValue::VTypeExpectedType (RPCResult::Type type)
 
static std::pair< int64_t, int64_t > ParseRange (const UniValue &value)
 
std::pair< int64_t, int64_t > ParseDescriptorRange (const UniValue &value)
 Parse a JSON range specified as int64, or [int64, int64]. More...
 
std::vector< CScriptEvalDescriptorStringOrObject (const UniValue &scanobject, FlatSigningProvider &provider)
 Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000. More...
 
UniValue GetServicesNames (ServiceFlags services)
 Returns, given services flags, a list of humanly readable (known) network services. More...
 

Variables

const std::string UNIX_EPOCH_TIME = "UNIX epoch time"
 String used to describe UNIX epoch time in documentation, factored out to a constant for consistency. More...
 
const std::string EXAMPLE_ADDRESS
 Example CashAddr address used in multiple RPCExamples. More...
 

Macro Definition Documentation

◆ TMPL_INST

#define TMPL_INST (   check_param,
  ret_type,
  return_code 
)
Value:
template <> ret_type RPCHelpMan::ArgValue<ret_type>(size_t i) const { \
const UniValue *maybe_arg{ \
DetailMaybeArg(check_param, m_args, m_req, i), \
}; \
return return_code \
} \
void force_semicolon(ret_type)
const std::vector< RPCArg > m_args
Definition: util.h:485
const JSONRPCRequest * m_req
A pointer to the request for the duration of m_fun()
Definition: util.h:489

Definition at line 696 of file util.cpp.

Typedef Documentation

◆ CheckFn

using CheckFn = void(const RPCArg &)

Definition at line 665 of file util.cpp.

Function Documentation

◆ AddAndGetMultisigDestination()

CTxDestination AddAndGetMultisigDestination ( const int  required,
const std::vector< CPubKey > &  pubkeys,
OutputType  type,
FillableSigningProvider keystore,
CScript script_out 
)

Definition at line 246 of file util.cpp.

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

◆ AddrToPubKey()

CPubKey AddrToPubKey ( const CChainParams chainparams,
const FillableSigningProvider keystore,
const std::string &  addr_in 
)

Definition at line 218 of file util.cpp.

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

◆ AmountFromValue()

Amount AmountFromValue ( const UniValue value)

Definition at line 68 of file util.cpp.

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

◆ CheckRequiredOrDefault()

static void CheckRequiredOrDefault ( const RPCArg param)
static

Definition at line 685 of file util.cpp.

◆ DescribeAddress()

UniValue DescribeAddress ( const CTxDestination dest)

Definition at line 314 of file util.cpp.

Here is the caller graph for this function:

◆ DetailMaybeArg()

static const UniValue * DetailMaybeArg ( CheckFn check,
const std::vector< RPCArg > &  params,
const JSONRPCRequest req,
size_t  i 
)
static

Definition at line 666 of file util.cpp.

◆ EvalDescriptorStringOrObject()

std::vector< CScript > EvalDescriptorStringOrObject ( const UniValue scanobject,
FlatSigningProvider provider 
)

Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000.

Definition at line 1382 of file util.cpp.

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

◆ ExpectedType() [1/2]

static std::optional< UniValue::VType > ExpectedType ( RPCArg::Type  type)
static

Definition at line 875 of file util.cpp.

Here is the caller graph for this function:

◆ ExpectedType() [2/2]

static std::optional< UniValue::VType > ExpectedType ( RPCResult::Type  type)
static

Definition at line 1130 of file util.cpp.

◆ GetAllOutputTypes()

std::string GetAllOutputTypes ( )

Definition at line 318 of file util.cpp.

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

◆ GetServicesNames()

UniValue GetServicesNames ( ServiceFlags  services)

Returns, given services flags, a list of humanly readable (known) network services.

Definition at line 1429 of file util.cpp.

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

◆ HelpExampleCli()

std::string HelpExampleCli ( const std::string &  methodname,
const std::string &  args 
)

Definition at line 163 of file util.cpp.

◆ HelpExampleCliNamed()

std::string HelpExampleCliNamed ( const std::string &  methodname,
const RPCArgList args 
)

Definition at line 168 of file util.cpp.

Here is the caller graph for this function:

◆ HelpExampleRpc()

std::string HelpExampleRpc ( const std::string &  methodname,
const std::string &  args 
)

Definition at line 180 of file util.cpp.

◆ HelpExampleRpcNamed()

std::string HelpExampleRpcNamed ( const std::string &  methodname,
const RPCArgList args 
)

Definition at line 189 of file util.cpp.

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

◆ HexToPubKey()

CPubKey HexToPubKey ( const std::string &  hex_in)

Definition at line 204 of file util.cpp.

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

◆ JSONRPCPSBTError()

UniValue JSONRPCPSBTError ( PSBTError  err)

Definition at line 351 of file util.cpp.

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

◆ JSONRPCTransactionError()

UniValue JSONRPCTransactionError ( TransactionError  terr,
const std::string &  err_string 
)

Definition at line 356 of file util.cpp.

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

◆ ParseDescriptorRange()

std::pair< int64_t, int64_t > ParseDescriptorRange ( const UniValue value)

Parse a JSON range specified as int64, or [int64, int64].

Definition at line 1365 of file util.cpp.

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

◆ ParseHashO()

uint256 ParseHashO ( const UniValue o,
std::string  strKey 
)

Definition at line 103 of file util.cpp.

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

◆ ParseHashV()

uint256 ParseHashV ( const UniValue v,
std::string  strName 
)

Utilities: convert hex-encoded values (throws error if not hex).

Definition at line 86 of file util.cpp.

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

◆ ParseHexO()

std::vector< uint8_t > ParseHexO ( const UniValue o,
std::string  strKey 
)

Definition at line 121 of file util.cpp.

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

◆ ParseHexV()

std::vector< uint8_t > ParseHexV ( const UniValue v,
std::string  strName 
)

Definition at line 107 of file util.cpp.

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

◆ ParseRange()

static std::pair< int64_t, int64_t > ParseRange ( const UniValue value)
static

Definition at line 1346 of file util.cpp.

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

◆ RPCErrorFromPSBTError()

RPCErrorCode RPCErrorFromPSBTError ( PSBTError  err)

Definition at line 327 of file util.cpp.

Here is the caller graph for this function:

◆ RPCErrorFromTransactionError()

RPCErrorCode RPCErrorFromTransactionError ( TransactionError  terr)

Definition at line 339 of file util.cpp.

Here is the caller graph for this function:

◆ RPCTypeCheckObj()

void RPCTypeCheckObj ( const UniValue o,
const std::map< std::string, UniValueType > &  typesExpected,
bool  fAllowNull,
bool  fStrict 
)

Check for expected keys/value types in an Object.

Definition at line 39 of file util.cpp.

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

◆ TMPL_INST() [1/7]

TMPL_INST ( CheckRequiredOrDefault  ,
bool  ,
CHECK_NONFATAL(maybe_arg) ->get_bool();   
)

◆ TMPL_INST() [2/7]

TMPL_INST ( CheckRequiredOrDefault  ,
const std::string &  ,
CHECK_NONFATAL(maybe_arg) ->get_str();   
)

◆ TMPL_INST() [3/7]

TMPL_INST ( CheckRequiredOrDefault  ,
int  ,
CHECK_NONFATAL(maybe_arg) ->getInt< int >();   
)

◆ TMPL_INST() [4/7]

TMPL_INST ( CheckRequiredOrDefault  ,
uint64_t  ,
CHECK_NONFATAL(maybe_arg) ->getInt< uint64_t >();   
)

◆ TMPL_INST() [5/7]

TMPL_INST ( nullptr  ,
const std::string *  ,
maybe_arg ? &maybe_arg->get_str() :nullptr;   
)

◆ TMPL_INST() [6/7]

TMPL_INST ( nullptr  ,
std::optional< bool >  ,
maybe_arg ? std::optional{maybe_arg->get_bool()} :std::nullopt;   
)

◆ TMPL_INST() [7/7]

TMPL_INST ( nullptr  ,
std::optional< double >  ,
maybe_arg ? std::optional{maybe_arg->get_real()} :std::nullopt;   
)

Variable Documentation

◆ EXAMPLE_ADDRESS

const std::string EXAMPLE_ADDRESS
Initial value:
=
"\"qrmzys48glkpevp2l4t24jtcltc9hyzx9cep2qffm4\""

Example CashAddr address used in multiple RPCExamples.

Definition at line 36 of file util.cpp.

◆ UNIX_EPOCH_TIME

const std::string UNIX_EPOCH_TIME = "UNIX epoch time"

String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.

Definition at line 35 of file util.cpp.