6#ifndef VERIBLOCK_POP_CPP_POP_STATE_HPP
7#define VERIBLOCK_POP_CPP_POP_STATE_HPP
13#include <veriblock/pop/algorithm.hpp>
14#include <veriblock/pop/serde.hpp>
15#include <veriblock/pop/uint.hpp>
20template <
typename EndorsementT>
22 using endorsement_t = EndorsementT;
23 using eid_t =
typename endorsement_t::id_t;
24 using containing_endorsement_store_t =
25 std::multimap<eid_t, std::shared_ptr<endorsement_t>>;
27 const containing_endorsement_store_t& getContainingEndorsements()
const {
28 return _containingEndorsements;
31 const std::vector<const endorsement_t*>& getEndorsedBy()
const {
35 void insertEndorsedBy(
const endorsement_t* e) {
36 VBK_ASSERT_MSG(e !=
nullptr,
"Inserted endorsement should not be nullptr");
37 _endorsedBy.push_back(e);
41 bool eraseLastFromEndorsedBy(
const endorsement_t* endorsement) {
42 auto rm = [&endorsement](
const endorsement_t* e) ->
bool {
43 return e == endorsement;
45 auto res = erase_last_item_if<const endorsement_t*>(_endorsedBy, rm);
52 void insertContainingEndorsement(std::shared_ptr<endorsement_t> e) {
53 VBK_ASSERT_MSG(e !=
nullptr,
"Inserted endorsement should not be nullptr");
54 _containingEndorsements.emplace(e->id, std::move(e));
58 const typename containing_endorsement_store_t::const_iterator
59 findContainingEndorsement(
const eid_t&
id)
const {
60 return _containingEndorsements.lower_bound(
id);
63 void removeContainingEndorsement(
64 const typename containing_endorsement_store_t::const_iterator it) {
65 _containingEndorsements.erase(it);
69 void toVbkEncoding(WriteStream& stream)
const {
71 using value_t =
typename decltype(_containingEndorsements)::value_type;
72 writeContainer<decltype(_containingEndorsements)>(
74 _containingEndorsements,
75 [&](WriteStream&,
const value_t& endorsement) {
76 endorsement.second->toVbkEncoding(stream);
83 containing_endorsement_store_t _containingEndorsements{};
87 std::vector<const endorsement_t*> _endorsedBy;
92 _containingEndorsements.clear();
99 ValidationState& state);
107 std::vector<T> endorsements;
118 return state.Invalid(
"popstate-bad-endorsement");
121 for (
const auto& endorsement : endorsements) {
122 auto it = out._containingEndorsements.emplace(
123 endorsement.getId(), std::make_shared<T>(endorsement));
125 VBK_ASSERT(it->second);
Class that is used for storing validation state.
constexpr const auto MAX_POPDATA_ATV
absolute maximum number of ATV blocks per ALT block
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr const auto MAX_POPDATA_VTB
absolute maximum number of VTB blocks per ALT block
Binary reading stream, that is useful during binary deserialization.