6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ALTBLOCK_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ALTBLOCK_HPP_
12#include <veriblock/pop/blockchain/alt_block_addon.hpp>
13#include <veriblock/pop/blockchain/block_index.hpp>
14#include <veriblock/pop/hashers.hpp>
15#include <veriblock/pop/json.hpp>
16#include <veriblock/pop/serde.hpp>
17#include <veriblock/pop/storage/stored_alt_block_addon.hpp>
30 using height_t = int32_t;
31 using hash_t = std::vector<uint8_t>;
32 using prev_hash_t = std::vector<uint8_t>;
33 using addon_t = StoredAltBlockAddon::addon_t;
34 using stored_addon_t = StoredAltBlockAddon;
49 std::vector<uint8_t>
toRaw()
const;
51 size_t estimateSize()
const;
53 uint32_t getBlockTime() const noexcept;
61 uint32_t getDifficulty()
const {
return 0; }
67 static const std::string& name() {
return _name; }
75 hash_t getPreviousBlock()
const {
return previousBlock; }
76 uint32_t getTimestamp()
const {
return timestamp; }
77 height_t getHeight()
const {
return height; }
80 hash_t previousBlock{};
85 static const std::string _name;
89template <
typename JsonValue>
90JsonValue ToJSON(
const AltBlock& alt,
bool reverseHashes =
true) {
91 JsonValue
object = json::makeEmptyObject<JsonValue>();
92 json::putStringKV(
object,
"hash",
HexStr(alt.
getHash(), reverseHashes));
94 object,
"previousBlock",
HexStr(alt.previousBlock, reverseHashes));
95 json::putIntKV(
object,
"timestamp", alt.getBlockTime());
96 json::putIntKV(
object,
"height", alt.height);
101inline void PrintTo(
const AltBlock& block, ::std::ostream* os) {
102 *os << block.toPrettyString();
110 const AltBlock::hash_t& = AltBlock::hash_t{});
117 const AltBlock::hash_t& = AltBlock::hash_t{});
125 std::hash<std::vector<uint8_t>> hasher;
126 return hasher(block.
getHash());
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...
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.
void PrintTo(const ArithUint256 &uint, ::std::ostream *os)
custom gtest printer, which prints Blob of any size as hexstring @ private
Represents a view on Altchain block - i.e.
std::vector< uint8_t > toRaw() const
Convert AltBlock to bytes data using AltBlock basic byte format.
void toRaw(WriteStream &stream) const
Convert AltBlock to data stream using AltBlock basic byte format.
std::string toPrettyString() const
Print this entity.
const hash_t & getHash() const
void toVbkEncoding(WriteStream &stream) const
for AltBlock Raw format == VbkEncoding
Binary reading stream, that is useful during binary deserialization.