veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
keystone_container.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 VERIBLOCK_POP_CPP_KEYSTONE_CONTAINER_HPP
7#define VERIBLOCK_POP_CPP_KEYSTONE_CONTAINER_HPP
8
9#include <cstddef>
10#include <cstdint>
11#include <vector>
12#include <veriblock/pop/blockchain/block_index.hpp>
13#include <veriblock/pop/entities/altblock.hpp>
14
15#include "veriblock/pop/json.hpp"
16#include "veriblock/pop/strutil.hpp"
17
18namespace altintegration {
19class ValidationState;
20class WriteStream;
21struct AltBlock;
22struct ReadStream;
23template <typename Block>
24struct BlockIndex;
25
33 std::vector<uint8_t> firstPreviousKeystone;
34 std::vector<uint8_t> secondPreviousKeystone;
35
36 static KeystoneContainer createFromPrevious(const BlockIndex<AltBlock>* prev,
37 const uint32_t keystoneInterval);
38
39 void toVbkEncoding(WriteStream& stream) const;
40
41 size_t estimateSize() const;
42
43 bool operator==(const KeystoneContainer& o) const {
44 return firstPreviousKeystone == o.firstPreviousKeystone &&
45 secondPreviousKeystone == o.secondPreviousKeystone;
46 }
47};
48
51 KeystoneContainer& container,
52 ValidationState& state);
53
55template <typename JsonValue>
56JsonValue ToJSON(const KeystoneContainer& c) {
57 auto obj = json::makeEmptyObject<JsonValue>();
58 json::putStringKV(
59 obj, "firstPreviousKeystone", HexStr(c.firstPreviousKeystone));
60 json::putStringKV(
61 obj, "secondPreviousKeystone", HexStr(c.secondPreviousKeystone));
62 return obj;
63}
64
65} // namespace altintegration
66
67#endif // VERIBLOCK_POP_CPP_KEYSTONE_CONTAINER_HPP
Class that is used for storing validation state.
Binary writer that is useful for binary serialization.
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...
std::string HexStr(const T itbegin, const T itend)
Convert bytes to hex.
Definition: strutil.hpp:44
A node in a block tree.
Definition: block_index.hpp:31
A container for two previous keystones of endorsed block.
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22