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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
use bytes::Bytes;
use smallvec::SmallVec;
use tl_proto::{BoxedConstructor, TlRead, TlWrite};
use super::{rldp, HashRef};
#[derive(TlWrite, TlRead)]
pub struct Nodes<'tl> {
pub nodes: SmallVec<[Node<'tl>; 5]>,
}
impl BoxedConstructor for Nodes<'_> {
const TL_ID: u32 = tl_proto::id!("overlay.nodes", scheme = "scheme.tl");
}
#[derive(Clone, TlWrite, TlRead)]
pub struct NodesOwned {
pub nodes: SmallVec<[NodeOwned; 5]>,
}
impl BoxedConstructor for NodesOwned {
const TL_ID: u32 = Nodes::TL_ID;
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, TlWrite, TlRead)]
pub struct Node<'tl> {
pub id: everscale_crypto::tl::PublicKey<'tl>,
#[tl(size_hint = 32)]
pub overlay: HashRef<'tl>,
#[tl(size_hint = 4)]
pub version: u32,
pub signature: &'tl [u8],
}
impl Node<'_> {
pub fn as_equivalent_owned(&self) -> NodeOwned {
NodeOwned {
id: self.id.as_equivalent_owned(),
overlay: *self.overlay,
version: self.version,
signature: self.signature.to_vec().into(),
}
}
}
#[derive(Debug, Clone, TlWrite, TlRead)]
pub struct NodeOwned {
pub id: everscale_crypto::tl::PublicKeyOwned,
pub overlay: [u8; 32],
pub version: u32,
pub signature: Bytes,
}
impl NodeOwned {
pub fn as_equivalent_ref(&self) -> Node {
Node {
id: self.id.as_equivalent_ref(),
overlay: &self.overlay,
version: self.version,
signature: &self.signature,
}
}
}
#[derive(TlWrite)]
#[tl(boxed, id = "overlay.node.toSign", scheme = "scheme.tl")]
pub struct NodeToSign<'tl> {
pub id: HashRef<'tl>,
pub overlay: HashRef<'tl>,
pub version: u32,
}
#[derive(TlWrite)]
#[tl(boxed, id = "tonNode.shardPublicOverlayId", scheme = "scheme.tl")]
pub struct ShardPublicOverlayId<'tl> {
pub workchain: i32,
pub shard: u64,
pub zero_state_file_hash: HashRef<'tl>,
}
pub struct CatchainFirstBlock<'a, 'tl: 'a, I> {
pub unique_hash: HashRef<'tl>,
pub nodes: tl_proto::IterRef<'a, I>,
}
impl<'a, 'tl: 'a, I> TlWrite for CatchainFirstBlock<'a, 'tl, I>
where
I: Iterator<Item = HashRef<'tl>> + ExactSizeIterator + Clone,
{
type Repr = tl_proto::Boxed;
fn max_size_hint(&self) -> usize {
4 + self.unique_hash.max_size_hint() + self.nodes.max_size_hint()
}
fn write_to<P>(&self, packet: &mut P)
where
P: tl_proto::TlPacket,
{
const ID: u32 = tl_proto::id!(scheme = "scheme.tl", "catchain.firstblock");
ID.write_to(packet);
self.unique_hash.write_to(packet);
self.nodes.write_to(packet);
}
}
#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
#[tl(boxed, id = "overlay.message", scheme = "scheme.tl", size_hint = 32)]
pub struct Message<'tl> {
pub overlay: HashRef<'tl>,
}
#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
#[tl(boxed, scheme = "scheme.tl")]
pub enum Broadcast<'tl> {
#[tl(id = "overlay.broadcast")]
Broadcast(OverlayBroadcast<'tl>),
#[tl(id = "overlay.broadcastFec")]
BroadcastFec(OverlayBroadcastFec<'tl>),
#[tl(id = "overlay.broadcastFecShort")]
BroadcastFecShort {
src: everscale_crypto::tl::PublicKey<'tl>,
certificate: Certificate<'tl>,
#[tl(size_hint = 32)]
broadcast_hash: HashRef<'tl>,
#[tl(size_hint = 32)]
part_data_hash: HashRef<'tl>,
seqno: u32,
signature: &'tl [u8],
},
#[tl(id = "overlay.broadcastNotFound", size_hint = 0)]
BroadcastNotFound,
#[tl(id = "overlay.fec.completed", size_hint = 32)]
FecCompleted { hash: HashRef<'tl> },
#[tl(id = "overlay.fec.received", size_hint = 32)]
FecReceived { hash: HashRef<'tl> },
#[tl(id = "overlay.unicast")]
Unicast { data: &'tl [u8] },
}
#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
pub struct OverlayBroadcast<'tl> {
pub src: everscale_crypto::tl::PublicKey<'tl>,
pub certificate: Certificate<'tl>,
pub flags: u32,
pub data: &'tl [u8],
pub date: u32,
pub signature: &'tl [u8],
}
#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
pub struct OverlayBroadcastFec<'tl> {
pub src: everscale_crypto::tl::PublicKey<'tl>,
pub certificate: Certificate<'tl>,
#[tl(size_hint = 32)]
pub data_hash: HashRef<'tl>,
pub data_size: u32,
pub flags: u32,
pub data: &'tl [u8],
pub seqno: u32,
pub fec: rldp::RaptorQFecType,
pub date: u32,
pub signature: &'tl [u8],
}
#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
#[tl(boxed, scheme = "scheme.tl")]
pub enum Certificate<'tl> {
#[tl(id = "overlay.certificate")]
Certificate {
issued_by: everscale_crypto::tl::PublicKey<'tl>,
expire_at: u32,
max_size: u32,
signature: &'tl [u8],
},
#[tl(id = "overlay.emptyCertificate", size_hint = 0)]
EmptyCertificate,
}