veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
block.hpp
1// Copyright (c) 2019-2022 Xenios SEZC
2// https://www.veriblock.org
3// Distributed under the MIT software license, see the accompanying
4// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BFI_BITCOIN_BLOCK_HPP
7#define BFI_BITCOIN_BLOCK_HPP
8
9#include <utility>
10#include <veriblock/bfi/bitcoin/serialize.hpp>
11#include <veriblock/bfi/bitcoin/transaction.hpp>
12#include <veriblock/pop/entities/btcblock.hpp>
13
14namespace altintegration {
15
16namespace btc {
17
18struct BlockHeader : public BtcBlock {
19 BlockHeader() = default;
20
21 BlockHeader(int32_t version,
22 uint256 previousBlock,
23 uint256 merkleRoot,
24 uint32_t timestamp,
25 uint32_t bits,
26 uint32_t nonce)
27 : BtcBlock(version,
28 std::move(previousBlock),
29 std::move(merkleRoot),
30 timestamp,
31 bits,
32 nonce) {}
33
34 ADD_SERIALIZE_METHODS;
35
36 template <typename Stream, typename Operation>
37 inline void SerializationOp(Stream& s, Operation ser_action) {
38 READWRITE(this->version);
39 READWRITE(this->previousBlock);
40 READWRITE(this->merkleRoot);
41 READWRITE(this->timestamp);
42 READWRITE(this->bits);
43 READWRITE(this->nonce);
44 }
45};
46
47struct Block : public BlockHeader {
48 std::vector<Transaction> vtx{};
49
50 Block() = default;
51
52 Block(int32_t version,
53 uint256 previousBlock,
54 uint256 merkleRoot,
55 uint32_t timestamp,
56 uint32_t bits,
57 uint32_t nonce)
58 : BlockHeader(version,
59 std::move(previousBlock),
60 std::move(merkleRoot),
61 timestamp,
62 bits,
63 nonce) {}
64
65 ADD_SERIALIZE_METHODS;
66
67 template <typename Stream, typename Operation>
68 inline void SerializationOp(Stream& s, Operation ser_action) {
69 READWRITEAS(BlockHeader, *this);
70 READWRITE(this->vtx);
71 }
72
73 friend bool operator==(const Block& a, const Block& b) {
74 const BlockHeader& A = a;
75 const BlockHeader& B = b;
76 return A == B && a.vtx == b.vtx;
77 }
78
79 friend bool operator!=(const Block& a, const Block& b) { return !(a == b); }
80};
81
83 std::vector<uint256> vHave;
84
85 BlockLocator() = default;
86
87 BlockLocator(const std::vector<uint256>& vHave) : vHave(vHave) {}
88
89 ADD_SERIALIZE_METHODS;
90
91 template <typename Stream, typename Operation>
92 inline void SerializationOp(Stream& s, Operation ser_action) {
93 int nVersion = s.getVersion();
94 READWRITE(nVersion);
95 READWRITE(vHave);
96 }
97
98 friend bool operator==(const BlockLocator& a, const BlockLocator& b) {
99 return a.vHave == b.vHave;
100 }
101
102 friend bool operator!=(const BlockLocator& a, const BlockLocator& b) {
103 return !(a == b);
104 }
105};
106
107} // namespace btc
108
109} // namespace altintegration
110
111#endif
Defines logging helpers.
Definition: block.hpp:14
Bitcoin block.
Definition: btcblock.hpp:41