diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index 9ab112a8..24b70a52 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -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}; diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs index a7dfc845..1f42d543 100644 --- a/bitcoin/src/lib.rs +++ b/bitcoin/src/lib.rs @@ -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; diff --git a/bitcoin/src/util/hash.rs b/bitcoin/src/merkle_tree.rs similarity index 93% rename from bitcoin/src/util/hash.rs rename to bitcoin/src/merkle_tree.rs index 79f75c77..c6fc3818 100644 --- a/bitcoin/src/util/hash.rs +++ b/bitcoin/src/merkle_tree.rs @@ -1,10 +1,7 @@ // Written in 2014 by Andrew Poelstra // 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. diff --git a/bitcoin/src/util/merkleblock.rs b/bitcoin/src/util/merkleblock.rs index b1f9fd36..25ac7532 100644 --- a/bitcoin/src/util/merkleblock.rs +++ b/bitcoin/src/util/merkleblock.rs @@ -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; diff --git a/bitcoin/src/util/mod.rs b/bitcoin/src/util/mod.rs index 3f96ab3e..50187490 100644 --- a/bitcoin/src/util/mod.rs +++ b/bitcoin/src/util/mod.rs @@ -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(hashes: &mut [T]) -> Option + where + T: Hash + Encodable, + ::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(hashes: I) -> Option + where + T: Hash + Encodable, + ::Engine: io::Write, + I: Iterator, + { + crate::merkle_tree::bitcoin_merkle_root(hashes) + } +} + /// The `misc` module was moved and re-named to `sign_message`. pub mod misc { use crate::prelude::*;