Bitcoin Core  0.20.99
P2P Digital Currency
blockchain.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2019 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;
18 class CTxMemPool;
19 class ChainstateManager;
20 class UniValue;
21 struct NodeContext;
22 namespace util {
23 class Ref;
24 } // namespace util
25 
26 static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
27 
34 double GetDifficulty(const CBlockIndex* blockindex);
35 
38 
40 UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false) LOCKS_EXCLUDED(cs_main);
41 
44 
46 UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose = false, bool include_mempool_sequence = false);
47 
49 UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex) LOCKS_EXCLUDED(cs_main);
50 
52 void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
53 
54 NodeContext& EnsureNodeContext(const util::Ref& context);
55 CTxMemPool& EnsureMemPool(const util::Ref& context);
56 ChainstateManager& EnsureChainman(const util::Ref& context);
57 
58 #endif
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES
Definition: blockchain.h:26
Definition: httprpc.h:8
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
Definition: block.h:62
ChainstateManager & EnsureChainman(const util::Ref &context)
Definition: blockchain.cpp:75
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:781
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose=false, bool include_mempool_sequence=false)
Mempool to JSON.
Definition: blockchain.cpp:503
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index.
Definition: blockchain.cpp:86
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:118
NodeContext struct containing references to chain state and connection state.
Definition: context.h:36
void RPCNotifyBlockChange(const CBlockIndex *)
Callback for when block tip changed.
Definition: blockchain.cpp:231
CTxMemPool & EnsureMemPool(const util::Ref &context)
Definition: blockchain.cpp:66
NodeContext & EnsureNodeContext(const util::Ref &context)
Definition: blockchain.cpp:58
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:129
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:488
#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:147