removed redundant FixedHash trait, fixes #4029 (#4866)

This commit is contained in:
Marek Kotewicz 2017-03-11 19:58:15 +01:00 committed by Nikolay Volf
parent 5d5e45ec0d
commit 3fe3353696
45 changed files with 155 additions and 173 deletions

View File

@ -373,7 +373,7 @@ pub fn write_announcement(announcement: &Announcement) -> Vec<u8> {
mod tests {
use super::*;
use super::super::request_credits::FlowParams;
use util::{U256, H256, FixedHash};
use util::{U256, H256};
use rlp::{RlpStream, Stream ,UntrustedRlp, View};
#[test]

View File

@ -267,7 +267,7 @@ impl TransactionProof {
#[cfg(test)]
mod tests {
use super::*;
use util::{MemoryDB, Address, H256, FixedHash};
use util::{MemoryDB, Address, H256};
use util::trie::{Trie, TrieMut, SecTrieDB, SecTrieDBMut};
use util::trie::recorder::Recorder;

View File

@ -23,7 +23,7 @@ use self::stores::{AddressBook, DappsSettingsStore, NewDappsPolicy};
use std::fmt;
use std::collections::{HashMap, HashSet};
use std::time::{Instant, Duration};
use util::{FixedHash, RwLock};
use util::{RwLock};
use ethstore::{SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
random_string, SecretVaultRef, StoreAccountRef};
use ethstore::dir::MemoryDirectory;

View File

@ -16,7 +16,7 @@
//! Evm input params.
use util::{Address, Bytes, Uint, U256};
use util::hash::{H256, FixedHash};
use util::hash::{H256};
use util::sha3::{Hashable, SHA3_EMPTY};
use ethjson;
use types::executed::CallType;

View File

@ -21,7 +21,7 @@ use std::sync::Arc;
use std::collections::HashSet;
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, Decoder, DecoderError, View, Stream};
use util::{Bytes, Address, Uint, FixedHash, Hashable, U256, H256, ordered_trie_root, SHA3_NULL_RLP};
use util::{Bytes, Address, Uint, Hashable, U256, H256, ordered_trie_root, SHA3_NULL_RLP};
use util::error::{Mismatch, OutOfBounds};
use basic_types::{LogBloom, Seal};
@ -618,7 +618,6 @@ mod tests {
use state_db::StateDB;
use views::BlockView;
use util::Address;
use util::hash::FixedHash;
use std::sync::Arc;
use transaction::SignedTransaction;

View File

@ -18,7 +18,7 @@ use crypto::sha2::Sha256 as Sha256Digest;
use crypto::ripemd160::Ripemd160 as Ripemd160Digest;
use crypto::digest::Digest;
use std::cmp::min;
use util::{U256, H256, Hashable, FixedHash, BytesRef};
use util::{U256, H256, Hashable, BytesRef};
use ethkey::{Signature, recover as ec_recover};
use ethjson;

View File

@ -25,7 +25,7 @@ use time::precise_time_ns;
// util
use util::{Bytes, PerfTimer, Itertools, Mutex, RwLock, MutexGuard, Hashable};
use util::{journaldb, DBValue, TrieFactory, Trie};
use util::{U256, H256, Address, H2048, Uint, FixedHash};
use util::{U256, H256, Address, H2048, Uint};
use util::trie::TrieSpec;
use util::kvdb::*;

View File

@ -5,7 +5,7 @@ use std::string::String;
use std::result::Result;
use std::fmt;
use {util, ethabi};
use util::{FixedHash, Uint};
use util::{Uint};
pub struct Registry {
contract: ethabi::Contract,

View File

@ -17,7 +17,7 @@
//! Tendermint specific parameters.
use ethjson;
use util::{U256, Uint, Address, FixedHash};
use util::{U256, Uint, Address};
use time::Duration;
use super::super::transition::Timeouts;
use super::Step;

View File

@ -92,7 +92,7 @@ mod provider {
use std::result::Result;
use std::fmt;
use {util, ethabi};
use util::{FixedHash, Uint};
use util::{Uint};
pub struct Contract {
contract: ethabi::Contract,

View File

@ -509,7 +509,7 @@ mod tests {
use std::sync::Arc;
use ethkey::{Generator, Random};
use super::*;
use util::{H256, U256, U512, Address, Uint, FixedHash, FromHex, FromStr};
use util::{H256, U256, U512, Address, Uint, FromHex, FromStr};
use util::bytes::BytesRef;
use action_params::{ActionParams, ActionValue};
use env_info::EnvInfo;

View File

@ -20,7 +20,7 @@
use std::collections::HashMap;
use util::Bytes;
use util::{Address, FixedHash, H256};
use util::{Address, H256};
use util::kvdb::Database;
use util::migration::{Batch, Config, Error, Migration, SimpleMigration, Progress};
use util::sha3::Hashable;

View File

@ -24,7 +24,7 @@ use views::HeaderView;
use bloom_journal::Bloom;
use util::migration::{Error, Migration, Progress, Batch, Config};
use util::journaldb;
use util::{H256, FixedHash, Trie};
use util::{H256, Trie};
use util::{Database, DBTransaction};
/// Account bloom upgrade routine. If bloom already present, does nothing.

View File

@ -62,7 +62,7 @@ mod provider {
use std::result::Result;
use std::fmt;
use {util, ethabi};
use util::{FixedHash, Uint};
use util::{Uint};
pub struct Contract {
contract: ethabi::Contract,

View File

@ -25,7 +25,7 @@ use std::sync::{Arc, Weak};
use std::net::{SocketAddr, AddrParseError};
use std::fmt;
use util::{H256, U256, FixedHash, H64, clean_0x};
use util::{H256, U256, H64, clean_0x};
use ethereum::ethash::Ethash;
use ethash::SeedHashCompute;
use util::Mutex;

View File

@ -20,7 +20,7 @@ use account_db::{AccountDB, AccountDBMut};
use basic_account::BasicAccount;
use snapshot::Error;
use util::{U256, FixedHash, H256, Bytes, HashDB, SHA3_EMPTY, SHA3_NULL_RLP};
use util::{U256, H256, Bytes, HashDB, SHA3_EMPTY, SHA3_NULL_RLP};
use util::trie::{TrieDB, Trie};
use rlp::{RlpStream, Stream, UntrustedRlp, View};
@ -179,7 +179,7 @@ mod tests {
use snapshot::tests::helpers::fill_storage;
use util::sha3::{SHA3_EMPTY, SHA3_NULL_RLP};
use util::{Address, FixedHash, H256, HashDB, DBValue};
use util::{Address, H256, HashDB, DBValue};
use rlp::{UntrustedRlp, View};
use std::collections::HashSet;

View File

@ -134,7 +134,7 @@ mod tests {
use super::AbridgedBlock;
use types::transaction::{Action, Transaction};
use util::{Address, H256, FixedHash, U256, Bytes};
use util::{Address, H256, U256, Bytes};
fn encode_block(b: &Block) -> Bytes {
b.rlp_bytes(::basic_types::Seal::With)

View File

@ -32,7 +32,7 @@ use views::BlockView;
use util::{Bytes, Hashable, HashDB, DBValue, snappy, U256, Uint};
use util::Mutex;
use util::hash::{FixedHash, H256};
use util::hash::{H256};
use util::journaldb::{self, Algorithm, JournalDB};
use util::kvdb::Database;
use util::trie::{TrieDB, TrieDBMut, Trie, TrieMut};

View File

@ -22,7 +22,7 @@ use account_db::AccountDBMut;
use rand::Rng;
use util::DBValue;
use util::hash::{FixedHash, H256};
use util::hash::H256;
use util::hashdb::HashDB;
use util::trie::{Alphabet, StandardMap, SecTrieDBMut, TrieMut, ValueMode};
use util::trie::{TrieDB, TrieDBMut, Trie};

View File

@ -96,7 +96,7 @@ fn snap_and_restore() {
fn get_code_from_prev_chunk() {
use std::collections::HashSet;
use rlp::{RlpStream, Stream};
use util::{HashDB, H256, FixedHash, U256, Hashable};
use util::{HashDB, H256, U256, Hashable};
use account_db::{AccountDBMut, AccountDB};

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::{Address, H256, Uint, U256, FixedHash};
use util::{Address, H256, Uint, U256};
use util::sha3::SHA3_NULL_RLP;
use ethjson;
use super::seal::Seal;

View File

@ -940,7 +940,7 @@ mod tests {
use rustc_serialize::hex::FromHex;
use super::*;
use ethkey::Secret;
use util::{U256, H256, FixedHash, Address, Hashable};
use util::{U256, H256, Address, Hashable};
use tests::helpers::*;
use devtools::*;
use env_info::EnvInfo;

View File

@ -454,7 +454,7 @@ impl state::Backend for StateDB {
#[cfg(test)]
mod tests {
use util::{U256, H256, FixedHash, Address, DBTransaction};
use util::{U256, H256, Address, DBTransaction};
use tests::helpers::*;
use state::{Account, Backend};
use util::log::init_log;

View File

@ -113,7 +113,6 @@ impl Filter {
#[cfg(test)]
mod tests {
use util::FixedHash;
use filter::Filter;
use client::BlockId;
use log_entry::LogEntry;

View File

@ -195,7 +195,7 @@ pub mod ecies {
use rcrypto::sha2::Sha256;
use rcrypto::hmac::Hmac;
use rcrypto::mac::Mac;
use bigint::hash::{FixedHash, H128};
use bigint::hash::H128;
use ethkey::{Random, Generator, Public, Secret};
use {Error, ecdh, aes, Keccak256};

View File

@ -18,7 +18,7 @@
use secret::Secret;
use Public;
use bigint::hash::{H256, FixedHash};
use bigint::hash::H256;
pub use self::derivation::Error as DerivationError;
/// Represents label that can be stored as a part of key derivation
@ -212,7 +212,7 @@ mod derivation {
use rcrypto::hmac::Hmac;
use rcrypto::mac::Mac;
use rcrypto::sha2::Sha512;
use bigint::hash::{H512, H256, FixedHash};
use bigint::hash::{H512, H256};
use bigint::prelude::{U256, U512, Uint};
use secp256k1;
use secp256k1::key::{SecretKey, PublicKey};

View File

@ -22,7 +22,7 @@ use std::hash::{Hash, Hasher};
use secp256k1::{Message as SecpMessage, RecoverableSignature, RecoveryId, Error as SecpError};
use secp256k1::key::{SecretKey, PublicKey};
use rustc_serialize::hex::{ToHex, FromHex};
use bigint::hash::{H520, H256, FixedHash};
use bigint::hash::{H520, H256};
use {Secret, Public, SECP256K1, Error, Message, public_to_address, Address};
#[repr(C)]

View File

@ -67,7 +67,7 @@ impl KeyDirectory for MemoryDirectory {
fn unique_repr(&self) -> Result<u64, Error> {
let mut val = 0u64;
let accounts = self.accounts.read();
for acc in accounts.keys() { val = val ^ ::util::FixedHash::low_u64(acc) }
for acc in accounts.keys() { val = val ^ acc.low_u64() }
Ok(val)
}
}

View File

@ -18,7 +18,7 @@
use std::sync::Arc;
use std::collections::HashMap;
use util::{U256, H256, Address, Bytes, FixedHash, trie};
use util::{U256, H256, Address, Bytes, trie};
use ethcore::client::EnvInfo;
use ethcore::evm::{self, Ext, ContractCreateResult, MessageCallResult, Schedule, CallType};

View File

@ -24,7 +24,7 @@ use std::str::FromStr;
use std::time::Duration;
use super::WalletInfo;
use ethkey::{Address, Signature};
use ethcore_bigint::hash::{H256, FixedHash};
use ethcore_bigint::hash::H256;
const LEDGER_VID: u16 = 0x2c97;
const LEDGER_PIDS: [u16; 2] = [0x0000, 0x0001]; // Nano S and Blue

View File

@ -19,7 +19,7 @@
use std::fmt;
use std::str::FromStr;
use semver::{Version};
use util::{H160, FixedHash};
use util::H160;
use util::misc::raw_package_info;
use release_track::ReleaseTrack;

View File

@ -23,7 +23,7 @@ use std::sync::{Arc, Weak};
use futures::{self, future, BoxFuture, Future};
use rlp::{self, UntrustedRlp, View};
use time::get_time;
use util::{H160, H256, Address, FixedHash, U256, H64, Uint};
use util::{H160, H256, Address, U256, H64, Uint};
use util::sha3::Hashable;
use util::Mutex;

View File

@ -38,7 +38,7 @@ use ethcore::transaction::{Action, SignedTransaction, Transaction as EthTransact
use ethsync::LightSync;
use rlp::{UntrustedRlp, View};
use util::sha3::{SHA3_NULL_RLP, SHA3_EMPTY_LIST_RLP};
use util::{RwLock, Mutex, FixedHash, Uint, U256};
use util::{RwLock, Mutex, Uint, U256};
use futures::{future, Future, BoxFuture, IntoFuture};
use futures::sync::oneshot;

View File

@ -17,7 +17,7 @@
//! Test implementation of miner service.
use std::collections::hash_map::Entry;
use util::{Address, H256, Bytes, U256, FixedHash, Uint};
use util::{Address, H256, Bytes, U256, Uint};
use util::standard::*;
use ethcore::error::{Error, CallError};
use ethcore::client::{MiningBlockChainClient, Executed, CallAnalytics};

View File

@ -22,7 +22,7 @@ use rustc_serialize::hex::{FromHex, ToHex};
use time::get_time;
use rlp;
use util::{Uint, U256, Address, H256, FixedHash, Mutex};
use util::{Uint, U256, Address, H256, Mutex};
use ethkey::Secret;
use ethcore::account_provider::AccountProvider;
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId};

View File

@ -28,7 +28,7 @@ use v1::types::ConfirmationResponse;
use v1::tests::helpers::TestMinerService;
use v1::tests::mocked::parity;
use util::{Address, FixedHash, Uint, U256, ToPretty};
use util::{Address, Uint, U256, ToPretty};
use ethkey::Secret;
use ethcore::account_provider::AccountProvider;
use ethcore::client::TestBlockChainClient;

View File

@ -32,7 +32,7 @@ use std::string::String;
use std::result::Result;
use std::fmt;
use {util, ethabi};
use util::{FixedHash, Uint};
use util::Uint;
${convertContract(name, json, prefs)}
`;

View File

@ -2175,7 +2175,7 @@ mod tests {
use tests::snapshot::TestSnapshotService;
use util::{Uint, U256, Address, RwLock};
use util::sha3::Hashable;
use util::hash::{H256, FixedHash};
use util::hash::H256;
use util::bytes::Bytes;
use rlp::{Rlp, RlpStream, UntrustedRlp, View, Stream};
use super::*;

View File

@ -4,7 +4,7 @@ use std::string::String;
use std::result::Result;
use std::fmt;
use ethabi;
use util::{self, FixedHash, Uint};
use util::{self, Uint};
pub struct Operations {
contract: ethabi::Contract,

View File

@ -22,7 +22,7 @@ use target_info::Target;
use util::misc;
use ipc_common_types::{VersionInfo, ReleaseTrack};
use util::path::restrict_permissions_owner;
use util::{Address, H160, H256, FixedHash, Mutex, Bytes};
use util::{Address, H160, H256, Mutex, Bytes};
use ethsync::{SyncProvider};
use ethcore::client::{BlockId, BlockChainClient, ChainNotify};
use hash_fetch::{self as fetch, HashFetch};

View File

@ -28,32 +28,6 @@ use rustc_serialize::hex::{FromHex, FromHexError};
use bigint::{Uint, U256};
use libc::{c_void, memcmp};
/// Trait for a fixed-size byte array to be used as the output of hash functions.
pub trait FixedHash: Sized {
/// Create a new, zero-initialised, instance.
fn new() -> Self;
/// Synonym for `new()`. Prefer to new as it's more readable.
fn zero() -> Self;
/// Create a new, cryptographically random, instance.
fn random() -> Self;
/// Assign self have a cryptographically random value.
fn randomize(&mut self);
/// Get the size of this object in bytes.
fn len() -> usize;
/// Convert a slice of bytes of length `len()` to an instance of this type.
fn from_slice(src: &[u8]) -> Self;
/// Assign self to be of the same value as a slice of bytes of length `len()`.
fn clone_from_slice(&mut self, src: &[u8]) -> usize;
/// Copy the data of this object into some mutable slice of length `len()`.
fn copy_to(&self, dest: &mut [u8]);
/// Returns `true` if all bits set in `b` are also set in `self`.
fn contains<'a>(&'a self, b: &'a Self) -> bool;
/// Returns `true` if no bits are set.
fn is_zero(&self) -> bool;
/// Returns the lowest 8 bytes interpreted as a BigEndian integer.
fn low_u64(&self) -> u64;
}
/// Return `s` without the `0x` at the beginning of it, if any.
pub fn clean_0x(s: &str) -> &str {
if s.starts_with("0x") {
@ -105,57 +79,68 @@ macro_rules! impl_hash {
}
}
impl FixedHash for $from {
fn new() -> $from {
impl $from {
/// Create a new, zero-initialised, instance.
pub fn new() -> $from {
$from([0; $size])
}
fn zero() -> $from {
/// Synonym for `new()`. Prefer to new as it's more readable.
pub fn zero() -> $from {
$from([0; $size])
}
fn random() -> $from {
/// Create a new, cryptographically random, instance.
pub fn random() -> $from {
let mut hash = $from::new();
hash.randomize();
hash
}
fn randomize(&mut self) {
/// Assign self have a cryptographically random value.
pub fn randomize(&mut self) {
let mut rng = OsRng::new().unwrap();
rng.fill_bytes(&mut self.0);
}
fn len() -> usize {
/// Get the size of this object in bytes.
pub fn len() -> usize {
$size
}
#[inline]
fn clone_from_slice(&mut self, src: &[u8]) -> usize {
/// Assign self to be of the same value as a slice of bytes of length `len()`.
pub fn clone_from_slice(&mut self, src: &[u8]) -> usize {
let min = cmp::min($size, src.len());
self.0[..min].copy_from_slice(&src[..min]);
min
}
fn from_slice(src: &[u8]) -> Self {
/// Convert a slice of bytes of length `len()` to an instance of this type.
pub fn from_slice(src: &[u8]) -> Self {
let mut r = Self::new();
r.clone_from_slice(src);
r
}
fn copy_to(&self, dest: &mut[u8]) {
/// Copy the data of this object into some mutable slice of length `len()`.
pub fn copy_to(&self, dest: &mut[u8]) {
let min = cmp::min($size, dest.len());
dest[..min].copy_from_slice(&self.0[..min]);
}
fn contains<'a>(&'a self, b: &'a Self) -> bool {
/// Returns `true` if all bits set in `b` are also set in `self`.
pub fn contains<'a>(&'a self, b: &'a Self) -> bool {
&(b & self) == b
}
fn is_zero(&self) -> bool {
/// Returns `true` if no bits are set.
pub fn is_zero(&self) -> bool {
self.eq(&Self::new())
}
fn low_u64(&self) -> u64 {
/// Returns the lowest 8 bytes interpreted as a BigEndian integer.
pub fn low_u64(&self) -> u64 {
let mut ret = 0u64;
for i in 0..min($size, 8) {
ret |= (self.0[$size - 1 - i] as u64) << (i * 8);

View File

@ -556,7 +556,6 @@ impl Discovery {
mod tests {
use super::*;
use std::net::{SocketAddr};
use util::FixedHash;
use node_table::{Node, NodeId, NodeEndpoint};
use std::str::FromStr;

View File

@ -333,7 +333,7 @@ mod test {
use std::sync::Arc;
use rustc_serialize::hex::FromHex;
use super::*;
use util::hash::{H256, FixedHash};
use util::hash::H256;
use io::*;
use mio::tcp::TcpStream;
use stats::NetworkStats;

View File

@ -18,7 +18,7 @@
use std::mem;
use std::ops::DerefMut;
use {H64, H160, H256, H512, H520, H2048, FixedHash};
use {H64, H160, H256, H512, H520, H2048};
/// Returns log2.
pub fn log2(x: usize) -> u32 {

View File

@ -19,7 +19,7 @@ extern crate sha3 as sha3_ext;
use std::io;
use tiny_keccak::Keccak;
use hash::{H256, FixedHash};
use hash::H256;
use self::sha3_ext::*;
/// Get the SHA3 (i.e. Keccak) hash of the empty bytes string.