1 // Copyright (c) 2017-2018 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 <vector>
9 #include <stdint.h>
10 #include <amount.h>
11 
12 class CBlock;
13 class CBlockIndex;
14 class UniValue;
15 
16 static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
17 
18 /**
19  * Get the difficulty of the net wrt to the given block index.
20  *
21  * @return A floating point number that is a multiple of the main net minimum
22  * difficulty (4295032833 hashes).
23  */
24 double GetDifficulty(const CBlockIndex* blockindex);
25 
26 /** Callback for when block tip changed. */
27 void RPCNotifyBlockChange(bool ibd, const CBlockIndex *);
28 
29 /** Block description to JSON */
30 UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false);
31 
32 /** Mempool information to JSON */
33 UniValue mempoolInfoToJSON();
34 
35 /** Mempool to JSON */
36 UniValue mempoolToJSON(bool fVerbose = false);
37 
38 /** Block header to JSON */
39 UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex);
40 
41 /** Used by getblockstats to get feerates at different percentiles by weight  */
42 void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
43 
44 #endif
45