veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
altintegration::adaptors::PayloadsStorageImpl Struct Reference

Detailed Description

Definition at line 48 of file payloads_provider_impl.hpp.

+ Inheritance diagram for altintegration::adaptors::PayloadsStorageImpl:
+ Collaboration diagram for altintegration::adaptors::PayloadsStorageImpl:

Public Member Functions

 PayloadsStorageImpl (Storage &storage)
 
template<typename pop_t >
bool getPayloads (const typename pop_t::id_t &id, pop_t &out, ValidationState &state)
 
bool getATV (const ATV::id_t &id, ATV &out, ValidationState &state) override
 should write ATV identified by id into out, or return false More...
 
bool getVTB (const VTB::id_t &id, VTB &out, ValidationState &state) override
 should write VTB identified by id into out, or return false More...
 
bool getVBK (const VbkBlock::id_t &id, VbkBlock &out, ValidationState &state) override
 should write VbkBlock identified by id into out, or return false More...
 
void writePayloads (const PopData &payloads) override
 
- Public Member Functions inherited from altintegration::PayloadsStorage
virtual bool getATV (const ATV::id_t &ids, ATV &out, ValidationState &state)=0
 should write ATV identified by id into out, or return false More...
 
virtual bool getVTB (const VTB::id_t &ids, VTB &out, ValidationState &state)=0
 should write VTB identified by id into out, or return false More...
 
virtual bool getVBK (const VbkBlock::id_t &id, VbkBlock &out, ValidationState &state)=0
 should write VbkBlock identified by id into out, or return false More...
 
virtual void writePayloads (const PopData &payloads)=0
 
bool getPayload (const VbkBlock::id_t &id, VbkBlock &out, ValidationState &state)
 alias for getVBK More...
 
bool getPayload (const VTB::id_t &id, VTB &out, ValidationState &state)
 alias for getVTB More...
 
bool getPayload (const ATV::id_t &id, ATV &out, ValidationState &state)
 alias for getATV More...
 

Constructor & Destructor Documentation

◆ PayloadsStorageImpl()

altintegration::adaptors::PayloadsStorageImpl::PayloadsStorageImpl ( Storage storage)
inline

Definition at line 51 of file payloads_provider_impl.hpp.

51: storage_(storage) {}

Member Function Documentation

◆ getATV()

bool altintegration::adaptors::PayloadsStorageImpl::getATV ( const ATV::id_t ids,
ATV out,
ValidationState state 
)
inlineoverridevirtual

Implements altintegration::PayloadsStorage.

Definition at line 74 of file payloads_provider_impl.hpp.

74 {
75 return getPayloads<ATV>(id, out, state);
76 }

◆ getPayloads()

template<typename pop_t >
bool altintegration::adaptors::PayloadsStorageImpl::getPayloads ( const typename pop_t::id_t &  id,
pop_t &  out,
ValidationState state 
)
inline

Definition at line 54 of file payloads_provider_impl.hpp.

56 {
57 std::vector<uint8_t> bytes_out;
58 if (!storage_.read(payloads_key<pop_t>(id), bytes_out)) {
59 return state.Invalid(
60 "bad-" + pop_t::name(),
61 format("can not read {} from storage", pop_t::name()));
62 }
63
64 ReadStream stream(bytes_out);
65 if (!DeserializeFromVbkEncoding(stream, out, state)) {
66 return state.Invalid(
67 "bad-" + pop_t::name(),
68 format("can not deserialize {} from bytes", pop_t::name()));
69 }
70
71 return true;
72 }
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ getVBK()

bool altintegration::adaptors::PayloadsStorageImpl::getVBK ( const VbkBlock::id_t id,
VbkBlock out,
ValidationState state 
)
inlineoverridevirtual

Implements altintegration::PayloadsStorage.

Definition at line 82 of file payloads_provider_impl.hpp.

84 {
85 return getPayloads<VbkBlock>(id, out, state);
86 }

◆ getVTB()

bool altintegration::adaptors::PayloadsStorageImpl::getVTB ( const VTB::id_t ids,
VTB out,
ValidationState state 
)
inlineoverridevirtual

Implements altintegration::PayloadsStorage.

Definition at line 78 of file payloads_provider_impl.hpp.

78 {
79 return getPayloads<VTB>(id, out, state);
80 }

◆ writePayloads()

void altintegration::adaptors::PayloadsStorageImpl::writePayloads ( const PopData payloads)
inlineoverridevirtual

Implements altintegration::PayloadsStorage.

Definition at line 88 of file payloads_provider_impl.hpp.

88 {
89 auto batch = storage_.generateWriteBatch();
90
91 for (const auto& atv : payloads.atvs) {
92 batch->write(payloads_key<VbkBlock>(atv.blockOfProof.getId()),
93 SerializeToVbkEncoding(atv.blockOfProof));
94
95 batch->write(payloads_key<ATV>(atv.getId()), SerializeToVbkEncoding(atv));
96 }
97
98 for (const auto& vtb : payloads.vtbs) {
99 batch->write(payloads_key<VbkBlock>(vtb.containingBlock.getId()),
100 SerializeToVbkEncoding(vtb.containingBlock));
101
102 batch->write(payloads_key<VTB>(vtb.getId()), SerializeToVbkEncoding(vtb));
103 }
104
105 for (const auto& vbk : payloads.context) {
106 batch->write(payloads_key<VbkBlock>(vbk.getId()),
108 }
109
110 batch->writeBatch();
111 }
std::vector< uint8_t > SerializeToVbkEncoding(const T &obj)
Serialize to VBK encoding.
Definition: serde.hpp:440

The documentation for this struct was generated from the following file: