pub use self::generic::{
RemoteCallRequest, RemoteChangesRequest, RemoteChangesResponse, RemoteHeaderRequest,
RemoteHeaderResponse, RemoteReadChildRequest, RemoteReadRequest,
};
use codec::{Decode, Encode};
use sc_client_api::StorageProof;
use sc_network_common::message::RequestId;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
pub type Message<B> = generic::Message<
<B as BlockT>::Header,
<B as BlockT>::Hash,
<<B as BlockT>::Header as HeaderT>::Number,
<B as BlockT>::Extrinsic,
>;
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteCallResponse {
pub id: RequestId,
pub proof: StorageProof,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteReadResponse {
pub id: RequestId,
pub proof: StorageProof,
}
pub mod generic {
use super::{RemoteCallResponse, RemoteReadResponse};
use codec::{Decode, Encode, Input};
use sc_client_api::StorageProof;
use sc_network_common::{
message::RequestId,
protocol::role::Roles,
sync::message::{
generic::{BlockRequest, BlockResponse},
BlockAnnounce,
},
};
use sp_runtime::ConsensusEngineId;
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct ConsensusMessage {
pub protocol: ConsensusEngineId,
pub data: Vec<u8>,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub enum Message<Header, Hash, Number, Extrinsic> {
Status(Status<Hash, Number>),
BlockRequest(BlockRequest<Hash, Number>),
BlockResponse(BlockResponse<Header, Hash, Extrinsic>),
BlockAnnounce(BlockAnnounce<Header>),
#[codec(index = 6)]
Consensus(ConsensusMessage),
RemoteCallRequest(RemoteCallRequest<Hash>),
RemoteCallResponse(RemoteCallResponse),
RemoteReadRequest(RemoteReadRequest<Hash>),
RemoteReadResponse(RemoteReadResponse),
RemoteHeaderRequest(RemoteHeaderRequest<Number>),
RemoteHeaderResponse(RemoteHeaderResponse<Header>),
RemoteChangesRequest(RemoteChangesRequest<Hash>),
RemoteChangesResponse(RemoteChangesResponse<Number, Hash>),
RemoteReadChildRequest(RemoteReadChildRequest<Hash>),
#[codec(index = 17)]
ConsensusBatch(Vec<ConsensusMessage>),
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct CompactStatus<Hash, Number> {
pub version: u32,
pub min_supported_version: u32,
pub roles: Roles,
pub best_number: Number,
pub best_hash: Hash,
pub genesis_hash: Hash,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode)]
pub struct Status<Hash, Number> {
pub version: u32,
pub min_supported_version: u32,
pub roles: Roles,
pub best_number: Number,
pub best_hash: Hash,
pub genesis_hash: Hash,
pub chain_status: Vec<u8>,
}
impl<Hash: Decode, Number: Decode> Decode for Status<Hash, Number> {
fn decode<I: Input>(value: &mut I) -> Result<Self, codec::Error> {
const LAST_CHAIN_STATUS_VERSION: u32 = 5;
let compact = CompactStatus::decode(value)?;
let chain_status = match <Vec<u8>>::decode(value) {
Ok(v) => v,
Err(e) =>
if compact.version <= LAST_CHAIN_STATUS_VERSION {
return Err(e)
} else {
Vec::new()
},
};
let CompactStatus {
version,
min_supported_version,
roles,
best_number,
best_hash,
genesis_hash,
} = compact;
Ok(Self {
version,
min_supported_version,
roles,
best_number,
best_hash,
genesis_hash,
chain_status,
})
}
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteCallRequest<H> {
pub id: RequestId,
pub block: H,
pub method: String,
pub data: Vec<u8>,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteReadRequest<H> {
pub id: RequestId,
pub block: H,
pub keys: Vec<Vec<u8>>,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteReadChildRequest<H> {
pub id: RequestId,
pub block: H,
pub storage_key: Vec<u8>,
pub keys: Vec<Vec<u8>>,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteHeaderRequest<N> {
pub id: RequestId,
pub block: N,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteHeaderResponse<Header> {
pub id: RequestId,
pub header: Option<Header>,
pub proof: StorageProof,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteChangesRequest<H> {
pub id: RequestId,
pub first: H,
pub last: H,
pub min: H,
pub max: H,
pub storage_key: Option<Vec<u8>>,
pub key: Vec<u8>,
}
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct RemoteChangesResponse<N, H> {
pub id: RequestId,
pub max: N,
pub proof: Vec<Vec<u8>>,
pub roots: Vec<(N, H)>,
pub roots_proof: StorageProof,
}
}