6#ifndef VERIBLOCK_POP_CPP_ADAPTORS_PAYLOADS_PROVIDER_IMPL_BINDINGS
7#define VERIBLOCK_POP_CPP_ADAPTORS_PAYLOADS_PROVIDER_IMPL_BINDINGS
9#include <veriblock/pop/c/extern.h>
11#include <veriblock/pop/serde.hpp>
12#include <veriblock/pop/storage/payloads_provider.hpp>
14#include "storage_interface.hpp"
20const char DB_VBK_PREFIX =
'^';
21const char DB_VTB_PREFIX =
'<';
22const char DB_ATV_PREFIX =
'>';
24template <
typename pop_t>
25std::vector<uint8_t> payloads_key(
const typename pop_t::id_t&
id);
28inline std::vector<uint8_t> payloads_key<ATV>(
const ATV::id_t&
id) {
29 auto res =
id.asVector();
30 res.insert(res.begin(), DB_ATV_PREFIX);
35inline std::vector<uint8_t> payloads_key<VTB>(
const VTB::id_t&
id) {
36 auto res =
id.asVector();
37 res.insert(res.begin(), DB_VTB_PREFIX);
42inline std::vector<uint8_t> payloads_key<VbkBlock>(
const VbkBlock::id_t&
id) {
43 auto res =
id.asVector();
44 res.insert(res.begin(), DB_VBK_PREFIX);
53 template <
typename pop_t>
54 bool getPayloads(
const typename pop_t::id_t&
id,
57 std::vector<uint8_t> bytes_out;
58 if (!storage_.read(payloads_key<pop_t>(
id), bytes_out)) {
60 "bad-" + pop_t::name(),
61 format(
"can not read {} from storage", pop_t::name()));
67 "bad-" + pop_t::name(),
68 format(
"can not deserialize {} from bytes", pop_t::name()));
75 return getPayloads<ATV>(
id, out, state);
79 return getPayloads<VTB>(
id, out, state);
85 return getPayloads<VbkBlock>(
id, out, state);
88 void writePayloads(
const PopData& payloads)
override {
89 auto batch = storage_.generateWriteBatch();
91 for (
const auto& atv : payloads.atvs) {
92 batch->write(payloads_key<VbkBlock>(atv.blockOfProof.getId()),
98 for (
const auto& vtb : payloads.vtbs) {
99 batch->write(payloads_key<VbkBlock>(vtb.containingBlock.getId()),
105 for (
const auto& vbk : payloads.context) {
106 batch->write(payloads_key<VbkBlock>(vbk.getId()),
Class that is used for storing validation state.
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::vector< uint8_t > SerializeToVbkEncoding(const T &obj)
Serialize to VBK encoding.
Accessor for ATV/VTB/VbkBlock bodies given hash.
Represents ALT block body of POP-related info.
Binary reading stream, that is useful during binary deserialization.
Veriblock to Bitcoin publication, committed to Veriblock blockchain in containingBlock.
bool getATV(const ATV::id_t &id, ATV &out, ValidationState &state) override
should write ATV identified by id into out, or return false
bool getVBK(const VbkBlock::id_t &id, VbkBlock &out, ValidationState &state) override
should write VbkBlock identified by id into out, or return false
bool getVTB(const VTB::id_t &id, VTB &out, ValidationState &state) override
should write VTB identified by id into out, or return false