Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Functions | Variables
bitcoin-cli.cpp File Reference
#include <chainparamsbase.h>
#include <clientversion.h>
#include <policy/feerate.h>
#include <rpc/client.h>
#include <rpc/mining.h>
#include <rpc/protocol.h>
#include <rpc/request.h>
#include <tinyformat.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/translation.h>
#include <util/url.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <memory>
#include <optional>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unistd.h>
#include <event2/buffer.h>
#include <event2/keyvalq_struct.h>
#include <support/events.h>
#include <univalue.h>
#include <compat/stdin.h>
Include dependency graph for bitcoin-cli.cpp:

Go to the source code of this file.

Classes

class  CConnectionFailed
 
struct  HTTPReply
 Reply structure for request_done to fill in. More...
 
class  BaseRequestHandler
 Class that handles the conversion from a command-line to a JSON-RPC request, as well as converting back to a JSON object that can be shown as result. More...
 
class  AddrinfoRequestHandler
 Process addrinfo requests. More...
 
class  GetinfoRequestHandler
 Process getinfo requests. More...
 
class  NetinfoRequestHandler
 Process netinfo requests. More...
 
struct  NetinfoRequestHandler::Peer
 
class  GenerateToAddressRequestHandler
 Process RPC generatetoaddress request. More...
 
class  DefaultRequestHandler
 Process default single requests. More...
 

Functions

static void SetupCliArgs (ArgsManager &argsman)
 
static void libevent_log_cb (int severity, const char *msg)
 libevent event log callback More...
 
static int AppInitRPC (int argc, char *argv[])
 
static std::string http_errorstring (int code)
 
static void http_request_done (struct evhttp_request *req, void *ctx)
 
static UniValue CallRPC (BaseRequestHandler *rh, const std::string &strMethod, const std::vector< std::string > &args, const std::optional< std::string > &rpcwallet={})
 
static UniValue ConnectAndCallRPC (BaseRequestHandler *rh, const std::string &strMethod, const std::vector< std::string > &args, const std::optional< std::string > &rpcwallet={})
 ConnectAndCallRPC wraps CallRPC with -rpcwait and an exception handler. More...
 
static void ParseResult (const UniValue &result, std::string &strPrint)
 Parse UniValue result to update the message to print to std::cout. More...
 
static void ParseError (const UniValue &error, std::string &strPrint, int &nRet)
 Parse UniValue error to update the message to print to std::cerr and the code to return. More...
 
static void GetWalletBalances (UniValue &result)
 GetWalletBalances calls listwallets; if more than one wallet is loaded, it then fetches mine.trusted balances for each loaded wallet and pushes them to result. More...
 
static void GetProgressBar (double progress, std::string &progress_bar)
 GetProgressBar constructs a progress bar with 5% intervals. More...
 
static void ParseGetInfoResult (UniValue &result)
 ParseGetInfoResult takes in -getinfo result in UniValue object and parses it into a user friendly UniValue string to be printed on the console. More...
 
static UniValue GetNewAddress ()
 Call RPC getnewaddress. More...
 
static void SetGenerateToAddressArgs (const std::string &address, std::vector< std::string > &args)
 Check bounds and set up args for RPC generatetoaddress params: nblocks, address, maxtries. More...
 
static int CommandLineRPC (int argc, char *argv[])
 
int main (int argc, char *argv[])
 

Variables

const std::function< std::string(const char *)> G_TRANSLATION_FUN = nullptr
 Translate string to current locale using Qt. More...
 
UrlDecodeFn *const URL_DECODE = urlDecode
 
static const char DEFAULT_RPCCONNECT [] = "127.0.0.1"
 
static const int DEFAULT_HTTP_CLIENT_TIMEOUT =900
 
static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0
 
static const bool DEFAULT_NAMED =false
 
static const int CONTINUE_EXECUTION =-1
 
static constexpr int8_t UNKNOWN_NETWORK {-1}
 
static const std::string DEFAULT_NBLOCKS = "1"
 Default number of blocks to generate for RPC generatetoaddress. More...
 
static const std::string DEFAULT_COLOR_SETTING {"auto"}
 Default -color setting. More...
 

Function Documentation

◆ AppInitRPC()

static int AppInitRPC ( int  argc,
char *  argv[] 
)
static

Definition at line 120 of file bitcoin-cli.cpp.

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

◆ CallRPC()

static UniValue CallRPC ( BaseRequestHandler rh,
const std::string &  strMethod,
const std::vector< std::string > &  args,
const std::optional< std::string > &  rpcwallet = {} 
)
static

Definition at line 696 of file bitcoin-cli.cpp.

Here is the caller graph for this function:

◆ CommandLineRPC()

static int CommandLineRPC ( int  argc,
char *  argv[] 
)
static

Definition at line 1057 of file bitcoin-cli.cpp.

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

◆ ConnectAndCallRPC()

static UniValue ConnectAndCallRPC ( BaseRequestHandler rh,
const std::string &  strMethod,
const std::vector< std::string > &  args,
const std::optional< std::string > &  rpcwallet = {} 
)
static

ConnectAndCallRPC wraps CallRPC with -rpcwait and an exception handler.

Parameters
[in]rhPointer to RequestHandler.
[in]strMethodReference to const string method to forward to CallRPC.
[in]rpcwalletReference to const optional string wallet name to forward to CallRPC.
Returns
the RPC response as a UniValue object.
Exceptions
aCConnectionFailed std::runtime_error if connection failed or RPC server still in warmup.

Definition at line 820 of file bitcoin-cli.cpp.

Here is the caller graph for this function:

◆ GetNewAddress()

static UniValue GetNewAddress ( )
static

Call RPC getnewaddress.

Returns
getnewaddress response as a UniValue object.

Definition at line 1033 of file bitcoin-cli.cpp.

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

◆ GetProgressBar()

static void GetProgressBar ( double  progress,
std::string &  progress_bar 
)
static

GetProgressBar constructs a progress bar with 5% intervals.

Parameters
[in]progressThe proportion of the progress bar to be filled between 0 and 1.
[out]progress_barString representation of the progress bar.

Definition at line 908 of file bitcoin-cli.cpp.

Here is the caller graph for this function:

◆ GetWalletBalances()

static void GetWalletBalances ( UniValue result)
static

GetWalletBalances calls listwallets; if more than one wallet is loaded, it then fetches mine.trusted balances for each loaded wallet and pushes them to result.

Parameters
resultReference to UniValue object the wallet names and balances are pushed to.

Definition at line 884 of file bitcoin-cli.cpp.

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

◆ http_errorstring()

static std::string http_errorstring ( int  code)
static

Definition at line 175 of file bitcoin-cli.cpp.

◆ http_request_done()

static void http_request_done ( struct evhttp_request *  req,
void *  ctx 
)
static

Definition at line 197 of file bitcoin-cli.cpp.

◆ libevent_log_cb()

static void libevent_log_cb ( int  severity,
const char *  msg 
)
static

libevent event log callback

Definition at line 94 of file bitcoin-cli.cpp.

Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 1187 of file bitcoin-cli.cpp.

Here is the call graph for this function:

◆ ParseError()

static void ParseError ( const UniValue error,
std::string &  strPrint,
int &  nRet 
)
static

Parse UniValue error to update the message to print to std::cerr and the code to return.

Definition at line 858 of file bitcoin-cli.cpp.

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

◆ ParseGetInfoResult()

static void ParseGetInfoResult ( UniValue result)
static

ParseGetInfoResult takes in -getinfo result in UniValue object and parses it into a user friendly UniValue string to be printed on the console.

Parameters
[out]resultReference to UniValue result containing the -getinfo output.

Definition at line 930 of file bitcoin-cli.cpp.

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

◆ ParseResult()

static void ParseResult ( const UniValue result,
std::string &  strPrint 
)
static

Parse UniValue result to update the message to print to std::cout.

Definition at line 851 of file bitcoin-cli.cpp.

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

◆ SetGenerateToAddressArgs()

static void SetGenerateToAddressArgs ( const std::string &  address,
std::vector< std::string > &  args 
)
static

Check bounds and set up args for RPC generatetoaddress params: nblocks, address, maxtries.

Parameters
[in]addressReference to const string address to insert into the args.
argsReference to vector of string args to modify.

Definition at line 1046 of file bitcoin-cli.cpp.

Here is the caller graph for this function:

◆ SetupCliArgs()

static void SetupCliArgs ( ArgsManager argsman)
static

Definition at line 59 of file bitcoin-cli.cpp.

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

Variable Documentation

◆ CONTINUE_EXECUTION

const int CONTINUE_EXECUTION =-1
static

Definition at line 50 of file bitcoin-cli.cpp.

◆ DEFAULT_COLOR_SETTING

const std::string DEFAULT_COLOR_SETTING {"auto"}
static

Default -color setting.

Definition at line 57 of file bitcoin-cli.cpp.

◆ DEFAULT_HTTP_CLIENT_TIMEOUT

const int DEFAULT_HTTP_CLIENT_TIMEOUT =900
static

Definition at line 47 of file bitcoin-cli.cpp.

◆ DEFAULT_NAMED

const bool DEFAULT_NAMED =false
static

Definition at line 49 of file bitcoin-cli.cpp.

◆ DEFAULT_NBLOCKS

const std::string DEFAULT_NBLOCKS = "1"
static

Default number of blocks to generate for RPC generatetoaddress.

Definition at line 54 of file bitcoin-cli.cpp.

◆ DEFAULT_RPCCONNECT

const char DEFAULT_RPCCONNECT[] = "127.0.0.1"
static

Definition at line 46 of file bitcoin-cli.cpp.

◆ DEFAULT_WAIT_CLIENT_TIMEOUT

constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0
staticconstexpr

Definition at line 48 of file bitcoin-cli.cpp.

◆ G_TRANSLATION_FUN

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr

Translate string to current locale using Qt.

Translate a message to the native language of the user.

Definition at line 43 of file bitcoin-cli.cpp.

◆ UNKNOWN_NETWORK

constexpr int8_t UNKNOWN_NETWORK {-1}
staticconstexpr

Definition at line 51 of file bitcoin-cli.cpp.

◆ URL_DECODE

UrlDecodeFn* const URL_DECODE = urlDecode

Definition at line 44 of file bitcoin-cli.cpp.