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