Bitcoin Core 29.99.0
P2P Digital Currency
Classes | Enumerations | Functions
request.h File Reference
#include <any>
#include <optional>
#include <string>
#include <univalue.h>
#include <util/fs.h>
Include dependency graph for request.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  JSONRPCRequest
 

Enumerations

enum class  JSONRPCVersion { V1_LEGACY , V2 }
 
enum class  GenerateAuthCookieResult : uint8_t { DISABLED , ERR , OK }
 

Functions

UniValue JSONRPCRequestObj (const std::string &strMethod, const UniValue &params, const UniValue &id)
 JSON-RPC 2.0 request, only used in bitcoin-cli. More...
 
UniValue JSONRPCReplyObj (UniValue result, UniValue error, std::optional< UniValue > id, JSONRPCVersion jsonrpc_version)
 
UniValue JSONRPCError (int code, const std::string &message)
 
GenerateAuthCookieResult GenerateAuthCookie (const std::optional< fs::perms > &cookie_perms, std::string &user, std::string &pass)
 Generate a new RPC authentication cookie and write it to disk. More...
 
bool GetAuthCookie (std::string *cookie_out)
 Read the RPC authentication cookie from disk. More...
 
void DeleteAuthCookie ()
 Delete RPC authentication cookie from disk. More...
 
std::vector< UniValueJSONRPCProcessBatchReply (const UniValue &in)
 Parse JSON-RPC batch reply into a vector. More...
 

Enumeration Type Documentation

◆ GenerateAuthCookieResult

enum class GenerateAuthCookieResult : uint8_t
strong
Enumerator
DISABLED 
ERR 
OK 

Definition at line 26 of file request.h.

◆ JSONRPCVersion

enum class JSONRPCVersion
strong
Enumerator
V1_LEGACY 
V2 

Definition at line 16 of file request.h.

Function Documentation

◆ DeleteAuthCookie()

void DeleteAuthCookie ( )

Delete RPC authentication cookie from disk.

Definition at line 167 of file request.cpp.

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

◆ GenerateAuthCookie()

GenerateAuthCookieResult GenerateAuthCookie ( const std::optional< fs::perms > &  cookie_perms,
std::string &  user,
std::string &  pass 
)

Generate a new RPC authentication cookie and write it to disk.

Parameters
[in]cookie_permsFilesystem permissions to use for the cookie file.
[out]userGenerated username, only set if OK is returned.
[out]passGenerated password, only set if OK is returned.
Return values
GenerateAuthCookieResult::DISABLEDAuthentication via cookie is disabled.
GenerateAuthCookieResult::ERRORError occurred, auth data could not be saved to disk.
GenerateAuthCookieResult::OKAuth data was generated, saved to disk and in user and pass.

the umask determines what permissions are used to create this file - these are set to 0077 in common/system.cpp.

Definition at line 100 of file request.cpp.

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

◆ GetAuthCookie()

bool GetAuthCookie ( std::string *  cookie_out)

Read the RPC authentication cookie from disk.

Definition at line 148 of file request.cpp.

Here is the call graph for this function:

◆ JSONRPCError()

UniValue JSONRPCError ( int  code,
const std::string &  message 
)

Definition at line 70 of file request.cpp.

Here is the call graph for this function:

◆ JSONRPCProcessBatchReply()

std::vector< UniValue > JSONRPCProcessBatchReply ( const UniValue in)

Parse JSON-RPC batch reply into a vector.

Definition at line 179 of file request.cpp.

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

◆ JSONRPCReplyObj()

UniValue JSONRPCReplyObj ( UniValue  result,
UniValue  error,
std::optional< UniValue id,
JSONRPCVersion  jsonrpc_version 
)

Definition at line 51 of file request.cpp.

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

◆ JSONRPCRequestObj()

UniValue JSONRPCRequestObj ( const std::string &  strMethod,
const UniValue params,
const UniValue id 
)

JSON-RPC 2.0 request, only used in bitcoin-cli.

JSON-RPC 2.0 request, only used in bitcoin-cli.

Bitcoin speaks version 1.0 for maximum compatibility, but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were unspecified (HTTP errors and contents of 'error').

1.0 spec: http://json-rpc.org/wiki/specification 1.2 spec: http://jsonrpc.org/historical/json-rpc-over-http.html

If the server receives a request with the JSON-RPC 2.0 marker {"jsonrpc": "2.0"} then Bitcoin will respond with a strictly specified response. It will only return an HTTP error code if an actual HTTP error is encountered such as the endpoint is not found (404) or the request is not formatted correctly (500). Otherwise the HTTP code is always OK (200) and RPC errors will be included in the response body.

2.0 spec: https://www.jsonrpc.org/specification

Also see http://www.simple-is-better.org/rpc/#differences-between-1-0-and-2-0

Definition at line 41 of file request.cpp.

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