veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
merkle_path.hpp
1// Copyright (c) 2019-2022 Xenios SEZC
2// https://www.veriblock.org
3// Distributed under the MIT software license, see the accompanying
4// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_MERKLE_PATH_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_MERKLE_PATH_HPP_
8
9#include <cstddef>
10#include <cstdint>
11#include <stdexcept>
12#include <vector>
13
15#include "veriblock/pop/hashutil.hpp"
16#include "veriblock/pop/json.hpp"
17#include "veriblock/pop/serde.hpp"
18#include "veriblock/pop/strutil.hpp"
19#include "veriblock/pop/uint.hpp"
20
21namespace altintegration {
22class ValidationState;
23class WriteStream;
24struct ReadStream;
25
31struct MerklePath {
32 int32_t index{};
33 uint256 subject{};
34 std::vector<uint256> layers{};
35
40 void toRaw(WriteStream& stream) const;
41
46 void toVbkEncoding(WriteStream& stream) const;
47
48 size_t estimateSize() const;
49
55};
56
58template <typename JsonValue>
59JsonValue ToJSON(const MerklePath& m) {
60 JsonValue obj = json::makeEmptyObject<JsonValue>();
61 json::putIntKV(obj, "index", m.index);
62 json::putStringKV(obj, "subject", HexStr(m.subject));
63 json::putArrayKV(obj, "layers", m.layers);
64 return obj;
65}
66
69 const uint256& subject,
70 MerklePath& out,
71 ValidationState& state);
72
75 const uint256& subject,
76 MerklePath& out,
77 ValidationState& state);
78
79} // namespace altintegration
80
81#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_MERKLE_PATH_HPP_
Class that is used for storing validation state.
Binary writer that is useful for binary serialization.
All constants in alt-cpp.
Defines logging helpers.
Definition: block.hpp:14
bool DeserializeFromRaw(ReadStream &stream, AltBlock &out, ValidationState &state, const AltBlock::hash_t &=AltBlock::hash_t{})
This is an overloaded member function, provided for convenience. It differs from the above function o...
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::string HexStr(const T itbegin, const T itend)
Convert bytes to hex.
Definition: strutil.hpp:44
Path in Merkle tree which proves that subject is inside this tree.
Definition: merkle_path.hpp:31
void toRaw(WriteStream &stream) const
Convert MerklePath to data stream using MerklePath basic byte format.
uint256 calculateMerkleRoot() const
Calculate the hash of the merkle root.
void toVbkEncoding(WriteStream &stream) const
Convert MerklePath to data stream using MerklePath VBK byte format.
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22