6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBKBLOCK_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBKBLOCK_HPP_
13#include <veriblock/pop/arith_uint256.hpp>
14#include <veriblock/pop/blockchain/vbk_block_addon.hpp>
15#include <veriblock/pop/fmt.hpp>
16#include <veriblock/pop/serde.hpp>
17#include <veriblock/pop/storage/stored_vbk_block_addon.hpp>
18#include <veriblock/pop/type_traits.hpp>
19#include <veriblock/pop/uint.hpp>
21#include "btcblock.hpp"
37 using height_t = int32_t;
38 using nonce_t = int32_t;
42 using addon_t = StoredVbkBlockAddon::addon_t;
43 using stored_addon_t = StoredVbkBlockAddon;
45 std::string toPrettyString()
const;
46 std::string toShortPrettyString()
const;
64 std::vector<uint8_t>
toRaw()
const;
73 return a.getHeight() < b.getHeight();
76 size_t estimateSize()
const;
82 uint32_t getBlockTime()
const;
87 hash_t calculateHash()
const;
103 static const std::string& name() {
return _name; }
105 VbkBlock() =
default;
116 int32_t getDifficulty()
const {
return difficulty; }
117 int32_t getHeight()
const {
return height; }
118 int16_t getVersion()
const {
return version; }
119 uint96 getPreviousBlock()
const {
return previousBlock; }
120 keystone_t getPreviousKeystone()
const {
return previousKeystone; }
121 keystone_t getSecondPreviousKeystone()
const {
122 return secondPreviousKeystone;
124 uint128 getMerkleRoot()
const {
return merkleRoot; }
125 uint32_t getTimestamp()
const {
return timestamp; }
126 uint64_t getNonce()
const {
return nonce; }
128 void setHeight(int32_t h);
129 void setVersion(int16_t v);
130 void setPreviousBlock(
const uint96& prev);
131 void setPreviousKeystone(
const keystone_t& ks);
132 void setSecondPreviousKeystone(
const keystone_t& ks);
133 void setMerkleRoot(
const uint128& mroot);
134 void setTimestamp(uint32_t ts);
135 void setDifficulty(int32_t diff);
136 void setNonce(uint64_t nnc);
139 static const std::string _name;
144 keystone_t previousKeystone{};
145 keystone_t secondPreviousKeystone{};
147 uint32_t timestamp{};
148 int32_t difficulty{};
150 mutable hash_t hash_{};
152 void invalidateHash() { hash_.fill(0); }
158 friend void setPrecalculatedHash(
VbkBlock& block,
165 static const bool value =
true;
169template <
typename JsonValue>
171 JsonValue obj = json::makeEmptyObject<JsonValue>();
173 json::putIntKV(obj,
"height", b.getHeight());
174 json::putIntKV(obj,
"version", b.getVersion());
175 json::putStringKV(obj,
"previousBlock",
HexStr(b.getPreviousBlock()));
176 json::putStringKV(obj,
"previousKeystone",
HexStr(b.getPreviousKeystone()));
178 obj,
"secondPreviousKeystone",
HexStr(b.getSecondPreviousKeystone()));
179 json::putStringKV(obj,
"merkleRoot",
HexStr(b.getMerkleRoot()));
180 json::putIntKV(obj,
"timestamp", b.getTimestamp());
181 json::putIntKV(obj,
"difficulty", b.getDifficulty());
182 json::putIntKV(obj,
"nonce", b.getNonce());
186 json::putStringKV(obj,
"id",
HexStr(b.getId()));
Class that is used for storing validation state.
Binary writer that is useful for binary serialization.
Blob< VBK_PREVIOUS_BLOCK_HASH_SIZE > uint96
This is an overloaded member function, provided for convenience. It differs from the above function o...
Blob< VBK_PREVIOUS_KEYSTONE_HASH_SIZE > uint72
This is an overloaded member function, provided for convenience. It differs from the above function o...
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...
Blob< VBK_BLOCK_HASH_SIZE > uint192
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.
std::string SerializeToHex(const T &obj)
Serialize to HEX VBK encoding.
Blob< VBK_MERKLE_ROOT_HASH_SIZE > uint128
Fixed-size array.
Contiguous byte array of fixed size.
type trait which returns true on types that are "POP Payloads"
Binary reading stream, that is useful during binary deserialization.
short_hash_t getShortHash() const
Calculate the hash of the vbk block.
friend bool DeserializeFromRaw(ReadStream &stream, VbkBlock &out, ValidationState &state, const VbkBlock::hash_t &precalculatedHash)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const hash_t & getHash() const
Get current block hash.
std::vector< uint8_t > toRaw() const
Convert VbkBlock to bytes data using VbkBlock basic byte format.
std::vector< uint8_t > toVbkEncoding() const
Convert VbkBlock to raw bytes data using VbkBlock byte format.
void toVbkEncoding(WriteStream &stream) const
Convert VbkBlock to data stream using VbkBlock VBK byte format.
void toRaw(WriteStream &stream) const
Convert VbkBlock to data stream using VbkBlock basic byte format.