Bitcoin Core  0.19.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 UniValue;
20 struct NodeContext;
21 
22 static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
23 
30 double GetDifficulty(const CBlockIndex* blockindex);
31 
33 void RPCNotifyBlockChange(bool ibd, const CBlockIndex *);
34 
36 UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false) LOCKS_EXCLUDED(cs_main);
37 
40 
42 UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose = false);
43 
45 UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex) LOCKS_EXCLUDED(cs_main);
46 
48 void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
49 
53 extern NodeContext* g_rpc_node;
54 
56 
57 #endif
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES
Definition: blockchain.h:22
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
Definition: block.h:72
void RPCNotifyBlockChange(bool ibd, const CBlockIndex *)
Callback for when block tip changed.
Definition: blockchain.cpp:208
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index.
Definition: blockchain.cpp:67
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:99
NodeContext struct containing references to chain state and connection state.
Definition: context.h:31
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose=false)
Mempool to JSON.
Definition: blockchain.cpp:468
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:105
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:443
NodeContext * g_rpc_node
Pointer to node state that needs to be declared as a global to be accessible RPC methods.
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:50
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:128
CTxMemPool & EnsureMemPool()
Definition: blockchain.cpp:56