6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_STORAGE_STORED_BLOCK_INDEX_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_STORAGE_STORED_BLOCK_INDEX_HPP_
9#include <veriblock/pop/blockchain/block_status.hpp>
10#include <veriblock/pop/read_stream.hpp>
11#include <veriblock/pop/write_stream.hpp>
17template <
typename Block>
19 using block_t = Block;
20 using height_t =
typename block_t::height_t;
21 using stored_addon_t =
typename block_t::stored_addon_t;
28 using height_t =
typename Block::height_t;
29 stream.writeBE<height_t>(
height);
31 stream.writeBE<uint32_t>(
status);
32 addon.toVbkEncoding(stream);
35 std::vector<uint8_t> toVbkEncoding()
const {
37 toVbkEncoding(stream);
41 std::string toPrettyString(
size_t level = 0)
const {
43 "{}{}StoredBlockIndex(height={}, hash={}, status={}, header={}, {})",
44 std::string(level,
' '),
50 addon.toPrettyString());
57 std::shared_ptr<block_t>
header = std::make_shared<block_t>();
65template <
typename Block>
70 typename Block::hash_t precalculatedHash =
typename Block::hash_t()) {
71 const auto& name = Block::name();
72 using height_t =
typename Block::height_t;
73 if (!stream.readBE<height_t>(out.
height, state)) {
74 return state.Invalid(name +
"-stored-block-index-height");
78 return state.Invalid(name +
"-stored-block-index-header");
80 out.
header = std::make_shared<Block>(block);
81 if (!stream.readBE<uint32_t>(out.
status, state)) {
82 return state.Invalid(name +
"-stored-block-index-status");
86 return state.Invalid(name +
"-stored-block-index-addon");
Class that is used for storing validation state.
Binary writer that is useful for binary serialization.
bool DeserializeFromRaw(ReadStream &stream, AltBlock &out, ValidationState &state, const AltBlock::hash_t &=AltBlock::hash_t{})
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ BLOCK_VALID_UNKNOWN
default state for validity - validity state is unknown
@ BLOCK_DELETED
the block is temporarily deleted
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::string HexStr(const T itbegin, const T itend)
Convert bytes to hex.
Binary reading stream, that is useful during binary deserialization.
uint32_t status
contains status flags
std::shared_ptr< block_t > header
block header
height_t height
height of the entry in the chain