veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
network_byte_pair.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_NETWORK_BYTE_PAIR_HPP
7#define VERIBLOCK_POP_CPP_NETWORK_BYTE_PAIR_HPP
8
9#include <cstdint>
10#include <string>
11#include <veriblock/pop/json.hpp>
12
13namespace altintegration {
14
18 bool hasValue = false;
20 uint8_t value = 0;
21
22 operator bool() const { return hasValue; }
23
24 bool operator==(const VbkNetworkType& other) const {
25 if (!hasValue && !other.hasValue) {
26 return true;
27 }
28
29 return hasValue && other.hasValue && value == other.value;
30 }
31
32 std::string toPrettyString() const {
33 if (hasValue) {
34 return std::to_string(value);
35 }
36
37 return {"null"};
38 }
39
40 template <typename JsonValue>
41 void putJson(JsonValue& obj) const {
42 if (hasValue) {
43 json::putIntKV(obj, "networkByte", value);
44 } else {
45 json::putNullKV(obj, "networkByte");
46 }
47 }
48};
49
56 uint8_t typeId = 0;
57};
58
59} // namespace altintegration
60
61#endif // VERIBLOCK_POP_CPP_NETWORK_BYTE_PAIR_HPP
Defines logging helpers.
Definition: block.hpp:14
VbkNetworkType networkType
< works as std::optional. if hasNetworkByte is true, networkByte is set
Stores pair of TxType and VBK network byte.
works as optional<uint8_t>
bool hasValue
if hasValue == false, it is mainnet
uint8_t value
otherwise, use value for network ID