Bitcoin Core  21.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 <sync.h>
10 
11 #include <stdint.h>
12 #include <vector>
13 
14 extern RecursiveMutex cs_main;
15 
16 class CBlock;
17 class CBlockIndex;
19 class CTxMemPool;
20 class ChainstateManager;
21 class UniValue;
22 struct NodeContext;
23 namespace util {
24 class Ref;
25 } // namespace util
26 
27 static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
28 
35 double GetDifficulty(const CBlockIndex* blockindex);
36 
39 
41 UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false) LOCKS_EXCLUDED(cs_main);
42 
45 
47 UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose = false, bool include_mempool_sequence = false);
48 
50 UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex) LOCKS_EXCLUDED(cs_main);
51 
53 void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
54 
55 NodeContext& EnsureNodeContext(const util::Ref& context);
56 CTxMemPool& EnsureMemPool(const util::Ref& context);
57 ChainstateManager& EnsureChainman(const util::Ref& context);
58 CBlockPolicyEstimator& EnsureFeeEstimator(const util::Ref& context);
59 
60 #endif
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES
Definition: blockchain.h:27
Definition: httprpc.h:8
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
CBlockPolicyEstimator & EnsureFeeEstimator(const util::Ref &context)
Definition: blockchain.cpp:85
Definition: block.h:62
ChainstateManager & EnsureChainman(const util::Ref &context)
Definition: blockchain.cpp:76
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:772
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose=false, bool include_mempool_sequence=false)
Mempool to JSON.
Definition: blockchain.cpp:518
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index.
Definition: blockchain.cpp:96
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
UniValue blockheaderToJSON(const CBlockIndex *tip, const CBlockIndex *blockindex) LOCKS_EXCLUDED(cs_main)
Block header to JSON.
Definition: blockchain.cpp:128
NodeContext struct containing references to chain state and connection state.
Definition: context.h:37
void RPCNotifyBlockChange(const CBlockIndex *)
Callback for when block tip changed.
Definition: blockchain.cpp:246
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition: fees.h:131
CTxMemPool & EnsureMemPool(const util::Ref &context)
Definition: blockchain.cpp:67
NodeContext & EnsureNodeContext(const util::Ref &context)
Definition: blockchain.cpp:59
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.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: validation.cpp:128
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:474
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:137
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:157