mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 21:51:06 +00:00
Rename Hashing Trait to Hash (#288)
This commit is contained in:
committed by
Gav Wood
parent
48aae39343
commit
52e0a1eada
@@ -18,7 +18,7 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::borrow::Borrow;
|
||||
use primitives::traits::{Executable, RefInto, Hashing};
|
||||
use primitives::traits::{Executable, RefInto, Hash};
|
||||
use runtime_io::print;
|
||||
use substrate_runtime_support::dispatch::Result;
|
||||
use substrate_runtime_support::{StorageValue, StorageMap, IsSubType};
|
||||
|
||||
@@ -54,7 +54,7 @@ use rstd::marker::PhantomData;
|
||||
use rstd::result;
|
||||
use runtime_support::StorageValue;
|
||||
use primitives::traits::{self, Header, Zero, One, Checkable, Applyable, CheckEqual, Executable,
|
||||
MakePayment, Hashing, AuxLookup};
|
||||
MakePayment, Hash, AuxLookup};
|
||||
use codec::Slicable;
|
||||
use system::extrinsics_root;
|
||||
use primitives::{ApplyOutcome, ApplyError};
|
||||
|
||||
@@ -26,7 +26,7 @@ use rstd::prelude::*;
|
||||
use codec::{Slicable, Input};
|
||||
use runtime_support::AuxDispatchable;
|
||||
use traits::{self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay, Block as BlockT,
|
||||
Header as HeaderT, Hashing as HashingT};
|
||||
Header as HeaderT, Hash as HashT};
|
||||
use rstd::ops;
|
||||
use bft::Justification;
|
||||
|
||||
@@ -262,15 +262,15 @@ impl<Item> traits::Digest for Digest<Item> where
|
||||
#[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 Header<Number, Hashing: HashingT, DigestItem> {
|
||||
pub struct Header<Number, Hash: HashT, DigestItem> {
|
||||
/// The parent hash.
|
||||
pub parent_hash: <Hashing as HashingT>::Output,
|
||||
pub parent_hash: <Hash as HashT>::Output,
|
||||
/// The block number.
|
||||
pub number: Number,
|
||||
/// The state trie merkle root
|
||||
pub state_root: <Hashing as HashingT>::Output,
|
||||
pub state_root: <Hash as HashT>::Output,
|
||||
/// The merkle root of the extrinsics.
|
||||
pub extrinsics_root: <Hashing as HashingT>::Output,
|
||||
pub extrinsics_root: <Hash as HashT>::Output,
|
||||
/// A chain-specific digest of data useful for light clients or referencing auxiliary data.
|
||||
pub digest: Digest<DigestItem>,
|
||||
}
|
||||
@@ -291,8 +291,8 @@ struct DeserializeHeader<N, H, D> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<N, D, Hashing: HashingT> From<DeserializeHeader<N, Hashing::Output, D>> for Header<N, Hashing, D> {
|
||||
fn from(other: DeserializeHeader<N, Hashing::Output, D>) -> Self {
|
||||
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,
|
||||
@@ -304,21 +304,21 @@ impl<N, D, Hashing: HashingT> From<DeserializeHeader<N, Hashing::Output, D>> for
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<'a, Number: 'a, Hashing: 'a + HashingT, DigestItem: 'a> Deserialize<'a> for Header<Number, Hashing, DigestItem> where
|
||||
impl<'a, Number: 'a, Hash: 'a + HashT, DigestItem: 'a> Deserialize<'a> for Header<Number, Hash, DigestItem> where
|
||||
Number: Deserialize<'a>,
|
||||
Hashing::Output: Deserialize<'a>,
|
||||
Hash::Output: Deserialize<'a>,
|
||||
DigestItem: Deserialize<'a>,
|
||||
{
|
||||
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
|
||||
DeserializeHeader::<Number, Hashing::Output, DigestItem>::deserialize(de).map(Into::into)
|
||||
DeserializeHeader::<Number, Hash::Output, DigestItem>::deserialize(de).map(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Number, Hashing, DigestItem> Slicable for Header<Number, Hashing, DigestItem> where
|
||||
impl<Number, Hash, DigestItem> Slicable for Header<Number, Hash, DigestItem> where
|
||||
Number: Member + Slicable + MaybeDisplay + SimpleArithmetic + Slicable,
|
||||
Hashing: HashingT,
|
||||
Hash: HashT,
|
||||
DigestItem: Member + Default + Slicable,
|
||||
Hashing::Output: Default + Member + MaybeDisplay + SimpleBitOps + Slicable,
|
||||
Hash::Output: Default + Member + MaybeDisplay + SimpleBitOps + Slicable,
|
||||
{
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(Header {
|
||||
@@ -341,15 +341,15 @@ impl<Number, Hashing, DigestItem> Slicable for Header<Number, Hashing, DigestIte
|
||||
}
|
||||
}
|
||||
|
||||
impl<Number, Hashing, DigestItem> traits::Header for Header<Number, Hashing, DigestItem> where
|
||||
impl<Number, Hash, DigestItem> traits::Header for Header<Number, Hash, DigestItem> where
|
||||
Number: Member + ::rstd::hash::Hash + Copy + Slicable + MaybeDisplay + SimpleArithmetic + Slicable,
|
||||
Hashing: HashingT,
|
||||
Hash: HashT,
|
||||
DigestItem: Member + Default + Slicable,
|
||||
Hashing::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Slicable,
|
||||
Hash::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Slicable,
|
||||
{
|
||||
type Number = Number;
|
||||
type Hash = <Hashing as HashingT>::Output;
|
||||
type Hashing = Hashing;
|
||||
type Hash = <Hash as HashT>::Output;
|
||||
type Hashing = Hash;
|
||||
type Digest = Digest<DigestItem>;
|
||||
|
||||
fn number(&self) -> &Self::Number { &self.number }
|
||||
@@ -380,16 +380,16 @@ impl<Number, Hashing, DigestItem> traits::Header for Header<Number, Hashing, Dig
|
||||
}
|
||||
}
|
||||
|
||||
impl<Number, Hashing, DigestItem> Header<Number, Hashing, DigestItem> where
|
||||
impl<Number, Hash, DigestItem> Header<Number, Hash, DigestItem> where
|
||||
Number: Member + ::rstd::hash::Hash + Copy + Slicable + MaybeDisplay + SimpleArithmetic + Slicable,
|
||||
Hashing: HashingT,
|
||||
Hash: HashT,
|
||||
DigestItem: Member + Default + Slicable,
|
||||
Hashing::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Slicable,
|
||||
Hash::Output: Default + ::rstd::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Slicable,
|
||||
{
|
||||
/// Convenience helper for computing the hash of the header without having
|
||||
/// to import the trait.
|
||||
pub fn hash(&self) -> Hashing::Output {
|
||||
Hashing::hash_of(self)
|
||||
pub fn hash(&self) -> Hash::Output {
|
||||
Hash::hash_of(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ impl<A: Executable, B: Executable> Executable for (A, B) {
|
||||
}
|
||||
|
||||
/// Abstraction around hashing
|
||||
pub trait Hashing: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq { // Stupid bug in the Rust compiler believes derived
|
||||
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]>;
|
||||
@@ -218,12 +218,12 @@ pub trait Hashing: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq { // S
|
||||
fn storage_root() -> Self::Output;
|
||||
}
|
||||
|
||||
/// Blake2-256 Hashing implementation.
|
||||
/// Blake2-256 Hash implementation.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
pub struct BlakeTwo256;
|
||||
|
||||
impl Hashing for BlakeTwo256 {
|
||||
impl Hash for BlakeTwo256 {
|
||||
type Output = substrate_primitives::H256;
|
||||
fn hash(s: &[u8]) -> Self::Output {
|
||||
runtime_io::blake2_256(s).into()
|
||||
@@ -321,7 +321,7 @@ pub trait Digest {
|
||||
pub trait Header: Clone + Send + Sync + Slicable + Eq + MaybeSerializeDebug + 'static {
|
||||
type Number: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Slicable;
|
||||
type Hash: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Slicable + AsRef<[u8]>;
|
||||
type Hashing: Hashing<Output = Self::Hash>;
|
||||
type Hashing: Hash<Output = Self::Hash>;
|
||||
type Digest: Member + Default;
|
||||
|
||||
fn new(
|
||||
@@ -348,7 +348,7 @@ pub trait Header: Clone + Send + Sync + Slicable + Eq + MaybeSerializeDebug + 's
|
||||
fn set_digest(&mut self, Self::Digest);
|
||||
|
||||
fn hash(&self) -> Self::Hash {
|
||||
<Self::Hashing as Hashing>::hash_of(self)
|
||||
<Self::Hashing as Hash>::hash_of(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,12 +366,12 @@ pub trait Block: Clone + Send + Sync + Slicable + Eq + MaybeSerializeDebug + 'st
|
||||
fn deconstruct(self) -> (Self::Header, Vec<Self::Extrinsic>);
|
||||
fn new(header: Self::Header, extrinsics: Vec<Self::Extrinsic>) -> Self;
|
||||
fn hash(&self) -> Self::Hash {
|
||||
<<Self::Header as Header>::Hashing as Hashing>::hash_of(self.header())
|
||||
<<Self::Header as Header>::Hashing as Hash>::hash_of(self.header())
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract the hashing type for a block.
|
||||
pub type HashingFor<B> = <<B as Block>::Header as Header>::Hashing;
|
||||
pub type HashFor<B> = <<B as Block>::Header as Header>::Hashing;
|
||||
|
||||
/// A "checkable" piece of information, used by the standard Substrate Executive in order to
|
||||
/// check the validity of a piece of extrinsic information, usually by verifying the signature.
|
||||
|
||||
@@ -55,7 +55,7 @@ use runtime_support::{StorageValue, StorageMap, Parameter};
|
||||
use runtime_support::dispatch::Result;
|
||||
use session::OnSessionChange;
|
||||
use primitives::traits::{Zero, One, Bounded, RefInto, SimpleArithmetic, Executable, MakePayment,
|
||||
As, AuxLookup, Hashing as HashingT, Member};
|
||||
As, AuxLookup, Hash as HashT, Member};
|
||||
use address::Address as RawAddress;
|
||||
use double_map::StorageDoubleMap;
|
||||
|
||||
@@ -108,15 +108,15 @@ impl ContractAddressFor<u64> for DummyContractAddressFor {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Hashing, AccountId> ContractAddressFor<AccountId> for Hashing where
|
||||
Hashing: HashingT,
|
||||
AccountId: Sized + Slicable + From<Hashing::Output>,
|
||||
Hashing::Output: Slicable
|
||||
impl<Hash, AccountId> ContractAddressFor<AccountId> for Hash where
|
||||
Hash: HashT,
|
||||
AccountId: Sized + Slicable + From<Hash::Output>,
|
||||
Hash::Output: Slicable
|
||||
{
|
||||
fn contract_address_for(code: &[u8], origin: &AccountId) -> AccountId {
|
||||
let mut dest_pre = Hashing::hash(code).encode();
|
||||
let mut dest_pre = Hash::hash(code).encode();
|
||||
origin.using_encoded(|s| dest_pre.extend(s));
|
||||
AccountId::from(Hashing::hash(&dest_pre))
|
||||
AccountId::from(Hash::hash(&dest_pre))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ extern crate safe_mix;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use primitives::traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps, Zero, One, Bounded,
|
||||
Hashing, Member, MaybeDisplay};
|
||||
Hash, Member, MaybeDisplay};
|
||||
use runtime_support::{StorageValue, StorageMap, Parameter};
|
||||
use safe_mix::TripletMix;
|
||||
|
||||
@@ -52,12 +52,12 @@ use codec::Slicable;
|
||||
use runtime_io::{twox_128, TestExternalities};
|
||||
|
||||
/// Compute the extrinsics root of a list of extrinsics.
|
||||
pub fn extrinsics_root<H: Hashing, E: codec::Slicable>(extrinsics: &[E]) -> H::Output {
|
||||
pub fn extrinsics_root<H: Hash, E: codec::Slicable>(extrinsics: &[E]) -> H::Output {
|
||||
extrinsics_data_root::<H>(extrinsics.iter().map(codec::Slicable::encode).collect())
|
||||
}
|
||||
|
||||
/// Compute the extrinsics root of a list of extrinsics.
|
||||
pub fn extrinsics_data_root<H: Hashing>(xts: Vec<Vec<u8>>) -> H::Output {
|
||||
pub fn extrinsics_data_root<H: Hash>(xts: Vec<Vec<u8>>) -> H::Output {
|
||||
let xts = xts.iter().map(Vec::as_slice).collect::<Vec<_>>();
|
||||
H::enumerated_trie_root(&xts)
|
||||
}
|
||||
@@ -66,12 +66,12 @@ pub trait Trait: Eq + Clone {
|
||||
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]>;
|
||||
type Hashing: Hashing<Output = Self::Hash>;
|
||||
type Hashing: Hash<Output = Self::Hash>;
|
||||
type Digest: Parameter + Member + Default + traits::Digest;
|
||||
type AccountId: Parameter + Member + MaybeDisplay + Ord + Default;
|
||||
type Header: Parameter + traits::Header<
|
||||
Number = Self::BlockNumber,
|
||||
Hashing = Self::Hashing,
|
||||
Hash = Self::Hash,
|
||||
Hash = Self::Hash,
|
||||
Digest = Self::Digest
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user