Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
rest.cpp File Reference
#include <rest.h>
#include <blockfilter.h>
#include <chain.h>
#include <coins.h>
#include <consensus/params.h>
#include <core_io.h>
#include <crypto/hex_base.h>
#include <flatfile.h>
#include <httpserver.h>
#include <index/blockfilterindex.h>
#include <index/txindex.h>
#include <node/blockstorage.h>
#include <node/context.h>
#include <node/transaction.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <rpc/blockchain.h>
#include <rpc/mempool.h>
#include <rpc/protocol.h>
#include <rpc/request.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <serialize.h>
#include <streams.h>
#include <sync.h>
#include <tinyformat.h>
#include <txmempool.h>
#include <uint256.h>
#include <undo.h>
#include <univalue.h>
#include <util/any.h>
#include <util/check.h>
#include <util/overflow.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <validation.h>
#include <any>
#include <cstdint>
#include <cstring>
#include <ios>
#include <memory>
#include <optional>
#include <span>
#include <stdexcept>
#include <string_view>
#include <utility>
#include <vector>
Include dependency graph for rest.cpp:

Go to the source code of this file.

Classes

struct  CCoin
struct  [struct].rf_names
struct  [struct].uri_prefixes

Functions

static bool RESTERR (HTTPRequest *req, enum HTTPStatusCode status, std::string message)
static NodeContext * GetNodeContext (const std::any &context, HTTPRequest *req)
 Get the node context.
static CTxMemPool * GetMemPool (const std::any &context, HTTPRequest *req)
 Get the node context mempool.
static ChainstateManager * GetChainman (const std::any &context, HTTPRequest *req)
 Get the node context chainstatemanager.
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.
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.
static void BlockUndoToJSON (const CBlockUndo &block_undo, UniValue &result)
 Serialize spent outputs as a list of per-transaction CTxOut lists using JSON format.
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:
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.
void InterruptREST ()
 Interrupt RPC REST subsystem.
void StopREST ()
 Stop HTTP REST subsystem.
CTransactionRef GetTransaction (const CBlockIndex *block_index, const CTxMemPool *mempool, const Txid &hash, const BlockManager &blockman, uint256 &hashBlock)
 Return transaction with a given hash.
std::vector< std::string > SplitString (std::string_view str, char sep)

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.
static constexpr const char * REST_CACHE_NO_STORE = "no-store"
 Mutable, node-local, or error response; must not be cached.
static const struct  rf_names []
static const struct  uri_prefixes []

Function Documentation

◆ AvailableDataFormatsString()

std::string AvailableDataFormatsString ( )
static

Definition at line 177 of file rest.cpp.

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

◆ BlockUndoToJSON()

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 321 of file rest.cpp.

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

◆ CheckWarmup()

bool CheckWarmup ( HTTPRequest * req)
static

Definition at line 194 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 1399 of file blockchain.cpp.

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

◆ GetChainman()

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 142 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 1545 of file blockchain.cpp.

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

◆ GetMemPool()

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 125 of file rest.cpp.

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

◆ GetNodeContext()

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 108 of file rest.cpp.

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

◆ GetTransaction()

CTransactionRef node::GetTransaction ( const CBlockIndex *const block_index,
const CTxMemPool *const mempool,
const Txid & hash,
const BlockManager & blockman,
uint256 & hashBlock )

Return transaction with a given hash.

If mempool is provided and block_index is not provided, check it first for the tx. If -txindex is available, check it next for the tx. Finally, if block_index is provided, check for tx by reading entire block from disk.

Parameters
[in]block_indexThe block to read from disk, or nullptr
[in]mempoolIf provided, check mempool for tx
[in]hashThe txid
[in]blockmanUsed to access and read blocks from disk
[out]hashBlockThe block hash, if the tx was found via -txindex or block_index
Returns
The tx if found, otherwise nullptr

Definition at line 142 of file transaction.cpp.

Here is the caller graph for this function:

◆ InterruptREST()

void InterruptREST ( )

Interrupt RPC REST subsystem.

Definition at line 1222 of file rest.cpp.

Here is the call graph for this function:
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 152 of file rest.cpp.

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

◆ rest_block()

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 419 of file rest.cpp.

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

◆ rest_block_extended()

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

Definition at line 504 of file rest.cpp.

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

◆ rest_block_filter()

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

Definition at line 659 of file rest.cpp.

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

◆ rest_block_notxdetails()

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

Definition at line 509 of file rest.cpp.

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

◆ rest_block_part()

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

Definition at line 514 of file rest.cpp.

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

◆ rest_blockhash_by_height()

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

Definition at line 1140 of file rest.cpp.

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

◆ rest_chaininfo()

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

Definition at line 756 of file rest.cpp.

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

◆ rest_deploymentinfo()

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

Definition at line 784 of file rest.cpp.

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

◆ rest_filter_header()

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

Definition at line 533 of file rest.cpp.

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

◆ rest_getutxos()

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

Definition at line 943 of file rest.cpp.

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

◆ rest_headers()

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

Definition at line 202 of file rest.cpp.

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

◆ rest_mempool()

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

Definition at line 825 of file rest.cpp.

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

◆ rest_spent_txouts()

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

Definition at line 340 of file rest.cpp.

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

◆ rest_tx()

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

Definition at line 882 of file rest.cpp.

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

◆ RESTERR()

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

Definition at line 93 of file rest.cpp.

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

◆ SerializeBlockUndo()

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 306 of file rest.cpp.

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

◆ SplitString()

std::vector< std::string > util::SplitString ( std::string_view str,
char sep )
inlinenodiscard

Definition at line 153 of file string.h.

◆ StartREST()

void StartREST ( const std::any & context)

Start HTTP REST subsystem.

Precondition; HTTP and RPC has been started.

Definition at line 1214 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 1226 of file rest.cpp.

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

Variable Documentation

◆ MAX_GETUTXOS_OUTPOINTS

const size_t MAX_GETUTXOS_OUTPOINTS = 15
static

Definition at line 60 of file rest.cpp.

◆ MAX_REST_HEADERS_RESULTS

unsigned int MAX_REST_HEADERS_RESULTS = 2000
staticconstexpr

Definition at line 61 of file rest.cpp.

◆ REST_CACHE_IMMUTABLE

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 65 of file rest.cpp.

◆ REST_CACHE_NO_STORE

const char* REST_CACHE_NO_STORE = "no-store"
staticconstexpr

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

Definition at line 67 of file rest.cpp.

◆ rf_names

◆ uri_prefixes

const struct [struct].uri_prefixes 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:202
static bool rest_block_extended(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:504
static bool rest_blockhash_by_height(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition rest.cpp:1140
static bool rest_block_part(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:514
static bool rest_block_filter(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:659
static bool rest_block_notxdetails(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:509
static bool rest_filter_header(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:533
static bool rest_getutxos(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:943
static bool rest_tx(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:882
static bool rest_deploymentinfo(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition rest.cpp:784
static bool rest_mempool(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition rest.cpp:825
static bool rest_chaininfo(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:756
static bool rest_spent_txouts(const std::any &context, HTTPRequest *req, const std::string &uri_part)
Definition rest.cpp:340