Bitcoin Core 22.99.0
P2P Digital Currency
blockchain.h
Go to the documentation of this file.
1// Copyright (c) 2017-2020 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_RPC_BLOCKCHAIN_H
6#define BITCOIN_RPC_BLOCKCHAIN_H
7
8#include <consensus/amount.h>
9#include <core_io.h>
10#include <streams.h>
11#include <sync.h>
12
13#include <any>
14#include <stdint.h>
15#include <vector>
16
18
19class CBlock;
20class CBlockIndex;
22class CChainState;
23class CTxMemPool;
25class UniValue;
26struct NodeContext;
27
28static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
29
36double GetDifficulty(const CBlockIndex* blockindex);
37
40
42UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, TxVerbosity verbosity) LOCKS_EXCLUDED(cs_main);
43
46
48UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose = false, bool include_mempool_sequence = false);
49
52
54void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
55
56NodeContext& EnsureAnyNodeContext(const std::any& context);
58CTxMemPool& EnsureAnyMemPool(const std::any& context);
60ChainstateManager& EnsureAnyChainman(const std::any& context);
62CBlockPolicyEstimator& EnsureAnyFeeEstimator(const std::any& context);
63
69
70#endif
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition: blockchain.cpp:95
CBlockPolicyEstimator & EnsureFeeEstimator(const NodeContext &node)
Definition: blockchain.cpp:100
UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, TxVerbosity verbosity) LOCKS_EXCLUDED(cs_main)
Block description to JSON.
Definition: blockchain.cpp:203
void RPCNotifyBlockChange(const CBlockIndex *)
Callback for when block tip changed.
Definition: blockchain.cpp:280
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES
Definition: blockchain.h:28
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index.
Definition: blockchain.cpp:115
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: blockchain.cpp:65
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition: blockchain.cpp:74
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition: blockchain.cpp:87
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition: blockchain.cpp:82
CBlockPolicyEstimator & EnsureAnyFeeEstimator(const std::any &context)
Definition: blockchain.cpp:108
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:118
void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector< std::pair< CAmount, int64_t > > &scores, int64_t total_weight)
Used by getblockstats to get feerates at different percentiles by weight
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose=false, bool include_mempool_sequence=false)
Mempool to JSON.
Definition: blockchain.cpp:553
UniValue blockheaderToJSON(const CBlockIndex *tip, const CBlockIndex *blockindex) LOCKS_EXCLUDED(cs_main)
Block header to JSON.
Definition: blockchain.cpp:174
UniValue CreateUTXOSnapshot(NodeContext &node, CChainState &chainstate, CAutoFile &afile)
Helper to create UTXO snapshots given a chainstate and a file handle.
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:565
Definition: block.h:63
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:146
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition: fees.h:132
CChainState stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:544
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:424
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:847
TxVerbosity
Verbose level for block's transaction.
Definition: core_io.h:26
NodeContext struct containing references to chain state and connection state.
Definition: context.h:39
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48