1+ #pragma once
2+
3+ // DGB block/header types. 1:1 mirror of src/impl/btc/coin/block.hpp (NON-MWEB).
4+ //
5+ // >>> MULTI-ALGO NOTE (project_v36_dgb_scrypt_only) <<<
6+ // The 80-byte header layout (version|prev|merkle|time|bits|nonce) is identical
7+ // across DGB`s 5 algos -- this serialization is algo-agnostic and correct as-is.
8+ // The block version field additionally ENCODES the mining algo in its bits;
9+ // DGB-Scrypt validation reads that algo selector in header_chain.hpp, NOT here.
10+ // Do not add per-algo branching to (de)serialization -- it is single-format.
11+
12+ #include " transaction.hpp"
13+
14+ #include < core/uint256.hpp>
15+ #include < core/pack_types.hpp>
16+ #include < core/netaddress.hpp>
17+
18+ namespace dgb
19+ {
20+
21+ namespace coin
22+ {
23+
24+ struct SmallBlockHeaderType
25+ {
26+ uint64_t m_version {};
27+ uint256 m_previous_block{};
28+ uint32_t m_timestamp{};
29+ uint32_t m_bits{};
30+ uint32_t m_nonce{};
31+
32+ C2POOL_SERIALIZE_METHODS (SmallBlockHeaderType) { READWRITE (VarInt (obj.m_version ), obj.m_previous_block , obj.m_timestamp , obj.m_bits , obj.m_nonce ); }
33+
34+ SmallBlockHeaderType () {}
35+
36+ void SetNull ()
37+ {
38+ m_version = 0 ;
39+ m_previous_block.SetNull ();
40+ m_timestamp = 0 ;
41+ m_bits = 0 ;
42+ m_nonce = 0 ;
43+ }
44+
45+ bool IsNull () const
46+ {
47+ return (m_bits == 0 );
48+ }
49+ };
50+
51+ struct BlockHeaderType : SmallBlockHeaderType
52+ {
53+ uint256 m_merkle_root;
54+
55+ // Full block header uses fixed 4-byte int32 version (not VarInt like SmallBlockHeaderType)
56+ template <typename Stream>
57+ void Serialize (Stream& s) const {
58+ uint32_t version32 = static_cast <uint32_t >(m_version);
59+ ::Serialize (s, version32);
60+ ::Serialize (s, m_previous_block);
61+ ::Serialize (s, m_merkle_root);
62+ ::Serialize (s, m_timestamp);
63+ ::Serialize (s, m_bits);
64+ ::Serialize (s, m_nonce);
65+ }
66+ template <typename Stream>
67+ void Unserialize (Stream& s) {
68+ uint32_t version32;
69+ ::Unserialize (s, version32);
70+ m_version = version32;
71+ ::Unserialize (s, m_previous_block);
72+ ::Unserialize (s, m_merkle_root);
73+ ::Unserialize (s, m_timestamp);
74+ ::Unserialize (s, m_bits);
75+ ::Unserialize (s, m_nonce);
76+ }
77+
78+ BlockHeaderType () : SmallBlockHeaderType() { }
79+
80+ void SetNull ()
81+ {
82+ SmallBlockHeaderType::SetNull ();
83+ m_merkle_root.SetNull ();
84+ }
85+
86+ bool IsNull () const
87+ {
88+ return (m_bits == 0 );
89+ }
90+
91+ };
92+
93+ struct BlockType : BlockHeaderType
94+ {
95+ std::vector<MutableTransaction> m_txs;
96+
97+ template <typename Stream>
98+ void Serialize (Stream& s) const {
99+ BlockHeaderType::Serialize (s);
100+ ::Serialize (s, TX_WITH_WITNESS (m_txs));
101+ }
102+
103+ template <typename Stream>
104+ void Unserialize (Stream& s) {
105+ BlockHeaderType::Unserialize (s);
106+ ::Unserialize (s, TX_WITH_WITNESS (m_txs));
107+ }
108+
109+ BlockType () : BlockHeaderType() { }
110+
111+ void SetNull ()
112+ {
113+ BlockHeaderType::SetNull ();
114+ m_txs.clear ();
115+ }
116+
117+ bool IsNull () const
118+ {
119+ return BlockHeaderType::IsNull ();
120+ }
121+ };
122+
123+ } // namespace coin
124+
125+ } // namespace dgb
0 commit comments