From 61351c917f1fb72c46f53e392a556b831bc1edf1 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 8 Nov 2023 08:58:06 +1100 Subject: [PATCH] Move impl_asref_push_bytes to internal_macros We are emptying the `hash_types` module. `impl_asref_push_bytes!` is an internal macro, as such it can live in the `internal_macros` module. While we are at it import the macro and call it without any qualifying path, this is typical for our usage of other internals/internal_macros usage. --- bitcoin/src/blockdata/script/mod.rs | 3 ++- bitcoin/src/crypto/key.rs | 3 ++- bitcoin/src/hash_types.rs | 22 ---------------------- bitcoin/src/internal_macros.rs | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index 413f06cc..05cf2957 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -72,6 +72,7 @@ use serde; use crate::blockdata::opcodes::all::*; use crate::blockdata::opcodes::{self, Opcode}; use crate::consensus::{encode, Decodable, Encodable}; +use crate::internal_macros::impl_asref_push_bytes; use crate::prelude::*; use crate::{io, OutPoint}; @@ -91,7 +92,7 @@ hashes::hash_newtype! { /// SegWit version of a Bitcoin Script bytecode hash. pub struct WScriptHash(sha256::Hash); } -crate::hash_types::impl_asref_push_bytes!(ScriptHash, WScriptHash); +impl_asref_push_bytes!(ScriptHash, WScriptHash); impl From for ScriptHash { fn from(script: ScriptBuf) -> ScriptHash { script.script_hash() } diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index 6c4d354c..91fe9cb7 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -14,6 +14,7 @@ use hex::FromHex; use internals::write_err; use crate::crypto::ecdsa; +use crate::internal_macros::impl_asref_push_bytes; use crate::network::Network; use crate::prelude::*; use crate::taproot::{TapNodeHash, TapTweakHash}; @@ -252,7 +253,7 @@ hashes::hash_newtype! { /// SegWit version of a public key hash. pub struct WPubkeyHash(hash160::Hash); } -crate::hash_types::impl_asref_push_bytes!(PubkeyHash, WPubkeyHash); +impl_asref_push_bytes!(PubkeyHash, WPubkeyHash); impl From for PubkeyHash { fn from(key: PublicKey) -> PubkeyHash { key.pubkey_hash() } diff --git a/bitcoin/src/hash_types.rs b/bitcoin/src/hash_types.rs index f63fb540..db0fbc9e 100644 --- a/bitcoin/src/hash_types.rs +++ b/bitcoin/src/hash_types.rs @@ -8,28 +8,6 @@ //! hash). //! -#[rustfmt::skip] -macro_rules! impl_asref_push_bytes { - ($($hashtype:ident),*) => { - $( - impl AsRef<$crate::blockdata::script::PushBytes> for $hashtype { - fn as_ref(&self) -> &$crate::blockdata::script::PushBytes { - use $crate::hashes::Hash; - self.as_byte_array().into() - } - } - - impl From<$hashtype> for $crate::blockdata::script::PushBytesBuf { - fn from(hash: $hashtype) -> Self { - use $crate::hashes::Hash; - hash.as_byte_array().into() - } - } - )* - }; -} -pub(crate) use impl_asref_push_bytes; - #[deprecated(since = "0.0.0-NEXT-RELEASE", note = "use crate::T instead")] pub use crate::{ BlockHash, FilterHash, FilterHeader, TxMerkleNode, Txid, WitnessCommitment, WitnessMerkleNode, diff --git a/bitcoin/src/internal_macros.rs b/bitcoin/src/internal_macros.rs index bfad3d6a..669c3ff6 100644 --- a/bitcoin/src/internal_macros.rs +++ b/bitcoin/src/internal_macros.rs @@ -210,3 +210,25 @@ macro_rules! impl_hashencode { }; } pub(crate) use impl_hashencode; + +#[rustfmt::skip] +macro_rules! impl_asref_push_bytes { + ($($hashtype:ident),*) => { + $( + impl AsRef<$crate::blockdata::script::PushBytes> for $hashtype { + fn as_ref(&self) -> &$crate::blockdata::script::PushBytes { + use $crate::hashes::Hash; + self.as_byte_array().into() + } + } + + impl From<$hashtype> for $crate::blockdata::script::PushBytesBuf { + fn from(hash: $hashtype) -> Self { + use $crate::hashes::Hash; + hash.as_byte_array().into() + } + } + )* + }; +} +pub(crate) use impl_asref_push_bytes;