1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6

7
#pragma once
8

9
#include "../Data.h"
10
#include "../PublicKey.h"
11

12
#include <array>
13
#include <string>
14

15
namespace TW::Groestlcoin {
16

17
class Address {
18
  public:
19
    /// Number of bytes in an address.
20
    static const size_t size = 21;
21

22
    /// Address data consisting of a prefix byte followed by the public key
23
    /// hash.
24
    std::array<byte, size> bytes;
25

26
    /// Determines whether a collection of bytes makes a valid  address.
27
    template <typename T>
28 0
    static bool isValid(const T& data) {
29 0
        return data.size() == size;
30
    }
31

32
    /// Determines whether a string makes a valid address.
33
    static bool isValid(const std::string& string);
34

35
    /// Determines whether a string makes a valid address, and the prefix is
36
    /// within the valid set.
37
    static bool isValid(const std::string& string, const std::vector<byte>& validPrefixes);
38

39
    /// Initializes a  address with a string representation.
40
    explicit Address(const std::string& string);
41

42
    /// Initializes a  address with a collection of bytes.
43
    explicit Address(const std::vector<uint8_t>& data);
44

45
    /// Initializes a  address with a public key and a prefix.
46
    Address(const PublicKey& publicKey, uint8_t prefix);
47

48
    /// Returns a string representation of the address.
49
    std::string string() const;
50
};
51

52
inline bool operator==(const Address& lhs, const Address& rhs) {
53
    return lhs.bytes == rhs.bytes;
54
}
55

56
} // namespace TW::Groestlcoin
57

58
/// Wrapper for C interface.
59
struct TWGroestlcoinAddress {
60
    TW::Groestlcoin::Address impl;
61
};

Read our documentation on viewing source code .

Loading