Migrate sr-primitives, sr-sandbox, sr-std and sr-version to the 2018 edition (#1694)

This commit is contained in:
Stanislav Tkach
2019-02-06 20:04:14 +02:00
committed by Gav Wood
parent 4e3eace15f
commit 3a4dda7beb
24 changed files with 113 additions and 122 deletions
@@ -19,10 +19,14 @@
#[cfg(feature = "std")]
use std::fmt;
#[cfg(feature = "std")]
use serde_derive::Serialize;
use rstd::prelude::*;
use codec::Codec;
use traits::{self, Member, Block as BlockT, Header as HeaderT, MaybeSerialize};
use ::Justification;
use parity_codec_derive::{Encode, Decode};
use crate::codec::Codec;
use crate::traits::{self, Member, Block as BlockT, Header as HeaderT, MaybeSerialize};
use crate::Justification;
/// Something to identify a block.
#[derive(PartialEq, Eq, Clone)]
@@ -17,7 +17,7 @@
//! Generic implementation of an extrinsic that has passed the verification
//! stage.
use traits::{self, Member, SimpleArithmetic, MaybeDisplay};
use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay};
/// Definition of something that the external world might want to say; its
/// existence implies that it has been checked and is good, particularly with
@@ -16,10 +16,14 @@
//! Generic implementation of a digest.
use rstd::prelude::*;
#[cfg(feature = "std")]
use serde_derive::Serialize;
use codec::{Decode, Encode, Codec, Input};
use traits::{self, Member, DigestItem as DigestItemT, MaybeHash};
use rstd::prelude::*;
use parity_codec_derive::{Encode, Decode};
use crate::codec::{Decode, Encode, Codec, Input};
use crate::traits::{self, Member, DigestItem as DigestItemT, MaybeHash};
use substrate_primitives::hash::H512 as Signature;
@@ -16,7 +16,10 @@
//! Generic implementation of an unchecked (pre-verification) extrinsic.
use codec::{Decode, Encode, Input, Output};
#[cfg(feature = "std")]
use serde_derive::{Serialize, Deserialize};
use crate::codec::{Decode, Encode, Input, Output};
pub type Period = u64;
pub type Phase = u64;
@@ -16,10 +16,12 @@
//! Generic implementation of a block header.
use codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef};
use traits::{self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay,
#[cfg(feature = "std")]
use serde_derive::Serialize;
use crate::codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef};
use crate::traits::{self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay,
Hash as HashT, DigestItem as DigestItemT, MaybeSerializeDebug, MaybeSerializeDebugButNotDeserialize};
use generic::Digest;
use crate::generic::Digest;
/// Abstraction over a block header for a substrate chain.
#[derive(PartialEq, Eq, Clone)]
@@ -38,7 +38,7 @@ pub use self::header::Header;
pub use self::block::{Block, SignedBlock, BlockId};
pub use self::digest::{Digest, DigestItem, DigestItemRef};
use codec::Encode;
use crate::codec::Encode;
use rstd::prelude::*;
fn encode_with_vec_prefix<T: Encode, F: Fn(&mut Vec<u8>)>(encoder: F) -> Vec<u8> {
@@ -16,7 +16,7 @@
//! Tests for the generic implementations of Extrinsic/Header/Block.
use codec::{Decode, Encode};
use crate::codec::{Decode, Encode};
use substrate_primitives::H256;
use super::DigestItem;
@@ -54,4 +54,4 @@ fn non_system_digest_item_encoding() {
let decoded: DigestItem<H256, u32> = Decode::decode(&mut &encoded[..]).unwrap();
assert_eq!(item, decoded);
}
}
@@ -20,8 +20,9 @@
use std::fmt;
use rstd::prelude::*;
use codec::{Decode, Encode, Codec, Input, HasCompact};
use traits::{self, Member, SimpleArithmetic, MaybeDisplay, Lookup, Extrinsic};
use parity_codec_derive::{Encode, Decode};
use crate::codec::{Decode, Encode, Codec, Input, HasCompact};
use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, Lookup, Extrinsic};
use super::CheckedExtrinsic;
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
@@ -92,7 +93,7 @@ where
Some(SignatureContent{signed, signature, index}) => {
let payload = (index, self.function);
let signed = context.lookup(signed)?;
if !::verify_encoded_lazy(&signature, &payload, &signed) {
if !crate::verify_encoded_lazy(&signature, &payload, &signed) {
return Err("bad signature in extrinsic")
}
CheckedExtrinsic {
@@ -172,7 +173,7 @@ where
#[cfg(test)]
mod test {
use codec::{Decode, Encode};
use crate::codec::{Decode, Encode};
use super::UncheckedExtrinsic;
#[test]
@@ -21,8 +21,8 @@ use std::fmt;
use rstd::prelude::*;
use runtime_io::blake2_256;
use codec::{Decode, Encode, Input, Compact};
use traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, Lookup,
use crate::codec::{Decode, Encode, Input, Compact};
use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, Lookup,
Checkable, Extrinsic};
use super::{CheckedExtrinsic, Era};
@@ -190,6 +190,8 @@ impl<Address, Index, Call, Signature> fmt::Debug for UncheckedMortalCompactExtri
mod tests {
use super::*;
use runtime_io::blake2_256;
use parity_codec_derive::{Encode, Decode};
use serde_derive::{Serialize, Deserialize};
struct TestContext;
impl Lookup for TestContext {
@@ -21,8 +21,8 @@ use std::fmt;
use rstd::prelude::*;
use runtime_io::blake2_256;
use codec::{Decode, Encode, Input};
use traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, Lookup,
use crate::codec::{Decode, Encode, Input};
use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, Lookup,
Checkable, Extrinsic};
use super::{CheckedExtrinsic, Era};
@@ -189,6 +189,8 @@ impl<Address, Index, Call, Signature> fmt::Debug for UncheckedMortalExtrinsic<Ad
mod tests {
use super::*;
use runtime_io::blake2_256;
use parity_codec_derive::{Encode, Decode};
use serde_derive::{Serialize, Deserialize};
struct TestContext;
impl Lookup for TestContext {
+23 -34
View File
@@ -21,36 +21,18 @@
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
extern crate serde;
#[cfg(feature = "std")]
#[macro_use]
extern crate serde_derive;
#[cfg(feature = "std")]
#[macro_use]
extern crate log;
#[macro_use]
extern crate parity_codec_derive;
extern crate num_traits;
extern crate integer_sqrt;
extern crate sr_std as rstd;
extern crate sr_io as runtime_io;
#[doc(hidden)]
pub extern crate parity_codec as codec;
extern crate substrate_primitives;
#[cfg(test)]
extern crate serde_json;
pub use parity_codec as codec;
#[cfg(feature = "std")]
#[doc(hidden)]
pub use serde_derive;
#[cfg(feature = "std")]
use std::collections::HashMap;
use rstd::prelude::*;
use substrate_primitives::hash::{H256, H512};
use parity_codec_derive::{Encode, Decode};
#[cfg(feature = "std")]
use substrate_primitives::hexdisplay::ascii_format;
@@ -88,6 +70,8 @@ macro_rules! create_runtime_str {
#[cfg(feature = "std")]
pub use serde::{Serialize, de::DeserializeOwned};
#[cfg(feature = "std")]
use serde_derive::{Serialize, Deserialize};
/// A set of key value pairs for storage.
#[cfg(feature = "std")]
@@ -105,7 +89,7 @@ pub trait BuildStorage {
/// Default to xx128 hashing.
fn hash(data: &[u8]) -> [u8; 16] {
let r = runtime_io::twox_128(data);
trace!(target: "build_storage", "{} <= {}", substrate_primitives::hexdisplay::HexDisplay::from(&r), ascii_format(data));
log::trace!(target: "build_storage", "{} <= {}", substrate_primitives::hexdisplay::HexDisplay::from(&r), ascii_format(data));
r
}
/// Build the storage out of this builder.
@@ -423,7 +407,7 @@ macro_rules! impl_outer_log {
/// Wrapper for all possible log entries for the `$trait` runtime. Provides binary-compatible
/// `Encode`/`Decode` implementations with the corresponding `generic::DigestItem`.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
#[cfg_attr(feature = "std", derive(Debug, $crate::serde_derive::Serialize))]
$(#[$attr])*
#[allow(non_camel_case_types)]
pub struct $name($internal);
@@ -431,7 +415,7 @@ macro_rules! impl_outer_log {
/// All possible log entries for the `$trait` runtime. `Encode`/`Decode` implementations
/// are auto-generated => it is not binary-compatible with `generic::DigestItem`.
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
#[cfg_attr(feature = "std", derive(Debug, $crate::serde_derive::Serialize))]
$(#[$attr])*
#[allow(non_camel_case_types)]
pub enum InternalLog {
@@ -540,7 +524,7 @@ pub struct OpaqueExtrinsic(pub Vec<u8>);
#[cfg(feature = "std")]
impl ::serde::Serialize for OpaqueExtrinsic {
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
::codec::Encode::using_encoded(&self.0, |bytes| ::substrate_primitives::bytes::serialize(bytes, seq))
codec::Encode::using_encoded(&self.0, |bytes| ::substrate_primitives::bytes::serialize(bytes, seq))
}
}
@@ -553,8 +537,9 @@ impl traits::Extrinsic for OpaqueExtrinsic {
#[cfg(test)]
mod tests {
use substrate_primitives::hash::H256;
use codec::{Encode as EncodeHidden, Decode as DecodeHidden};
use traits::DigestItem;
use crate::codec::{Encode as EncodeHidden, Decode as DecodeHidden};
use parity_codec_derive::{Encode, Decode};
use crate::traits::DigestItem;
pub trait RuntimeT {
type AuthorityId;
@@ -568,6 +553,8 @@ mod tests {
mod a {
use super::RuntimeT;
use parity_codec_derive::{Encode, Decode};
use serde_derive::Serialize;
pub type Log<R> = RawLog<<R as RuntimeT>::AuthorityId>;
#[derive(Serialize, Debug, Encode, Decode, PartialEq, Eq, Clone)]
@@ -576,6 +563,8 @@ mod tests {
mod b {
use super::RuntimeT;
use parity_codec_derive::{Encode, Decode};
use serde_derive::Serialize;
pub type Log<R> = RawLog<<R as RuntimeT>::AuthorityId>;
#[derive(Serialize, Debug, Encode, Decode, PartialEq, Eq, Clone)]
@@ -633,24 +622,24 @@ mod tests {
fn compact_permill_perbill_encoding() {
let tests = [(0u32, 1usize), (63, 1), (64, 2), (16383, 2), (16384, 4), (1073741823, 4), (1073741824, 5), (u32::max_value(), 5)];
for &(n, l) in &tests {
let compact: codec::Compact<super::Permill> = super::Permill(n).into();
let compact: crate::codec::Compact<super::Permill> = super::Permill(n).into();
let encoded = compact.encode();
assert_eq!(encoded.len(), l);
let decoded = <codec::Compact<super::Permill>>::decode(&mut & encoded[..]).unwrap();
let decoded = <crate::codec::Compact<super::Permill>>::decode(&mut & encoded[..]).unwrap();
let permill: super::Permill = decoded.into();
assert_eq!(permill, super::Permill(n));
let compact: codec::Compact<super::Perbill> = super::Perbill(n).into();
let compact: crate::codec::Compact<super::Perbill> = super::Perbill(n).into();
let encoded = compact.encode();
assert_eq!(encoded.len(), l);
let decoded = <codec::Compact<super::Perbill>>::decode(&mut & encoded[..]).unwrap();
let decoded = <crate::codec::Compact<super::Perbill>>::decode(&mut & encoded[..]).unwrap();
let perbill: super::Perbill = decoded.into();
assert_eq!(perbill, super::Perbill(n));
}
}
#[derive(Encode, Decode, PartialEq, Eq, Debug)]
struct WithCompact<T: codec::HasCompact> {
struct WithCompact<T: crate::codec::HasCompact> {
data: T,
}
+7 -3
View File
@@ -17,10 +17,14 @@
//! Testing utilities.
use serde::{Serialize, Serializer, Deserialize, de::Error as DeError, Deserializer};
use serde_derive::Serialize;
#[cfg(feature = "std")]
use serde_derive::Deserialize;
use std::{fmt::Debug, ops::Deref, fmt};
use codec::{Codec, Encode, Decode};
use traits::{self, Checkable, Applyable, BlakeTwo256, Convert};
use generic::DigestItem as GenDigestItem;
use crate::codec::{Codec, Encode, Decode};
use crate::traits::{self, Checkable, Applyable, BlakeTwo256, Convert};
use crate::generic::DigestItem as GenDigestItem;
use parity_codec_derive::{Encode, Decode};
pub use substrate_primitives::{H256, Ed25519AuthorityId};
use substrate_primitives::U256;
+10 -8
View File
@@ -21,9 +21,11 @@ use rstd::{self, result, marker::PhantomData};
use runtime_io;
#[cfg(feature = "std")] use std::fmt::{Debug, Display};
#[cfg(feature = "std")] use serde::{Serialize, de::DeserializeOwned};
#[cfg(feature = "std")]
use serde_derive::{Serialize, Deserialize};
use substrate_primitives;
use substrate_primitives::Blake2Hasher;
use codec::{Codec, Encode, HasCompact};
use crate::codec::{Codec, Encode, HasCompact};
pub use integer_sqrt::IntegerSquareRoot;
pub use num_traits::{Zero, One, Bounded};
pub use num_traits::ops::checked::{
@@ -147,7 +149,7 @@ pub trait As<T> {
/// Convert forward (ala `Into::into`).
fn as_(self) -> T;
/// Convert backward (ala `From::from`).
fn sa(T) -> Self;
fn sa(_: T) -> Self;
}
macro_rules! impl_numerics {
@@ -518,29 +520,29 @@ pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDe
/// Returns a reference to the header number.
fn number(&self) -> &Self::Number;
/// Sets the header number.
fn set_number(&mut self, Self::Number);
fn set_number(&mut self, number: Self::Number);
/// Returns a reference to the extrinsics root.
fn extrinsics_root(&self) -> &Self::Hash;
/// Sets the extrinsic root.
fn set_extrinsics_root(&mut self, Self::Hash);
fn set_extrinsics_root(&mut self, root: Self::Hash);
/// Returns a reference to the state root.
fn state_root(&self) -> &Self::Hash;
/// Sets the state root.
fn set_state_root(&mut self, Self::Hash);
fn set_state_root(&mut self, root: Self::Hash);
/// Returns a reference to the parent hash.
fn parent_hash(&self) -> &Self::Hash;
/// Sets the parent hash.
fn set_parent_hash(&mut self, Self::Hash);
fn set_parent_hash(&mut self, hash: Self::Hash);
/// Returns a reference to the digest.
fn digest(&self) -> &Self::Digest;
/// Get a mutable reference to the digest.
fn digest_mut(&mut self) -> &mut Self::Digest;
/// Sets the digest.
fn set_digest(&mut self, Self::Digest);
fn set_digest(&mut self, digest: Self::Digest);
/// Returns the hash of the header.
fn hash(&self) -> Self::Hash {
@@ -676,7 +678,7 @@ pub trait DigestItem: Codec + Member + MaybeSerializeDebugButNotDeserialize {
/// `ChangesTrieRoot` payload.
type Hash: Member;
/// `AuthorityChange` payload.
type AuthorityId: Member + MaybeHash + codec::Encode + codec::Decode;
type AuthorityId: Member + MaybeHash + crate::codec::Encode + crate::codec::Decode;
/// Returns Some if the entry is the `AuthoritiesChange` entry.
fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]>;
@@ -17,6 +17,7 @@
//! Transaction validity interface.
use rstd::prelude::*;
use parity_codec_derive::{Encode, Decode};
/// Priority for a transaction. Additive. Higher is better.
pub type TransactionPriority = u64;