/// Calculates the merkle root of a list of txids hashes directly
Calculates the merkle root of a list of txids hashes directly
Calculates the merkle root of a list of txids hashes directly
pub fn bitcoin_merkle_root(data: Vec<sha256d::Hash>) -> sha256d::Hash {
    // Base case
    if data.len() < 1 {
        return Default::default();
    }
    if data.len() < 2 {
        return data[0];
    }
    // Recursion
    let mut next = vec![];
    for idx in 0..((data.len() + 1) / 2) {
        let idx1 = 2 * idx;
        let idx2 = min(idx1 + 1, data.len() - 1);
        let mut encoder = sha256d::Hash::engine();
        data[idx1].consensus_encode(&mut encoder).unwrap();
        data[idx2].consensus_encode(&mut encoder).unwrap();
        next.push(sha256d::Hash::from_engine(encoder));
    }
    bitcoin_merkle_root(next)
}
pub fn bitcoin_merkle_root ( data : Vec < sha256d :: Hash > ) -> sha256d :: Hash { // Base case if data . len ( ) < 1 { return Default :: default ( ) ; } if data . len ( ) < 2 { return data [ 0 ] ; } // Recursion let mut next = vec ! [ ] ; for idx in 0 .. ( ( data . len ( ) + 1 ) / 2 ) { let idx1 = 2 * idx ; let idx2 = min ( idx1 + 1 , data . len ( ) - 1 ) ; let mut encoder = sha256d :: Hash :: engine ( ) ; data [ idx1 ] . consensus_encode ( & mut encoder ) . unwrap ( ) ; data [ idx2 ] . consensus_encode ( & mut encoder ) . unwrap ( ) ; next . push ( sha256d :: Hash :: from_engine ( encoder ) ) ; } bitcoin_merkle_root ( next ) }
Calculates the merkle root of a list of txids hashes directly
Calculates the merkle root of a list of txids hashes directly
data
Vec<sha256d::Hash>