Merge rust-bitcoin/rust-bitcoin#3400: Move `merkle_tree` hash types to `primitives`

9ded58fc99 Move merkle_tree hash types to primitives (Tobin C. Harding)

Pull request description:

  In preparation for moving the `block::Header` struct over to `primitives` move the `merkle_tree` hash types.

ACKs for top commit:
  apoelstra:
    ACK 9ded58fc99 successfully ran local tests

Tree-SHA512: 98017cf0403871f01a6efeda22e8f319cc8104b9bc2f3a9bae2d6a31f6df8172307466c6486a9259204166933137fa03e565e08a0c156c278cfeb72cdae09b89
This commit is contained in:
merge-script 2024-09-30 18:29:56 +00:00
commit 08eaab2ecf
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 16 additions and 8 deletions

View File

@ -26,13 +26,8 @@ use crate::{Txid, Wtxid};
#[rustfmt::skip] #[rustfmt::skip]
#[doc(inline)] #[doc(inline)]
pub use self::block::{MerkleBlock, MerkleBlockError, PartialMerkleTree}; pub use self::block::{MerkleBlock, MerkleBlockError, PartialMerkleTree};
pub use primitives::merkle_tree::*;
hashes::hash_newtype! {
/// A hash of the Merkle tree branch or root for transactions.
pub struct TxMerkleNode(sha256d::Hash);
/// A hash corresponding to the Merkle tree root for witness data.
pub struct WitnessMerkleNode(sha256d::Hash);
}
impl_hashencode!(TxMerkleNode); impl_hashencode!(TxMerkleNode);
impl_hashencode!(WitnessMerkleNode); impl_hashencode!(WitnessMerkleNode);
@ -104,7 +99,7 @@ impl MerkleNode for TxMerkleNode {
let mut encoder = sha256d::Hash::engine(); let mut encoder = sha256d::Hash::engine();
encoder.input(self.as_byte_array()); encoder.input(self.as_byte_array());
encoder.input(other.as_byte_array()); encoder.input(other.as_byte_array());
Self(sha256d::Hash::from_engine(encoder)) Self::from_byte_array(sha256d::Hash::from_engine(encoder).to_byte_array())
} }
} }
impl MerkleNode for WitnessMerkleNode { impl MerkleNode for WitnessMerkleNode {
@ -115,7 +110,7 @@ impl MerkleNode for WitnessMerkleNode {
let mut encoder = sha256d::Hash::engine(); let mut encoder = sha256d::Hash::engine();
encoder.input(self.as_byte_array()); encoder.input(self.as_byte_array());
encoder.input(other.as_byte_array()); encoder.input(other.as_byte_array());
Self(sha256d::Hash::from_engine(encoder)) Self::from_byte_array(sha256d::Hash::from_engine(encoder).to_byte_array())
} }
} }

View File

@ -32,6 +32,7 @@ extern crate serde;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub mod locktime; pub mod locktime;
pub mod opcodes; pub mod opcodes;
pub mod merkle_tree;
pub mod pow; pub mod pow;
pub mod sequence; pub mod sequence;
pub mod transaction; pub mod transaction;

View File

@ -0,0 +1,12 @@
// SPDX-License-Identifier: CC0-1.0
//! Bitcoin Merkle tree functions.
use hashes::sha256d;
hashes::hash_newtype! {
/// A hash of the Merkle tree branch or root for transactions.
pub struct TxMerkleNode(sha256d::Hash);
/// A hash corresponding to the Merkle tree root for witness data.
pub struct WitnessMerkleNode(sha256d::Hash);
}