merkle_tree: remove some now-redundant code from block.rs

This commit is contained in:
Andrew Poelstra 2024-06-16 15:11:52 +00:00
parent 48ad5e4789
commit 90b6d6748b
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 5 additions and 13 deletions

View File

@ -18,7 +18,7 @@ use crate::blockdata::block::{self, Block};
use crate::blockdata::transaction::{Transaction, Txid}; use crate::blockdata::transaction::{Transaction, Txid};
use crate::blockdata::weight::Weight; use crate::blockdata::weight::Weight;
use crate::consensus::encode::{self, Decodable, Encodable, MAX_VEC_SIZE}; use crate::consensus::encode::{self, Decodable, Encodable, MAX_VEC_SIZE};
use crate::merkle_tree::TxMerkleNode; use crate::merkle_tree::{MerkleNode as _, TxMerkleNode};
use crate::prelude::*; use crate::prelude::*;
/// Data structure that represents a block header paired to a partial merkle tree. /// Data structure that represents a block header paired to a partial merkle tree.
@ -273,7 +273,7 @@ impl PartialMerkleTree {
if hash_used != self.hashes.len() as u32 { if hash_used != self.hashes.len() as u32 {
return Err(NotAllHashesConsumed); return Err(NotAllHashesConsumed);
} }
Ok(TxMerkleNode::from_byte_array(hash_merkle_root.to_byte_array())) Ok(hash_merkle_root)
} }
/// Calculates the height of the tree. /// Calculates the height of the tree.
@ -307,7 +307,7 @@ impl PartialMerkleTree {
left left
}; };
// Combine subhashes // Combine subhashes
PartialMerkleTree::parent_hash(left, right) left.combine(&right)
} }
} }
@ -394,17 +394,9 @@ impl PartialMerkleTree {
right = left; right = left;
} }
// and combine them before returning // and combine them before returning
Ok(PartialMerkleTree::parent_hash(left, right)) Ok(left.combine(&right))
} }
} }
/// Helper method to produce SHA256D(left + right)
fn parent_hash(left: TxMerkleNode, right: TxMerkleNode) -> TxMerkleNode {
let mut encoder = TxMerkleNode::engine();
left.consensus_encode(&mut encoder).expect("engines don't error");
right.consensus_encode(&mut encoder).expect("engines don't error");
TxMerkleNode::from_engine(encoder)
}
} }
impl Encodable for PartialMerkleTree { impl Encodable for PartialMerkleTree {
@ -515,7 +507,7 @@ impl std::error::Error for MerkleBlockError {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[cfg(feature = "rand-std")] #[cfg(feature = "rand-std")]
use {crate::merkle_tree::MerkleNode as _, core::cmp, secp256k1::rand::prelude::*}; use {core::cmp, secp256k1::rand::prelude::*};
use super::*; use super::*;
use crate::consensus::encode; use crate::consensus::encode;