fixed grumbles

This commit is contained in:
Svyatoslav Nikolsky 2017-08-28 09:10:49 +03:00
parent c10214c5ed
commit 1f1e274dd1
2 changed files with 17 additions and 12 deletions

View File

@ -34,12 +34,14 @@ impl Block {
/// Returns block's witness merkle root.
pub fn witness_merkle_root(&self) -> H256 {
let hashes = self.transactions.iter()
.enumerate()
.map(|(i, tx)| match i {
0 => H256::from(0),
_ => tx.witness_hash(),
}).collect::<Vec<H256>>();
let hashes = match self.transactions.split_first() {
None => vec![],
Some((_, rest)) => {
let mut hashes = vec![H256::from(0)];
hashes.extend(rest.iter().map(Transaction::witness_hash));
hashes
},
};
merkle_root(&hashes)
}

View File

@ -66,12 +66,15 @@ impl IndexedBlock {
}
pub fn witness_merkle_root(&self) -> H256 {
merkle_root(&self.transactions.iter()
.enumerate()
.map(|(i, tx)| match i {
0 => H256::from(0),
_ => tx.raw.witness_hash(),
}).collect::<Vec<H256>>())
let hashes = match self.transactions.split_first() {
None => vec![],
Some((_, rest)) => {
let mut hashes = vec![H256::from(0)];
hashes.extend(rest.iter().map(|tx| tx.raw.witness_hash()));
hashes
},
};
merkle_root(&hashes)
}
pub fn is_final(&self, height: u32) -> bool {