veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
vbkpoptx.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_VBKPOPTX_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBKPOPTX_HPP_
8
9#include <cstddef>
10#include <cstdint>
11#include <string>
12#include <vector>
14#include <veriblock/pop/hashutil.hpp>
15#include <veriblock/pop/serde.hpp>
16#include <veriblock/pop/slice.hpp>
17
18#include "address.hpp"
19#include "btcblock.hpp"
20#include "btctx.hpp"
21#include "merkle_path.hpp"
22#include "vbkblock.hpp"
23#include "veriblock/pop/blob.hpp"
24#include "veriblock/pop/entities/network_byte_pair.hpp"
25#include "veriblock/pop/json.hpp"
26#include "veriblock/pop/strutil.hpp"
27#include "veriblock/pop/uint.hpp"
28
29namespace altintegration {
30class ValidationState;
31class WriteStream;
32struct ReadStream;
33template <class ElementType>
34struct Slice;
35
42struct VbkPopTx {
43 using hash_t = uint256;
44
45 NetworkBytePair networkOrType{};
46 Address address{};
47 VbkBlock publishedBlock{};
48 BtcTx bitcoinTransaction{};
49 MerklePath merklePath{};
50 BtcBlock blockOfProof{};
51 std::vector<BtcBlock> blockOfProofContext{};
52 std::vector<uint8_t> signature{};
53 std::vector<uint8_t> publicKey{};
54
59 void toVbkEncoding(WriteStream& stream) const;
60
61 size_t estimateSize() const;
62
67 hash_t getHash() const;
68
69 std::string toPrettyString() const;
70
71 friend bool operator==(const VbkPopTx& a, const VbkPopTx& b) {
72 return a.getHash() == b.getHash();
73 }
74
75 friend bool operator!=(const VbkPopTx& a, const VbkPopTx& b) {
76 return !(a == b);
77 }
78
79 private:
85 void toRaw(WriteStream& stream) const;
86};
87
89template <typename JsonValue>
90JsonValue ToJSON(const VbkPopTx& tx) {
91 JsonValue obj = json::makeEmptyObject<JsonValue>();
92 tx.networkOrType.networkType.template putJson<JsonValue>(obj);
93 json::putStringKV(obj, "hash", tx.getHash().toHex());
94 json::putIntKV(obj, "type", tx.networkOrType.typeId);
95 json::putStringKV(obj, "address", tx.address.toString());
96 json::putKV(obj, "publishedBlock", ToJSON<JsonValue>(tx.publishedBlock));
97 json::putStringKV(
98 obj, "bitcoinTransaction", SerializeToRawHex(tx.bitcoinTransaction));
99 json::putKV(obj, "merklePath", ToJSON<JsonValue>(tx.merklePath));
100 json::putKV(obj, "blockOfProof", ToJSON<JsonValue>(tx.blockOfProof));
101 json::putArrayKV(obj, "blockOfProofContext", tx.blockOfProofContext);
102 json::putStringKV(obj, "signature", HexStr(tx.signature));
103 json::putStringKV(obj, "publicKey", HexStr(tx.publicKey));
104 return obj;
105}
106
109 Slice<const uint8_t> signature,
110 Slice<const uint8_t> publicKey,
111 VbkPopTx& out,
112 ValidationState& state);
113
116 VbkPopTx& out,
117 ValidationState& state);
118
119} // namespace altintegration
120
121#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBKPOPTX_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
std::string SerializeToRawHex(const T &obj)
Serialize to HEX RAW encoding.
Definition: serde.hpp:462
Blob< SHA256_HASH_SIZE > uint256
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: uint.hpp:24
VbkNetworkType networkType
< works as std::optional. if hasNetworkByte is true, networkByte is set
Stores pair of TxType and VBK network byte.
Represents address on VBK chain.
Definition: address.hpp:28
std::string toString() const noexcept
Convert VBK address to text representation.
Bitcoin block.
Definition: btcblock.hpp:41
Bitcoin transaction representation.
Definition: btctx.hpp:29
Path in Merkle tree which proves that subject is inside this tree.
Definition: merkle_path.hpp:31
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22
Non-owning contiguous array.
Definition: slice.hpp:22
Veriblock block.
Definition: vbkblock.hpp:32
Veriblock POP transaction, which endorses VBK block in BTC blockchain.
Definition: vbkpoptx.hpp:42
hash_t getHash() const
Calculate the hash of the vbk pop transaction.
void toVbkEncoding(WriteStream &stream) const
Convert VbkPopTx to data stream using VbkPopTx VBK byte format.