mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 18:21:02 +00:00
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:
@@ -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<B, E, Block> Client<B, E, Block> where
|
||||
|
||||
/// Get full block by id.
|
||||
pub fn block(&self, id: &BlockId<Block>)
|
||||
-> error::Result<Option<SignedBlock<Block::Header, Block::Extrinsic>>>
|
||||
-> error::Result<Option<SignedBlock<Block>>>
|
||||
{
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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<Metadata>;
|
||||
@@ -40,7 +40,7 @@ pub type HttpServer = http::Server;
|
||||
pub type WsServer = ws::Server;
|
||||
|
||||
/// Construct rpc `IoHandler`
|
||||
pub fn rpc_handler<Block: BlockT, ExHash, PendingExtrinsics, S, C, A, Y>(
|
||||
pub fn rpc_handler<Block: BlockT, ExHash, S, C, A, Y>(
|
||||
state: S,
|
||||
chain: C,
|
||||
author: A,
|
||||
@@ -48,10 +48,10 @@ pub fn rpc_handler<Block: BlockT, ExHash, PendingExtrinsics, S, C, A, Y>(
|
||||
) -> 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<Block>: serde::Serialize + sr_primitives::DeserializeOwned,
|
||||
S: apis::state::StateApi<Block::Hash, Metadata=Metadata>,
|
||||
C: apis::chain::ChainApi<Block::Hash, Block::Header, NumberFor<Block>, Block::Extrinsic, Metadata=Metadata>,
|
||||
A: apis::author::AuthorApi<ExHash, Block::Hash, Block::Extrinsic, PendingExtrinsics, Metadata=Metadata>,
|
||||
C: apis::chain::ChainApi<Block::Hash, Block::Header, NumberFor<Block>, SignedBlock<Block>, Metadata=Metadata>,
|
||||
A: apis::author::AuthorApi<ExHash, Block::Hash, Metadata=Metadata>,
|
||||
Y: apis::system::SystemApi,
|
||||
{
|
||||
let mut io = pubsub::PubSubHandler::default();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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())]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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))?)
|
||||
|
||||
@@ -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<F, E, W>(config: FactoryFullConfiguration<F>, exit: E, mut output: W, from: FactoryBlockNumber<F>, to: Option<FactoryBlockNumber<F>>, json: bool) -> error::Result<()>
|
||||
where F: ServiceFactory, E: Future<Item=(),Error=()> + Send + 'static, W: Write,
|
||||
where
|
||||
F: ServiceFactory,
|
||||
E: Future<Item=(),Error=()> + Send + 'static,
|
||||
W: Write,
|
||||
{
|
||||
let client = new_client::<F>(&config)?;
|
||||
let mut block = from;
|
||||
@@ -104,14 +106,14 @@ pub fn import_blocks<F, E, R>(config: FactoryFullConfiguration<F>, exit: E, mut
|
||||
if exit_recv.try_recv().is_ok() {
|
||||
break;
|
||||
}
|
||||
if let Some(signed) = SignedBlock::<<F::Block as Block>::Header, <F::Block as Block>::Extrinsic>::decode(&mut input) {
|
||||
let header = signed.block.header;
|
||||
if let Some(signed) = SignedBlock::<F::Block>::decode(&mut input) {
|
||||
let (header, extrinsics) = signed.block.deconstruct();
|
||||
let hash = header.hash();
|
||||
let block = message::BlockData::<F::Block> {
|
||||
hash: hash,
|
||||
justification: Some(signed.justification),
|
||||
header: Some(header),
|
||||
body: Some(signed.block.extrinsics),
|
||||
body: Some(extrinsics),
|
||||
receipt: None,
|
||||
message_queue: None
|
||||
};
|
||||
|
||||
@@ -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<Components> Service<Components>
|
||||
where
|
||||
Components: components::Components,
|
||||
<Components as components::Components>::Executor: std::clone::Clone,
|
||||
txpool::ExHash<Components::TransactionPoolApi>: serde::de::DeserializeOwned + serde::Serialize,
|
||||
txpool::ExtrinsicFor<Components::TransactionPoolApi>: serde::de::DeserializeOwned + serde::Serialize,
|
||||
for<'de> SignedBlock<ComponentBlock<Components>>: ::serde::Deserialize<'de>,
|
||||
{
|
||||
/// Creates a new service.
|
||||
pub fn new(
|
||||
@@ -247,7 +246,7 @@ impl<Components> Service<Components>
|
||||
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::<ComponentBlock<Components>, ComponentExHash<Components>, _, _, _, _, _>(
|
||||
rpc::rpc_handler::<ComponentBlock<Components>, ComponentExHash<Components>, _, _, _, _>(
|
||||
state,
|
||||
chain,
|
||||
author,
|
||||
|
||||
@@ -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<AccountId, Index>(account: AccountId) -> Index;
|
||||
fn lookup_address<Address, LookupId>(address: Address) -> Option<LookupId>;
|
||||
}
|
||||
|
||||
/// The `TaggedTransactionQueue` api trait for interfering with the new transaction queue.
|
||||
pub trait TaggedTransactionQueue<Block: BlockT> {
|
||||
fn validate_transaction<TransactionValidity>(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity;
|
||||
|
||||
@@ -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<Block: BlockT> fmt::Display for BlockId<Block> {
|
||||
|
||||
/// 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<Header, Extrinsic> {
|
||||
pub struct Block<Header, Extrinsic: MaybeSerialize> {
|
||||
/// The block header.
|
||||
pub header: Header,
|
||||
/// The accompanying extrinsics.
|
||||
pub extrinsics: Vec<Extrinsic>,
|
||||
}
|
||||
|
||||
impl<Header, Extrinsic> traits::Block for Block<Header, 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,
|
||||
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<H, E> {
|
||||
pub struct SignedBlock<Block> {
|
||||
/// Full block.
|
||||
pub block: Block<H, E>,
|
||||
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<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"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AccountId, Index, Call> {
|
||||
/// 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<AccountId, Index, Call> traits::Applyable
|
||||
where
|
||||
AccountId: Member + MaybeDisplay,
|
||||
Index: Member + MaybeDisplay + SimpleArithmetic,
|
||||
Call: Member
|
||||
Call: Member,
|
||||
{
|
||||
type Index = Index;
|
||||
type AccountId = AccountId;
|
||||
|
||||
@@ -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<Hash, AuthorityId> DigestItem<Hash, AuthorityId> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Hash: Codec + Member, AuthorityId: Codec + Member> traits::DigestItem for DigestItem<Hash, AuthorityId> {
|
||||
impl<
|
||||
Hash: Codec + Member + MaybeSerializeDebug,
|
||||
AuthorityId: Codec + Member + MaybeSerializeDebug
|
||||
> traits::DigestItem for DigestItem<Hash, AuthorityId> {
|
||||
type Hash = Hash;
|
||||
type AuthorityId = AuthorityId;
|
||||
|
||||
|
||||
@@ -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<Number, Hash: HashT, DigestItem> {
|
||||
pub digest: Digest<DigestItem>,
|
||||
}
|
||||
|
||||
// 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<N, H, D> {
|
||||
parent_hash: H,
|
||||
number: N,
|
||||
state_root: H,
|
||||
extrinsics_root: H,
|
||||
digest: Digest<D>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<N, D, Hash: HashT> From<DeserializeHeader<N, Hash::Output, D>> for Header<N, Hash, D> {
|
||||
fn from(other: DeserializeHeader<N, Hash::Output, D>) -> 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<Number, Hash, DigestItem> where
|
||||
Number: Deserialize<'a>,
|
||||
Hash::Output: Deserialize<'a>,
|
||||
DigestItem: Deserialize<'a>,
|
||||
Header<Number, Hash, DigestItem>: Decode,
|
||||
{
|
||||
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
|
||||
DeserializeHeader::<Number, Hash::Output, DigestItem>::deserialize(de).map(Into::into)
|
||||
let r = <Vec<u8>>::deserialize(de)?;
|
||||
Decode::decode(&mut &r[..]).ok_or(::serde::de::Error::custom("Invalid value passed into decode"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,11 +86,11 @@ impl<Number, Hash, DigestItem> Encode for Header<Number, Hash, DigestItem> where
|
||||
}
|
||||
|
||||
impl<Number, Hash, DigestItem> traits::Header for Header<Number, Hash, DigestItem> where
|
||||
Number: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec,
|
||||
Number: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec,
|
||||
Hash: HashT,
|
||||
DigestItem: DigestItemT<Hash = Hash::Output> + 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 = <Hash as HashT>::Output;
|
||||
type Hashing = Hash;
|
||||
|
||||
@@ -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<u64, ::traits::BlakeTwo256, DigestItem<H256, u32>>,
|
||||
UncheckedExtrinsic<H256, u64, u64, ::Ed25519Signature>,
|
||||
>;
|
||||
|
||||
#[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::<H256, u32>(vec![1, 2, 3]),
|
||||
DigestItem::Other::<H256, u32>(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() {
|
||||
|
||||
@@ -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<Address, Index, Signature>
|
||||
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<Address, Index, Call, Signature>
|
||||
where
|
||||
Address: Codec,
|
||||
@@ -143,6 +141,15 @@ impl<Address: Codec, Index: HasCompact + Codec, Signature: Codec, Call: Encode>
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<Address: Codec, Index: HasCompact + Codec, Signature: Codec, Call: Encode> serde::Serialize
|
||||
for UncheckedExtrinsic<Address, Index, Call, Signature>
|
||||
{
|
||||
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
|
||||
self.using_encoded(|bytes| seq.serialize_bytes(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: use derive when possible.
|
||||
#[cfg(feature = "std")]
|
||||
impl<Address, Index, Signature, Call> fmt::Debug
|
||||
|
||||
@@ -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<Address, Index, Call, Signature> {
|
||||
/// 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<Address, Index, Call, Signature> UncheckedMortalExtrinsic<Address, Index, C
|
||||
}
|
||||
}
|
||||
|
||||
impl<Address, Index, Call, Signature> Extrinsic for UncheckedMortalExtrinsic<Address, Index, Call, Signature> {
|
||||
impl<Address: Encode, Index: Encode, Call: Encode, Signature: Encode> Extrinsic for UncheckedMortalExtrinsic<Address, Index, Call, Signature> {
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
Some(self.signature.is_some())
|
||||
}
|
||||
@@ -158,6 +157,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<Address: Encode, Index: Encode, Signature: Encode, Call: Encode> serde::Serialize
|
||||
for UncheckedMortalExtrinsic<Address, Index, Call, Signature>
|
||||
{
|
||||
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
|
||||
self.using_encoded(|bytes| seq.serialize_bytes(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: use derive when possible.
|
||||
#[cfg(feature = "std")]
|
||||
impl<Address, Index, Call, Signature> fmt::Debug for UncheckedMortalExtrinsic<Address, Index, Call, Signature> where
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
//! Testing utilities.
|
||||
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use std::{fmt::Debug, ops::Deref};
|
||||
use codec::Codec;
|
||||
use serde::{Serialize, Serializer, Deserialize, de::Error as DeError, Deserializer};
|
||||
use std::{fmt::Debug, ops::Deref, fmt};
|
||||
use codec::{Codec, Encode, Decode};
|
||||
use traits::{self, Checkable, Applyable, BlakeTwo256};
|
||||
use generic::DigestItem as GenDigestItem;
|
||||
|
||||
@@ -101,7 +101,7 @@ impl traits::Header for Header {
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
|
||||
pub struct ExtrinsicWrapper<Xt>(Xt);
|
||||
|
||||
impl<Xt> traits::Extrinsic for ExtrinsicWrapper<Xt> {
|
||||
impl<Xt> traits::Extrinsic for ExtrinsicWrapper<Xt> where Xt: Serialize {
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
@@ -121,13 +121,13 @@ impl<Xt> Deref for ExtrinsicWrapper<Xt> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Debug, Encode, Decode)]
|
||||
pub struct Block<Xt> {
|
||||
pub header: Header,
|
||||
pub extrinsics: Vec<Xt>,
|
||||
}
|
||||
|
||||
impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug + traits::Extrinsic> traits::Block for Block<Xt> {
|
||||
impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + Clone + Eq + Debug + traits::Extrinsic> traits::Block for Block<Xt> {
|
||||
type Extrinsic = Xt;
|
||||
type Header = Header;
|
||||
type Hash = <Header as traits::Header>::Hash;
|
||||
@@ -146,20 +146,40 @@ impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + DeserializeOwned +
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
|
||||
impl<'a, Xt> Deserialize<'a> for Block<Xt> where Block<Xt>: Decode {
|
||||
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
|
||||
let r = <Vec<u8>>::deserialize(de)?;
|
||||
Decode::decode(&mut &r[..]).ok_or(DeError::custom("Invalid value passed into decode"))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
pub struct TestXt<Call>(pub Option<u64>, pub u64, pub Call);
|
||||
|
||||
impl<Call: Codec + Sync + Send + Serialize, Context> Checkable<Context> for TestXt<Call> {
|
||||
impl<Call> Serialize for TestXt<Call> where TestXt<Call>: Encode
|
||||
{
|
||||
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
self.using_encoded(|bytes| seq.serialize_bytes(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call> Debug for TestXt<Call> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "TestXt({:?}, {:?})", self.0, self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call: Codec + Sync + Send, Context> Checkable<Context> for TestXt<Call> {
|
||||
type Checked = Self;
|
||||
fn check(self, _: &Context) -> Result<Self::Checked, &'static str> { Ok(self) }
|
||||
}
|
||||
impl<Call: Codec + Sync + Send + Serialize> traits::Extrinsic for TestXt<Call> {
|
||||
impl<Call: Codec + Sync + Send> traits::Extrinsic for TestXt<Call> {
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
}
|
||||
impl<Call> Applyable for TestXt<Call> where
|
||||
Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Serialize + DeserializeOwned,
|
||||
Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug,
|
||||
{
|
||||
type AccountId = u64;
|
||||
type Index = u64;
|
||||
|
||||
@@ -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<T> MaybeSerializeDebugButNotDeserialize for T {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub trait MaybeSerialize: Serialize {}
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Serialize> MaybeSerialize for T {}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub trait MaybeSerialize {}
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<T> 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<T> MaybeSerializeDebug for T {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub trait MaybeDebug: Debug {}
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Debug> MaybeDebug for T {}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub trait MaybeDebug {}
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<T> 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<T> MaybeDecode for T {}
|
||||
|
||||
|
||||
pub trait Member: Send + Sync + Sized + MaybeSerializeDebug + Eq + PartialEq + Clone + 'static {}
|
||||
impl<T: Send + Sync + Sized + MaybeSerializeDebug + Eq + PartialEq + Clone + 'static> Member for T {}
|
||||
pub trait Member: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static {}
|
||||
impl<T: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static> 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<T: Send + Sync + Sized + MaybeSerializeDebug + Eq + PartialEq + Clone + 'st
|
||||
///
|
||||
/// You can also create a `new` one from those fields.
|
||||
pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'static {
|
||||
type Number: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec;
|
||||
type Hash: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + 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<Output = Self::Hash>;
|
||||
type Digest: Digest<Hash = Self::Hash>;
|
||||
|
||||
@@ -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<Hash=Self::Hash>;
|
||||
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<bool> { None }
|
||||
}
|
||||
|
||||
/// Extract the hashing type for a block.
|
||||
pub type HashFor<B> = <<B as Block>::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<Hash = Self::Hash>;
|
||||
|
||||
/// 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<bool> { None }
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
BIN
Binary file not shown.
@@ -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<Hash, Ex> {
|
||||
|
||||
/// Immutable transaction
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Transaction<Hash, Extrinsic> {
|
||||
/// Raw extrinsic representing that transaction.
|
||||
pub data: Extrinsic,
|
||||
@@ -120,7 +121,7 @@ impl<Hash: hash::Hash + Eq, Ex> Default for BasePool<Hash, Ex> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Hash: hash::Hash + Member, Ex: ::std::fmt::Debug> BasePool<Hash, Ex> {
|
||||
impl<Hash: hash::Hash + Member + Serialize, Ex: ::std::fmt::Debug> BasePool<Hash, Ex> {
|
||||
/// Imports transaction to the pool.
|
||||
///
|
||||
/// The pool consists of two parts: Future and Ready.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -19,6 +19,7 @@ use std::{
|
||||
collections::HashMap,
|
||||
hash,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use watcher;
|
||||
use sr_primitives::traits;
|
||||
|
||||
@@ -35,7 +36,7 @@ impl<H: hash::Hash + Eq, H2> Default for Listener<H, H2> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: hash::Hash + traits::Member, H2: Clone> Listener<H, H2> {
|
||||
impl<H: hash::Hash + traits::Member + Serialize, H2: Clone> Listener<H, H2> {
|
||||
fn fire<F>(&mut self, hash: &H, fun: F) where F: FnOnce(&mut watcher::Sender<H, H2>) {
|
||||
let clean = if let Some(h) = self.watchers.get_mut(hash) {
|
||||
fun(h);
|
||||
|
||||
@@ -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::Error> + error::IntoPoolError;
|
||||
|
||||
@@ -287,7 +288,7 @@ fn fire_events<H, H2, Ex>(
|
||||
listener: &mut Listener<H, H2>,
|
||||
imported: &base::Imported<H, Ex>,
|
||||
) where
|
||||
H: hash::Hash + Eq + traits::Member,
|
||||
H: hash::Hash + Eq + traits::Member + Serialize,
|
||||
H2: Clone,
|
||||
{
|
||||
match *imported {
|
||||
|
||||
@@ -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<Hash: hash::Hash + Eq, Ex> Default for ReadyTransactions<Hash, Ex> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Hash: hash::Hash + Member, Ex> ReadyTransactions<Hash, Ex> {
|
||||
impl<Hash: hash::Hash + Member + Serialize, Ex> ReadyTransactions<Hash, Ex> {
|
||||
/// Borrows a map of tags that are provided by transactions in this queue.
|
||||
pub fn provided_tags(&self) -> &HashMap<Tag, Hash> {
|
||||
&self.provided_tags
|
||||
|
||||
Reference in New Issue
Block a user