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
+19 -2
View File
@@ -70,7 +70,7 @@ pub trait Context {
}
/// Statements circulated among peers.
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum Statement<C, D> {
/// Broadcast by a authority to indicate that this is his candidate for
/// inclusion.
@@ -141,7 +141,7 @@ impl<C: Decode, D: Decode> Decode for Statement<C, D> {
}
/// A signed statement.
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct SignedStatement<C, D, V, S> {
/// The statement.
pub statement: Statement<C, D>,
@@ -151,6 +151,23 @@ pub struct SignedStatement<C, D, V, S> {
pub sender: V,
}
impl<C: Encode, D: Encode, V: Encode, S: Encode> Encode for SignedStatement<C, D, V, S> {
fn encode_to<T: Output>(&self, dest: &mut T) {
dest.push(&self.statement);
dest.push(&self.signature);
dest.push(&self.sender);
}
}
impl<C: Decode, D: Decode, V: Decode, S: Decode> Decode for SignedStatement<C, D, V, S> {
fn decode<I: Input>(value: &mut I) -> Option<Self> {
Some(SignedStatement {
statement: Decode::decode(value)?,
signature: Decode::decode(value)?,
sender: Decode::decode(value)?,
})
}
}
/// Misbehavior: voting more than one way on candidate validity.
///
/// Since there are three possible ways to vote, a double vote is possible in
-4
View File
@@ -18,10 +18,6 @@ extern crate substrate_codec as codec;
extern crate substrate_primitives;
extern crate polkadot_primitives as primitives;
extern crate serde;
#[macro_use]
extern crate serde_derive;
pub mod generic;
pub use generic::Table;