Hashable::sha3 -> fn keccak for ethcore
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
//! View onto block rlp.
|
||||
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
@@ -44,7 +45,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Block header hash.
|
||||
pub fn hash(&self) -> H256 {
|
||||
self.sha3()
|
||||
self.header_view().hash()
|
||||
}
|
||||
|
||||
/// Return reference to underlaying rlp.
|
||||
@@ -75,7 +76,7 @@ impl<'a> BlockView<'a> {
|
||||
/// Return List of transactions with additional localization info.
|
||||
pub fn localized_transactions(&self) -> Vec<LocalizedTransaction> {
|
||||
let header = self.header_view();
|
||||
let block_hash = header.sha3();
|
||||
let block_hash = header.hash();
|
||||
let block_number = header.number();
|
||||
self.transactions()
|
||||
.into_iter()
|
||||
@@ -101,7 +102,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return transaction hashes.
|
||||
pub fn transaction_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(1).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Returns transaction at given index without deserializing unnecessary data.
|
||||
@@ -112,7 +113,7 @@ impl<'a> BlockView<'a> {
|
||||
/// Returns localized transaction at given index.
|
||||
pub fn localized_transaction_at(&self, index: usize) -> Option<LocalizedTransaction> {
|
||||
let header = self.header_view();
|
||||
let block_hash = header.sha3();
|
||||
let block_hash = header.hash();
|
||||
let block_number = header.number();
|
||||
self.transaction_at(index).map(|t| LocalizedTransaction {
|
||||
signed: t,
|
||||
@@ -140,7 +141,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(2).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(2).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Return nth uncle.
|
||||
@@ -154,12 +155,6 @@ impl<'a> BlockView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Hashable for BlockView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.header_view().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
//! View onto block body rlp.
|
||||
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
@@ -78,7 +79,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return transaction hashes.
|
||||
pub fn transaction_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(0).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(0).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Returns transaction at given index without deserializing unnecessary data.
|
||||
@@ -114,7 +115,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(1).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Return nth uncle.
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
//! View onto block header rlp
|
||||
|
||||
use util::{U256, Bytes, Hashable, H256, Address, H2048};
|
||||
use hash::keccak;
|
||||
use util::{U256, Bytes, H256, Address, H2048};
|
||||
use rlp::Rlp;
|
||||
use header::BlockNumber;
|
||||
|
||||
@@ -41,7 +42,9 @@ impl<'a> HeaderView<'a> {
|
||||
}
|
||||
|
||||
/// Returns header hash.
|
||||
pub fn hash(&self) -> H256 { self.sha3() }
|
||||
pub fn hash(&self) -> H256 {
|
||||
keccak(self.rlp.as_raw())
|
||||
}
|
||||
|
||||
/// Returns raw rlp.
|
||||
pub fn rlp(&self) -> &Rlp<'a> { &self.rlp }
|
||||
@@ -95,12 +98,6 @@ impl<'a> HeaderView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Hashable for HeaderView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.rlp.as_raw().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! View onto transaction rlp
|
||||
use util::{U256, Bytes, Hashable, H256};
|
||||
use util::{U256, Bytes, H256};
|
||||
use hash::keccak;
|
||||
use rlp::Rlp;
|
||||
|
||||
/// View onto transaction rlp.
|
||||
@@ -43,6 +44,11 @@ impl<'a> TransactionView<'a> {
|
||||
&self.rlp
|
||||
}
|
||||
|
||||
/// Returns transaction hash.
|
||||
pub fn hash(&self) -> H256 {
|
||||
keccak(self.rlp.as_raw())
|
||||
}
|
||||
|
||||
/// Get the nonce field of the transaction.
|
||||
pub fn nonce(&self) -> U256 { self.rlp.val_at(0) }
|
||||
|
||||
@@ -68,12 +74,6 @@ impl<'a> TransactionView<'a> {
|
||||
pub fn s(&self) -> U256 { self.rlp.val_at(8) }
|
||||
}
|
||||
|
||||
impl<'a> Hashable for TransactionView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.rlp.as_raw().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
||||
Reference in New Issue
Block a user