6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_BTCBLOCK_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_BTCBLOCK_HPP_
14#include <system_error>
18#include "veriblock/pop/arith_uint256.hpp"
19#include "veriblock/pop/blob.hpp"
20#include "veriblock/pop/blockchain/btc_block_addon.hpp"
21#include "veriblock/pop/fmt.hpp"
22#include "veriblock/pop/hashutil.hpp"
23#include "veriblock/pop/json.hpp"
24#include "veriblock/pop/serde.hpp"
25#include "veriblock/pop/storage/stored_btc_block_addon.hpp"
26#include "veriblock/pop/strutil.hpp"
27#include "veriblock/pop/uint.hpp"
28#include "veriblock/pop/validation_state.hpp"
44 using height_t = int32_t;
45 using nonce_t = uint32_t;
47 using addon_t = StoredBtcBlockAddon::addon_t;
48 using stored_addon_t = StoredBtcBlockAddon;
70 size_t estimateSize()
const;
74 return a.bits == b.bits &&
75 a.version == b.version &&
76 a.timestamp == b.timestamp &&
78 a.merkleRoot == b.merkleRoot &&
79 a.previousBlock == b.previousBlock;
87 hash_t calculateHash()
const;
95 static const std::string& name() {
return _name; }
97 std::string toPrettyString()
const;
99 int32_t getVersion()
const {
return version; }
100 uint256 getPreviousBlock()
const {
return previousBlock; }
101 uint256 getMerkleRoot()
const {
return merkleRoot; }
102 uint32_t getNonce()
const {
return nonce; }
103 uint32_t getTimestamp()
const {
return timestamp; }
104 uint32_t getDifficulty()
const {
return bits; }
106 void setVersion(int32_t v);
107 void setPreviousBlock(
const uint256& prev);
108 void setMerkleRoot(
const uint256& mr);
109 void setDifficulty(uint32_t bits);
110 void setNonce(uint32_t nnc);
111 void setTimestamp(uint32_t ts);
114 static const std::string _name;
116 void invalidateHash()
const { hash_.fill(0); }
121 uint32_t timestamp = 0;
125 mutable hash_t hash_;
140template <
typename JsonValue>
142 JsonValue
object = json::makeEmptyObject<JsonValue>();
144 json::putIntKV(
object,
"version", b.getVersion());
145 json::putStringKV(
object,
"previousBlock",
HexStr(b.getPreviousBlock()));
146 json::putStringKV(
object,
"merkleRoot",
HexStr(b.getMerkleRoot()));
147 json::putIntKV(
object,
"timestamp", b.getTimestamp());
148 json::putIntKV(
object,
"bits", b.getDifficulty());
149 json::putIntKV(
object,
"nonce", b.getNonce());
256-bit unsigned big integer.
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.
Blob< SHA256_HASH_SIZE > uint256
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool DeserializeFromRaw(ReadStream &stream, BtcBlock &block, ValidationState &state, const BtcBlock::hash_t &precalculatedHash)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void toRaw(WriteStream &stream) const
Convert BtcBlock to data stream using BtcBlock basic byte format.
friend bool DeserializeFromVbkEncoding(ReadStream &stream, BtcBlock &block, ValidationState &state, const BtcBlock::hash_t &precalculatedHash)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const hash_t & getHash() const
Calculate the hash of the btc block.
void toVbkEncoding(WriteStream &stream) const
Convert BtcBlock to data stream using BtcBlock VBK byte format.
Binary reading stream, that is useful during binary deserialization.