Hashable::sha3 -> fn keccak for ethcore
This commit is contained in:
@@ -511,7 +511,7 @@ impl BlockChain {
|
||||
// we need to insert genesis into the cache
|
||||
let block = BlockView::new(genesis);
|
||||
let header = block.header_view();
|
||||
let hash = block.sha3();
|
||||
let hash = block.hash();
|
||||
|
||||
let details = BlockDetails {
|
||||
number: header.number(),
|
||||
@@ -763,7 +763,7 @@ impl BlockChain {
|
||||
pub fn insert_unordered_block(&self, batch: &mut DBTransaction, bytes: &[u8], receipts: Vec<Receipt>, parent_td: Option<U256>, is_best: bool, is_ancient: bool) -> bool {
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
|
||||
if self.is_known(&hash) {
|
||||
return false;
|
||||
@@ -965,7 +965,7 @@ impl BlockChain {
|
||||
// create views onto rlp
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
|
||||
if self.is_known_child(&header.parent_hash(), &hash) {
|
||||
return ImportRoute::none();
|
||||
@@ -1004,7 +1004,7 @@ impl BlockChain {
|
||||
|
||||
/// Get inserted block info which is critical to prepare extras updates.
|
||||
fn block_info(&self, header: &HeaderView) -> BlockInfo {
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
let number = header.number();
|
||||
let parent_hash = header.parent_hash();
|
||||
let parent_details = self.block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash));
|
||||
@@ -1465,9 +1465,9 @@ mod tests {
|
||||
#![cfg_attr(feature="dev", allow(similar_names))]
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::kvdb::KeyValueDB;
|
||||
use util::hash::*;
|
||||
use util::sha3::Hashable;
|
||||
use receipt::Receipt;
|
||||
use blockchain::{BlockProvider, BlockChain, Config, ImportRoute};
|
||||
use tests::helpers::*;
|
||||
@@ -1517,8 +1517,8 @@ mod tests {
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@@ -1548,7 +1548,7 @@ mod tests {
|
||||
let mut canon_chain = ChainGenerator::default();
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@@ -1557,7 +1557,7 @@ mod tests {
|
||||
let mut batch = db.transaction();
|
||||
for _ in 0..10 {
|
||||
let block = canon_chain.generate(&mut finalizer).unwrap();
|
||||
block_hashes.push(BlockView::new(&block).header_view().sha3());
|
||||
block_hashes.push(BlockView::new(&block).header_view().hash());
|
||||
bc.insert_block(&mut batch, &block, vec![]);
|
||||
bc.commit();
|
||||
}
|
||||
@@ -1606,14 +1606,14 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
[&b4b, &b3b, &b2b].iter().map(|b| BlockView::new(b).header()).collect::<Vec<_>>(),
|
||||
bc.find_uncle_headers(&BlockView::new(&b4a).header_view().sha3(), 3).unwrap()
|
||||
bc.find_uncle_headers(&BlockView::new(&b4a).header_view().hash(), 3).unwrap()
|
||||
);
|
||||
|
||||
// TODO: insert block that already includes one of them as an uncle to check it's not allowed.
|
||||
}
|
||||
|
||||
fn secret() -> Secret {
|
||||
"".sha3().into()
|
||||
keccak("").into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1645,8 +1645,8 @@ mod tests {
|
||||
let b2 = fork_chain
|
||||
.generate(&mut fork_finalizer).unwrap();
|
||||
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().sha3();
|
||||
let b2_hash = BlockView::new(&b2).header_view().sha3();
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().hash();
|
||||
let b2_hash = BlockView::new(&b2).header_view().hash();
|
||||
|
||||
let t1_hash = t1.hash();
|
||||
|
||||
@@ -1729,9 +1729,9 @@ mod tests {
|
||||
.with_transaction(t3.clone())
|
||||
.generate(&mut fork_finalizer).unwrap();
|
||||
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().sha3();
|
||||
let b1b_hash = BlockView::new(&b1b).header_view().sha3();
|
||||
let b2_hash = BlockView::new(&b2).header_view().sha3();
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().hash();
|
||||
let b1b_hash = BlockView::new(&b1b).header_view().hash();
|
||||
let b2_hash = BlockView::new(&b2).header_view().hash();
|
||||
|
||||
let t1_hash = t1.hash();
|
||||
let t2_hash = t2.hash();
|
||||
@@ -1789,11 +1789,11 @@ mod tests {
|
||||
let b3b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||
let b3a = canon_chain.generate(&mut finalizer).unwrap();
|
||||
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let b1_hash= BlockView::new(&b1).header_view().sha3();
|
||||
let b2_hash= BlockView::new(&b2).header_view().sha3();
|
||||
let b3a_hash= BlockView::new(&b3a).header_view().sha3();
|
||||
let b3b_hash= BlockView::new(&b3b).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let b1_hash= BlockView::new(&b1).header_view().hash();
|
||||
let b2_hash= BlockView::new(&b2).header_view().hash();
|
||||
let b3a_hash= BlockView::new(&b3a).header_view().hash();
|
||||
let b3b_hash= BlockView::new(&b3b).header_view().hash();
|
||||
|
||||
// b3a is a part of canon chain, whereas b3b is part of sidechain
|
||||
let best_block_hash = b3a_hash.clone();
|
||||
@@ -1909,8 +1909,8 @@ mod tests {
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
let db = new_db();
|
||||
|
||||
{
|
||||
@@ -2225,9 +2225,9 @@ mod tests {
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let second = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let second_hash = BlockView::new(&second).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
let second_hash = BlockView::new(&second).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@@ -2265,7 +2265,7 @@ mod tests {
|
||||
// create a longer fork
|
||||
for i in 0..5 {
|
||||
let canon_block = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let hash = BlockView::new(&canon_block).header_view().sha3();
|
||||
let hash = BlockView::new(&canon_block).header_view().hash();
|
||||
|
||||
bc.insert_block(&mut batch, &canon_block, vec![]);
|
||||
bc.insert_epoch_transition(&mut batch, i, EpochTransition {
|
||||
@@ -2278,7 +2278,7 @@ mod tests {
|
||||
|
||||
assert_eq!(bc.best_block_number(), 5);
|
||||
|
||||
let hash = BlockView::new(&uncle).header_view().sha3();
|
||||
let hash = BlockView::new(&uncle).header_view().hash();
|
||||
bc.insert_block(&mut batch, &uncle, vec![]);
|
||||
bc.insert_epoch_transition(&mut batch, 999, EpochTransition {
|
||||
block_hash: hash,
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
use util::hash::H256;
|
||||
use util::bytes::Bytes;
|
||||
use util::sha3::Hashable;
|
||||
use views::BlockView;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@@ -46,7 +45,7 @@ impl<'a, I> Iterator for Complete<'a, I> where I: Iterator, <I as Iterator>::Ite
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next().map(|item| {
|
||||
let rlp = item.complete(self.finalizer.parent_hash.clone());
|
||||
self.finalizer.parent_hash = BlockView::new(&rlp).header_view().sha3();
|
||||
self.finalizer.parent_hash = BlockView::new(&rlp).header_view().hash();
|
||||
rlp
|
||||
})
|
||||
}
|
||||
|
||||
@@ -111,7 +111,6 @@ impl Iterator for ChainGenerator {
|
||||
|
||||
mod tests {
|
||||
use util::hash::{H256, H2048};
|
||||
use util::sha3::Hashable;
|
||||
use views::BlockView;
|
||||
use blockchain::generator::{ChainIterator, ChainGenerator, BlockFinalizer};
|
||||
|
||||
@@ -129,7 +128,7 @@ mod tests {
|
||||
let b1_rlp = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let b1 = BlockView::new(&b1_rlp);
|
||||
|
||||
assert_eq!(b1.header_view().parent_hash(), genesis.header_view().sha3());
|
||||
assert_eq!(b1.header_view().parent_hash(), genesis.header_view().hash());
|
||||
assert_eq!(b1.header_view().number(), 1);
|
||||
|
||||
let mut fork_chain = canon_chain.fork(1);
|
||||
@@ -137,13 +136,13 @@ mod tests {
|
||||
let b2_rlp_fork = fork_chain.generate(&mut finalizer.fork()).unwrap();
|
||||
let b2_fork = BlockView::new(&b2_rlp_fork);
|
||||
|
||||
assert_eq!(b2_fork.header_view().parent_hash(), b1.header_view().sha3());
|
||||
assert_eq!(b2_fork.header_view().parent_hash(), b1.header_view().hash());
|
||||
assert_eq!(b2_fork.header_view().number(), 2);
|
||||
|
||||
let b2_rlp = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let b2 = BlockView::new(&b2_rlp);
|
||||
|
||||
assert_eq!(b2.header_view().parent_hash(), b1.header_view().sha3());
|
||||
assert_eq!(b2.header_view().parent_hash(), b1.header_view().hash());
|
||||
assert_eq!(b2.header_view().number(), 2);
|
||||
assert!(b2.header_view().difficulty() > b2_fork.header_view().difficulty());
|
||||
}
|
||||
@@ -163,7 +162,7 @@ mod tests {
|
||||
assert_eq!(block0.header_view().parent_hash(), H256::default());
|
||||
|
||||
assert_eq!(block1.header_view().number(), 1);
|
||||
assert_eq!(block1.header_view().parent_hash(), block0.header_view().sha3());
|
||||
assert_eq!(block1.header_view().parent_hash(), block0.header_view().hash());
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user