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
+8 -16
View File
@@ -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<Hash, BlockHash, Extrinsic, PendingExtrinsics> {
pub trait AuthorApi<Hash, BlockHash> {
type Metadata;
/// Submit extrinsic for inclusion in block.
#[rpc(name = "author_submitRichExtrinsic")]
fn submit_rich_extrinsic(&self, Extrinsic) -> Result<Hash>;
/// Submit hex-encoded extrinsic for inclusion in block.
#[rpc(name = "author_submitExtrinsic")]
fn submit_extrinsic(&self, Bytes) -> Result<Hash>;
/// Returns all pending extrinsics, potentially grouped by sender.
#[rpc(name = "author_pendingExtrinsics")]
fn pending_extrinsics(&self) -> Result<PendingExtrinsics>;
fn pending_extrinsics(&self) -> Result<Vec<Bytes>>;
#[pubsub(name = "author_extrinsicUpdate")] {
/// Submit an extrinsic to watch.
@@ -103,7 +99,7 @@ impl<B, E, P> Author<B, E, P> where
}
}
impl<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>, ExtrinsicFor<P>, Vec<ExtrinsicFor<P>>> for Author<B, E, P> where
impl<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P> where
B: client::backend::Backend<<P as PoolChainApi>::Block, Blake2Hasher> + Send + Sync + 'static,
E: client::CallExecutor<<P as PoolChainApi>::Block, Blake2Hasher> + Send + Sync + 'static,
P: PoolChainApi + Sync + Send + 'static,
@@ -112,12 +108,8 @@ impl<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>, ExtrinsicFor<P>, Vec<ExtrinsicF
{
type Metadata = ::metadata::Metadata;
fn submit_extrinsic(&self, xt: Bytes) -> Result<ExHash<P>> {
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: <<P as PoolChainApi>::Block as traits::Block>::Extrinsic) -> Result<ExHash<P>> {
fn submit_extrinsic(&self, ext: Bytes) -> Result<ExHash<P>> {
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<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>, ExtrinsicFor<P>, Vec<ExtrinsicF
)
}
fn pending_extrinsics(&self) -> Result<Vec<ExtrinsicFor<P>>> {
Ok(self.pool.ready().map(|tx| tx.data.clone()).collect())
fn pending_extrinsics(&self) -> Result<Vec<Bytes>> {
Ok(self.pool.ready().map(|tx| tx.data.encode().into()).collect())
}
fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: pubsub::Subscriber<Status<ExHash<P>, BlockHash<P>>>, xt: Bytes) {
+5 -5
View File
@@ -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())]
);
}
+4 -4
View File
@@ -39,7 +39,7 @@ use self::error::Result;
build_rpc_trait! {
/// Substrate blockchain API
pub trait ChainApi<Hash, Header, Number, Extrinsic> {
pub trait ChainApi<Hash, Header, Number, SignedBlock> {
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<Hash>) -> Result<Option<SignedBlock<Header, Extrinsic>>>;
fn block(&self, Trailing<Hash>) -> Result<Option<SignedBlock>>;
/// Get hash of the n-th block in the canon chain.
///
@@ -163,7 +163,7 @@ impl<B, E, Block> Chain<B, E, Block> where
}
}
impl<B, E, Block> ChainApi<Block::Hash, Block::Header, NumberFor<Block>, Block::Extrinsic> for Chain<B, E, Block> where
impl<B, E, Block> ChainApi<Block::Hash, Block::Header, NumberFor<Block>, SignedBlock<Block>> for Chain<B, E, Block> where
Block: BlockT<Hash=H256> + 'static,
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
E: client::CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static,
@@ -176,7 +176,7 @@ impl<B, E, Block> ChainApi<Block::Hash, Block::Header, NumberFor<Block>, Block::
}
fn block(&self, hash: Trailing<Block::Hash>)
-> Result<Option<SignedBlock<Block::Header, Block::Extrinsic>>>
-> Result<Option<SignedBlock<Block>>>
{
let hash = self.unwrap_or_best(hash)?;
Ok(self.client.block(&BlockId::Hash(hash))?)