1use codec::{Decode, Encode};
23use sc_client_api::StorageProof;
24use sc_network_common::message::RequestId;
25use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
26
27#[allow(unused)]
29pub type Message<B> = generic::Message<
30 <B as BlockT>::Header,
31 <B as BlockT>::Hash,
32 <<B as BlockT>::Header as HeaderT>::Number,
33 <B as BlockT>::Extrinsic,
34>;
35
36#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
38pub struct RemoteCallResponse {
39 pub id: RequestId,
41 pub proof: StorageProof,
43}
44
45#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
46pub struct RemoteReadResponse {
48 pub id: RequestId,
50 pub proof: StorageProof,
52}
53
54pub mod generic {
56 use super::{RemoteCallResponse, RemoteReadResponse};
57 use codec::{Decode, Encode, Input};
58 use sc_client_api::StorageProof;
59 use sc_network_common::{
60 message::RequestId,
61 role::Roles,
62 sync::message::{
63 generic::{BlockRequest, BlockResponse},
64 BlockAnnounce,
65 },
66 };
67 use sp_runtime::ConsensusEngineId;
68
69 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
71 pub struct ConsensusMessage {
72 pub protocol: ConsensusEngineId,
74 pub data: Vec<u8>,
76 }
77
78 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
80 pub enum Message<Header, Hash, Number, Extrinsic> {
81 Status(Status<Hash, Number>),
83 BlockRequest(BlockRequest<Hash, Number>),
85 BlockResponse(BlockResponse<Header, Hash, Extrinsic>),
87 BlockAnnounce(BlockAnnounce<Header>),
89 #[codec(index = 6)]
93 Consensus(ConsensusMessage),
94 RemoteCallRequest(RemoteCallRequest<Hash>),
96 RemoteCallResponse(RemoteCallResponse),
98 RemoteReadRequest(RemoteReadRequest<Hash>),
100 RemoteReadResponse(RemoteReadResponse),
102 RemoteHeaderRequest(RemoteHeaderRequest<Number>),
104 RemoteHeaderResponse(RemoteHeaderResponse<Header>),
106 RemoteChangesRequest(RemoteChangesRequest<Hash>),
108 RemoteChangesResponse(RemoteChangesResponse<Number, Hash>),
110 RemoteReadChildRequest(RemoteReadChildRequest<Hash>),
112 #[codec(index = 17)]
116 ConsensusBatch(Vec<ConsensusMessage>),
117 }
118
119 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
126 pub struct CompactStatus<Hash, Number> {
127 pub version: u32,
129 pub min_supported_version: u32,
131 pub roles: Roles,
133 pub best_number: Number,
135 pub best_hash: Hash,
137 pub genesis_hash: Hash,
139 }
140
141 #[derive(Debug, PartialEq, Eq, Clone, Encode)]
143 pub struct Status<Hash, Number> {
144 pub version: u32,
146 pub min_supported_version: u32,
148 pub roles: Roles,
150 pub best_number: Number,
152 pub best_hash: Hash,
154 pub genesis_hash: Hash,
156 pub chain_status: Vec<u8>,
158 }
159
160 impl<Hash: Decode, Number: Decode> Decode for Status<Hash, Number> {
161 fn decode<I: Input>(value: &mut I) -> Result<Self, codec::Error> {
162 const LAST_CHAIN_STATUS_VERSION: u32 = 5;
163 let compact = CompactStatus::decode(value)?;
164 let chain_status = match <Vec<u8>>::decode(value) {
165 Ok(v) => v,
166 Err(e) =>
167 if compact.version <= LAST_CHAIN_STATUS_VERSION {
168 return Err(e)
169 } else {
170 Vec::new()
171 },
172 };
173
174 let CompactStatus {
175 version,
176 min_supported_version,
177 roles,
178 best_number,
179 best_hash,
180 genesis_hash,
181 } = compact;
182
183 Ok(Self {
184 version,
185 min_supported_version,
186 roles,
187 best_number,
188 best_hash,
189 genesis_hash,
190 chain_status,
191 })
192 }
193 }
194
195 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
196 pub struct RemoteCallRequest<H> {
198 pub id: RequestId,
200 pub block: H,
202 pub method: String,
204 pub data: Vec<u8>,
206 }
207
208 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
209 pub struct RemoteReadRequest<H> {
211 pub id: RequestId,
213 pub block: H,
215 pub keys: Vec<Vec<u8>>,
217 }
218
219 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
220 pub struct RemoteReadChildRequest<H> {
222 pub id: RequestId,
224 pub block: H,
226 pub storage_key: Vec<u8>,
228 pub keys: Vec<Vec<u8>>,
230 }
231
232 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
233 pub struct RemoteHeaderRequest<N> {
235 pub id: RequestId,
237 pub block: N,
239 }
240
241 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
242 pub struct RemoteHeaderResponse<Header> {
244 pub id: RequestId,
246 pub header: Option<Header>,
248 pub proof: StorageProof,
250 }
251
252 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
253 pub struct RemoteChangesRequest<H> {
255 pub id: RequestId,
257 pub first: H,
259 pub last: H,
261 pub min: H,
264 pub max: H,
266 pub storage_key: Option<Vec<u8>>,
268 pub key: Vec<u8>,
270 }
271
272 #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
273 pub struct RemoteChangesResponse<N, H> {
275 pub id: RequestId,
277 pub max: N,
280 pub proof: Vec<Vec<u8>>,
282 pub roots: Vec<(N, H)>,
284 pub roots_proof: StorageProof,
286 }
287}