Merge pull request #90 from TheBlueMatt/merkle-expose
Expose merkleroot(Vec<Sha256dHash>) publicly
This commit is contained in:
commit
eebd185a01
|
@ -419,9 +419,8 @@ pub trait MerkleRoot {
|
|||
fn merkle_root(&self) -> Sha256dHash;
|
||||
}
|
||||
|
||||
impl<'a, T: BitcoinHash> MerkleRoot for &'a [T] {
|
||||
fn merkle_root(&self) -> Sha256dHash {
|
||||
fn merkle_root(data: Vec<Sha256dHash>) -> Sha256dHash {
|
||||
/// Calculates the merkle root of a list of txids hashes directly
|
||||
pub fn bitcoin_merkle_root(data: Vec<Sha256dHash>) -> Sha256dHash {
|
||||
// Base case
|
||||
if data.len() < 1 {
|
||||
return Default::default();
|
||||
|
@ -439,9 +438,12 @@ impl<'a, T: BitcoinHash> MerkleRoot for &'a [T] {
|
|||
data[idx2].consensus_encode(&mut encoder).unwrap();
|
||||
next.push(encoder.into_inner().into_inner().bitcoin_hash());
|
||||
}
|
||||
merkle_root(next)
|
||||
}
|
||||
merkle_root(self.iter().map(|obj| obj.bitcoin_hash()).collect())
|
||||
bitcoin_merkle_root(next)
|
||||
}
|
||||
|
||||
impl<'a, T: BitcoinHash> MerkleRoot for &'a [T] {
|
||||
fn merkle_root(&self) -> Sha256dHash {
|
||||
bitcoin_merkle_root(self.iter().map(|obj| obj.bitcoin_hash()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue