veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
address.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_ADDRESS_HPP
7#define ALT_INTEGRATION_ADDRESS_HPP
8
9#include <cstdint>
10#include <string>
11#include <veriblock/pop/read_stream.hpp>
12#include <veriblock/pop/slice.hpp>
13#include <veriblock/pop/write_stream.hpp>
14
15namespace altintegration {
16
18enum class AddressType {
19 STANDARD = 1,
20 MULTISIG = 3,
21};
22
28struct Address {
29 Address();
30
31 bool operator==(const Address& other) const noexcept;
32 bool operator!=(const Address& other) const noexcept;
33 bool operator==(const std::string& other) const noexcept;
34
39 AddressType getType() const noexcept { return m_Type; }
40
45 void getPopBytes(WriteStream& stream) const;
46
53
60
67 bool fromString(const std::string& input, ValidationState& state);
68
69 static Address assertFromString(const std::string& input);
70
75 std::string toString() const noexcept;
76
82 void toVbkEncoding(WriteStream& stream) const;
83
84 size_t estimateSize() const;
85
87 Address& out,
88 ValidationState& state);
89
90 private:
91 Address(const AddressType type, std::string addr)
92 : m_Type(type), m_Address(std::move(addr)) {}
93
94 AddressType m_Type{};
95 std::string m_Address{};
96};
97
99template <typename Value>
100inline Value ToJSON(const Address& addr) {
101 return ToJSON<Value>(addr.toString());
102}
103
112 Address& out,
113 ValidationState& state);
114
115} // namespace altintegration
116
117#endif
Class that is used for storing validation state.
Binary writer that is useful for binary serialization.
Defines logging helpers.
Definition: block.hpp:14
AddressType
VBK Address type (modelled after transaction type).
Definition: address.hpp:18
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Represents address on VBK chain.
Definition: address.hpp:28
bool isDerivedFromPublicKey(Slice< const uint8_t > publicKey) const
Check if given address is generated with provided public key.
static Address fromPublicKey(Slice< const uint8_t > publicKey)
Convert public key to VBK standard address.
void toVbkEncoding(WriteStream &stream) const
Convert VBK address to data stream using VBK byte format.
AddressType getType() const noexcept
Return address type.
Definition: address.hpp:39
bool fromString(const std::string &input, ValidationState &state)
Parse provided string and convert it to VBK address.
void getPopBytes(WriteStream &stream) const
Return a Pop bytes from the address.
friend bool DeserializeFromVbkEncoding(ReadStream &stream, Address &out, ValidationState &state)
Read data from the stream and convert it to VBK address.
std::string toString() const noexcept
Convert VBK address to text representation.
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22
Non-owning contiguous array.
Definition: slice.hpp:22