6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ALT_POP_TRANSACTION_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ALT_POP_TRANSACTION_HPP_
12#include <veriblock/pop/serde.hpp>
13#include <veriblock/pop/slice.hpp>
31 std::vector<VbkBlock> context;
32 std::vector<VTB> vtbs{};
33 std::vector<ATV> atvs{};
37 static uint256 getMerkleRoot(uint32_t version,
38 const std::vector<ATV::id_t>& atvs,
39 const std::vector<VTB::id_t>& vtbs,
40 const std::vector<VbkBlock::id_t>& vbks);
42 void mergeFrom(
const PopData& p) {
43 context.insert(context.end(), p.context.begin(), p.context.end());
44 vtbs.insert(vtbs.end(), p.vtbs.begin(), p.vtbs.end());
45 atvs.insert(atvs.end(), p.atvs.begin(), p.atvs.end());
66 size_t estimateSize()
const;
68 std::string toPrettyString()
const;
70 bool empty()
const {
return context.empty() && atvs.empty() && vtbs.empty(); }
80 mutable bool checked =
false;
85template <
typename JsonValue,
typename T>
86inline void putArrayOfIds(JsonValue& obj,
88 const std::vector<T>& t) {
89 JsonValue arr = json::makeEmptyArray<JsonValue>();
90 for (
const auto& b : t) {
91 json::arrayPushBack(arr, ToJSON<JsonValue>(b.getId()));
94 json::putKV(obj, key, arr);
97template <
typename Value,
typename Item>
98void putArrayKV(Value&
object,
99 const std::string& key,
100 const std::vector<Item>& val) {
101 auto arr = json::makeEmptyArray<Value>();
102 for (
const auto& it : val) {
103 json::arrayPushBack(arr, ToJSON<Value>(it));
105 json::putKV(
object, key, arr);
111template <
typename JsonValue>
112JsonValue ToJSON(
const PopData& p,
bool verbose =
false) {
113 JsonValue obj = json::makeEmptyObject<JsonValue>();
114 json::putIntKV(obj,
"version", p.version);
116 detail::putArrayKV(obj,
"vbkblocks", p.context);
117 detail::putArrayKV(obj,
"vtbs", p.vtbs);
118 detail::putArrayKV(obj,
"atvs", p.atvs);
120 detail::putArrayOfIds(obj,
"vbkblocks", p.context);
121 detail::putArrayOfIds(obj,
"vtbs", p.vtbs);
122 detail::putArrayOfIds(obj,
"atvs", p.atvs);
Class that is used for storing validation state.
Binary writer that is useful for binary serialization.
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...
Represents ALT block body of POP-related info.
void toVbkEncoding(WriteStream &stream) const
Convert PopData to data stream using Vbk byte format.
std::vector< uint8_t > toVbkEncoding() const
Convert PopData to raw bytes data using Vbk byte format.
Binary reading stream, that is useful during binary deserialization.