Bitcoin Core 31.99.0
P2P Digital Currency
Classes | Functions | Variables
rest.cpp File Reference
#include <rest.h>
#include <blockfilter.h>
#include <chain.h>
#include <chainparams.h>
#include <core_io.h>
#include <flatfile.h>
#include <httpserver.h>
#include <index/blockfilterindex.h>
#include <index/txindex.h>
#include <node/blockstorage.h>
#include <node/context.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <rpc/blockchain.h>
#include <rpc/mempool.h>
#include <rpc/protocol.h>
#include <rpc/server.h>
#include <rpc/server_util.h>
#include <streams.h>
#include <sync.h>
#include <txmempool.h>
#include <undo.h>
#include <util/any.h>
#include <util/check.h>
#include <util/overflow.h>
#include <util/strencodings.h>
#include <validation.h>
#include <any>
#include <vector>
#include <univalue.h>
Include dependency graph for rest.cpp:

Go to the source code of this file.

Classes

struct  CCoin
 

Functions

static bool RESTERR (HTTPRequest *req, enum HTTPStatusCode status, std::string message)
 
static NodeContextGetNodeContext (const std::any &context, HTTPRequest *req)
 Get the node context. More...
 
static CTxMemPoolGetMemPool (const std::any &context, HTTPRequest *req)
 Get the node context mempool. More...
 
static ChainstateManagerGetChainman (const std::any &context, HTTPRequest *req)
 Get the node context chainstatemanager. More...
 
RESTResponseFormat ParseDataFormat (std::string &param, const std::string &strReq)
 Parse a URI to get the data format and URI without data format and query string. More...
 
static std::string AvailableDataFormatsString ()
 
static bool CheckWarmup (HTTPRequest *req)
 
static bool rest_headers (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static void SerializeBlockUndo (DataStream &stream, const CBlockUndo &block_undo)
 Serialize spent outputs as a list of per-transaction CTxOut lists using binary format. More...
 
static void BlockUndoToJSON (const CBlockUndo &block_undo, UniValue &result)
 Serialize spent outputs as a list of per-transaction CTxOut lists using JSON format. More...
 
static bool rest_spent_txouts (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static bool rest_block (const std::any &context, HTTPRequest *req, const std::string &uri_part, std::optional< TxVerbosity > tx_verbosity, std::optional< std::pair< size_t, size_t > > block_part=std::nullopt)
 This handler is used by multiple HTTP endpoints: More...
 
static bool rest_block_extended (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static bool rest_block_notxdetails (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static bool rest_block_part (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static bool rest_filter_header (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static bool rest_block_filter (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
RPCMethod getblockchaininfo ()
 
static bool rest_chaininfo (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
RPCMethod getdeploymentinfo ()
 
static bool rest_deploymentinfo (const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
 
static bool rest_mempool (const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
 
static bool rest_tx (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static bool rest_getutxos (const std::any &context, HTTPRequest *req, const std::string &uri_part)
 
static bool rest_blockhash_by_height (const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
 
void StartREST (const std::any &context)
 Start HTTP REST subsystem. More...
 
void InterruptREST ()
 Interrupt RPC REST subsystem. More...
 
void StopREST ()
 Stop HTTP REST subsystem. More...
 

Variables

static const size_t MAX_GETUTXOS_OUTPOINTS = 15
 
static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000
 
static constexpr const char * REST_CACHE_IMMUTABLE = "public, immutable, max-age=86400"
 Response bytes never change. More...
 
static constexpr const char * REST_CACHE_NO_STORE = "no-store"
 Mutable, node-local, or error response; must not be cached. More...
 
struct {
   RESTResponseFormat   rf
 
   const char *   name
 
rf_names []
 
struct {
   const char *   prefix
 
   bool(*   handler )(const std::any &context,
       HTTPRequest *req, const
      std::string &strReq)
 
uri_prefixes []
 

Function Documentation

◆ AvailableDataFormatsString()

static std::string AvailableDataFormatsString ( )
static

Definition at line 162 of file rest.cpp.

Here is the caller graph for this function:

◆ BlockUndoToJSON()

static void BlockUndoToJSON ( const CBlockUndo block_undo,
UniValue result 
)
static

Serialize spent outputs as a list of per-transaction CTxOut lists using JSON format.

Definition at line 306 of file rest.cpp.

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

◆ CheckWarmup()

static bool CheckWarmup ( HTTPRequest req)
static

Definition at line 179 of file rest.cpp.

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

◆ getblockchaininfo()

RPCMethod getblockchaininfo ( )

Definition at line 1369 of file blockchain.cpp.

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

◆ GetChainman()

static ChainstateManager * GetChainman ( const std::any &  context,
HTTPRequest req 
)
static

Get the node context chainstatemanager.

Parameters
[in]reqThe HTTP request, whose status code will be set if node context chainstatemanager is not found.
Returns
Pointer to the chainstatemanager or nullptr if none found.

Definition at line 127 of file rest.cpp.

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

◆ getdeploymentinfo()

RPCMethod getdeploymentinfo ( )

Definition at line 1515 of file blockchain.cpp.

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

◆ GetMemPool()

static CTxMemPool * GetMemPool ( const std::any &  context,
HTTPRequest req 
)
static

Get the node context mempool.

Parameters
[in]reqThe HTTP request, whose status code will be set if node context mempool is not found.
Returns
Pointer to the mempool or nullptr if no mempool found.

Definition at line 110 of file rest.cpp.

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

◆ GetNodeContext()

static NodeContext * GetNodeContext ( const std::any &  context,
HTTPRequest req 
)
static

Get the node context.

Parameters
[in]reqThe HTTP request, whose status code will be set if node context is not found.
Returns
Pointer to the node context or nullptr if not found.

Definition at line 93 of file rest.cpp.

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

◆ InterruptREST()

void InterruptREST ( )

Interrupt RPC REST subsystem.

Definition at line 1207 of file rest.cpp.

Here is the caller graph for this function:

◆ ParseDataFormat()

RESTResponseFormat ParseDataFormat ( std::string &  param,
const std::string &  strReq 
)

Parse a URI to get the data format and URI without data format and query string.

Parameters
[out]paramThe strReq without the data format string and without the query string (if any).
[in]strReqThe URI to be parsed.
Returns
RESTResponseFormat that was parsed from the URI.

Definition at line 137 of file rest.cpp.

Here is the caller graph for this function:

◆ rest_block()

static bool rest_block ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part,
std::optional< TxVerbosity tx_verbosity,
std::optional< std::pair< size_t, size_t > >  block_part = std::nullopt 
)
static

This handler is used by multiple HTTP endpoints:

Definition at line 404 of file rest.cpp.

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

◆ rest_block_extended()

static bool rest_block_extended ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 489 of file rest.cpp.

Here is the call graph for this function:

◆ rest_block_filter()

static bool rest_block_filter ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 644 of file rest.cpp.

Here is the call graph for this function:

◆ rest_block_notxdetails()

static bool rest_block_notxdetails ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 494 of file rest.cpp.

Here is the call graph for this function:

◆ rest_block_part()

static bool rest_block_part ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 499 of file rest.cpp.

Here is the call graph for this function:

◆ rest_blockhash_by_height()

static bool rest_blockhash_by_height ( const std::any &  context,
HTTPRequest req,
const std::string &  str_uri_part 
)
static

Definition at line 1125 of file rest.cpp.

Here is the call graph for this function:

◆ rest_chaininfo()

static bool rest_chaininfo ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 741 of file rest.cpp.

Here is the call graph for this function:

◆ rest_deploymentinfo()

static bool rest_deploymentinfo ( const std::any &  context,
HTTPRequest req,
const std::string &  str_uri_part 
)
static

Definition at line 769 of file rest.cpp.

Here is the call graph for this function:

◆ rest_filter_header()

static bool rest_filter_header ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 518 of file rest.cpp.

Here is the call graph for this function:

◆ rest_getutxos()

static bool rest_getutxos ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 928 of file rest.cpp.

Here is the call graph for this function:

◆ rest_headers()

static bool rest_headers ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 187 of file rest.cpp.

Here is the call graph for this function:

◆ rest_mempool()

static bool rest_mempool ( const std::any &  context,
HTTPRequest req,
const std::string &  str_uri_part 
)
static

Definition at line 810 of file rest.cpp.

Here is the call graph for this function:

◆ rest_spent_txouts()

static bool rest_spent_txouts ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 325 of file rest.cpp.

Here is the call graph for this function:

◆ rest_tx()

static bool rest_tx ( const std::any &  context,
HTTPRequest req,
const std::string &  uri_part 
)
static

Definition at line 867 of file rest.cpp.

Here is the call graph for this function:

◆ RESTERR()

static bool RESTERR ( HTTPRequest req,
enum HTTPStatusCode  status,
std::string  message 
)
static

Definition at line 78 of file rest.cpp.

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

◆ SerializeBlockUndo()

static void SerializeBlockUndo ( DataStream stream,
const CBlockUndo block_undo 
)
static

Serialize spent outputs as a list of per-transaction CTxOut lists using binary format.

Definition at line 291 of file rest.cpp.

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

◆ StartREST()

void StartREST ( const std::any &  context)

Start HTTP REST subsystem.

Precondition; HTTP and RPC has been started.

Definition at line 1199 of file rest.cpp.

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

◆ StopREST()

void StopREST ( )

Stop HTTP REST subsystem.

Precondition; HTTP and RPC has been stopped.

Definition at line 1211 of file rest.cpp.

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

Variable Documentation

◆ handler

bool(* handler) (const std::any &context, HTTPRequest *req, const std::string &strReq) ( const std::any &  context,
HTTPRequest req,
const std::string &  strReq 
)

Definition at line 1181 of file rest.cpp.

◆ MAX_GETUTXOS_OUTPOINTS

const size_t MAX_GETUTXOS_OUTPOINTS = 15
static

Definition at line 45 of file rest.cpp.

◆ MAX_REST_HEADERS_RESULTS

constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000
staticconstexpr

Definition at line 46 of file rest.cpp.

◆ name

const char* name

Definition at line 56 of file rest.cpp.

◆ prefix

const char* prefix

Definition at line 1180 of file rest.cpp.

◆ REST_CACHE_IMMUTABLE

constexpr const char* REST_CACHE_IMMUTABLE = "public, immutable, max-age=86400"
staticconstexpr

Response bytes never change.

One-day TTL limits staleness across software upgrades.

Definition at line 50 of file rest.cpp.

◆ REST_CACHE_NO_STORE

constexpr const char* REST_CACHE_NO_STORE = "no-store"
staticconstexpr

Mutable, node-local, or error response; must not be cached.

Definition at line 52 of file rest.cpp.

◆ rf

Definition at line 55 of file rest.cpp.

◆ 

const struct { ... } rf_names[]

◆ 

const struct { ... } uri_prefixes[]
Initial value:
= {
{"/rest/tx/", rest_tx},
{"/rest/block/notxdetails/", rest_block_notxdetails},
{"/rest/block/", rest_block_extended},
{"/rest/blockpart/", rest_block_part},
{"/rest/blockfilter/", rest_block_filter},
{"/rest/blockfilterheaders/", rest_filter_header},
{"/rest/chaininfo", rest_chaininfo},
{"/rest/mempool/", rest_mempool},
{"/rest/headers/", rest_headers},
{"/rest/getutxos", rest_getutxos},
{"/rest/deploymentinfo/", rest_deploymentinfo},
{"/rest/deploymentinfo", rest_deploymentinfo},
{"/rest/blockhashbyheight/", rest_blockhash_by_height},
{"/rest/spenttxouts/", rest_spent_txouts},
}
static bool rest_headers(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:187
static bool rest_block_extended(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:489
static bool rest_blockhash_by_height(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:1125
static bool rest_block_part(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:499
static bool rest_block_filter(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:644
static bool rest_block_notxdetails(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:494
static bool rest_filter_header(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:518
static bool rest_getutxos(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:928
static bool rest_tx(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:867
static bool rest_deploymentinfo(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:769
static bool rest_mempool(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:810
static bool rest_chaininfo(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:741
static bool rest_spent_txouts(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition: rest.cpp:325