Bitcoin Core  27.99.0
P2P Digital Currency
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
util.h File Reference
#include <addresstype.h>
#include <consensus/amount.h>
#include <node/transaction.h>
#include <outputtype.h>
#include <pubkey.h>
#include <rpc/protocol.h>
#include <rpc/request.h>
#include <script/script.h>
#include <script/sign.h>
#include <uint256.h>
#include <univalue.h>
#include <util/check.h>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <initializer_list>
#include <map>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  UniValueType
 Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type. More...
 
struct  RPCArgOptions
 
struct  RPCArg
 
struct  RPCResult
 
struct  RPCResults
 
struct  RPCExamples
 
class  RPCHelpMan
 

Namespaces

 common
 
 node
 

Typedefs

using RPCArgList = std::vector< std::pair< std::string, UniValue > >
 

Enumerations

enum class  OuterType { ARR , OBJ , NONE }
 Serializing JSON objects depends on the outer type. More...
 

Functions

std::string GetAllOutputTypes ()
 Gets all existing output types formatted for RPC help sections. More...
 
void RPCTypeCheckObj (const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull=false, bool fStrict=false)
 
uint256 ParseHashV (const UniValue &v, std::string_view name)
 Utilities: convert hex-encoded Values (throws error if not hex). More...
 
uint256 ParseHashO (const UniValue &o, std::string_view strKey)
 
std::vector< unsigned char > ParseHexV (const UniValue &v, std::string_view name)
 
std::vector< unsigned char > ParseHexO (const UniValue &o, std::string_view strKey)
 
CAmount AmountFromValue (const UniValue &value, int decimals=8)
 Validate and return a CAmount from a UniValue number or string. More...
 
CFeeRate ParseFeeRate (const UniValue &json)
 Parse a json number or string, denoting BTC/kvB, into a CFeeRate (sat/kvB). More...
 
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, FlatSigningProvider &keystore, CScript &script_out)
 
UniValue DescribeAddress (const CTxDestination &dest)
 
int ParseSighashString (const UniValue &sighash)
 Parse a sighash string representation and raise an RPC error if it is invalid. More...
 
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 (node::TransactionError terr)
 
UniValue JSONRPCPSBTError (common::PSBTError err)
 
UniValue JSONRPCTransactionError (node::TransactionError terr, const std::string &err_string="")
 
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, const bool expand_priv=false)
 Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000. More...
 
void PushWarnings (const UniValue &warnings, UniValue &obj)
 Push warning messages to an RPC "warnings" field as a JSON array of strings. More...
 
void PushWarnings (const std::vector< bilingual_str > &warnings, UniValue &obj)
 
UniValue GetNodeWarnings (bool use_deprecated)
 

Variables

static constexpr bool DEFAULT_RPC_DOC_CHECK
 
const std::string 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]
 Example bech32 addresses for the RPCExamples help documentation. More...
 

Typedef Documentation

◆ RPCArgList

using RPCArgList = std::vector<std::pair<std::string, UniValue> >

Definition at line 117 of file util.h.

Enumeration Type Documentation

◆ OuterType

enum OuterType
strong

Serializing JSON objects depends on the outer type.

Only arrays and dictionaries can be nested in json. The top-level outer type is "NONE".

Enumerator
ARR 
OBJ 
NONE 

Definition at line 149 of file util.h.

Function Documentation

◆ AddAndGetMultisigDestination()

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

Definition at line 242 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 221 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 84 of file util.cpp.

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

◆ DescribeAddress()

UniValue DescribeAddress ( const CTxDestination dest)

Definition at line 346 of file util.cpp.

Here is the caller graph for this function:

◆ EvalDescriptorStringOrObject()

std::vector<CScript> EvalDescriptorStringOrObject ( const UniValue scanobject,
FlatSigningProvider provider,
const bool  expand_priv = false 
)

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

Definition at line 1322 of file util.cpp.

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

◆ GetAllOutputTypes()

std::string GetAllOutputTypes ( )

Gets all existing output types formatted for RPC help sections.

Returns
Comma separated string representing output type names.

Definition at line 47 of file util.cpp.

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

◆ GetNodeWarnings()

UniValue GetNodeWarnings ( bool  use_deprecated)

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

◆ HelpExampleCliNamed()

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

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

◆ HelpExampleRpcNamed()

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

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

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

◆ JSONRPCPSBTError()

UniValue JSONRPCPSBTError ( common::PSBTError  err)

◆ JSONRPCTransactionError()

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

◆ 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 368 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 1306 of file util.cpp.

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

◆ ParseFeeRate()

CFeeRate ParseFeeRate ( const UniValue json)

Parse a json number or string, denoting BTC/kvB, into a CFeeRate (sat/kvB).

Reject negative values or rates larger than 1BTC/kvB.

Definition at line 96 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_view  strKey 
)

Definition at line 112 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_view  name 
)

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

Definition at line 103 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_view  strKey 
)

Definition at line 125 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_view  name 
)

Definition at line 116 of file util.cpp.

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

◆ ParseSighashString()

int ParseSighashString ( const UniValue sighash)

Parse a sighash string representation and raise an RPC error if it is invalid.

Parse a sighash string representation and raise an RPC error if it is invalid.

Precondition
The sighash argument should be string or null.

Definition at line 356 of file util.cpp.

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

◆ PushWarnings() [1/2]

void PushWarnings ( const std::vector< bilingual_str > &  warnings,
UniValue obj 
)

Definition at line 1380 of file util.cpp.

Here is the call graph for this function:

◆ PushWarnings() [2/2]

void PushWarnings ( const UniValue warnings,
UniValue obj 
)

Push warning messages to an RPC "warnings" field as a JSON array of strings.

Parameters
[in]warningsWarning messages to push.
[out]objUniValue object to push the warnings array object to.

Definition at line 1374 of file util.cpp.

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

◆ RPCErrorFromTransactionError()

RPCErrorCode RPCErrorFromTransactionError ( node::TransactionError  terr)

◆ RPCTypeCheckObj()

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

Definition at line 57 of file util.cpp.

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

Variable Documentation

◆ DEFAULT_RPC_DOC_CHECK

constexpr bool DEFAULT_RPC_DOC_CHECK
staticconstexpr
Initial value:
{
false
}

Definition at line 46 of file util.h.

◆ EXAMPLE_ADDRESS

const std::string EXAMPLE_ADDRESS[2]
extern

Example bech32 addresses for the RPCExamples help documentation.

They are intentionally invalid to prevent accidental transactions by users.

Definition at line 45 of file util.cpp.

◆ UNIX_EPOCH_TIME

const std::string UNIX_EPOCH_TIME
extern

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

Definition at line 44 of file util.cpp.