veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
context_info_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_CONTEXT_INFO_CONTAINER_HPP
7#define VERIBLOCK_POP_CPP_CONTEXT_INFO_CONTAINER_HPP
8
9#include <veriblock/pop/blockchain/alt_chain_params.hpp>
10#include <veriblock/pop/serde.hpp>
11
12#include "keystone_container.hpp"
13
14namespace altintegration {
15
21 int height = 0;
22
25
26 static ContextInfoContainer createFromPrevious(
27 const BlockIndex<AltBlock>* prev, const AltChainParams& param);
28
29 uint256 getHash() const;
30
31 void toVbkEncoding(WriteStream& w) const;
32 size_t estimateSize() const;
33
34 bool operator==(const ContextInfoContainer& other) const {
35 return height == other.height && keystones == other.keystones;
36 }
37
38 bool operator!=(const ContextInfoContainer& other) const {
39 return !(this->operator==(other));
40 }
41
42 std::string toPrettyString() const;
43};
44
61 // state root = sha256d(original merkle root || popdata merkle root)
62 // This is a merkle path which consists of 1 node. This merkle path
63 // authenticates 'ctx' to 'endorsed block header' in
64 // PublicationData::contextInfo
65 uint256 stateRoot{};
66
71 const uint256& stateRoot,
72 const BlockIndex<AltBlock>* prev,
73 const AltChainParams& p);
74
77 const std::vector<uint8_t>& txRoot,
78 const uint256& popDataRoot,
79 const BlockIndex<AltBlock>* prev,
80 const AltChainParams& p);
81
82 bool operator==(const AuthenticatedContextInfoContainer& other) const {
83 return ctx == other.ctx && stateRoot == other.stateRoot;
84 }
85
86 void toVbkEncoding(WriteStream& w) const;
87
88 size_t estimateSize() const;
89
90 uint256 getTopLevelMerkleRoot() const;
91};
92
96 ValidationState& state);
97
101 ValidationState& state);
102
104template <typename JsonValue>
105JsonValue ToJSON(const ContextInfoContainer& a) {
106 auto o = json::makeEmptyObject<JsonValue>();
107 json::putIntKV(o, "height", a.height);
108 json::putStringKV(
109 o, "firstPreviousKeystone", HexStr(a.keystones.firstPreviousKeystone));
110 json::putStringKV(
111 o, "secondPreviousKeystone", HexStr(a.keystones.secondPreviousKeystone));
112 return o;
113}
114
116template <typename JsonValue>
117JsonValue ToJSON(const AuthenticatedContextInfoContainer& a) {
118 auto o = json::makeEmptyObject<JsonValue>();
119
120 WriteStream w;
121 a.toVbkEncoding(w);
122
123 json::putStringKV(o, "serialized", HexStr(w.data()));
124 json::putStringKV(o, "stateRoot", HexStr(a.stateRoot));
125 json::putKV(o, "context", ToJSON<JsonValue>(a.ctx));
126 return o;
127}
128
129} // namespace altintegration
130
131#endif // VERIBLOCK_POP_CPP_CONTEXT_INFO_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
Base class for all Altchain-related configs.
Contains ContextInfoContainer and merkle path which authenticates hash of ContextInfoContainer to a b...
static AuthenticatedContextInfoContainer createFromPrevious(const uint256 &stateRoot, const BlockIndex< AltBlock > *prev, const AltChainParams &p)
static AuthenticatedContextInfoContainer createFromPrevious(const std::vector< uint8_t > &txRoot, const uint256 &popDataRoot, const BlockIndex< AltBlock > *prev, const AltChainParams &p)
This is an overloaded member function, provided for convenience. It differs from the above function o...
A node in a block tree.
Definition: block_index.hpp:31
Container of context info for endorsed block.
KeystoneContainer keystones
endorsed block previous keystones
A container for two previous keystones of endorsed block.
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22