Skip to content

Commit

Permalink
Merge 9e924cf into c4d017e
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharding committed Apr 26, 2024
2 parents c4d017e + 9e924cf commit d93a80a
Show file tree
Hide file tree
Showing 29 changed files with 63 additions and 71 deletions.
2 changes: 1 addition & 1 deletion bitcoin/examples/sign-tx-segwit-v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::str::FromStr;

use bitcoin::hashes::Hash;
use bitcoin::hashes::Hash as _;
use bitcoin::locktime::absolute;
use bitcoin::secp256k1::{rand, Message, Secp256k1, SecretKey, Signing};
use bitcoin::sighash::{EcdsaSighashType, SighashCache};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/examples/sign-tx-taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::str::FromStr;

use bitcoin::hashes::Hash;
use bitcoin::hashes::Hash as _;
use bitcoin::key::{Keypair, TapTweak, TweakedKeypair, UntweakedPublicKey};
use bitcoin::locktime::absolute;
use bitcoin::secp256k1::{rand, Message, Secp256k1, SecretKey, Signing, Verification};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use core::marker::PhantomData;
use core::str::FromStr;

use bech32::primitives::hrp::Hrp;
use hashes::{sha256, Hash, HashEngine};
use hashes::{sha256, Hash as _, HashEngine as _};
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};

use crate::blockdata::constants::{
Expand Down
6 changes: 3 additions & 3 deletions bitcoin/src/bip152.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::{convert, fmt, mem};
#[cfg(feature = "std")]
use std::error;

use hashes::{sha256, siphash24, Hash};
use hashes::{sha256, siphash24, Hash as _};
use internals::impl_array_newtype;
use io::{BufRead, Write};

Expand Down Expand Up @@ -468,7 +468,7 @@ mod test {
{
// test serialization
let raw: Vec<u8> = serialize(&BlockTransactionsRequest {
block_hash: Hash::all_zeros(),
block_hash: BlockHash::all_zeros(),
indexes: testcase.1,
});
let mut expected_raw: Vec<u8> = [0u8; 32].to_vec();
Expand All @@ -491,7 +491,7 @@ mod test {
#[should_panic] // 'attempt to add with overflow' in consensus_encode()
fn test_getblocktx_panic_when_encoding_u64_max() {
serialize(&BlockTransactionsRequest {
block_hash: Hash::all_zeros(),
block_hash: BlockHash::all_zeros(),
indexes: vec![u64::MAX],
});
}
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/bip158.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
use core::cmp::{self, Ordering};
use core::fmt::{self, Display, Formatter};

use hashes::{sha256d, siphash24, Hash};
use hashes::{sha256d, siphash24, Hash as _};
use internals::write_err;
use io::{BufRead, Write};

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::ops::Index;
use core::str::FromStr;
use core::{fmt, slice};

use hashes::{hash160, hash_newtype, sha512, Hash, HashEngine, Hmac, HmacEngine};
use hashes::{hash160, hash_newtype, sha512, Hash as _, HashEngine as _, Hmac, HmacEngine};
use internals::{impl_array_newtype, write_err};
use io::Write;
use secp256k1::{Secp256k1, XOnlyPublicKey};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use core::fmt;

use hashes::{sha256d, Hash, HashEngine};
use hashes::{sha256d, Hash as _, HashEngine as _};
use io::{BufRead, Write};

use super::Weight;
Expand Down
21 changes: 11 additions & 10 deletions bitcoin/src/blockdata/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! single transaction.
//!

use hashes::{sha256d, Hash};
use hashes::{sha256d, Hash as _};
use hex_lit::hex;
use internals::impl_array_newtype;

Expand All @@ -21,7 +21,7 @@ use crate::consensus::Params;
use crate::internal_macros::impl_bytes_newtype;
use crate::network::Network;
use crate::pow::CompactTarget;
use crate::Amount;
use crate::{Amount, BlockHash};

/// How many seconds between blocks we expect on average.
pub const TARGET_BLOCK_SPACING: u32 = 600;
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
Network::Bitcoin => Block {
header: block::Header {
version: block::Version::ONE,
prev_blockhash: Hash::all_zeros(),
prev_blockhash: BlockHash::all_zeros(),
merkle_root,
time: 1231006505,
bits: CompactTarget::from_consensus(0x1d00ffff),
Expand All @@ -104,7 +104,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
Network::Testnet => Block {
header: block::Header {
version: block::Version::ONE,
prev_blockhash: Hash::all_zeros(),
prev_blockhash: BlockHash::all_zeros(),
merkle_root,
time: 1296688602,
bits: CompactTarget::from_consensus(0x1d00ffff),
Expand All @@ -115,7 +115,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
Network::Signet => Block {
header: block::Header {
version: block::Version::ONE,
prev_blockhash: Hash::all_zeros(),
prev_blockhash: BlockHash::all_zeros(),
merkle_root,
time: 1598918400,
bits: CompactTarget::from_consensus(0x1e0377ae),
Expand All @@ -126,7 +126,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
Network::Regtest => Block {
header: block::Header {
version: block::Version::ONE,
prev_blockhash: Hash::all_zeros(),
prev_blockhash: BlockHash::all_zeros(),
merkle_root,
time: 1296688602,
bits: CompactTarget::from_consensus(0x207fffff),
Expand Down Expand Up @@ -200,14 +200,15 @@ mod test {
use super::*;
use crate::consensus::encode::serialize;
use crate::consensus::params;
use crate::Txid;

#[test]
fn bitcoin_genesis_first_transaction() {
let gen = bitcoin_genesis_tx();

assert_eq!(gen.version, transaction::Version::ONE);
assert_eq!(gen.input.len(), 1);
assert_eq!(gen.input[0].previous_output.txid, Hash::all_zeros());
assert_eq!(gen.input[0].previous_output.txid, Txid::all_zeros());
assert_eq!(gen.input[0].previous_output.vout, 0xFFFFFFFF);
assert_eq!(serialize(&gen.input[0].script_sig),
hex!("4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"));
Expand Down Expand Up @@ -242,7 +243,7 @@ mod test {
let gen = genesis_block(&params::MAINNET);

assert_eq!(gen.header.version, block::Version::ONE);
assert_eq!(gen.header.prev_blockhash, Hash::all_zeros());
assert_eq!(gen.header.prev_blockhash, BlockHash::all_zeros());
assert_eq!(
gen.header.merkle_root.to_string(),
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
Expand All @@ -261,7 +262,7 @@ mod test {
fn testnet_genesis_full_block() {
let gen = genesis_block(&params::TESTNET);
assert_eq!(gen.header.version, block::Version::ONE);
assert_eq!(gen.header.prev_blockhash, Hash::all_zeros());
assert_eq!(gen.header.prev_blockhash, BlockHash::all_zeros());
assert_eq!(
gen.header.merkle_root.to_string(),
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
Expand All @@ -279,7 +280,7 @@ mod test {
fn signet_genesis_full_block() {
let gen = genesis_block(&params::SIGNET);
assert_eq!(gen.header.version, block::Version::ONE);
assert_eq!(gen.header.prev_blockhash, Hash::all_zeros());
assert_eq!(gen.header.prev_blockhash, BlockHash::all_zeros());
assert_eq!(
gen.header.merkle_root.to_string(),
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/script/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::ops::{
Bound, Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
};

use hashes::Hash;
use hashes::Hash as _;
use secp256k1::{Secp256k1, Verification};

use super::PushBytes;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/script/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use core::str::FromStr;

use hashes::Hash;
use hashes::Hash as _;
use hex_lit::hex;

use super::*;
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/blockdata/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use core::{cmp, fmt, str};

use hashes::{sha256d, Hash};
use hashes::{sha256d, Hash as _};
use internals::write_err;
use io::{BufRead, Write};
use units::parse;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl OutPoint {
///
/// This value is used for coinbase transactions because they don't have any previous outputs.
#[inline]
pub fn null() -> OutPoint { OutPoint { txid: Hash::all_zeros(), vout: u32::MAX } }
pub fn null() -> OutPoint { OutPoint { txid: Txid::all_zeros(), vout: u32::MAX } }

/// Checks if an `OutPoint` is "null".
///
Expand Down
10 changes: 5 additions & 5 deletions bitcoin/src/consensus/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use core::{fmt, mem};

use hashes::{sha256, sha256d, Hash};
use hashes::{sha256, sha256d, Hash as _};
use hex::error::{InvalidCharError, OddLengthStringError};
use internals::write_err;
use io::{BufRead, Cursor, Read, Write};
Expand Down Expand Up @@ -768,7 +768,7 @@ impl Decodable for Box<[u8]> {

/// Does a double-SHA256 on `data` and returns the first 4 bytes.
fn sha2_checksum(data: &[u8]) -> [u8; 4] {
let checksum = <sha256d::Hash as Hash>::hash(data);
let checksum = <sha256d::Hash as hashes::Hash>::hash(data);
[checksum[0], checksum[1], checksum[2], checksum[3]]
}

Expand Down Expand Up @@ -869,7 +869,7 @@ impl Encodable for sha256d::Hash {

impl Decodable for sha256d::Hash {
fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> Result<Self, Error> {
Ok(Self::from_byte_array(<<Self as Hash>::Bytes>::consensus_decode(r)?))
Ok(Self::from_byte_array(<<Self as hashes::Hash>::Bytes>::consensus_decode(r)?))
}
}

Expand All @@ -881,7 +881,7 @@ impl Encodable for sha256::Hash {

impl Decodable for sha256::Hash {
fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> Result<Self, Error> {
Ok(Self::from_byte_array(<<Self as Hash>::Bytes>::consensus_decode(r)?))
Ok(Self::from_byte_array(<<Self as hashes::Hash>::Bytes>::consensus_decode(r)?))
}
}

Expand All @@ -893,7 +893,7 @@ impl Encodable for TapLeafHash {

impl Decodable for TapLeafHash {
fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> Result<Self, Error> {
Ok(Self::from_byte_array(<<Self as Hash>::Bytes>::consensus_decode(r)?))
Ok(Self::from_byte_array(<<Self as hashes::Hash>::Bytes>::consensus_decode(r)?))
}
}

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/crypto/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::fmt::{self, Write as _};
use core::ops;
use core::str::FromStr;

use hashes::{hash160, Hash};
use hashes::{hash160, Hash as _};
use hex::{FromHex, HexToArrayError};
use internals::array_vec::ArrayVec;
use internals::write_err;
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use core::{fmt, str};

use hashes::{hash_newtype, sha256, sha256d, sha256t_hash_newtype, Hash};
use hashes::{hash_newtype, sha256, sha256d, sha256t_hash_newtype, Hash as _};
use internals::write_err;
use io::Write;

Expand Down Expand Up @@ -1450,7 +1450,7 @@ impl<E: std::error::Error + 'static> std::error::Error for SigningDataError<E> {
mod tests {
use std::str::FromStr;

use hashes::HashEngine;
use hashes::HashEngine as _;
use hex::{test_hex_unwrap as hex, FromHex};

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/hash_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use crate::{
#[cfg(test)]
mod tests {
use super::*;
use crate::hashes::Hash;
use crate::hashes::Hash as _;
use crate::{
LegacySighash, PubkeyHash, ScriptHash, SegwitV0Sighash, TapSighash, WPubkeyHash,
WScriptHash, XKeyIdentifier,
Expand Down
6 changes: 3 additions & 3 deletions bitcoin/src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ macro_rules! impl_hashencode {

impl $crate::consensus::Decodable for $hashtype {
fn consensus_decode<R: $crate::io::BufRead + ?Sized>(r: &mut R) -> core::result::Result<Self, $crate::consensus::encode::Error> {
use $crate::hashes::Hash;
use $crate::hashes::Hash as _;
Ok(Self::from_byte_array(<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?))
}
}
Expand All @@ -213,14 +213,14 @@ macro_rules! impl_asref_push_bytes {
$(
impl AsRef<$crate::blockdata::script::PushBytes> for $hashtype {
fn as_ref(&self) -> &$crate::blockdata::script::PushBytes {
use $crate::hashes::Hash;
use $crate::hashes::Hash as _;
self.as_byte_array().into()
}
}

impl From<$hashtype> for $crate::blockdata::script::PushBytesBuf {
fn from(hash: $hashtype) -> Self {
use $crate::hashes::Hash;
use $crate::hashes::Hash as _;
hash.as_byte_array().into()
}
}
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/merkle_tree/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

use core::fmt;

use hashes::Hash;
use hashes::Hash as _;
use io::{BufRead, Write};

use self::MerkleBlockError::*;
Expand Down
19 changes: 9 additions & 10 deletions bitcoin/src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! ```
//! # use bitcoin::{merkle_tree, Txid};
//! # use bitcoin::hashes::Hash;
//! # use bitcoin::hashes::Hash as _;
//! # let tx1 = Txid::all_zeros(); // Dummy hash values.
//! # let tx2 = Txid::all_zeros();
//! let tx_hashes = vec![tx1, tx2]; // All the hashes we wish to merkelize.
Expand All @@ -18,7 +18,6 @@ mod block;
use core::cmp::min;
use core::iter;

use hashes::Hash;
use io::Write;

use crate::consensus::encode::Encodable;
Expand All @@ -40,8 +39,8 @@ pub use self::block::{MerkleBlock, MerkleBlockError, PartialMerkleTree};
/// - `Some(merkle_root)` if length of `hashes` is greater than one.
pub fn calculate_root_inline<T>(hashes: &mut [T]) -> Option<T>
where
T: Hash + Encodable,
<T as Hash>::Engine: Write,
T: hashes::Hash + Encodable,
<T as hashes::Hash>::Engine: Write,
{
match hashes.len() {
0 => None,
Expand All @@ -58,8 +57,8 @@ where
/// - `Some(merkle_root)` if length of `hashes` is greater than one.
pub fn calculate_root<T, I>(mut hashes: I) -> Option<T>
where
T: Hash + Encodable,
<T as Hash>::Engine: Write,
T: hashes::Hash + Encodable,
<T as hashes::Hash>::Engine: Write,
I: Iterator<Item = T>,
{
let first = hashes.next()?;
Expand Down Expand Up @@ -90,8 +89,8 @@ where
// `hashes` must contain at least one hash.
fn merkle_root_r<T>(hashes: &mut [T]) -> T
where
T: Hash + Encodable,
<T as Hash>::Engine: Write,
T: hashes::Hash + Encodable,
<T as hashes::Hash>::Engine: Write,
{
if hashes.len() == 1 {
return hashes[0];
Expand All @@ -112,7 +111,7 @@ where

#[cfg(test)]
mod tests {
use hashes::sha256d;
use hashes::{sha256d, Hash as _};

use super::*;
use crate::blockdata::block::Block;
Expand All @@ -127,7 +126,7 @@ mod tests {

let hashes_iter = block.txdata.iter().map(|obj| obj.compute_txid().to_raw_hash());

let mut hashes_array: [sha256d::Hash; 15] = [Hash::all_zeros(); 15];
let mut hashes_array = [sha256d::Hash::all_zeros(); 15];
for (i, hash) in hashes_iter.clone().enumerate() {
hashes_array[i] = hash;
}
Expand Down

0 comments on commit d93a80a

Please sign in to comment.