define Id type in polkadot-parachain and depend on that in primitives. (#144)

* define Id type in polkadot-parachain and depend on that in primitives.

* fix tests
This commit is contained in:
Robert Habermeier
2019-02-20 08:33:52 -03:00
committed by Gav Wood
parent 84d8629de6
commit 4ef53912e6
14 changed files with 63 additions and 35 deletions
+29 -3
View File
@@ -62,6 +62,13 @@ extern crate wasmi;
#[macro_use]
extern crate error_chain;
#[cfg(feature = "std")]
extern crate serde;
#[cfg(feature = "std")]
#[macro_use]
extern crate serde_derive;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
@@ -93,12 +100,32 @@ pub struct ValidationResult {
pub head_data: Vec<u8>,
}
/// Unique identifier of a parachain.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
pub struct Id(u32);
impl From<Id> for u32 {
fn from(x: Id) -> Self { x.0 }
}
impl From<u32> for Id {
fn from(x: u32) -> Self { Id(x) }
}
impl Id {
/// Convert this Id into its inner representation.
pub fn into_inner(self) -> u32 {
self.0
}
}
/// An incoming message.
#[derive(PartialEq, Eq, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Encode))]
pub struct IncomingMessage {
/// The source parachain.
pub source: u32,
pub source: Id,
/// The data of the message.
pub data: Vec<u8>,
}
@@ -106,8 +133,7 @@ pub struct IncomingMessage {
/// A reference to a message.
pub struct MessageRef<'a> {
/// The target parachain.
pub target: u32,
pub target: Id,
/// Underlying data of the message.
pub data: &'a [u8],
}