blockchain.h raw
1 // Copyright (c) 2017-present 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 <consensus/amount.h>
9 #include <core_io.h>
10 #include <streams.h>
11 #include <sync.h>
12 #include <util/fs.h>
13 #include <validation.h>
14
15 #include <any>
16 #include <cstdint>
17 #include <optional>
18 #include <vector>
19
20 class CBlock;
21 class CBlockIndex;
22 class CChain;
23 class Chainstate;
24 class UniValue;
25 namespace node {
26 class BlockManager;
27 struct NodeContext;
28 } // namespace node
29
30 static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
31
32 /**
33 * Get the difficulty of the net wrt to the given block index.
34 *
35 * @return A floating point number that is a multiple of the main net minimum
36 * difficulty (4295032833 hashes).
37 */
38 double GetDifficulty(const CBlockIndex& blockindex);
39
40 /** Block description to JSON */
41 UniValue blockToJSON(node::BlockManager& blockman, const CBlock& block, const CBlockIndex& tip, const CBlockIndex& blockindex, TxVerbosity verbosity, uint256 pow_limit) LOCKS_EXCLUDED(cs_main);
42
43 /** Block header to JSON */
44 UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex, uint256 pow_limit) LOCKS_EXCLUDED(cs_main);
45
46 /** Used by getblockstats to get feerates at different percentiles by weight */
47 void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
48
49 /**
50 * Helper to create UTXO snapshots given a chainstate and a file handle.
51 * @return a UniValue map containing metadata about the snapshot.
52 */
53 UniValue CreateUTXOSnapshot(
54 node::NodeContext& node,
55 Chainstate& chainstate,
56 AutoFile&& afile,
57 const fs::path& path,
58 const fs::path& tmppath);
59
60 //! Return height of highest block that has been pruned, or std::nullopt if no blocks have been pruned
61 std::optional<int> GetPruneHeight(const node::BlockManager& blockman, const CChain& chain) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
62 void CheckBlockDataAvailability(node::BlockManager& blockman, const CBlockIndex& blockindex, bool check_for_undo) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
63
64 #endif // BITCOIN_RPC_BLOCKCHAIN_H
65