Remove unneeded Serde requirements (#1076)

* Remove superfluous serde requirements.

* Try to ensure hash is serde

* Fixups

* Building again

* Attempt to reenable Block (doesn't build)

* Fixes compilation for node cli

* Fixes test compilation

* Fix wasm

* Fix tests

* Remove unneeded changes

* Fix up comments

* Reenable some code

* Compile error when origin misused.

* Remove unnecessary includes of `serde_derive`

* Cleanups
This commit is contained in:
Gav Wood
2018-11-12 18:40:18 +01:00
committed by GitHub
parent b76ba06472
commit 57b2896332
62 changed files with 253 additions and 343 deletions
+30 -10
View File
@@ -16,9 +16,9 @@
//! Testing utilities.
use serde::{Serialize, de::DeserializeOwned};
use std::{fmt::Debug, ops::Deref};
use codec::Codec;
use serde::{Serialize, Serializer, Deserialize, de::Error as DeError, Deserializer};
use std::{fmt::Debug, ops::Deref, fmt};
use codec::{Codec, Encode, Decode};
use traits::{self, Checkable, Applyable, BlakeTwo256};
use generic::DigestItem as GenDigestItem;
@@ -101,7 +101,7 @@ impl traits::Header for Header {
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
pub struct ExtrinsicWrapper<Xt>(Xt);
impl<Xt> traits::Extrinsic for ExtrinsicWrapper<Xt> {
impl<Xt> traits::Extrinsic for ExtrinsicWrapper<Xt> where Xt: Serialize {
fn is_signed(&self) -> Option<bool> {
None
}
@@ -121,13 +121,13 @@ impl<Xt> Deref for ExtrinsicWrapper<Xt> {
}
}
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
#[derive(PartialEq, Eq, Clone, Serialize, Debug, Encode, Decode)]
pub struct Block<Xt> {
pub header: Header,
pub extrinsics: Vec<Xt>,
}
impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug + traits::Extrinsic> traits::Block for Block<Xt> {
impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + Clone + Eq + Debug + traits::Extrinsic> traits::Block for Block<Xt> {
type Extrinsic = Xt;
type Header = Header;
type Hash = <Header as traits::Header>::Hash;
@@ -146,20 +146,40 @@ impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + DeserializeOwned +
}
}
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
impl<'a, Xt> Deserialize<'a> for Block<Xt> where Block<Xt>: Decode {
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
let r = <Vec<u8>>::deserialize(de)?;
Decode::decode(&mut &r[..]).ok_or(DeError::custom("Invalid value passed into decode"))
}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
pub struct TestXt<Call>(pub Option<u64>, pub u64, pub Call);
impl<Call: Codec + Sync + Send + Serialize, Context> Checkable<Context> for TestXt<Call> {
impl<Call> Serialize for TestXt<Call> where TestXt<Call>: Encode
{
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: Serializer {
self.using_encoded(|bytes| seq.serialize_bytes(bytes))
}
}
impl<Call> Debug for TestXt<Call> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "TestXt({:?}, {:?})", self.0, self.1)
}
}
impl<Call: Codec + Sync + Send, Context> Checkable<Context> for TestXt<Call> {
type Checked = Self;
fn check(self, _: &Context) -> Result<Self::Checked, &'static str> { Ok(self) }
}
impl<Call: Codec + Sync + Send + Serialize> traits::Extrinsic for TestXt<Call> {
impl<Call: Codec + Sync + Send> traits::Extrinsic for TestXt<Call> {
fn is_signed(&self) -> Option<bool> {
None
}
}
impl<Call> Applyable for TestXt<Call> where
Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Serialize + DeserializeOwned,
Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug,
{
type AccountId = u64;
type Index = u64;