Rename util::hash module

The `util::hash` module provides two functions for computing a merkle
root from a list/iterator of hashes.

Rename the module to `merkle_root` and move it to the crate root,
deprecate the original functions.

Done as part of flattening the `util` module.
This commit is contained in:
Tobin C. Harding 2022-10-21 09:30:20 +11:00
parent bbf89dd5a4
commit 22dd904735
5 changed files with 33 additions and 8 deletions

View File

@ -15,7 +15,7 @@ use core::fmt;
use crate::util;
use crate::util::Error::{BlockBadTarget, BlockBadProofOfWork};
use crate::util::hash::bitcoin_merkle_root;
use crate::merkle_tree::bitcoin_merkle_root;
use crate::hashes::{Hash, HashEngine};
use crate::hash_types::{Wtxid, BlockHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment};
use crate::consensus::{encode, Encodable, Decodable};

View File

@ -92,6 +92,7 @@ pub mod blockdata;
pub mod consensus;
pub mod error;
pub mod hash_types;
pub mod merkle_tree;
pub mod policy;
pub mod pow;
pub mod sighash;

View File

@ -1,10 +1,7 @@
// Written in 2014 by Andrew Poelstra <apoelstra@wpsoftware.net>
// SPDX-License-Identifier: CC0-1.0
//! Bitcoin hash functions.
//!
//! This module provides utility functions related to hashing data, including
//! merkleization.
//! Bitcoin merkle tree functions.
//!
use core::iter;
@ -108,7 +105,7 @@ mod tests {
#[test]
fn both_merkle_root_functions_return_the_same_result() {
// testnet block 000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b
let segwit_block = include_bytes!("../../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw");
let segwit_block = include_bytes!("../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw");
let block: Block = deserialize(&segwit_block[..]).expect("Failed to deserialize block");
assert!(block.check_merkle_root()); // Sanity check.

View File

@ -528,7 +528,7 @@ mod tests {
use secp256k1::rand::prelude::*;
use crate::consensus::encode::{deserialize, serialize};
use crate::util::hash::bitcoin_merkle_root;
use crate::merkle_tree::bitcoin_merkle_root;
use crate::util::merkleblock::{MerkleBlock, PartialMerkleTree};
use crate::Block;

View File

@ -11,7 +11,6 @@ pub mod ecdsa;
pub mod schnorr;
pub mod amount;
pub mod base58;
pub mod hash;
pub mod merkleblock;
pub mod psbt;
pub mod taproot;
@ -95,6 +94,34 @@ pub use crate::bip32;
#[deprecated(since = "0.30.0", note = "Please use crate::bip158")]
pub use crate::bip158;
/// Functions from the `hash` module were renamed and moved to `../merkle_tree`.
pub mod hash {
use crate::consensus::encode::Encodable;
use crate::hashes::Hash;
use crate::io;
/// Calculates the merkle root of a list of *hashes*, inline (in place) in `hashes`.
#[deprecated(since = "0.30.0", note = "Please use crate::merkle_tree::bitcoin_merkle_root_inline")]
pub fn bitcoin_merkle_root_inline<T>(hashes: &mut [T]) -> Option<T>
where
T: Hash + Encodable,
<T as Hash>::Engine: io::Write,
{
crate::merkle_tree::bitcoin_merkle_root_inline(hashes)
}
/// Calculates the merkle root of an iterator of *hashes*.
#[deprecated(since = "0.30.0", note = "Please use crate::merkle_tree::bitcoin_merkle_root")]
pub fn bitcoin_merkle_root<T, I>(hashes: I) -> Option<T>
where
T: Hash + Encodable,
<T as Hash>::Engine: io::Write,
I: Iterator<Item=T>,
{
crate::merkle_tree::bitcoin_merkle_root(hashes)
}
}
/// The `misc` module was moved and re-named to `sign_message`.
pub mod misc {
use crate::prelude::*;