From 2b4b66dee30c3a1d7ccbc101ae9b87084c44ff71 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 8 Nov 2023 08:53:41 +1100 Subject: [PATCH] Move impl_hashencode to internal_macros We are emptying the `hash_types` module. `impl_hashencode!` is an internal macro, as such it can live in the `internal_macros` module. --- bitcoin/src/bip158.rs | 2 +- bitcoin/src/blockdata/block.rs | 3 +-- bitcoin/src/blockdata/transaction.rs | 3 +-- bitcoin/src/hash_types.rs | 19 ------------------- bitcoin/src/internal_macros.rs | 19 +++++++++++++++++++ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs index 1b6f03da..88875966 100644 --- a/bitcoin/src/bip158.rs +++ b/bitcoin/src/bip158.rs @@ -49,7 +49,7 @@ use crate::blockdata::script::Script; use crate::blockdata::transaction::OutPoint; use crate::consensus::encode::VarInt; use crate::consensus::{Decodable, Encodable}; -use crate::hash_types::impl_hashencode; +use crate::internal_macros::impl_hashencode; use crate::prelude::*; /// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845 diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index be216d00..50a66f41 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -16,8 +16,7 @@ use super::Weight; use crate::blockdata::script; use crate::blockdata::transaction::{Transaction, Txid, Wtxid}; use crate::consensus::{encode, Decodable, Encodable}; -use crate::hash_types::impl_hashencode; -use crate::internal_macros::impl_consensus_encoding; +use crate::internal_macros::{impl_consensus_encoding, impl_hashencode}; use crate::pow::{CompactTarget, Target, Work}; use crate::prelude::*; use crate::{merkle_tree, Network, VarInt}; diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index a481a789..02a34055 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -23,8 +23,7 @@ use crate::blockdata::locktime::relative; use crate::blockdata::script::{Script, ScriptBuf}; use crate::blockdata::witness::Witness; use crate::consensus::{encode, Decodable, Encodable}; -use crate::hash_types::impl_hashencode; -use crate::internal_macros::impl_consensus_encoding; +use crate::internal_macros::{impl_consensus_encoding, impl_hashencode}; use crate::parse::impl_parse_str_from_int_infallible; use crate::prelude::*; use crate::script::Push; diff --git a/bitcoin/src/hash_types.rs b/bitcoin/src/hash_types.rs index 531eadc4..f63fb540 100644 --- a/bitcoin/src/hash_types.rs +++ b/bitcoin/src/hash_types.rs @@ -8,25 +8,6 @@ //! hash). //! -#[rustfmt::skip] -macro_rules! impl_hashencode { - ($hashtype:ident) => { - impl $crate::consensus::Encodable for $hashtype { - fn consensus_encode(&self, w: &mut W) -> Result { - self.0.consensus_encode(w) - } - } - - impl $crate::consensus::Decodable for $hashtype { - fn consensus_decode(r: &mut R) -> Result { - use $crate::hashes::Hash; - Ok(Self::from_byte_array(<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?)) - } - } - }; -} -pub(crate) use impl_hashencode; - #[rustfmt::skip] macro_rules! impl_asref_push_bytes { ($($hashtype:ident),*) => { diff --git a/bitcoin/src/internal_macros.rs b/bitcoin/src/internal_macros.rs index db46f944..bfad3d6a 100644 --- a/bitcoin/src/internal_macros.rs +++ b/bitcoin/src/internal_macros.rs @@ -191,3 +191,22 @@ macro_rules! impl_bytes_newtype { }; } pub(crate) use impl_bytes_newtype; + +#[rustfmt::skip] +macro_rules! impl_hashencode { + ($hashtype:ident) => { + impl $crate::consensus::Encodable for $hashtype { + fn consensus_encode(&self, w: &mut W) -> Result { + self.0.consensus_encode(w) + } + } + + impl $crate::consensus::Decodable for $hashtype { + fn consensus_decode(r: &mut R) -> Result { + use $crate::hashes::Hash; + Ok(Self::from_byte_array(<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?)) + } + } + }; +} +pub(crate) use impl_hashencode;