veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
block_reader.hpp
1// Copyright (c) 2019-2022 Xenios SEZC
2// https://www.veriblock.org
3// Distributed under the MIT software license, see the accompanying
4// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef VERIBLOCK_POP_CPP_BLOCK_READER_HPP
7#define VERIBLOCK_POP_CPP_BLOCK_READER_HPP
8
9#include <memory>
10#include <veriblock/pop/blockchain/block_index.hpp>
11#include <veriblock/pop/entities/altblock.hpp>
12#include <veriblock/pop/entities/btcblock.hpp>
13#include <veriblock/pop/entities/vbkblock.hpp>
14#include <veriblock/pop/storage/stored_block_index.hpp>
15#include <veriblock/pop/validation_state.hpp>
16
17#include "block_iterator.hpp"
18
19namespace altintegration {
20
27 virtual ~BlockReader() = default;
28
30 virtual bool getAltTip(AltBlock::hash_t& out) const = 0;
32 virtual bool getVbkTip(VbkBlock::hash_t& out) const = 0;
34 virtual bool getBtcTip(BtcBlock::hash_t& out) const = 0;
35
36 virtual bool getBlock(const AltBlock::prev_hash_t& hash,
37 StoredBlockIndex<AltBlock>& out) const = 0;
38
39 virtual bool getBlock(const VbkBlock::prev_hash_t& hash,
40 StoredBlockIndex<VbkBlock>& out) const = 0;
41
42 virtual bool getBlock(const BtcBlock::prev_hash_t& hash,
43 StoredBlockIndex<BtcBlock>& out) const = 0;
44
45 // clang-format off
47 virtual std::shared_ptr<BlockIterator<AltBlock>> getAltBlockIterator() const = 0;
49 virtual std::shared_ptr<BlockIterator<VbkBlock>> getVbkBlockIterator() const = 0;
51 virtual std::shared_ptr<BlockIterator<BtcBlock>> getBtcBlockIterator() const = 0;
52 // clang-format on
53
54 template <typename Block>
55 std::shared_ptr<BlockIterator<Block>> getBlockIterator() const;
56
57 template <typename Block>
58 bool getTip(typename Block::hash_t& out) const;
59};
60
61// clang-format off
62template <>
63inline std::shared_ptr<BlockIterator<AltBlock>> BlockReader::getBlockIterator() const {
64 return this->getAltBlockIterator();
65}
66
67template <>
68inline std::shared_ptr<BlockIterator<VbkBlock>> BlockReader::getBlockIterator() const {
69 return this->getVbkBlockIterator();
70}
71
72template <>
73inline std::shared_ptr<BlockIterator<BtcBlock>> BlockReader::getBlockIterator() const {
74 return this->getBtcBlockIterator();
75}
76// clang-format on
77
78template <>
79inline bool BlockReader::getTip<AltBlock>(AltBlock::hash_t& out) const {
80 return this->getAltTip(out);
81}
82
83template <>
84inline bool BlockReader::getTip<VbkBlock>(VbkBlock::hash_t& out) const {
85 return this->getVbkTip(out);
86}
87
88template <>
89inline bool BlockReader::getTip<BtcBlock>(BtcBlock::hash_t& out) const {
90 return this->getBtcTip(out);
91}
92
93} // namespace altintegration
94
95#endif
Defines logging helpers.
Definition: block.hpp:14
Contiguous byte array of fixed size.
Definition: blob.hpp:25
An abstraction over on-disk storage iterator.