Branch data Line data Source code
1 : : // Copyright (c) 2022 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 : : #include <chain.h>
6 : : #include <interfaces/chain.h>
7 : : #include <kernel/chain.h>
8 : : #include <kernel/types.h>
9 : : #include <sync.h>
10 : : #include <uint256.h>
11 : :
12 : : class CBlock;
13 : :
14 : : using kernel::ChainstateRole;
15 : :
16 : : namespace kernel {
17 : 80875 : interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* index, const CBlock* data)
18 : : {
19 [ + - ]: 80875 : interfaces::BlockInfo info{index ? *index->phashBlock : uint256::ZERO};
20 [ + - ]: 80875 : if (index) {
21 [ + + ]: 80875 : info.prev_hash = index->pprev ? index->pprev->phashBlock : nullptr;
22 : 80875 : info.height = index->nHeight;
23 : 80875 : info.chain_time_max = index->GetBlockTimeMax();
24 : 80875 : LOCK(::cs_main);
25 : 80875 : info.file_number = index->nFile;
26 [ + - ]: 80875 : info.data_pos = index->nDataPos;
27 : 80875 : }
28 : 80875 : info.data = data;
29 : 80875 : return info;
30 : : }
31 : :
32 : 510 : std::ostream& operator<<(std::ostream& os, const ChainstateRole& role) {
33 [ + + ]: 510 : if (!role.validated) {
34 : 14 : os << "assumedvalid";
35 [ + + ]: 496 : } else if (role.historical) {
36 : 4 : os << "background";
37 : : } else {
38 : 492 : os << "normal";
39 : : }
40 : 510 : return os;
41 : : }
42 : : } // namespace kernel
|