forked from ton-blockchain/ton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadnl-node-id.hpp
134 lines (113 loc) · 3.34 KB
/
adnl-node-id.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2020 Telegram Systems LLP
*/
#pragma once
#include "keys/keys.hpp"
#include "common/io.hpp"
namespace ton {
namespace adnl {
class AdnlNodeIdShort {
public:
explicit AdnlNodeIdShort(const PublicKeyHash &hash) : hash_(hash) {
}
explicit AdnlNodeIdShort(PublicKeyHash &&hash) : hash_(std::move(hash)) {
}
AdnlNodeIdShort() {
}
explicit AdnlNodeIdShort(td::Slice data) : hash_(data) {
}
explicit AdnlNodeIdShort(td::Bits256 value) : hash_(value) {
}
explicit AdnlNodeIdShort(tl_object_ptr<ton_api::adnl_id_short> obj) : hash_(obj->id_) {
}
const auto &pubkey_hash() const {
return hash_;
}
bool operator==(const AdnlNodeIdShort &with) const {
return hash_ == with.hash_;
}
bool operator!=(const AdnlNodeIdShort &with) const {
return hash_ != with.hash_;
}
bool operator<(const AdnlNodeIdShort &with) const {
return hash_ < with.hash_;
}
tl_object_ptr<ton_api::adnl_id_short> tl() const {
return create_tl_object<ton_api::adnl_id_short>(hash_.tl());
}
auto as_slice() {
return hash_.as_slice();
}
auto as_slice() const {
return hash_.as_slice();
}
auto uint256_value() const {
return hash_.uint256_value();
}
auto bits256_value() const {
return hash_.bits256_value();
}
static AdnlNodeIdShort zero() {
return AdnlNodeIdShort{PublicKeyHash::zero()};
}
bool is_zero() const {
return hash_.is_zero();
}
static td::Result<AdnlNodeIdShort> parse(td::Slice key);
std::string serialize();
private:
PublicKeyHash hash_;
};
class AdnlNodeIdFull {
private:
explicit AdnlNodeIdFull(const tl_object_ptr<ton_api::PublicKey> &pub) : pub_(pub) {
}
public:
explicit AdnlNodeIdFull(const PublicKey &pub) : pub_(pub) {
}
explicit AdnlNodeIdFull(PublicKey &&pub) : pub_(std::move(pub)) {
}
static td::Result<AdnlNodeIdFull> create(const tl_object_ptr<ton_api::PublicKey> &pub) {
return AdnlNodeIdFull{pub};
}
AdnlNodeIdFull() {
}
const auto &pubkey() const {
return pub_;
}
bool empty() const {
return pub_.empty();
}
bool operator==(const AdnlNodeIdFull &with) const {
return pub_ == with.pub_;
}
bool operator!=(const AdnlNodeIdFull &with) const {
return pub_ != with.pub_;
}
auto tl() const {
return pub_.tl();
}
AdnlNodeIdShort compute_short_id() const {
return AdnlNodeIdShort{pub_.compute_short_id()};
}
private:
PublicKey pub_;
};
} // namespace adnl
} // namespace ton
namespace td {
inline StringBuilder &operator<<(StringBuilder &stream, const ton::adnl::AdnlNodeIdShort &value) {
return stream << value.bits256_value();
}
} // namespace td