diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index eabd0d765f..c17744a472 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -2653,7 +2653,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2671,7 +2670,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2689,7 +2687,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2708,7 +2705,6 @@ dependencies = [ "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-sandbox 0.1.0", @@ -2729,7 +2725,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2749,7 +2744,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2767,7 +2761,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2785,7 +2778,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2804,7 +2796,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2824,7 +2815,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2864,7 +2854,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2880,7 +2869,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2898,7 +2886,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -2916,7 +2903,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", diff --git a/substrate/core/client/src/client.rs b/substrate/core/client/src/client.rs index 4645a56a2f..1279bc486a 100644 --- a/substrate/core/client/src/client.rs +++ b/substrate/core/client/src/client.rs @@ -23,7 +23,7 @@ use parking_lot::{Mutex, RwLock}; use primitives::AuthorityId; use runtime_primitives::{ Justification, - generic::{BlockId, SignedBlock, Block as RuntimeBlock}, + generic::{BlockId, SignedBlock}, transaction_validity::{TransactionValidity, TransactionTag}, }; use consensus::{ImportBlock, ImportResult, BlockOrigin}; @@ -775,11 +775,11 @@ impl Client where /// Get full block by id. pub fn block(&self, id: &BlockId) - -> error::Result>> + -> error::Result>> { Ok(match (self.header(id)?, self.body(id)?, self.justification(id)?) { (Some(header), Some(extrinsics), Some(justification)) => - Some(SignedBlock { block: RuntimeBlock { header, extrinsics }, justification }), + Some(SignedBlock { block: Block::new(header, extrinsics), justification }), _ => None, }) } diff --git a/substrate/core/rpc-servers/src/lib.rs b/substrate/core/rpc-servers/src/lib.rs index 47934f805a..faa6f2bf41 100644 --- a/substrate/core/rpc-servers/src/lib.rs +++ b/substrate/core/rpc-servers/src/lib.rs @@ -32,7 +32,7 @@ extern crate sr_primitives; extern crate log; use std::io; -use sr_primitives::traits::{Block as BlockT, NumberFor}; +use sr_primitives::{traits::{Block as BlockT, NumberFor}, generic::SignedBlock}; type Metadata = apis::metadata::Metadata; type RpcHandler = pubsub::PubSubHandler; @@ -40,7 +40,7 @@ pub type HttpServer = http::Server; pub type WsServer = ws::Server; /// Construct rpc `IoHandler` -pub fn rpc_handler( +pub fn rpc_handler( state: S, chain: C, author: A, @@ -48,10 +48,10 @@ pub fn rpc_handler( ) -> RpcHandler where Block: BlockT + 'static, ExHash: Send + Sync + 'static + sr_primitives::Serialize + sr_primitives::DeserializeOwned, - PendingExtrinsics: serde::Serialize + serde::de::DeserializeOwned + Send + Sync + 'static, + SignedBlock: serde::Serialize + sr_primitives::DeserializeOwned, S: apis::state::StateApi, - C: apis::chain::ChainApi, Block::Extrinsic, Metadata=Metadata>, - A: apis::author::AuthorApi, + C: apis::chain::ChainApi, SignedBlock, Metadata=Metadata>, + A: apis::author::AuthorApi, Y: apis::system::SystemApi, { let mut io = pubsub::PubSubHandler::default(); diff --git a/substrate/core/rpc/src/author/mod.rs b/substrate/core/rpc/src/author/mod.rs index ff08c4c840..287b51dcc3 100644 --- a/substrate/core/rpc/src/author/mod.rs +++ b/substrate/core/rpc/src/author/mod.rs @@ -19,13 +19,12 @@ use std::sync::Arc; use client::{self, Client}; -use codec::Decode; +use codec::{Encode, Decode}; use transaction_pool::{ txpool::{ ChainApi as PoolChainApi, BlockHash, ExHash, - ExtrinsicFor, IntoPoolError, Pool, watcher::Status, @@ -47,19 +46,16 @@ use self::error::Result; build_rpc_trait! { /// Substrate authoring RPC API - pub trait AuthorApi { + pub trait AuthorApi { type Metadata; - /// Submit extrinsic for inclusion in block. - #[rpc(name = "author_submitRichExtrinsic")] - fn submit_rich_extrinsic(&self, Extrinsic) -> Result; /// Submit hex-encoded extrinsic for inclusion in block. #[rpc(name = "author_submitExtrinsic")] fn submit_extrinsic(&self, Bytes) -> Result; /// Returns all pending extrinsics, potentially grouped by sender. #[rpc(name = "author_pendingExtrinsics")] - fn pending_extrinsics(&self) -> Result; + fn pending_extrinsics(&self) -> Result>; #[pubsub(name = "author_extrinsicUpdate")] { /// Submit an extrinsic to watch. @@ -103,7 +99,7 @@ impl Author where } } -impl AuthorApi, BlockHash

, ExtrinsicFor

, Vec>> for Author where +impl AuthorApi, BlockHash

> for Author where B: client::backend::Backend<

::Block, Blake2Hasher> + Send + Sync + 'static, E: client::CallExecutor<

::Block, Blake2Hasher> + Send + Sync + 'static, P: PoolChainApi + Sync + Send + 'static, @@ -112,12 +108,8 @@ impl AuthorApi, BlockHash

, ExtrinsicFor

, Vec Result> { - let dxt = Decode::decode(&mut &xt[..]).ok_or(error::Error::from(error::ErrorKind::BadFormat))?; - self.submit_rich_extrinsic(dxt) - } - - fn submit_rich_extrinsic(&self, xt: <

::Block as traits::Block>::Extrinsic) -> Result> { + fn submit_extrinsic(&self, ext: Bytes) -> Result> { + let xt = Decode::decode(&mut &ext[..]).ok_or(error::Error::from(error::ErrorKind::BadFormat))?; let best_block_hash = self.client.info()?.chain.best_hash; self.pool .submit_one(&generic::BlockId::hash(best_block_hash), xt) @@ -127,8 +119,8 @@ impl AuthorApi, BlockHash

, ExtrinsicFor

, Vec Result>> { - Ok(self.pool.ready().map(|tx| tx.data.clone()).collect()) + fn pending_extrinsics(&self) -> Result> { + Ok(self.pool.ready().map(|tx| tx.data.encode().into()).collect()) } fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: pubsub::Subscriber, BlockHash

>>, xt: Bytes) { diff --git a/substrate/core/rpc/src/author/tests.rs b/substrate/core/rpc/src/author/tests.rs index 7032355ef2..82f5d37162 100644 --- a/substrate/core/rpc/src/author/tests.rs +++ b/substrate/core/rpc/src/author/tests.rs @@ -71,11 +71,11 @@ fn submit_rich_transaction_should_not_cause_error() { let h: H256 = hex!("fccc48291473c53746cd267cf848449edd7711ee6511fba96919d5f9f4859e4f").into(); assert_matches!( - AuthorApi::submit_rich_extrinsic(&p, uxt(Keyring::Alice, 0)), + AuthorApi::submit_extrinsic(&p, uxt(Keyring::Alice, 0).encode().into()), Ok(h2) if h == h2 ); assert!( - AuthorApi::submit_rich_extrinsic(&p, uxt(Keyring::Alice, 0)).is_err() + AuthorApi::submit_extrinsic(&p, uxt(Keyring::Alice, 0).encode().into()).is_err() ); } @@ -108,7 +108,7 @@ fn should_watch_extrinsic() { let signature = Keyring::from_raw_public(tx.from.to_fixed_bytes()).unwrap().sign(&tx.encode()).into(); Extrinsic { transfer: tx, signature } }; - AuthorApi::submit_rich_extrinsic(&p, replacement).unwrap(); + AuthorApi::submit_extrinsic(&p, replacement.encode().into()).unwrap(); let (res, data) = runtime.block_on(data.into_future()).unwrap(); assert_eq!( res, @@ -131,9 +131,9 @@ fn should_return_pending_extrinsics() { subscriptions: Subscriptions::new(runtime.executor()), }; let ex = uxt(Keyring::Alice, 0); - AuthorApi::submit_rich_extrinsic(&p, ex.clone()).unwrap(); + AuthorApi::submit_extrinsic(&p, ex.encode().into()).unwrap(); assert_matches!( p.pending_extrinsics(), - Ok(ref expected) if expected == &vec![ex] + Ok(ref expected) if *expected == vec![Bytes(ex.encode())] ); } diff --git a/substrate/core/rpc/src/chain/mod.rs b/substrate/core/rpc/src/chain/mod.rs index 8542d2ff4c..62b76ed232 100644 --- a/substrate/core/rpc/src/chain/mod.rs +++ b/substrate/core/rpc/src/chain/mod.rs @@ -39,7 +39,7 @@ use self::error::Result; build_rpc_trait! { /// Substrate blockchain API - pub trait ChainApi { + pub trait ChainApi { type Metadata; /// Get header of a relay chain block. @@ -48,7 +48,7 @@ build_rpc_trait! { /// Get header and body of a relay chain block. #[rpc(name = "chain_getBlock")] - fn block(&self, Trailing) -> Result>>; + fn block(&self, Trailing) -> Result>; /// Get hash of the n-th block in the canon chain. /// @@ -163,7 +163,7 @@ impl Chain where } } -impl ChainApi, Block::Extrinsic> for Chain where +impl ChainApi, SignedBlock> for Chain where Block: BlockT + 'static, B: client::backend::Backend + Send + Sync + 'static, E: client::CallExecutor + Send + Sync + 'static, @@ -176,7 +176,7 @@ impl ChainApi, Block:: } fn block(&self, hash: Trailing) - -> Result>> + -> Result>> { let hash = self.unwrap_or_best(hash)?; Ok(self.client.block(&BlockId::Hash(hash))?) diff --git a/substrate/core/service/src/chain_ops.rs b/substrate/core/service/src/chain_ops.rs index e94db8c6f0..221b05dd77 100644 --- a/substrate/core/service/src/chain_ops.rs +++ b/substrate/core/service/src/chain_ops.rs @@ -18,7 +18,6 @@ use std::{self, io::{Read, Write}}; use futures::Future; -use serde_json; use runtime_primitives::generic::{SignedBlock, BlockId}; use runtime_primitives::traits::{As, Block, Header}; @@ -34,7 +33,10 @@ use chain_spec::ChainSpec; /// Export a range of blocks to a binary stream. pub fn export_blocks(config: FactoryFullConfiguration, exit: E, mut output: W, from: FactoryBlockNumber, to: Option>, json: bool) -> error::Result<()> - where F: ServiceFactory, E: Future + Send + 'static, W: Write, + where + F: ServiceFactory, + E: Future + Send + 'static, + W: Write, { let client = new_client::(&config)?; let mut block = from; @@ -104,14 +106,14 @@ pub fn import_blocks(config: FactoryFullConfiguration, exit: E, mut if exit_recv.try_recv().is_ok() { break; } - if let Some(signed) = SignedBlock::<::Header, ::Extrinsic>::decode(&mut input) { - let header = signed.block.header; + if let Some(signed) = SignedBlock::::decode(&mut input) { + let (header, extrinsics) = signed.block.deconstruct(); let hash = header.hash(); let block = message::BlockData:: { hash: hash, justification: Some(signed.justification), header: Some(header), - body: Some(signed.block.extrinsics), + body: Some(extrinsics), receipt: None, message_queue: None }; diff --git a/substrate/core/service/src/lib.rs b/substrate/core/service/src/lib.rs index 9e7c201e8f..3b817e4ced 100644 --- a/substrate/core/service/src/lib.rs +++ b/substrate/core/service/src/lib.rs @@ -69,7 +69,7 @@ use parking_lot::{Mutex, RwLock}; use keystore::Store as Keystore; use client::BlockchainEvents; use runtime_primitives::traits::{Header, As}; -use runtime_primitives::generic::BlockId; +use runtime_primitives::generic::{BlockId, SignedBlock}; use exit_future::Signal; #[doc(hidden)] pub use tokio::runtime::TaskExecutor; @@ -124,8 +124,7 @@ impl Service where Components: components::Components, ::Executor: std::clone::Clone, - txpool::ExHash: serde::de::DeserializeOwned + serde::Serialize, - txpool::ExtrinsicFor: serde::de::DeserializeOwned + serde::Serialize, + for<'de> SignedBlock>: ::serde::Deserialize<'de>, { /// Creates a new service. pub fn new( @@ -247,7 +246,7 @@ impl Service let chain = rpc::apis::chain::Chain::new(client.clone(), subscriptions.clone()); let state = rpc::apis::state::State::new(client.clone(), subscriptions.clone()); let author = rpc::apis::author::Author::new(client.clone(), transaction_pool.clone(), subscriptions.clone()); - rpc::rpc_handler::, ComponentExHash, _, _, _, _, _>( + rpc::rpc_handler::, ComponentExHash, _, _, _, _>( state, chain, author, diff --git a/substrate/core/sr-api/src/lib.rs b/substrate/core/sr-api/src/lib.rs index 7fffc43590..a80420a8d7 100644 --- a/substrate/core/sr-api/src/lib.rs +++ b/substrate/core/sr-api/src/lib.rs @@ -456,12 +456,6 @@ decl_apis! { fn metadata() -> Data; } - /// The `OldTxQueue` api trait for interfering with the old transaction queue. - pub trait OldTxQueue { - fn account_nonce(account: AccountId) -> Index; - fn lookup_address(address: Address) -> Option; - } - /// The `TaggedTransactionQueue` api trait for interfering with the new transaction queue. pub trait TaggedTransactionQueue { fn validate_transaction(tx: ::Extrinsic) -> TransactionValidity; diff --git a/substrate/core/sr-primitives/src/generic/block.rs b/substrate/core/sr-primitives/src/generic/block.rs index 6cbb7929d8..61452668ad 100644 --- a/substrate/core/sr-primitives/src/generic/block.rs +++ b/substrate/core/sr-primitives/src/generic/block.rs @@ -19,9 +19,13 @@ #[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}; +use traits::{self, Member, Block as BlockT, Header as HeaderT, MaybeSerialize}; use ::Justification; /// Something to identify a block. @@ -59,17 +63,28 @@ impl fmt::Display for BlockId { /// Abstraction over a substrate block. #[derive(PartialEq, Eq, Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] +#[cfg_attr(feature = "std", derive(Debug, Serialize))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] #[cfg_attr(feature = "std", serde(deny_unknown_fields))] -pub struct Block { +pub struct Block { /// The block header. pub header: Header, /// The accompanying extrinsics. pub extrinsics: Vec, } -impl traits::Block for Block +// 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 where + Block: Decode, +{ + fn deserialize>(de: D) -> Result { + let r = >::deserialize(de)?; + Decode::decode(&mut &r[..]).ok_or(::serde::de::Error::custom("Invalid value passed into decode")) + } +} + +impl traits::Block for Block where Header: HeaderT, Extrinsic: Member + Codec + traits::Extrinsic, @@ -94,12 +109,25 @@ where /// Abstraction over a substrate block and justification. #[derive(PartialEq, Eq, Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] +#[cfg_attr(feature = "std", derive(Debug, Serialize))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] #[cfg_attr(feature = "std", serde(deny_unknown_fields))] -pub struct SignedBlock { +pub struct SignedBlock { /// Full block. - pub block: Block, + pub block: Block, /// Block justification. pub justification: Justification, } + +// TODO: Remove Deserialize for SignedBlock once RPC no longer needs it #1098 +#[cfg(feature = "std")] +impl<'a, Block: BlockT,> Deserialize<'a> for SignedBlock where + Block::Header: 'a, + Block::Extrinsic: 'a + Codec + MaybeSerialize, + SignedBlock: Decode, +{ + fn deserialize>(de: D) -> Result { + let r = >::deserialize(de)?; + Decode::decode(&mut &r[..]).ok_or(::serde::de::Error::custom("Invalid value passed into decode")) + } +} diff --git a/substrate/core/sr-primitives/src/generic/checked_extrinsic.rs b/substrate/core/sr-primitives/src/generic/checked_extrinsic.rs index e69ce77336..749577cdd6 100644 --- a/substrate/core/sr-primitives/src/generic/checked_extrinsic.rs +++ b/substrate/core/sr-primitives/src/generic/checked_extrinsic.rs @@ -23,7 +23,7 @@ use traits::{self, Member, SimpleArithmetic, MaybeDisplay}; /// existence implies that it has been checked and is good, particularly with /// regards to the signature. #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] +#[cfg_attr(feature = "std", derive(Debug))] pub struct CheckedExtrinsic { /// Who this purports to be from and the number of extrinsics have come before /// from the same signer, if anyone (note this is not a signature). @@ -37,7 +37,7 @@ impl traits::Applyable where AccountId: Member + MaybeDisplay, Index: Member + MaybeDisplay + SimpleArithmetic, - Call: Member + Call: Member, { type Index = Index; type AccountId = AccountId; diff --git a/substrate/core/sr-primitives/src/generic/digest.rs b/substrate/core/sr-primitives/src/generic/digest.rs index 41ffd6da0d..c71ee4c7aa 100644 --- a/substrate/core/sr-primitives/src/generic/digest.rs +++ b/substrate/core/sr-primitives/src/generic/digest.rs @@ -19,7 +19,7 @@ use rstd::prelude::*; use codec::{Decode, Encode, Codec, Input}; -use traits::{self, Member, DigestItem as DigestItemT}; +use traits::{self, Member, DigestItem as DigestItemT, MaybeSerializeDebug}; use substrate_primitives::hash::H512 as Signature; @@ -122,7 +122,10 @@ impl DigestItem { } } -impl traits::DigestItem for DigestItem { +impl< + Hash: Codec + Member + MaybeSerializeDebug, + AuthorityId: Codec + Member + MaybeSerializeDebug +> traits::DigestItem for DigestItem { type Hash = Hash; type AuthorityId = AuthorityId; diff --git a/substrate/core/sr-primitives/src/generic/header.rs b/substrate/core/sr-primitives/src/generic/header.rs index fc6f73b5cf..ec70d5d66b 100644 --- a/substrate/core/sr-primitives/src/generic/header.rs +++ b/substrate/core/sr-primitives/src/generic/header.rs @@ -21,7 +21,7 @@ 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}; + Hash as HashT, DigestItem as DigestItemT, MaybeSerializeDebug, MaybeSerializeDebugButNotDeserialize}; use generic::Digest; /// Abstraction over a block header for a substrate chain. @@ -42,42 +42,14 @@ pub struct Header { pub digest: Digest, } -// Hack to work around the fact that deriving deserialize doesn't work nicely with -// the `hashing` trait used as a parameter. -// dummy struct that uses the hash type directly. -// https://github.com/serde-rs/serde/issues/1296 -#[cfg(feature = "std")] -#[serde(rename_all = "camelCase")] -#[derive(Deserialize)] -struct DeserializeHeader { - parent_hash: H, - number: N, - state_root: H, - extrinsics_root: H, - digest: Digest, -} - -#[cfg(feature = "std")] -impl From> for Header { - fn from(other: DeserializeHeader) -> Self { - Header { - parent_hash: other.parent_hash, - number: other.number, - state_root: other.state_root, - extrinsics_root: other.extrinsics_root, - digest: other.digest, - } - } -} - +// 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 where - Number: Deserialize<'a>, - Hash::Output: Deserialize<'a>, - DigestItem: Deserialize<'a>, + Header: Decode, { fn deserialize>(de: D) -> Result { - DeserializeHeader::::deserialize(de).map(Into::into) + let r = >::deserialize(de)?; + Decode::decode(&mut &r[..]).ok_or(::serde::de::Error::custom("Invalid value passed into decode")) } } @@ -114,11 +86,11 @@ impl Encode for Header where } impl traits::Header for Header where - Number: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec, + Number: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec, Hash: HashT, DigestItem: DigestItemT + Codec, - Hash::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Codec, - { + Hash::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeSerializeDebugButNotDeserialize + MaybeDisplay + SimpleBitOps + Codec, +{ type Number = Number; type Hash = ::Output; type Hashing = Hash; diff --git a/substrate/core/sr-primitives/src/generic/tests.rs b/substrate/core/sr-primitives/src/generic/tests.rs index c095a2b45d..7689610617 100644 --- a/substrate/core/sr-primitives/src/generic/tests.rs +++ b/substrate/core/sr-primitives/src/generic/tests.rs @@ -17,56 +17,8 @@ //! Tests for the generic implementations of Extrinsic/Header/Block. use codec::{Decode, Encode}; -use substrate_primitives::{H256, H512}; -use super::{Digest, Header, DigestItem, UncheckedExtrinsic}; - -type Block = super::Block< - Header>, - UncheckedExtrinsic, ->; - -#[test] -fn block_roundtrip_serialization() { - let block: Block = Block { - header: Header { - parent_hash: [0u8; 32].into(), - number: 100_000, - state_root: [1u8; 32].into(), - extrinsics_root: [2u8; 32].into(), - digest: Digest { logs: vec![ - DigestItem::Other::(vec![1, 2, 3]), - DigestItem::Other::(vec![4, 5, 6]), - ] }, - }, - extrinsics: vec![ - UncheckedExtrinsic::new_signed( - 0, - 100, - [255u8; 32].into(), - H512::from([0u8; 64]).into() - ), - UncheckedExtrinsic::new_signed( - 100, - 99, - [128u8; 32].into(), - H512::from([255u8; 64]).into() - ) - ] - }; - - { - let encoded = ::serde_json::to_vec(&block).unwrap(); - let decoded: Block = ::serde_json::from_slice(&encoded).unwrap(); - - assert_eq!(block, decoded); - } - { - let encoded = block.encode(); - let decoded = Block::decode(&mut &encoded[..]).unwrap(); - - assert_eq!(block, decoded); - } -} +use substrate_primitives::H256; +use super::DigestItem; #[test] fn system_digest_item_encoding() { diff --git a/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs b/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs index a37affd9ca..ec3801591d 100644 --- a/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs +++ b/substrate/core/sr-primitives/src/generic/unchecked_extrinsic.rs @@ -25,7 +25,6 @@ use traits::{self, Member, SimpleArithmetic, MaybeDisplay, Lookup}; use super::CheckedExtrinsic; #[derive(PartialEq, Eq, Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct SignatureContent where Address: Codec, @@ -40,7 +39,6 @@ where /// A extrinsic right from the external world. This is unchecked and so /// can contain a signature. #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct UncheckedExtrinsic where Address: Codec, @@ -143,6 +141,15 @@ impl } } +#[cfg(feature = "std")] +impl serde::Serialize + for UncheckedExtrinsic +{ + fn serialize(&self, seq: S) -> Result where S: ::serde::Serializer { + self.using_encoded(|bytes| seq.serialize_bytes(bytes)) + } +} + /// TODO: use derive when possible. #[cfg(feature = "std")] impl fmt::Debug diff --git a/substrate/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs b/substrate/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs index 5d91556d8c..e15a37c3bf 100644 --- a/substrate/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs +++ b/substrate/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs @@ -30,7 +30,6 @@ const TRANSACTION_VERSION: u8 = 1; /// A extrinsic right from the external world. This is unchecked and so /// can contain a signature. #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct UncheckedMortalExtrinsic { /// The signature, address, number of extrinsics have come before from /// the same signer and an era describing the longevity of this transaction, @@ -58,7 +57,7 @@ impl UncheckedMortalExtrinsic Extrinsic for UncheckedMortalExtrinsic { +impl Extrinsic for UncheckedMortalExtrinsic { fn is_signed(&self) -> Option { Some(self.signature.is_some()) } @@ -158,6 +157,15 @@ where } } +#[cfg(feature = "std")] +impl serde::Serialize + for UncheckedMortalExtrinsic +{ + fn serialize(&self, seq: S) -> Result where S: ::serde::Serializer { + self.using_encoded(|bytes| seq.serialize_bytes(bytes)) + } +} + /// TODO: use derive when possible. #[cfg(feature = "std")] impl fmt::Debug for UncheckedMortalExtrinsic where diff --git a/substrate/core/sr-primitives/src/testing.rs b/substrate/core/sr-primitives/src/testing.rs index 847af9a3c2..cd1ca5cb4a 100644 --- a/substrate/core/sr-primitives/src/testing.rs +++ b/substrate/core/sr-primitives/src/testing.rs @@ -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); -impl traits::Extrinsic for ExtrinsicWrapper { +impl traits::Extrinsic for ExtrinsicWrapper where Xt: Serialize { fn is_signed(&self) -> Option { None } @@ -121,13 +121,13 @@ impl Deref for ExtrinsicWrapper { } } -#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)] +#[derive(PartialEq, Eq, Clone, Serialize, Debug, Encode, Decode)] pub struct Block { pub header: Header, pub extrinsics: Vec, } -impl traits::Block for Block { +impl traits::Block for Block { type Extrinsic = Xt; type Header = Header; type Hash =

::Hash; @@ -146,20 +146,40 @@ impl Deserialize<'a> for Block where Block: Decode { + fn deserialize>(de: D) -> Result { + let r = >::deserialize(de)?; + Decode::decode(&mut &r[..]).ok_or(DeError::custom("Invalid value passed into decode")) + } +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode)] pub struct TestXt(pub Option, pub u64, pub Call); -impl Checkable for TestXt { +impl Serialize for TestXt where TestXt: Encode +{ + fn serialize(&self, seq: S) -> Result where S: Serializer { + self.using_encoded(|bytes| seq.serialize_bytes(bytes)) + } +} + +impl Debug for TestXt { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "TestXt({:?}, {:?})", self.0, self.1) + } +} + +impl Checkable for TestXt { type Checked = Self; fn check(self, _: &Context) -> Result { Ok(self) } } -impl traits::Extrinsic for TestXt { +impl traits::Extrinsic for TestXt { fn is_signed(&self) -> Option { None } } impl Applyable for TestXt 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; diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index 5c568460ee..809c617218 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -246,7 +246,7 @@ tuple_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, pub trait Hash: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq { // Stupid bug in the Rust compiler believes derived // traits must be fulfilled by all type parameters. /// The hash type produced. - type Output: Member + AsRef<[u8]> + AsMut<[u8]>; + type Output: Member + MaybeSerializeDebug + AsRef<[u8]> + AsMut<[u8]>; /// Produce the hash of some byte-slice. fn hash(s: &[u8]) -> Self::Output; @@ -365,6 +365,16 @@ pub trait MaybeSerializeDebugButNotDeserialize {} #[cfg(not(feature = "std"))] impl MaybeSerializeDebugButNotDeserialize for T {} +#[cfg(feature = "std")] +pub trait MaybeSerialize: Serialize {} +#[cfg(feature = "std")] +impl MaybeSerialize for T {} + +#[cfg(not(feature = "std"))] +pub trait MaybeSerialize {} +#[cfg(not(feature = "std"))] +impl MaybeSerialize for T {} + #[cfg(feature = "std")] pub trait MaybeSerializeDebug: Serialize + DeserializeOwned + Debug {} #[cfg(feature = "std")] @@ -375,6 +385,16 @@ pub trait MaybeSerializeDebug {} #[cfg(not(feature = "std"))] impl MaybeSerializeDebug for T {} +#[cfg(feature = "std")] +pub trait MaybeDebug: Debug {} +#[cfg(feature = "std")] +impl MaybeDebug for T {} + +#[cfg(not(feature = "std"))] +pub trait MaybeDebug {} +#[cfg(not(feature = "std"))] +impl MaybeDebug for T {} + #[cfg(feature = "std")] pub trait MaybeDisplay: Display {} #[cfg(feature = "std")] @@ -395,9 +415,8 @@ pub trait MaybeDecode {} #[cfg(not(feature = "std"))] impl MaybeDecode for T {} - -pub trait Member: Send + Sync + Sized + MaybeSerializeDebug + Eq + PartialEq + Clone + 'static {} -impl Member for T {} +pub trait Member: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static {} +impl Member for T {} /// Something which fulfills the abstract idea of a Substrate header. It has types for a `Number`, /// a `Hash` and a `Digest`. It provides access to an `extrinsics_root`, `state_root` and @@ -405,8 +424,8 @@ impl + AsMut<[u8]>; + 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; type Digest: Digest; @@ -445,9 +464,9 @@ pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'stat /// /// You can get an iterator over each of the `extrinsics` and retrieve the `header`. pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'static { - type Extrinsic: Member + Codec + Extrinsic; + type Extrinsic: Member + Codec + Extrinsic + MaybeSerialize; type Header: Header; - type Hash: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>; + type Hash: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>; fn header(&self) -> &Self::Header; fn extrinsics(&self) -> &[Self::Extrinsic]; @@ -458,6 +477,13 @@ pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'stati } } +/// Something that acts like an `Extrinsic`. +pub trait Extrinsic { + /// Is this `Extrinsic` signed? + /// If no information are available about signed/unsigned, `None` should be returned. + fn is_signed(&self) -> Option { None } +} + /// Extract the hashing type for a block. pub type HashFor = <::Header as Header>::Hashing; /// Extract the number type for a block. @@ -516,8 +542,8 @@ pub trait Applyable: Sized + Send + Sync { /// Something that acts like a `Digest` - it can have `Log`s `push`ed onto it and these `Log`s are /// each `Codec`. -pub trait Digest: Member + Default { - type Hash: Member; +pub trait Digest: Member + MaybeSerializeDebug + Default { + type Hash: Member + MaybeSerializeDebug; type Item: DigestItem; /// Get reference to all digest items. @@ -539,9 +565,9 @@ pub trait Digest: Member + Default { /// for casting member to 'system' log items, known to substrate. /// /// If the runtime does not supports some 'system' items, use `()` as a stub. -pub trait DigestItem: Codec + Member { - type Hash: Member; - type AuthorityId: Member; +pub trait DigestItem: Codec + Member + MaybeSerializeDebug { + type Hash: Member + MaybeSerializeDebug; + type AuthorityId: Member + MaybeSerializeDebug; /// Returns Some if the entry is the `AuthoritiesChange` entry. fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]>; @@ -571,10 +597,3 @@ pub trait ProvideInherent { block: &Block, data: Self::Inherent, extract_function: &F ) -> Result<(), Self::Error>; } - -/// Something that acts like an `Extrinsic`. -pub trait Extrinsic { - /// Is this `Extrinsic` signed? - /// If no information are available about signed/unsigned, `None` should be returned. - fn is_signed(&self) -> Option { None } -} diff --git a/substrate/core/test-runtime/src/lib.rs b/substrate/core/test-runtime/src/lib.rs index de678e7205..5844ecbbb9 100644 --- a/substrate/core/test-runtime/src/lib.rs +++ b/substrate/core/test-runtime/src/lib.rs @@ -24,10 +24,6 @@ extern crate sr_std as rstd; extern crate parity_codec as codec; extern crate sr_primitives as runtime_primitives; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[macro_use] extern crate srml_support as runtime_support; #[macro_use] diff --git a/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index 72683d7e19..fe88a3463d 100644 Binary files a/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/substrate/core/transaction-pool/graph/src/base_pool.rs b/substrate/core/transaction-pool/graph/src/base_pool.rs index 21a52a9750..e6ad3cd6dd 100644 --- a/substrate/core/transaction-pool/graph/src/base_pool.rs +++ b/substrate/core/transaction-pool/graph/src/base_pool.rs @@ -23,6 +23,7 @@ use std::{ sync::Arc, }; +use serde::Serialize; use sr_primitives::traits::Member; use sr_primitives::transaction_validity::{ TransactionTag as Tag, @@ -79,7 +80,7 @@ pub struct PruneStatus { /// Immutable transaction #[cfg_attr(test, derive(Clone))] -#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq)] pub struct Transaction { /// Raw extrinsic representing that transaction. pub data: Extrinsic, @@ -120,7 +121,7 @@ impl Default for BasePool { } } -impl BasePool { +impl BasePool { /// Imports transaction to the pool. /// /// The pool consists of two parts: Future and Ready. diff --git a/substrate/core/transaction-pool/graph/src/lib.rs b/substrate/core/transaction-pool/graph/src/lib.rs index e41284efe3..2c456aac52 100644 --- a/substrate/core/transaction-pool/graph/src/lib.rs +++ b/substrate/core/transaction-pool/graph/src/lib.rs @@ -33,6 +33,7 @@ extern crate futures; extern crate parking_lot; extern crate sr_primitives; +extern crate serde; #[macro_use] extern crate error_chain; #[macro_use] extern crate log; #[macro_use] extern crate serde_derive; diff --git a/substrate/core/transaction-pool/graph/src/listener.rs b/substrate/core/transaction-pool/graph/src/listener.rs index 1947bfb93b..d4645eb2c5 100644 --- a/substrate/core/transaction-pool/graph/src/listener.rs +++ b/substrate/core/transaction-pool/graph/src/listener.rs @@ -19,6 +19,7 @@ use std::{ collections::HashMap, hash, }; +use serde::Serialize; use watcher; use sr_primitives::traits; @@ -35,7 +36,7 @@ impl Default for Listener { } } -impl Listener { +impl Listener { fn fire(&mut self, hash: &H, fun: F) where F: FnOnce(&mut watcher::Sender) { let clean = if let Some(h) = self.watchers.get_mut(hash) { fun(h); diff --git a/substrate/core/transaction-pool/graph/src/pool.rs b/substrate/core/transaction-pool/graph/src/pool.rs index fe1f2d2aee..d9b4b33f36 100644 --- a/substrate/core/transaction-pool/graph/src/pool.rs +++ b/substrate/core/transaction-pool/graph/src/pool.rs @@ -26,6 +26,7 @@ use error; use listener::Listener; use rotator::PoolRotator; use watcher::Watcher; +use serde::Serialize; use futures::sync::mpsc; use parking_lot::{Mutex, RwLock}; @@ -54,7 +55,7 @@ pub trait ChainApi: Send + Sync { /// Block type. type Block: traits::Block; /// Hash type - type Hash: hash::Hash + Eq + traits::Member; + type Hash: hash::Hash + Eq + traits::Member + Serialize; /// Error type. type Error: From + error::IntoPoolError; @@ -287,7 +288,7 @@ fn fire_events( listener: &mut Listener, imported: &base::Imported, ) where - H: hash::Hash + Eq + traits::Member, + H: hash::Hash + Eq + traits::Member + Serialize, H2: Clone, { match *imported { diff --git a/substrate/core/transaction-pool/graph/src/ready.rs b/substrate/core/transaction-pool/graph/src/ready.rs index 47ab34c7fb..1a531b3f49 100644 --- a/substrate/core/transaction-pool/graph/src/ready.rs +++ b/substrate/core/transaction-pool/graph/src/ready.rs @@ -21,6 +21,7 @@ use std::{ sync::Arc, }; +use serde::Serialize; use parking_lot::RwLock; use sr_primitives::traits::Member; use sr_primitives::transaction_validity::{ @@ -120,7 +121,7 @@ impl Default for ReadyTransactions { } } -impl ReadyTransactions { +impl ReadyTransactions { /// Borrows a map of tags that are provided by transactions in this queue. pub fn provided_tags(&self) -> &HashMap { &self.provided_tags diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index d1afc82c44..8a982b9ff8 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -226,7 +226,7 @@ pub type Header = generic::Header; /// Block type as expected by this runtime. pub type Block = generic::Block; /// A Block signed with a Justification -pub type SignedBlock = generic::SignedBlock; +pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// Unchecked extrinsic type as expected by this runtime. diff --git a/substrate/node/runtime/wasm/Cargo.lock b/substrate/node/runtime/wasm/Cargo.lock index 355963104b..231ddef3f7 100644 --- a/substrate/node/runtime/wasm/Cargo.lock +++ b/substrate/node/runtime/wasm/Cargo.lock @@ -606,7 +606,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -624,7 +623,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -642,7 +640,6 @@ dependencies = [ "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-sandbox 0.1.0", @@ -662,7 +659,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -682,7 +678,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -700,7 +695,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -717,7 +711,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -737,7 +730,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -775,7 +767,6 @@ dependencies = [ "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -791,7 +782,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -809,7 +799,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", @@ -827,7 +816,6 @@ dependencies = [ "parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0", "sr-primitives 0.1.0", "sr-std 0.1.0", diff --git a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm index 4fbcc974d0..8d53eefe47 100644 Binary files a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm and b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm differ diff --git a/substrate/srml/assets/Cargo.toml b/substrate/srml/assets/Cargo.toml index 58d84fb9bb..e695453c1e 100644 --- a/substrate/srml/assets/Cargo.toml +++ b/substrate/srml/assets/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } @@ -20,7 +19,6 @@ srml-system = { path = "../system", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "parity-codec/std", "parity-codec-derive/std", "substrate-primitives/std", diff --git a/substrate/srml/assets/src/lib.rs b/substrate/srml/assets/src/lib.rs index e266a00bdd..09f81cb843 100644 --- a/substrate/srml/assets/src/lib.rs +++ b/substrate/srml/assets/src/lib.rs @@ -30,13 +30,6 @@ extern crate sr_io as runtime_io; #[cfg(test)] extern crate substrate_primitives; -// Needed for deriving `Serialize` and `Deserialize` for various types. -// We only implement the serde traits for std builds - they're unneeded -// in the wasm runtime. -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - // Needed for deriving `Encode` and `Decode` for `RawEvent`. #[macro_use] extern crate parity_codec_derive; diff --git a/substrate/srml/balances/Cargo.toml b/substrate/srml/balances/Cargo.toml index 769e801ca9..9f7fd249b0 100644 --- a/substrate/srml/balances/Cargo.toml +++ b/substrate/srml/balances/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } @@ -22,7 +21,6 @@ srml-system = { path = "../system", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "safe-mix/std", "substrate-keyring", "parity-codec/std", diff --git a/substrate/srml/balances/src/address.rs b/substrate/srml/balances/src/address.rs index 2cd545d0d1..ccaa6b46a5 100644 --- a/substrate/srml/balances/src/address.rs +++ b/substrate/srml/balances/src/address.rs @@ -22,16 +22,14 @@ use super::{Member, Decode, Encode, As, Input, Output}; /// A vetted and verified extrinsic from the external world. #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, Hash))] +#[cfg_attr(feature = "std", derive(Debug, Hash))] pub enum Address where AccountId: Member, AccountIndex: Member, { /// It's an account ID (pubkey). - #[cfg_attr(feature = "std", serde(deserialize_with="AccountId::deserialize"))] Id(AccountId), /// It's an account index. - #[cfg_attr(feature = "std", serde(deserialize_with="AccountIndex::deserialize"))] Index(AccountIndex), } diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index cf2f9bc4da..7fd694d98c 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -18,10 +18,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[macro_use] extern crate srml_support as runtime_support; diff --git a/substrate/srml/balances/src/mock.rs b/substrate/srml/balances/src/mock.rs index d2e62cb83d..5fb6bb80dc 100644 --- a/substrate/srml/balances/src/mock.rs +++ b/substrate/srml/balances/src/mock.rs @@ -72,6 +72,7 @@ impl ExtBuilder { self.existential_deposit = existential_deposit; self } + #[allow(dead_code)] pub fn transfer_fee(mut self, transfer_fee: u64) -> Self { self.transfer_fee = transfer_fee; self diff --git a/substrate/srml/consensus/Cargo.toml b/substrate/srml/consensus/Cargo.toml index c7bbfe03f6..d099cb120f 100644 --- a/substrate/srml/consensus/Cargo.toml +++ b/substrate/srml/consensus/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } @@ -20,7 +19,6 @@ srml-system = { path = "../system", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "parity-codec/std", "substrate-primitives/std", "sr-std/std", diff --git a/substrate/srml/consensus/src/lib.rs b/substrate/srml/consensus/src/lib.rs index 0d2bd7f279..302d7a2b35 100644 --- a/substrate/srml/consensus/src/lib.rs +++ b/substrate/srml/consensus/src/lib.rs @@ -25,10 +25,6 @@ extern crate sr_std as rstd; #[macro_use] extern crate srml_support as runtime_support; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - extern crate parity_codec; #[macro_use] extern crate parity_codec_derive; diff --git a/substrate/srml/contract/Cargo.toml b/substrate/srml/contract/Cargo.toml index 51a0b172db..60da497f0e 100644 --- a/substrate/srml/contract/Cargo.toml +++ b/substrate/srml/contract/Cargo.toml @@ -5,7 +5,6 @@ authors = ["Parity Technologies "] [dependencies] serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } pwasm-utils = { version = "0.3", default-features = false } parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } @@ -26,7 +25,6 @@ assert_matches = "1.1" [features] default = ["std"] std = [ - "serde_derive", "serde/std", "parity-codec/std", "parity-codec-derive/std", diff --git a/substrate/srml/contract/src/lib.rs b/substrate/srml/contract/src/lib.rs index 5e3722bb04..e3f6a600b3 100644 --- a/substrate/srml/contract/src/lib.rs +++ b/substrate/srml/contract/src/lib.rs @@ -52,10 +52,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[macro_use] extern crate parity_codec_derive; diff --git a/substrate/srml/council/Cargo.toml b/substrate/srml/council/Cargo.toml index 39cd73e96c..e2bad6b3c8 100644 --- a/substrate/srml/council/Cargo.toml +++ b/substrate/srml/council/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } @@ -23,7 +22,6 @@ srml-system = { path = "../system", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "safe-mix/std", "parity-codec/std", "parity-codec-derive/std", diff --git a/substrate/srml/council/src/lib.rs b/substrate/srml/council/src/lib.rs index 412de7d2b2..26d88c6c7b 100644 --- a/substrate/srml/council/src/lib.rs +++ b/substrate/srml/council/src/lib.rs @@ -21,10 +21,6 @@ #[cfg(feature = "std")] extern crate serde; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[cfg(test)] #[macro_use] extern crate hex_literal; diff --git a/substrate/srml/council/src/motions.rs b/substrate/srml/council/src/motions.rs index 2b3850369b..69af4a563e 100644 --- a/substrate/srml/council/src/motions.rs +++ b/substrate/srml/council/src/motions.rs @@ -20,7 +20,7 @@ use rstd::prelude::*; use rstd::result; use codec::Compact; use substrate_primitives::u32_trait::Value as U32; -use primitives::traits::{Hash, EnsureOrigin, MaybeSerializeDebug}; +use primitives::traits::{Hash, EnsureOrigin}; use srml_support::dispatch::{Result, Dispatchable, Parameter}; use srml_support::{StorageValue, StorageMap}; use super::{Trait as CouncilTrait, Module as Council}; @@ -29,12 +29,12 @@ use system::{self, ensure_signed}; /// Simple index type for proposal counting. pub type ProposalIndex = u32; -pub trait Trait: CouncilTrait + MaybeSerializeDebug { +pub trait Trait: CouncilTrait { /// The outer origin type. type Origin: From; /// The outer call dispatch type. - type Proposal: Parameter + Dispatchable::Origin> + MaybeSerializeDebug; + type Proposal: Parameter + Dispatchable::Origin>; /// The outer event type. type Event: From> + Into<::Event>; @@ -66,7 +66,6 @@ decl_event!( ); decl_module! { - #[cfg_attr(feature = "std", serde(bound(deserialize = "::Proposal: ::serde::de::DeserializeOwned")))] pub struct Module for enum Call where origin: ::Origin { fn deposit_event() = default; fn propose(origin, threshold: Compact, proposal: Box<::Proposal>) -> Result { diff --git a/substrate/srml/democracy/Cargo.toml b/substrate/srml/democracy/Cargo.toml index c037a4b219..ea8b63920f 100644 --- a/substrate/srml/democracy/Cargo.toml +++ b/substrate/srml/democracy/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } @@ -22,7 +21,6 @@ srml-system = { path = "../system", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "safe-mix/std", "parity-codec/std", "substrate-primitives/std", diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs index 34aad5856c..0c589d5893 100644 --- a/substrate/srml/democracy/src/lib.rs +++ b/substrate/srml/democracy/src/lib.rs @@ -21,10 +21,6 @@ #[cfg(test)] extern crate substrate_primitives; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[macro_use] extern crate parity_codec_derive; #[cfg_attr(not(feature = "std"), macro_use)] @@ -41,7 +37,7 @@ extern crate srml_system as system; use rstd::prelude::*; use rstd::result; use codec::{HasCompact, Compact}; -use primitives::traits::{Zero, As, MaybeSerializeDebug}; +use primitives::traits::{Zero, As}; use srml_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType}; use srml_support::dispatch::Result; use system::ensure_signed; @@ -55,7 +51,7 @@ pub type PropIndex = u32; pub type ReferendumIndex = u32; pub trait Trait: balances::Trait + Sized { - type Proposal: Parameter + Dispatchable + IsSubType> + MaybeSerializeDebug; + type Proposal: Parameter + Dispatchable + IsSubType>; type Event: From> + Into<::Event>; } diff --git a/substrate/srml/example/Cargo.toml b/substrate/srml/example/Cargo.toml index 34d8d058d1..8fe76d9bf0 100644 --- a/substrate/srml/example/Cargo.toml +++ b/substrate/srml/example/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } @@ -21,7 +20,6 @@ srml-balances = { path = "../balances", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "parity-codec/std", "parity-codec-derive/std", "sr-std/std", diff --git a/substrate/srml/example/src/lib.rs b/substrate/srml/example/src/lib.rs index 4c2708e953..8dcbb7094b 100644 --- a/substrate/srml/example/src/lib.rs +++ b/substrate/srml/example/src/lib.rs @@ -34,13 +34,6 @@ extern crate substrate_primitives; // Needed for various traits. In our case, `OnFinalise`. extern crate sr_primitives; -// Needed for deriving `Serialize` and `Deserialize` for various types. -// We only implement the serde traits for std builds - they're unneeded -// in the wasm runtime. -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - // Needed for deriving `Encode` and `Decode` for `RawEvent`. #[macro_use] extern crate parity_codec_derive; diff --git a/substrate/srml/executive/Cargo.toml b/substrate/srml/executive/Cargo.toml index 33cd0432e0..ee956e9399 100644 --- a/substrate/srml/executive/Cargo.toml +++ b/substrate/srml/executive/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } sr-std = { path = "../../core/sr-std", default-features = false } @@ -25,7 +24,6 @@ std = [ "sr-std/std", "srml-support/std", "serde/std", - "serde_derive", "parity-codec/std", "parity-codec-derive/std", "sr-primitives/std", diff --git a/substrate/srml/executive/src/lib.rs b/substrate/srml/executive/src/lib.rs index ea83267c91..005b8508db 100644 --- a/substrate/srml/executive/src/lib.rs +++ b/substrate/srml/executive/src/lib.rs @@ -18,10 +18,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(test)] -#[macro_use] -extern crate serde_derive; - #[cfg(test)] #[macro_use] extern crate parity_codec_derive; @@ -295,7 +291,7 @@ mod tests { } // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. - #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] + #[derive(Clone, Eq, PartialEq)] pub struct Runtime; impl system::Trait for Runtime { type Origin = Origin; diff --git a/substrate/srml/session/Cargo.toml b/substrate/srml/session/Cargo.toml index c006eff0a4..ad798edbdb 100644 --- a/substrate/srml/session/Cargo.toml +++ b/substrate/srml/session/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} substrate-primitives = { path = "../../core/primitives", default-features = false } parity-codec = { version = "2.1", default-features = false } @@ -23,7 +22,6 @@ srml-timestamp = { path = "../timestamp", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "safe-mix/std", "parity-codec/std", "parity-codec-derive/std", diff --git a/substrate/srml/session/src/lib.rs b/substrate/srml/session/src/lib.rs index df3afa9aa1..99bf182cf8 100644 --- a/substrate/srml/session/src/lib.rs +++ b/substrate/srml/session/src/lib.rs @@ -19,10 +19,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - extern crate sr_std as rstd; #[macro_use] diff --git a/substrate/srml/staking/Cargo.toml b/substrate/srml/staking/Cargo.toml index 7a1f4ef4eb..4d35592144 100644 --- a/substrate/srml/staking/Cargo.toml +++ b/substrate/srml/staking/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } @@ -26,7 +25,6 @@ srml-timestamp = { path = "../timestamp", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "safe-mix/std", "substrate-keyring", "parity-codec/std", diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs index 680da340c5..cd21fe05ad 100644 --- a/substrate/srml/staking/src/lib.rs +++ b/substrate/srml/staking/src/lib.rs @@ -23,10 +23,6 @@ #[cfg(feature = "std")] extern crate serde; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[macro_use] extern crate srml_support as runtime_support; @@ -75,7 +71,7 @@ pub enum LockStatus { /// Preference of what happens on a slash event. #[derive(PartialEq, Eq, Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] +#[cfg_attr(feature = "std", derive(Debug))] pub struct ValidatorPrefs { // TODO: @bkchr shouldn't need this Copy but derive(Encode) breaks otherwise /// Validator should ensure this many more slashes than is necessary before being unstaked. #[codec(compact)] @@ -103,7 +99,6 @@ pub trait Trait: balances::Trait + session::Trait { } decl_module! { - #[cfg_attr(feature = "std", serde(bound(deserialize = "T::Balance: ::serde::de::DeserializeOwned")))] pub struct Module for enum Call where origin: T::Origin { fn deposit_event() = default; diff --git a/substrate/srml/support/src/dispatch.rs b/substrate/srml/support/src/dispatch.rs index dd52e35b3c..24ba2a9c75 100644 --- a/substrate/srml/support/src/dispatch.rs +++ b/substrate/srml/support/src/dispatch.rs @@ -20,8 +20,6 @@ pub use rstd::prelude::{Vec, Clone, Eq, PartialEq}; #[cfg(feature = "std")] pub use std::fmt; pub use rstd::result; -#[cfg(feature = "std")] -use serde; pub use codec::{Codec, Decode, Encode, Input, Output}; pub use substrate_metadata::{ ModuleMetadata, FunctionMetadata, DecodeDifferent, @@ -36,11 +34,6 @@ pub trait Dispatchable { fn dispatch(self, origin: Self::Origin) -> Result; } -#[cfg(feature = "std")] -pub trait Callable { - type Call: Dispatchable + Codec + ::serde::Serialize + Clone + PartialEq + Eq; -} -#[cfg(not(feature = "std"))] pub trait Callable { type Call: Dispatchable + Codec + Clone + PartialEq + Eq; } @@ -50,10 +43,10 @@ pub trait Callable { pub type CallableCallFor = ::Call; #[cfg(feature = "std")] -pub trait Parameter: Codec + serde::Serialize + Clone + Eq + fmt::Debug {} +pub trait Parameter: Codec + Clone + Eq + fmt::Debug {} #[cfg(feature = "std")] -impl Parameter for T where T: Codec + serde::Serialize + Clone + Eq + fmt::Debug {} +impl Parameter for T where T: Codec + Clone + Eq + fmt::Debug {} #[cfg(not(feature = "std"))] pub trait Parameter: Codec + Clone + Eq {} @@ -188,6 +181,42 @@ macro_rules! decl_module { $($rest)* ); }; + (@normalize + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident + { $( $deposit_event:tt )* } + { $( $on_finalise:tt )* } + [ $($t:tt)* ] + $(#[doc = $doc_attr:tt])* + $fn_vis:vis fn $fn_name:ident($origin:ident : T::Origin $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* } + $($rest:tt)* + ) => { + compile_error!("\ +First parameter of dispatch should be marked `origin` only, with no\n\ +type specified (a bit like `self`).\n\ +(For root-matching dispatches, ensure the first parameter does not use\n\ +the `T::Origin` type.)\ +") + }; + (@normalize + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident + { $( $deposit_event:tt )* } + { $( $on_finalise:tt )* } + [ $($t:tt)* ] + $(#[doc = $doc_attr:tt])* + $fn_vis:vis fn $fn_name:ident(origin : $origin:ty $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* } + $($rest:tt)* + ) => { + compile_error!("\ +First parameter of dispatch should be marked `origin` only, with no\n\ +type specified (a bit like `self`).\n\ +(For root-matching dispatches, ensure the first parameter is not named\n\ +`origin`.)\ +") + }; (@normalize $(#[$attr:meta])* pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> @@ -351,7 +380,7 @@ macro_rules! decl_module { ) => { // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Clone, Copy, PartialEq, Eq)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[cfg_attr(feature = "std", derive(Debug))] // TODO: switching based on std feature is because of an issue in // serde-derive for when we attempt to derive `Deserialize` on these types, // in a situation where we've imported `srml_support` as another name. @@ -360,7 +389,7 @@ macro_rules! decl_module { // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Clone, Copy, PartialEq, Eq)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[cfg_attr(feature = "std", derive(Debug))] #[cfg(not(feature = "std"))] pub struct $mod_type<$trait_instance: $trait_name>(::core::marker::PhantomData<$trait_instance>); @@ -389,7 +418,6 @@ macro_rules! decl_module { #[cfg(feature = "std")] $(#[$attr])* - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum $call_type<$trait_instance: $trait_name> { __PhantomItem(::std::marker::PhantomData<$trait_instance>), __OtherPhantomItem(::std::marker::PhantomData<$trait_instance>), @@ -401,7 +429,6 @@ macro_rules! decl_module { #[cfg(not(feature = "std"))] $(#[$attr])* - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum $call_type<$trait_instance: $trait_name> { __PhantomItem(::core::marker::PhantomData<$trait_instance>), __OtherPhantomItem(::core::marker::PhantomData<$trait_instance>), @@ -610,7 +637,7 @@ macro_rules! impl_outer_dispatch { ) => { $(#[$attr])* #[derive(Clone, PartialEq, Eq)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[cfg_attr(feature = "std", derive(Debug))] pub enum $call_type { $( $camelcase ( $crate::dispatch::CallableCallFor<$camelcase> ) diff --git a/substrate/srml/support/src/event.rs b/substrate/srml/support/src/event.rs index ae7ddea412..02f295ab18 100644 --- a/substrate/srml/support/src/event.rs +++ b/substrate/srml/support/src/event.rs @@ -115,7 +115,7 @@ macro_rules! decl_event { ) => { // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Clone, PartialEq, Eq, Encode, Decode)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[cfg_attr(feature = "std", derive(Debug))] $(#[$attr])* pub enum Event { $( @@ -216,7 +216,7 @@ macro_rules! __decl_generic_event { pub type Event<$event_generic_param> = RawEvent<$( <$generic as $trait>::$trait_type ),*>; // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Clone, PartialEq, Eq, Encode, Decode)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[cfg_attr(feature = "std", derive(Debug))] $(#[$attr])* pub enum RawEvent<$( $generic_param ),*> { $( @@ -364,7 +364,7 @@ macro_rules! impl_outer_event { ) => { // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Clone, PartialEq, Eq, Encode, Decode)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[cfg_attr(feature = "std", derive(Debug))] $(#[$attr])* #[allow(non_camel_case_types)] pub enum $name { @@ -518,7 +518,7 @@ mod tests { ); } - #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Deserialize, Serialize)] + #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize)] pub struct TestRuntime; impl_outer_event! { @@ -529,7 +529,7 @@ mod tests { } } - #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Deserialize, Serialize)] + #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize)] pub struct TestRuntime2; impl_outer_event! { diff --git a/substrate/srml/support/src/lib.rs b/substrate/srml/support/src/lib.rs index e9cd35afa5..e70af960f1 100644 --- a/substrate/srml/support/src/lib.rs +++ b/substrate/srml/support/src/lib.rs @@ -36,7 +36,7 @@ extern crate mashup; #[cfg(test)] #[macro_use] extern crate pretty_assertions; -#[cfg(test)] +#[cfg(feature = "std")] #[macro_use] extern crate serde_derive; #[cfg(test)] @@ -122,3 +122,6 @@ pub enum Void {} #[doc(hidden)] pub use mashup::*; + +#[cfg(feature = "std")] +pub use serde_derive::*; diff --git a/substrate/srml/system/Cargo.toml b/substrate/srml/system/Cargo.toml index c4bde66fc8..5bc00b1230 100644 --- a/substrate/srml/system/Cargo.toml +++ b/substrate/srml/system/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } safe-mix = { version = "1.0", default-features = false} parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } @@ -20,7 +19,6 @@ srml-support = { path = "../support", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "safe-mix/std", "parity-codec/std", "parity-codec-derive/std", diff --git a/substrate/srml/system/src/lib.rs b/substrate/srml/system/src/lib.rs index b10b311259..eccd99a98c 100644 --- a/substrate/srml/system/src/lib.rs +++ b/substrate/srml/system/src/lib.rs @@ -27,10 +27,6 @@ extern crate sr_std as rstd; #[macro_use] extern crate srml_support as runtime_support; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[macro_use] extern crate parity_codec_derive; @@ -41,7 +37,8 @@ extern crate safe_mix; use rstd::prelude::*; use primitives::traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps, Zero, One, Bounded, Lookup, - Hash, Member, MaybeDisplay, EnsureOrigin, Digest as DigestT, As, CurrentHeight, BlockNumberToHash}; + Hash, Member, MaybeDisplay, EnsureOrigin, Digest as DigestT, As, CurrentHeight, BlockNumberToHash, + MaybeSerializeDebugButNotDeserialize, MaybeSerializeDebug}; use substrate_primitives::storage::well_known_keys; use runtime_support::{storage, StorageValue, StorageMap, Parameter}; use safe_mix::TripletMix; @@ -68,12 +65,12 @@ pub fn extrinsics_data_root(xts: Vec>) -> H::Output { pub trait Trait: Eq + Clone { type Origin: Into>> + From>; - type Index: Parameter + Member + Default + MaybeDisplay + SimpleArithmetic + Copy; - type BlockNumber: Parameter + Member + MaybeDisplay + SimpleArithmetic + Default + Bounded + Copy + rstd::hash::Hash; - type Hash: Parameter + Member + MaybeDisplay + SimpleBitOps + Default + Copy + CheckEqual + rstd::hash::Hash + AsRef<[u8]> + AsMut<[u8]>; + type Index: Parameter + Member + MaybeSerializeDebugButNotDeserialize + Default + MaybeDisplay + SimpleArithmetic + Copy; + type BlockNumber: Parameter + Member + MaybeSerializeDebug + MaybeDisplay + SimpleArithmetic + Default + Bounded + Copy + rstd::hash::Hash; + type Hash: Parameter + Member + MaybeSerializeDebug + MaybeDisplay + SimpleBitOps + Default + Copy + CheckEqual + rstd::hash::Hash + AsRef<[u8]> + AsMut<[u8]>; type Hashing: Hash; - type Digest: Parameter + Member + Default + traits::Digest; - type AccountId: Parameter + Member + MaybeDisplay + Ord + Default; + type Digest: Parameter + Member + MaybeSerializeDebugButNotDeserialize + Default + traits::Digest; + type AccountId: Parameter + Member + MaybeSerializeDebug + MaybeDisplay + Ord + Default; type Header: Parameter + traits::Header< Number = Self::BlockNumber, Hash = Self::Hash, diff --git a/substrate/srml/timestamp/Cargo.toml b/substrate/srml/timestamp/Cargo.toml index c07a62aeda..8472bb89ca 100644 --- a/substrate/srml/timestamp/Cargo.toml +++ b/substrate/srml/timestamp/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } parity-codec-derive = { version = "2.1", default-features = false } parity-codec = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } @@ -29,7 +28,6 @@ std = [ "sr-primitives/std", "srml-consensus/std", "serde/std", - "serde_derive", "parity-codec-derive/std", "parity-codec/std", "substrate-primitives/std", diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index 36004e88c3..8911a7e5df 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -39,10 +39,6 @@ extern crate sr_std as rstd; #[macro_use] extern crate srml_support as runtime_support; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; - #[cfg(test)] extern crate substrate_primitives; #[cfg(test)] diff --git a/substrate/srml/treasury/Cargo.toml b/substrate/srml/treasury/Cargo.toml index 32621e1561..9090ac4d9b 100644 --- a/substrate/srml/treasury/Cargo.toml +++ b/substrate/srml/treasury/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } @@ -21,7 +20,6 @@ srml-balances = { path = "../balances", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "parity-codec/std", "parity-codec-derive/std", "substrate-primitives/std", diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index 94e60e4b32..340ab48a8c 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -25,10 +25,6 @@ extern crate srml_support as runtime_support; #[cfg(test)] extern crate sr_io as runtime_io; - -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; #[cfg(feature = "std")] extern crate serde; diff --git a/substrate/srml/upgrade-key/Cargo.toml b/substrate/srml/upgrade-key/Cargo.toml index 980a7240a9..74561894ac 100644 --- a/substrate/srml/upgrade-key/Cargo.toml +++ b/substrate/srml/upgrade-key/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Parity Technologies "] [dependencies] hex-literal = "0.1.0" serde = { version = "1.0", default-features = false } -serde_derive = { version = "1.0", optional = true } parity-codec = { version = "2.1", default-features = false } parity-codec-derive = { version = "2.1", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } @@ -21,7 +20,6 @@ srml-consensus = { path = "../consensus", default-features = false } default = ["std"] std = [ "serde/std", - "serde_derive", "parity-codec/std", "parity-codec-derive/std", "sr-std/std", diff --git a/substrate/srml/upgrade-key/src/lib.rs b/substrate/srml/upgrade-key/src/lib.rs index 28433d8fbd..9a8e7493e9 100644 --- a/substrate/srml/upgrade-key/src/lib.rs +++ b/substrate/srml/upgrade-key/src/lib.rs @@ -25,9 +25,6 @@ extern crate sr_io; #[cfg(test)] extern crate substrate_primitives; extern crate sr_primitives; -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; #[macro_use] extern crate parity_codec_derive; extern crate parity_codec as codec;