veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
vbk_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_VBK_MERKLE_PATH_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBK_MERKLE_PATH_HPP_
8
9#include <cstddef>
10#include <cstdint>
11#include <vector>
12
14#include "veriblock/pop/hashutil.hpp"
15#include "veriblock/pop/json.hpp"
16#include "veriblock/pop/serde.hpp"
17#include "veriblock/pop/uint.hpp"
18
19namespace altintegration {
20class ValidationState;
21class WriteStream;
22struct ReadStream;
23
31 int32_t treeIndex = 0;
33 int32_t index{};
37 std::vector<uint256> layers{};
38
43 void toVbkEncoding(WriteStream& stream) const;
44
45 size_t estimateSize() const;
46
52
57 std::vector<uint32_t> equalLayerIndexes() const;
58};
59
61template <typename JsonValue>
62JsonValue ToJSON(const VbkMerklePath& mp) {
63 JsonValue obj = json::makeEmptyObject<JsonValue>();
64 json::putIntKV(obj, "treeIndex", mp.treeIndex);
65 json::putIntKV(obj, "index", mp.index);
66 json::putStringKV(obj, "subject", mp.subject.toHex());
67 json::putArrayKV(obj, "layers", mp.layers);
68 return obj;
69}
70
73 VbkMerklePath& out,
74 ValidationState& state);
75
76} // namespace altintegration
77
78#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBK_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 DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22
Path in Merkle tree, which proves that subject exists in the tree.
int32_t treeIndex
an indentifier of which transactions tree (pop=0, normal=1)
std::vector< uint256 > layers
the layers in the merkle path
int32_t index
the index of the bottom data TxID in the block it came from
uint128 calculateMerkleRoot() const
Calculate the hash of the vb merkle root.
void toVbkEncoding(WriteStream &stream) const
Convert VbkMerklePath to data stream using VbkMerklePath VBK byte format.
uint256 subject
TxID that this merkle path authenticates.
std::vector< uint32_t > equalLayerIndexes() const
Return layer indexes where left and right nodes are equal.