Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Rename Hashing Trait to Hash (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunicorn authored and gavofyork committed Jul 10, 2018
1 parent 136c045 commit 9b438dc
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion polkadot/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ pub struct CreateProposal<C: PolkadotApi> {
impl<C> CreateProposal<C> where C: PolkadotApi {
fn propose_with(&self, candidates: Vec<CandidateReceipt>) -> Result<Block, Error> {
use polkadot_api::BlockBuilder;
use runtime_primitives::traits::{Hashing, BlakeTwo256};
use runtime_primitives::traits::{Hash as HashT, BlakeTwo256};

// TODO: handle case when current timestamp behind that in state.
let timestamp = current_timestamp();
Expand Down
4 changes: 2 additions & 2 deletions polkadot/primitives/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl CandidateReceipt {
/// Get the blake2_256 hash
#[cfg(feature = "std")]
pub fn hash(&self) -> Hash {
use runtime_primitives::traits::{BlakeTwo256, Hashing};
use runtime_primitives::traits::{BlakeTwo256, Hash};
BlakeTwo256::hash_of(self)
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ impl BlockData {
/// Compute hash of block data.
#[cfg(feature = "std")]
pub fn hash(&self) -> Hash {
use runtime_primitives::traits::{BlakeTwo256, Hashing};
use runtime_primitives::traits::{BlakeTwo256, Hash};
BlakeTwo256::hash(&self.0[..])
}
}
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use rstd::prelude::*;
use codec::Slicable;

use runtime_primitives::traits::{Hashing, BlakeTwo256, Executable, RefInto, MaybeEmpty};
use runtime_primitives::traits::{Hash, BlakeTwo256, Executable, RefInto, MaybeEmpty};
use primitives::parachain::{Id, Chain, DutyRoster, CandidateReceipt};
use {system, session};

Expand Down
2 changes: 1 addition & 1 deletion polkadot/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use extrinsic_pool::api::ExtrinsicPool;
use polkadot_api::PolkadotApi;
use primitives::{AccountId, BlockId, Hash, Index, UncheckedExtrinsic as FutureProofUncheckedExtrinsic};
use runtime::{Address, UncheckedExtrinsic};
use substrate_runtime_primitives::traits::{Bounded, Checkable, Hashing, BlakeTwo256};
use substrate_runtime_primitives::traits::{Bounded, Checkable, Hash as HashT, BlakeTwo256};

pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps};
pub use error::{Error, ErrorKind, Result};
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use parking_lot::RwLock;
use primitives::H256;
use runtime_primitives::generic::BlockId;
use runtime_primitives::bft::Justification;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, Hashing, HashingFor, Zero};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, Hash, HashFor, Zero};
use runtime_primitives::BuildStorage;
use state_machine::backend::Backend as StateBackend;
use executor::RuntimeInfo;
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<Block: BlockT> client::blockchain::HeaderBackend<Block> for BlockchainDb<Bl

fn hash(&self, number: <Block::Header as HeaderT>::Number) -> Result<Option<Block::Hash>, client::error::Error> {
read_db::<Block>(&*self.db, columns::BLOCK_INDEX, columns::HEADER, BlockId::Number(number)).map(|x|
x.map(|raw| HashingFor::<Block>::hash(&raw[..])).map(Into::into)
x.map(|raw| HashFor::<Block>::hash(&raw[..])).map(Into::into)
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/db/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use client::light::blockchain::Storage as LightBlockchainStorage;
use codec::Slicable;
use primitives::AuthorityId;
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, Hashing, HashingFor, Zero};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, Hash, HashFor, Zero};
use utils::{meta_keys, Meta, db_err, number_to_db_key, open_database, read_db, read_id, read_meta};
use DatabaseSettings;

Expand Down Expand Up @@ -132,7 +132,7 @@ impl<Block> BlockchainHeaderBackend<Block> for LightStorage<Block>

fn hash(&self, number: <<Block as BlockT>::Header as HeaderT>::Number) -> ClientResult<Option<Block::Hash>> {
read_db::<Block>(&*self.db, columns::BLOCK_INDEX, columns::HEADER, BlockId::Number(number)).map(|x|
x.map(|raw| HashingFor::<Block>::hash(&raw[..])).map(Into::into)
x.map(|raw| HashFor::<Block>::hash(&raw[..])).map(Into::into)
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/db/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use client;
use codec::Slicable;
use hashdb::DBValue;
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT, Hashing, HashingFor, Zero};
use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT, Hash, HashFor, Zero};
use DatabaseSettings;

/// Number of columns in the db. Must be the same for both full && light dbs.
Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn read_meta<Block>(db: &KeyValueDB, col_header: Option<u32>) -> Result<Meta

let genesis_hash = db.get(col_header, &number_to_db_key(genesis_number))
.map_err(db_err)?
.map(|raw| HashingFor::<Block>::hash(&raw[..]))
.map(|raw| HashFor::<Block>::hash(&raw[..]))
.unwrap_or_default()
.into();

Expand Down
4 changes: 2 additions & 2 deletions substrate/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use std::vec::Vec;
use codec::Slicable;
use state_machine;
use runtime_primitives::traits::{Header as HeaderT, Hashing as HashingT, Block as BlockT, One, HashingFor};
use runtime_primitives::traits::{Header as HeaderT, Hash, Block as BlockT, One, HashFor};
use runtime_primitives::generic::BlockId;
use {backend, error, Client, CallExecutor};

Expand Down Expand Up @@ -109,7 +109,7 @@ impl<B, E, Block> BlockBuilder<B, E, Block> where

debug_assert_eq!(
self.header.extrinsics_root().clone(),
HashingFor::<Block>::ordered_trie_root(self.extrinsics.iter().map(Slicable::encode)),
HashFor::<Block>::ordered_trie_root(self.extrinsics.iter().map(Slicable::encode)),
);

Ok(<Block as BlockT>::new(self.header, self.extrinsics))
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Tool for creating the genesis block.

use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hashing as HashingT, Zero};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, Zero};
use runtime_primitives::StorageMap;

/// Create a genesis block, given the initial storage.
Expand All @@ -25,8 +25,8 @@ pub fn construct_genesis_block<
> (
storage: &StorageMap
) -> Block {
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashingT>::trie_root(storage.clone().into_iter());
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashingT>::trie_root(::std::iter::empty::<(&[u8], &[u8])>());
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(storage.clone().into_iter());
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(::std::iter::empty::<(&[u8], &[u8])>());
Block::new(
<<Block as BlockT>::Header as HeaderT>::new(
Zero::zero(),
Expand Down
4 changes: 2 additions & 2 deletions substrate/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use std::time;
use parking_lot::RwLock;
use serde_json;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hashing, HashingFor};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hash, HashFor};
use runtime_primitives::generic::BlockId;
use network::PeerId;

Expand Down Expand Up @@ -631,5 +631,5 @@ fn send_message<B: BlockT>(peers: &RwLock<HashMap<PeerId, Peer<B>>>, io: &mut Sy
/// Hash a message.
pub(crate) fn hash_message<B: BlockT>(message: &Message<B>) -> B::Hash {
let data = serde_json::to_vec(&message).expect("Serializer is infallible; qed");
HashingFor::<B>::hash(&data)
HashFor::<B>::hash(&data)
}
2 changes: 1 addition & 1 deletion substrate/rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<B, E, Block> StateApi<Block::Hash> for Arc<Client<B, E, Block>> where
}

fn storage_hash_at(&self, key: StorageKey, block: Block::Hash) -> Result<Block::Hash> {
use runtime_primitives::traits::{Hashing, Header as HeaderT};
use runtime_primitives::traits::{Hash, Header as HeaderT};
self.storage_at(key, block).map(|x| <Block::Header as HeaderT>::Hashing::hash(&x.0))
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime/council/src/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
46 changes: 23 additions & 23 deletions substrate/runtime/primitives/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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>,
}
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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 }
Expand Down Expand Up @@ -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)
}
}

Expand Down
14 changes: 7 additions & 7 deletions substrate/runtime/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]>;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -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)
}
}

Expand All @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions substrate/runtime/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
}
}

Expand Down
Loading

0 comments on commit 9b438dc

Please sign in to comment.