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.
This commit is contained in:
Tobin C. Harding 2023-11-08 08:58:06 +11:00
parent 2b4b66dee3
commit 61351c917f
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
4 changed files with 26 additions and 24 deletions

View File

@ -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<ScriptBuf> for ScriptHash {
fn from(script: ScriptBuf) -> ScriptHash { script.script_hash() }

View File

@ -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<PublicKey> for PubkeyHash {
fn from(key: PublicKey) -> PubkeyHash { key.pubkey_hash() }

View File

@ -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,

View File

@ -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;