veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
vbktx.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_VBKTX_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBKTX_HPP_
8
9#include <cstddef>
10#include <cstdint>
11#include <vector>
13#include <veriblock/pop/hashutil.hpp>
14#include <veriblock/pop/serde.hpp>
15#include <veriblock/pop/slice.hpp>
16#include <veriblock/pop/uint.hpp>
17
18#include "address.hpp"
19#include "coin.hpp"
20#include "output.hpp"
21#include "publication_data.hpp"
22#include "veriblock/pop/blob.hpp"
23#include "veriblock/pop/entities/network_byte_pair.hpp"
24#include "veriblock/pop/json.hpp"
25#include "veriblock/pop/strutil.hpp"
26
27namespace altintegration {
28class ValidationState;
29class WriteStream;
30struct ReadStream;
31template <class ElementType>
32struct Slice;
33
40struct VbkTx {
41 using hash_t = uint256;
42
43 NetworkBytePair networkOrType{};
44 Address sourceAddress{};
45 Coin sourceAmount{};
46 std::vector<Output> outputs{};
47 int64_t signatureIndex{};
48 PublicationData publicationData{};
49 std::vector<uint8_t> signature{};
50 std::vector<uint8_t> publicKey{};
51
56 void toVbkEncoding(WriteStream& stream) const;
57
62 std::vector<uint8_t> toVbkEncoding() const;
63
64 size_t estimateSize() const;
65
71
77
78 friend bool operator==(const VbkTx& a, const VbkTx& b) {
79 return a.getHash() == b.getHash();
80 }
81
82 friend bool operator!=(const VbkTx& a, const VbkTx& b) { return !(a == b); }
83
84 private:
90 void toRaw(WriteStream& stream) const;
91};
92
94template <typename JsonValue>
95JsonValue ToJSON(const VbkTx& tx) {
96 JsonValue obj = json::makeEmptyObject<JsonValue>();
97 tx.networkOrType.networkType.template putJson<JsonValue>(obj);
98 json::putStringKV(obj, "hash", tx.getHash().toHex());
99 json::putIntKV(obj, "type", tx.networkOrType.typeId);
100 json::putStringKV(obj, "sourceAddress", tx.sourceAddress.toString());
101 json::putIntKV(obj, "sourceAmount", tx.sourceAmount.units);
102 json::putArrayKV(obj, "outputs", tx.outputs);
103 json::putIntKV(obj, "signatureIndex", tx.signatureIndex);
104 json::putKV(obj, "publicationData", ToJSON<JsonValue>(tx.publicationData));
105 json::putStringKV(obj, "signature", HexStr(tx.signature));
106 json::putStringKV(obj, "publicKey", HexStr(tx.publicKey));
107 return obj;
108}
109
112 Slice<const uint8_t> signature,
113 Slice<const uint8_t> publicKey,
114 VbkTx& out,
115 ValidationState& state);
116
119 VbkTx& out,
120 ValidationState& state);
121
122} // namespace altintegration
123
124#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_VBKTX_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
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.
represents VBK atomic units
Definition: coin.hpp:21
Publication data about ALT block inside VBK blockchain.
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22
Non-owning contiguous array.
Definition: slice.hpp:22
Veriblock transaction, which endorses ALT block in VBK blockchain.
Definition: vbktx.hpp:40
void toVbkEncoding(WriteStream &stream) const
Convert VbkTx to data stream using VbkTx VBK byte format.
Coin calculateTxFee() const
Calculate the fee of the VBK transaction.
uint256 getHash() const
Calculate the hash of the VBK transaction.
std::vector< uint8_t > toVbkEncoding() const
Convert VbkTx to raw bytes data using VBK byte format.