Use substrate codec for network messages (#333)

* Use substrate codec for network messages

* Version bump

* Removed redundant format
This commit is contained in:
Arkadiy Paronyan
2018-07-16 15:28:31 +02:00
committed by Robert Habermeier
parent 0e40983f3b
commit 20f3e9f636
11 changed files with 145 additions and 52 deletions
+20 -3
View File
@@ -18,6 +18,7 @@
use polkadot_primitives::{AccountId, Hash};
use polkadot_primitives::parachain::{Id as ParaId, Collation};
use codec;
use futures::sync::oneshot;
@@ -27,12 +28,28 @@ use std::time::{Duration, Instant};
const COLLATION_LIFETIME: Duration = Duration::from_secs(60 * 5);
/// The role of the collator. Whether they're the primary or backup for this parachain.
#[derive(PartialEq, Debug, Serialize, Deserialize)]
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum Role {
/// Primary collators should send collations whenever it's time.
Primary,
Primary = 0,
/// Backup collators should not.
Backup,
Backup = 1,
}
impl codec::Encode for Role {
fn encode_to<T: codec::Output>(&self, dest: &mut T) {
dest.push_byte(*self as u8);
}
}
impl codec::Decode for Role {
fn decode<I: codec::Input>(input: &mut I) -> Option<Self> {
match input.read_byte()? {
x if x == Role::Primary as u8 => Some(Role::Primary),
x if x == Role::Backup as u8 => Some(Role::Backup),
_ => None,
}
}
}
/// A maintenance action for the collator set.