veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
btctx.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_BTCTX_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_BTCTX_HPP_
8
9#include <cstddef>
10#include <cstdint>
11#include <utility>
12#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
18namespace altintegration {
19class ValidationState;
20class WriteStream;
21struct ReadStream;
22
29struct BtcTx {
30 using hash_t = uint256;
31 std::vector<uint8_t> tx{};
32
33 BtcTx() = default;
34 BtcTx(std::vector<uint8_t> bytes) : tx(std::move(bytes)) {}
35 BtcTx(Slice<const uint8_t> slice) : tx(slice.begin(), slice.end()) {}
36
37 friend bool operator==(const BtcTx& a, const BtcTx& b) {
38 return a.tx == b.tx;
39 }
40
41 friend bool operator!=(const BtcTx& a, const BtcTx& b) {
42 return !(a.tx == b.tx);
43 }
44
49 void toVbkEncoding(WriteStream& stream) const;
50
55 void toRaw(WriteStream& stream) const;
56
57 size_t estimateSize() const;
58
63 hash_t getHash() const;
64};
65
68 BtcTx& out,
69 ValidationState& state);
70
71} // namespace altintegration
72
73#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_ENTITIES_BTCTX_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...
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
Bitcoin transaction representation.
Definition: btctx.hpp:29
void toVbkEncoding(WriteStream &stream) const
Convert BtcTx to data stream using BtcTx VBK byte format.
void toRaw(WriteStream &stream) const
Convert BtcTx to data stream using BtcTx basic byte format.
hash_t getHash() const
Calculate the hash of the btc transaction.
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22
Non-owning contiguous array.
Definition: slice.hpp:22