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