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 <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 
17 extern RecursiveMutex cs_main;
18 
19 class CBlock;
20 class CBlockIndex;
22 class CChainState;
23 class CTxMemPool;
24 class ChainstateManager;
25 class UniValue;
26 struct NodeContext;
27 
28 static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
29 
36 double GetDifficulty(const CBlockIndex* blockindex);
37 
40 
42 UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false) LOCKS_EXCLUDED(cs_main);
43 
46 
48 UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose = false, bool include_mempool_sequence = false);
49 
52 
54 void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
55 
56 void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
57 void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
58 
59 NodeContext& EnsureAnyNodeContext(const std::any& context);
61 CTxMemPool& EnsureAnyMemPool(const std::any& context);
63 ChainstateManager& EnsureAnyChainman(const std::any& context);
65 CBlockPolicyEstimator& EnsureAnyFeeEstimator(const std::any& context);
66 
72 
73 #endif
TxToUniv
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, bool include_hex=true, int serialize_flags=0, const CTxUndo *txundo=nullptr)
Definition: blockchain.cpp:1941
CTxUndo
Undo information for a CTransaction.
Definition: undo.h:53
streams.h
ScriptPubKeyToUniv
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
Definition: blockchain.cpp:1936
sync.h
EnsureAnyChainman
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition: blockchain.cpp:95
NUM_GETBLOCKSTATS_PERCENTILES
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES
Definition: blockchain.h:28
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:478
MempoolInfoToJSON
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
Definition: blockchain.cpp:1643
GetDifficulty
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index.
Definition: blockchain.cpp:115
blockheaderToJSON
UniValue blockheaderToJSON(const CBlockIndex *tip, const CBlockIndex *blockindex) LOCKS_EXCLUDED(cs_main)
Block header to JSON.
Definition: blockchain.cpp:174
EnsureAnyNodeContext
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: blockchain.cpp:65
AnnotatedMixin< std::recursive_mutex >
MempoolToJSON
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose=false, bool include_mempool_sequence=false)
Mempool to JSON.
Definition: blockchain.cpp:546
core_io.h
UniValue
Definition: univalue.h:19
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:259
EnsureMemPool
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition: blockchain.cpp:74
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:564
CBlockPolicyEstimator
Definition: fees.h:131
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
RPCNotifyBlockChange
void RPCNotifyBlockChange(const CBlockIndex *)
Callback for when block tip changed.
Definition: blockchain.cpp:273
uint256
256-bit opaque blob.
Definition: uint256.h:124
CChainState
CChainState stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:556
CreateUTXOSnapshot
UniValue CreateUTXOSnapshot(NodeContext &node, CChainState &chainstate, CAutoFile &afile)
Helper to create UTXO snapshots given a chainstate and a file handle.
Definition: blockchain.cpp:2577
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:858
CBlock
Definition: block.h:62
CalculatePercentilesByWeight
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
Definition: blockchain.cpp:1907
EnsureChainman
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition: blockchain.cpp:87
LOCKS_EXCLUDED
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:116
EnsureAnyMemPool
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition: blockchain.cpp:82
node
Definition: interfaces.cpp:68
EnsureFeeEstimator
CBlockPolicyEstimator & EnsureFeeEstimator(const NodeContext &node)
Definition: blockchain.cpp:100
NodeContext
NodeContext struct containing references to chain state and connection state.
Definition: context.h:39
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:137
EnsureAnyFeeEstimator
CBlockPolicyEstimator & EnsureAnyFeeEstimator(const std::any &context)
Definition: blockchain.cpp:108
amount.h
blockToJSON
UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, bool txDetails=false) LOCKS_EXCLUDED(cs_main)
Block description to JSON.
Definition: blockchain.cpp:203