Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Functions | Variables
util.cpp File Reference
#include <key_io.h>
#include <outputtype.h>
#include <rpc/util.h>
#include <script/descriptor.h>
#include <script/signingprovider.h>
#include <tinyformat.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/translation.h>
#include <tuple>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
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...
 

Functions

void RPCTypeCheck (const UniValue &params, const std::list< UniValueType > &typesExpected, bool fAllowNull)
 Type-check arguments; throws JSONRPCError if wrong type given. More...
 
void RPCTypeCheckArgument (const UniValue &value, const UniValueType &typeExpected)
 Type-check one argument; throws JSONRPCError if wrong type given. More...
 
void RPCTypeCheckObj (const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
 
CAmount AmountFromValue (const UniValue &value, int decimals)
 Validate and return a CAmount from a UniValue number or string. More...
 
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< unsigned char > ParseHexV (const UniValue &v, std::string strName)
 
std::vector< unsigned char > 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 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)
 
unsigned int ParseConfirmTarget (const UniValue &value, unsigned int max_target)
 Parse a confirm target option and raise an RPC error if it is invalid. More...
 
RPCErrorCode RPCErrorFromTransactionError (TransactionError terr)
 
UniValue JSONRPCTransactionError (TransactionError terr, const std::string &err_string)
 
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 [2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"}
 Example bech32 addresses for the RPCExamples help documentation. More...
 

Function Documentation

◆ AddAndGetMultisigDestination()

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

Definition at line 225 of file util.cpp.

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

◆ AddrToPubKey()

CPubKey AddrToPubKey ( const FillableSigningProvider keystore,
const std::string &  addr_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:

◆ AmountFromValue()

CAmount AmountFromValue ( const UniValue value,
int  decimals = 8 
)

Validate and return a CAmount from a UniValue number or string.

Parameters
[in]valueUniValue number or string to parse.
[in]decimalsNumber of significant digits (default: 8).
Returns
a CAmount if the various checks pass.

Definition at line 77 of file util.cpp.

Here is the call graph for this function:

◆ DescribeAddress()

UniValue DescribeAddress ( const CTxDestination dest)

Definition at line 324 of file util.cpp.

Here is the caller graph for this function:

◆ 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 991 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 1029 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 155 of file util.cpp.

◆ HelpExampleCliNamed()

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

Definition at line 160 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 173 of file util.cpp.

◆ HelpExampleRpcNamed()

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

Definition at line 179 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 191 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 358 of file util.cpp.

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

◆ ParseConfirmTarget()

unsigned int ParseConfirmTarget ( const UniValue value,
unsigned int  max_target 
)

Parse a confirm target option and raise an RPC error if it is invalid.

Definition at line 329 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 975 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 98 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 89 of file util.cpp.

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

◆ ParseHexO()

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

Definition at line 111 of file util.cpp.

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

◆ ParseHexV()

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

Definition at line 102 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 961 of file util.cpp.

Here is the call graph for this function:
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:

◆ RPCTypeCheck()

void RPCTypeCheck ( const UniValue params,
const std::list< UniValueType > &  typesExpected,
bool  fAllowNull = false 
)

Type-check arguments; throws JSONRPCError if wrong type given.

Does not check that the right number of arguments are passed, just that any passed are the correct type.

Definition at line 23 of file util.cpp.

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

◆ RPCTypeCheckArgument()

void RPCTypeCheckArgument ( const UniValue value,
const UniValueType typeExpected 
)

Type-check one argument; throws JSONRPCError if wrong type given.

Definition at line 40 of file util.cpp.

Here is the call graph for this function:
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 
)

Definition at line 47 of file util.cpp.

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

Variable Documentation

◆ EXAMPLE_ADDRESS

const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"}

Example bech32 addresses for the RPCExamples help documentation.

They are intentionally invalid to prevent accidental transactions by users.

Definition at line 21 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 20 of file util.cpp.