Skip to content

Commit 7ff8872

Browse files
committed
Shield hash_newtypes from rustfmt
In preparation for running the formatter on root level modules and a submodule that holds all the macro calls in `hash_types` so we can configure rustfmt to skip formatting them.
1 parent 2879cc3 commit 7ff8872

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/hash_types.rs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//! hash).
1010
//!
1111
12-
use bitcoin_hashes::{sha256, sha256d, hash160, hash_newtype};
13-
1412
macro_rules! impl_hashencode {
1513
($hashtype:ident) => {
1614
impl $crate::consensus::Encodable for $hashtype {
@@ -28,40 +26,47 @@ macro_rules! impl_hashencode {
2826
}
2927
}
3028

31-
hash_newtype!(
32-
Txid, sha256d::Hash, 32, doc="A bitcoin transaction hash/transaction ID.
29+
// newtypes module is solely here so we can rustfmt::skip.
30+
pub use newtypes::*;
31+
32+
#[rustfmt::skip]
33+
mod newtypes {
34+
use crate::hashes::{sha256, sha256d, hash160, hash_newtype};
35+
36+
hash_newtype!(
37+
Txid, sha256d::Hash, 32, doc="A bitcoin transaction hash/transaction ID.
3338
3439
For compatibility with the existing Bitcoin infrastructure and historical
3540
and current versions of the Bitcoin Core software itself, this and
3641
other [`sha256d::Hash`] types, are serialized in reverse
3742
byte order when converted to a hex string via [`std::fmt::Display`] trait operations.
3843
See [`hashes::Hash::DISPLAY_BACKWARD`] for more details.
3944
");
40-
hash_newtype!(Wtxid, sha256d::Hash, 32, doc="A bitcoin witness transaction ID.");
41-
hash_newtype!(BlockHash, sha256d::Hash, 32, doc="A bitcoin block hash.");
42-
hash_newtype!(Sighash, sha256d::Hash, 32, doc="Hash of the transaction according to the signature algorithm");
45+
hash_newtype!(Wtxid, sha256d::Hash, 32, doc="A bitcoin witness transaction ID.");
46+
hash_newtype!(BlockHash, sha256d::Hash, 32, doc="A bitcoin block hash.");
47+
hash_newtype!(Sighash, sha256d::Hash, 32, doc="Hash of the transaction according to the signature algorithm");
4348

44-
hash_newtype!(PubkeyHash, hash160::Hash, 20, doc="A hash of a public key.");
45-
hash_newtype!(ScriptHash, hash160::Hash, 20, doc="A hash of Bitcoin Script bytecode.");
46-
hash_newtype!(WPubkeyHash, hash160::Hash, 20, doc="SegWit version of a public key hash.");
47-
hash_newtype!(WScriptHash, sha256::Hash, 32, doc="SegWit version of a Bitcoin Script bytecode hash.");
49+
hash_newtype!(PubkeyHash, hash160::Hash, 20, doc="A hash of a public key.");
50+
hash_newtype!(ScriptHash, hash160::Hash, 20, doc="A hash of Bitcoin Script bytecode.");
51+
hash_newtype!(WPubkeyHash, hash160::Hash, 20, doc="SegWit version of a public key hash.");
52+
hash_newtype!(WScriptHash, sha256::Hash, 32, doc="SegWit version of a Bitcoin Script bytecode hash.");
4853

49-
hash_newtype!(TxMerkleNode, sha256d::Hash, 32, doc="A hash of the Merkle tree branch or root for transactions");
50-
hash_newtype!(WitnessMerkleNode, sha256d::Hash, 32, doc="A hash corresponding to the Merkle tree root for witness data");
51-
hash_newtype!(WitnessCommitment, sha256d::Hash, 32, doc="A hash corresponding to the witness structure commitment in the coinbase transaction");
52-
hash_newtype!(XpubIdentifier, hash160::Hash, 20, doc="XpubIdentifier as defined in BIP-32.");
54+
hash_newtype!(TxMerkleNode, sha256d::Hash, 32, doc="A hash of the Merkle tree branch or root for transactions");
55+
hash_newtype!(WitnessMerkleNode, sha256d::Hash, 32, doc="A hash corresponding to the Merkle tree root for witness data");
56+
hash_newtype!(WitnessCommitment, sha256d::Hash, 32, doc="A hash corresponding to the witness structure commitment in the coinbase transaction");
57+
hash_newtype!(XpubIdentifier, hash160::Hash, 20, doc="XpubIdentifier as defined in BIP-32.");
5358

54-
hash_newtype!(FilterHash, sha256d::Hash, 32, doc="Filter hash, as defined in BIP-157");
55-
hash_newtype!(FilterHeader, sha256d::Hash, 32, doc="Filter header, as defined in BIP-157");
59+
hash_newtype!(FilterHash, sha256d::Hash, 32, doc="Filter hash, as defined in BIP-157");
60+
hash_newtype!(FilterHeader, sha256d::Hash, 32, doc="Filter header, as defined in BIP-157");
5661

62+
impl_hashencode!(Txid);
63+
impl_hashencode!(Wtxid);
64+
impl_hashencode!(BlockHash);
65+
impl_hashencode!(Sighash);
5766

58-
impl_hashencode!(Txid);
59-
impl_hashencode!(Wtxid);
60-
impl_hashencode!(BlockHash);
61-
impl_hashencode!(Sighash);
67+
impl_hashencode!(TxMerkleNode);
68+
impl_hashencode!(WitnessMerkleNode);
6269

63-
impl_hashencode!(TxMerkleNode);
64-
impl_hashencode!(WitnessMerkleNode);
65-
66-
impl_hashencode!(FilterHash);
67-
impl_hashencode!(FilterHeader);
70+
impl_hashencode!(FilterHash);
71+
impl_hashencode!(FilterHeader);
72+
}

0 commit comments

Comments
 (0)