Remove unneeded Deserialize impls. (#1370)

This commit is contained in:
Tomasz Drwięga
2019-01-08 22:44:39 +01:00
committed by Gav Wood
parent 38cdd0a5c6
commit 8d4129aa22
9 changed files with 22 additions and 61 deletions
+10 -10
View File
@@ -1088,7 +1088,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "jsonrpc-core"
version = "9.0.0"
source = "git+https://github.com/paritytech/jsonrpc.git#0227e70fdce25cad9c71be222dc9e7f754c08033"
source = "git+https://github.com/paritytech/jsonrpc.git#24b9befa3389d9aa64b49b2573d1250143f17743"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1100,7 +1100,7 @@ dependencies = [
[[package]]
name = "jsonrpc-http-server"
version = "9.0.0"
source = "git+https://github.com/paritytech/jsonrpc.git#0227e70fdce25cad9c71be222dc9e7f754c08033"
source = "git+https://github.com/paritytech/jsonrpc.git#24b9befa3389d9aa64b49b2573d1250143f17743"
dependencies = [
"hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)",
@@ -1113,7 +1113,7 @@ dependencies = [
[[package]]
name = "jsonrpc-macros"
version = "9.0.0"
source = "git+https://github.com/paritytech/jsonrpc.git#0227e70fdce25cad9c71be222dc9e7f754c08033"
source = "git+https://github.com/paritytech/jsonrpc.git#24b9befa3389d9aa64b49b2573d1250143f17743"
dependencies = [
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)",
"jsonrpc-pubsub 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)",
@@ -1123,7 +1123,7 @@ dependencies = [
[[package]]
name = "jsonrpc-pubsub"
version = "9.0.0"
source = "git+https://github.com/paritytech/jsonrpc.git#0227e70fdce25cad9c71be222dc9e7f754c08033"
source = "git+https://github.com/paritytech/jsonrpc.git#24b9befa3389d9aa64b49b2573d1250143f17743"
dependencies = [
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1133,7 +1133,7 @@ dependencies = [
[[package]]
name = "jsonrpc-server-utils"
version = "9.0.0"
source = "git+https://github.com/paritytech/jsonrpc.git#0227e70fdce25cad9c71be222dc9e7f754c08033"
source = "git+https://github.com/paritytech/jsonrpc.git#24b9befa3389d9aa64b49b2573d1250143f17743"
dependencies = [
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1149,7 +1149,7 @@ dependencies = [
[[package]]
name = "jsonrpc-ws-server"
version = "9.0.0"
source = "git+https://github.com/paritytech/jsonrpc.git#0227e70fdce25cad9c71be222dc9e7f754c08033"
source = "git+https://github.com/paritytech/jsonrpc.git#24b9befa3389d9aa64b49b2573d1250143f17743"
dependencies = [
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)",
@@ -2358,7 +2358,7 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2379,7 +2379,7 @@ name = "rand_hc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2416,7 +2416,7 @@ name = "rand_xorshift"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4363,7 +4363,7 @@ name = "twox-hash"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -26,7 +26,7 @@ use client::{self, error, Client as SubstrateClient, CallExecutor};
use client::{block_builder::api::BlockBuilder as BlockBuilderApi, runtime_api::Core};
use codec::{Decode, Encode};
use consensus_common::{self, evaluation};
use primitives::{H256, Ed25519AuthorityId, ed25519, Blake2Hasher};
use primitives::{H256, Blake2Hasher};
use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi, AuthorityIdFor};
use runtime_primitives::generic::BlockId;
use runtime_primitives::BasicInherentData;
+1 -2
View File
@@ -49,9 +49,8 @@ pub fn rpc_handler<Block: BlockT, ExHash, S, C, A, Y>(
) -> RpcHandler where
Block: BlockT + 'static,
ExHash: Send + Sync + 'static + sr_primitives::Serialize + sr_primitives::DeserializeOwned,
SignedBlock<Block>: serde::Serialize + sr_primitives::DeserializeOwned,
S: apis::state::StateApi<Block::Hash, Metadata=Metadata>,
C: apis::chain::ChainApi<Block::Hash, Block::Header, NumberFor<Block>, SignedBlock<Block>, Metadata=Metadata>,
C: apis::chain::ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>, Metadata=Metadata>,
A: apis::author::AuthorApi<ExHash, Block::Hash, Metadata=Metadata>,
Y: apis::system::SystemApi,
{
+6 -2
View File
@@ -26,6 +26,7 @@ use rpc::Result as RpcResult;
use rpc::futures::{stream, Future, Sink, Stream};
use runtime_primitives::generic::{BlockId, SignedBlock};
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor};
use serde::Serialize;
use subscriptions::Subscriptions;
@@ -37,7 +38,10 @@ use self::error::Result;
build_rpc_trait! {
/// Substrate blockchain API
pub trait ChainApi<Hash, Header, Number, SignedBlock> {
pub trait ChainApi<Number, Hash> where
Header: Serialize,
SignedBlock: Serialize,
{
type Metadata;
/// Get header of a relay chain block.
@@ -148,7 +152,7 @@ impl<B, E, Block, RA> Chain<B, E, Block, RA> where
}
}
impl<B, E, Block, RA> ChainApi<Block::Hash, Block::Header, NumberFor<Block>, SignedBlock<Block>> for Chain<B, E, Block, RA> where
impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> for Chain<B, E, Block, RA> where
Block: BlockT<Hash=H256> + 'static,
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
E: client::CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static,
+1
View File
@@ -22,6 +22,7 @@ extern crate jsonrpc_core as rpc;
extern crate jsonrpc_pubsub;
extern crate parity_codec as codec;
extern crate parking_lot;
extern crate serde;
extern crate serde_json;
extern crate sr_primitives as runtime_primitives;
extern crate sr_version as runtime_version;
+1 -2
View File
@@ -27,7 +27,7 @@ use consensus_common::import_queue::ImportQueue;
use network::{self, OnDemand};
use substrate_executor::{NativeExecutor, NativeExecutionDispatch};
use transaction_pool::txpool::{self, Options as TransactionPoolOptions, Pool as TransactionPool};
use runtime_primitives::{BuildStorage, traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi}, generic::{BlockId, SignedBlock}};
use runtime_primitives::{BuildStorage, traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi}, generic::BlockId};
use config::Configuration;
use primitives::{Blake2Hasher, H256};
use rpc::{self, apis::system::SystemInfo};
@@ -136,7 +136,6 @@ pub trait StartRPC<C: Components> {
impl<C: Components> StartRPC<Self> for C where
C::RuntimeApi: Metadata<ComponentBlock<C>>,
for<'de> SignedBlock<ComponentBlock<C>>: ::serde::Deserialize<'de>,
{
type ServersHandle = (Option<rpc::HttpServer>, Option<Mutex<rpc::WsServer>>);
@@ -19,10 +19,6 @@
#[cfg(feature = "std")]
use std::fmt;
#[cfg(feature = "std")]
use serde::{Deserialize, Deserializer};
#[cfg(feature = "std")]
use codec::Decode;
use rstd::prelude::*;
use codec::Codec;
use traits::{self, Member, Block as BlockT, Header as HeaderT, MaybeSerialize};
@@ -73,17 +69,6 @@ pub struct Block<Header, Extrinsic: MaybeSerialize> {
pub extrinsics: Vec<Extrinsic>,
}
// TODO: Remove Deserialize for Block once RPC no longer needs it #1098
#[cfg(feature = "std")]
impl<'a, Header: 'a, Extrinsic: 'a + MaybeSerialize> Deserialize<'a> for Block<Header, Extrinsic> where
Block<Header, Extrinsic>: Decode,
{
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
let r = <Vec<u8>>::deserialize(de)?;
Decode::decode(&mut &r[..]).ok_or(::serde::de::Error::custom("Invalid value passed into decode"))
}
}
impl<Header, Extrinsic: MaybeSerialize> traits::Block for Block<Header, Extrinsic>
where
Header: HeaderT,
@@ -118,16 +103,3 @@ pub struct SignedBlock<Block> {
/// Block justification.
pub justification: Option<Justification>,
}
// TODO: Remove Deserialize for SignedBlock once RPC no longer needs it #1098
#[cfg(feature = "std")]
impl<'a, Block: BlockT,> Deserialize<'a> for SignedBlock<Block> where
Block::Header: 'a,
Block::Extrinsic: 'a + Codec + MaybeSerialize,
SignedBlock<Block>: Decode,
{
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
let r = <Vec<u8>>::deserialize(de)?;
Decode::decode(&mut &r[..]).ok_or(::serde::de::Error::custom("Invalid value passed into decode"))
}
}
@@ -16,9 +16,6 @@
//! Generic implementation of a block header.
#[cfg(feature = "std")]
use serde::{Deserialize, Deserializer};
use codec::{Decode, Encode, Codec, Input, Output, HasCompact};
use traits::{self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay,
Hash as HashT, DigestItem as DigestItemT, MaybeSerializeDebug, MaybeSerializeDebugButNotDeserialize};
@@ -42,17 +39,6 @@ pub struct Header<Number, Hash: HashT, DigestItem> {
pub digest: Digest<DigestItem>,
}
// TODO: Remove Deserialize for Header once RPC no longer needs it #1098
#[cfg(feature = "std")]
impl<'a, Number: 'a, Hash: 'a + HashT, DigestItem: 'a> Deserialize<'a> for Header<Number, Hash, DigestItem> where
Header<Number, Hash, DigestItem>: Decode,
{
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
let r = <Vec<u8>>::deserialize(de)?;
Decode::decode(&mut &r[..]).ok_or(::serde::de::Error::custom("Invalid value passed into decode"))
}
}
impl<Number, Hash, DigestItem> Decode for Header<Number, Hash, DigestItem> where
Number: HasCompact,
Hash: HashT,
+2 -2
View File
@@ -441,7 +441,7 @@ impl<T: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static> Mem
/// `parent_hash`, as well as a `digest` and a block `number`.
///
/// You can also create a `new` one from those fields.
pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'static {
pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDeserialize + 'static {
type Number: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec;
type Hash: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>;
type Hashing: Hash<Output = Self::Hash>;
@@ -481,7 +481,7 @@ pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'stat
/// `Extrinsic` piece of information as well as a `Header`.
///
/// You can get an iterator over each of the `extrinsics` and retrieve the `header`.
pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'static {
pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDeserialize + 'static {
type Extrinsic: Member + Codec + Extrinsic + MaybeSerialize;
type Header: Header<Hash=Self::Hash>;
type Hash: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>;