Use full path for internal consensus macros
What changed, and why it matters
This commit is a routine code cleanup in the Rust Bitcoin library. It changes how internal helper macros are referenced, making their full module path explicit (e.g., `internal_macros::impl_consensus_encoding!` instead of importing and calling them directly). There is no change to program logic, data handling, or security behavior.
No security action required. This is a refactoring change and can be reviewed as part of normal code-quality checks.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies macro invocation style across five source files. It removes direct imports of specific macros from crate::internal_macros and instead imports the internal_macros module, then calls macros with the module prefix. The generated code remains identical because Rust macro expansion is unaffected by whether the macro is imported by name or called via a path. No consensus encoding logic, trait implementations, or type definitions were altered.
Changed components
bitcoin/src/bip152.rsbitcoin/src/bip158.rsbitcoin/src/blockdata/block.rsbitcoin/src/blockdata/transaction.rsbitcoin/src/merkle_tree/mod.rsInspect captured patch +15 / −17
diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs
index 289c7097..94951125 100644
--- a/bitcoin/src/bip152.rs
+++ b/bitcoin/src/bip152.rs
@@ -18,7 +18,7 @@ use io::{BufRead, Write};
use crate::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
use crate::internal_macros::{
- impl_array_newtype, impl_array_newtype_stringify, impl_consensus_encoding,
+ self, impl_array_newtype, impl_array_newtype_stringify,
};
use crate::prelude::Vec;
use crate::transaction::TxIdentifier;
@@ -381,7 +381,7 @@ pub struct BlockTransactions {
/// The transactions provided.
pub transactions: Vec<Transaction>,
}
-impl_consensus_encoding!(BlockTransactions, block_hash, transactions);
+internal_macros::impl_consensus_encoding!(BlockTransactions, block_hash, transactions);
impl BlockTransactions {
/// Constructs a new [`BlockTransactions`] from a [`BlockTransactionsRequest`] and
diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs
index 8926ba6d..c495b59b 100644
--- a/bitcoin/src/bip158.rs
+++ b/bitcoin/src/bip158.rs
@@ -50,10 +50,10 @@ use io::{BufRead, Write};
use crate::block::{Block, BlockHash, Checked};
use crate::consensus::{ReadExt, WriteExt};
-use crate::internal_macros::impl_hashencode;
use crate::prelude::{BTreeSet, Borrow, Vec};
use crate::script::{Script, ScriptExt as _};
use crate::transaction::OutPoint;
+use crate::internal_macros;
/// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845
const P: u8 = 19;
@@ -70,8 +70,8 @@ hashes::impl_hex_for_newtype!(FilterHash, FilterHeader);
#[cfg(feature = "serde")]
hashes::impl_serde_for_newtype!(FilterHash, FilterHeader);
-impl_hashencode!(FilterHash);
-impl_hashencode!(FilterHeader);
+internal_macros::impl_hashencode!(FilterHash);
+internal_macros::impl_hashencode!(FilterHeader);
/// Errors for blockfilter.
#[derive(Debug)]
diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs
index 3411a4a0..85ff421f 100644
--- a/bitcoin/src/blockdata/block.rs
+++ b/bitcoin/src/blockdata/block.rs
@@ -19,13 +19,13 @@ use super::transaction::Coinbase;
use super::Weight;
use crate::consensus::encode::WriteExt as _;
use crate::consensus::{encode, Decodable, Encodable};
-use crate::internal_macros::{impl_consensus_encoding, impl_hashencode};
use crate::merkle_tree::{MerkleNode as _, TxMerkleNode, WitnessMerkleNode};
use crate::network::Params;
use crate::pow::{Target, Work};
use crate::prelude::Vec;
use crate::script::{self, ScriptExt as _};
use crate::transaction::{Transaction, TransactionExt as _, Wtxid};
+use crate::internal_macros;
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
@@ -37,9 +37,9 @@ pub use units::block::{BlockHeight, BlockHeightInterval, TooBigForRelativeHeight
#[doc(hidden)]
pub type BlockInterval = BlockHeightInterval;
-impl_hashencode!(BlockHash);
+internal_macros::impl_hashencode!(BlockHash);
-impl_consensus_encoding!(Header, version, prev_blockhash, merkle_root, time, bits, nonce);
+internal_macros::impl_consensus_encoding!(Header, version, prev_blockhash, merkle_root, time, bits, nonce);
crate::internal_macros::define_extension_trait! {
/// Extension functionality for the [`Header`] type.
diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs
index 999696b7..4db61f7a 100644
--- a/bitcoin/src/blockdata/transaction.rs
+++ b/bitcoin/src/blockdata/transaction.rs
@@ -21,21 +21,20 @@ use primitives::Sequence;
use super::Weight;
use crate::consensus::{self, encode, Decodable, Encodable};
-use crate::internal_macros::{impl_consensus_encoding, impl_hashencode};
use crate::locktime::absolute::{self, Height, MedianTimePast};
use crate::prelude::{Borrow, Vec};
use crate::script::{Script, ScriptBuf, ScriptExt as _, ScriptExtPriv as _};
#[cfg(doc)]
use crate::sighash::{EcdsaSighashType, TapSighashType};
use crate::witness::Witness;
-use crate::{Amount, FeeRate, SignedAmount};
+use crate::{internal_macros, Amount, FeeRate, SignedAmount};
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
pub use primitives::transaction::{OutPoint, ParseOutPointError, Transaction, Txid, Wtxid, Version, TxIn, TxOut};
-impl_hashencode!(Txid);
-impl_hashencode!(Wtxid);
+internal_macros::impl_hashencode!(Txid);
+internal_macros::impl_hashencode!(Wtxid);
crate::internal_macros::define_extension_trait! {
/// Extension functionality for the [`Txid`] type.
@@ -637,7 +636,7 @@ impl Decodable for Version {
}
}
-impl_consensus_encoding!(TxOut, value, script_pubkey);
+crate::internal_macros::impl_consensus_encoding!(TxOut, value, script_pubkey);
impl Encodable for OutPoint {
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
diff --git a/bitcoin/src/merkle_tree/mod.rs b/bitcoin/src/merkle_tree/mod.rs
index 82801fdd..b72d51ec 100644
--- a/bitcoin/src/merkle_tree/mod.rs
+++ b/bitcoin/src/merkle_tree/mod.rs
@@ -18,18 +18,17 @@ mod block;
use hashes::{sha256d, HashEngine as _};
-use crate::internal_macros::impl_hashencode;
use crate::prelude::Vec;
use crate::transaction::TxIdentifier;
-use crate::{Txid, Wtxid};
+use crate::{internal_macros, Txid, Wtxid};
#[rustfmt::skip]
#[doc(inline)]
pub use self::block::{MerkleBlock, MerkleBlockError, PartialMerkleTree};
pub use primitives::merkle_tree::{TxMerkleNode, WitnessMerkleNode};
-impl_hashencode!(TxMerkleNode);
-impl_hashencode!(WitnessMerkleNode);
+internal_macros::impl_hashencode!(TxMerkleNode);
+internal_macros::impl_hashencode!(WitnessMerkleNode);
/// A node in a Merkle tree of transactions or witness data within a block.
///
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.