6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ENDORSEMENT_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_ENDORSEMENT_HPP_
10#include <veriblock/pop/serde.hpp>
11#include <veriblock/pop/uint.hpp>
36template <
class EndorsedHash,
class ContainingHash,
class Container>
40 using endorsed_hash_t = EndorsedHash;
41 using containing_hash_t = ContainingHash;
42 using container_t = Container;
46 EndorsedHash endorsedHash;
47 EndorsedHash containingHash;
48 ContainingHash blockOfProof;
57 std::vector<uint8_t> toVbkEncoding()
const {
59 toVbkEncoding(stream);
63 static type fromContainer(
const Container& c);
65 static type fromContainer(
const Container& c,
66 const EndorsedHash& containingHash,
67 const EndorsedHash& endorsedHash);
69 static std::shared_ptr<type> fromContainerPtr(
71 const EndorsedHash& containingHash,
72 const EndorsedHash& endorsedHash) {
73 return std::make_shared<type>(
74 fromContainer(c, containingHash, endorsedHash));
77 static std::shared_ptr<type> fromContainerPtr(
const Container& c) {
78 return std::make_shared<type>(fromContainer(c));
85 bool operator==(
const type& other)
const {
return id == other.id; }
87 friend bool operator<(
const type& a,
const type& b) {
88 if (a.id < b.id)
return true;
89 if (a.id > b.id)
return false;
90 if (a.endorsedHash < b.endorsedHash)
return true;
91 if (a.endorsedHash > b.endorsedHash)
return false;
92 if (a.containingHash < b.containingHash)
return true;
93 if (a.containingHash > b.containingHash)
return false;
94 return a.blockOfProof < b.blockOfProof;
97 bool operator!=(
const type& other)
const {
return !operator==(other); }
99 std::string toPrettyString(
size_t level = 0)
const {
101 "{}{}Endorsement{{id={}, containing={}, endorsed={}, blockOfProof={}}}",
102 std::string(level,
' '),
110 static const std::string name();
114template <
typename Value,
class A,
class B,
class C>
116 auto obj = json::makeEmptyObject<Value>();
117 json::putStringKV(obj,
"id",
HexStr(e.id));
118 json::putStringKV(obj,
"endorsedHash",
HexStr(e.endorsedHash));
119 json::putStringKV(obj,
"containingHash", e.containingHash);
120 json::putStringKV(obj,
"blockOfProof", e.blockOfProof);
125template <
typename A,
typename B,
typename C>
126void PrintTo(
const Endorsement<A, B, C>& e, std::ostream* os) {
127 *os << e.toPrettyString();
Binary writer that is useful for binary serialization.
void writeSingleByteLenValue(WriteStream &stream, Slice< const uint8_t > value)
Write single byte length value, which consists of N bytes vector Appends 1 byte data length to the st...
std::string HexStr(const T itbegin, const T itend)
Convert bytes to hex.
void PrintTo(const ArithUint256 &uint, ::std::ostream *os)
custom gtest printer, which prints Blob of any size as hexstring @ private
Blob< SHA256_HASH_SIZE > uint256
This is an overloaded member function, provided for convenience. It differs from the above function o...