veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
atv.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 ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ATV_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ATV_HPP_
8
9#include <cstddef>
10#include <cstdint>
11#include <string>
12#include <vector>
13
14#include "vbk_merkle_path.hpp"
15#include "vbkblock.hpp"
16#include "vbktx.hpp"
17#include "veriblock/pop/blob.hpp"
19#include "veriblock/pop/json.hpp"
20#include "veriblock/pop/serde.hpp"
21#include "veriblock/pop/type_traits.hpp"
22#include "veriblock/pop/uint.hpp"
23
24namespace altintegration {
25class ValidationState;
26class WriteStream;
27struct ReadStream;
28template <typename T>
29struct IsPopPayload;
30
36struct ATV {
37 using id_t = uint256;
38
40 uint32_t version = 1;
41
44
47
50
52 mutable bool checked{false};
53
55 std::string toPrettyString() const;
56 std::string toShortPrettyString() const;
57
62 void toVbkEncoding(WriteStream& stream) const;
63
68 std::vector<uint8_t> toVbkEncoding() const;
69
71 size_t estimateSize() const;
72
77 id_t getId() const;
78
79 static const std::string& name() { return _name; }
80
81 friend bool operator==(const ATV& a, const ATV& b) {
82 return a.getId() == b.getId();
83 }
84
85 friend bool operator!=(const ATV& a, const ATV& b) { return !(a == b); }
86
87 friend bool operator<(const ATV& a, const ATV& b) {
88 return a.blockOfProof.getHeight() < b.blockOfProof.getHeight();
89 }
90
91 private:
92 static const std::string _name;
93};
94
96template <>
97struct IsPopPayload<ATV> {
98 static const bool value = true;
99};
100
102template <typename JsonValue>
103JsonValue ToJSON(const ATV& atv) {
104 JsonValue obj = json::makeEmptyObject<JsonValue>();
105 json::putIntKV(obj, "version", atv.version);
106 json::putKV(obj, "transaction", ToJSON<JsonValue>(atv.transaction));
107 json::putKV(obj, "merklePath", ToJSON<JsonValue>(atv.merklePath));
108 json::putKV(obj, "blockOfProof", ToJSON<JsonValue>(atv.blockOfProof));
109
110 // return this entity in VBK-serialized form for easy consumption.
111 // DO NOT REMOVE these fields - otherwise Stratum compat will break.
112 json::putStringKV(obj, "id", atv.getId().toHex());
113 json::putStringKV(obj, "serialized", SerializeToHex(atv));
114 return obj;
115}
116
119 ATV& out,
120 ValidationState& state);
121
122} // namespace altintegration
123
124#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ATV_HPP_
Class that is used for storing validation state.
Binary writer that is useful for binary serialization.
All constants in alt-cpp.
Defines logging helpers.
Definition: block.hpp:14
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Blob< SHA256_HASH_SIZE > uint256
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: uint.hpp:24
std::string SerializeToHex(const T &obj)
Serialize to HEX VBK encoding.
Definition: serde.hpp:456
Atlchain endorsement.
Definition: atv.hpp:36
uint32_t version
ATV serialization version.
Definition: atv.hpp:40
std::vector< uint8_t > toVbkEncoding() const
Convert ATV to raw bytes data using Vbk byte format.
id_t getId() const
Calculate a ATV id that is the sha256 hash of the ATV rawBytes.
std::string toPrettyString() const
create pretty string
void toVbkEncoding(WriteStream &stream) const
Convert ATV to data stream using Vbk byte format.
VbkTx transaction
endorsing transaction.
Definition: atv.hpp:43
bool checked
(memory only) indicates whether we already did 'checkATV' on this ATV
Definition: atv.hpp:52
size_t estimateSize() const
Estimate serialization size.
VbkMerklePath merklePath
merkle path that proves that endorsing transaction is in blockOfProof.
Definition: atv.hpp:46
VbkBlock blockOfProof
VBK block which contains endorsing transaction.
Definition: atv.hpp:49
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22
Veriblock block.
Definition: vbkblock.hpp:32
Path in Merkle tree, which proves that subject exists in the tree.
Veriblock transaction, which endorses ALT block in VBK blockchain.
Definition: vbktx.hpp:40