From facd8ba5563378912bde1a4696ea9f58fcb7c6c3 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 24 Aug 2022 16:29:13 +1000 Subject: [PATCH 1/2] Move bip152 module to crate root We are attempting to flatten the `util` module; move the `bip152` module to the crate root out of `util`. Currently `src/util/` is ignored by the formatter so this move causes the `bip152` module to be formatted. --- bitcoin/src/{util => }/bip152.rs | 0 bitcoin/src/consensus/encode.rs | 2 +- bitcoin/src/lib.rs | 1 + bitcoin/src/network/message.rs | 2 +- bitcoin/src/network/message_compact_blocks.rs | 2 +- bitcoin/src/util/mod.rs | 1 - fuzz/fuzz_targets/deserialize_prefilled_transaction.rs | 2 +- 7 files changed, 5 insertions(+), 5 deletions(-) rename bitcoin/src/{util => }/bip152.rs (100%) diff --git a/bitcoin/src/util/bip152.rs b/bitcoin/src/bip152.rs similarity index 100% rename from bitcoin/src/util/bip152.rs rename to bitcoin/src/bip152.rs diff --git a/bitcoin/src/consensus/encode.rs b/bitcoin/src/consensus/encode.rs index 89599af4..5d22bda3 100644 --- a/bitcoin/src/consensus/encode.rs +++ b/bitcoin/src/consensus/encode.rs @@ -28,7 +28,7 @@ use crate::io::{self, Cursor, Read}; use crate::util::endian; use crate::util::psbt; -use crate::util::bip152::{ShortId, PrefilledTransaction}; +use crate::bip152::{ShortId, PrefilledTransaction}; use crate::util::taproot::TapLeafHash; use crate::hashes::hex::ToHex; diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs index 2e039e22..8fd276d2 100644 --- a/bitcoin/src/lib.rs +++ b/bitcoin/src/lib.rs @@ -80,6 +80,7 @@ mod serde_utils; #[macro_use] pub mod network; pub mod address; +pub mod bip152; pub mod bip158; pub mod bip32; pub mod blockdata; diff --git a/bitcoin/src/network/message.rs b/bitcoin/src/network/message.rs index 17234df7..5e1b0ee1 100644 --- a/bitcoin/src/network/message.rs +++ b/bitcoin/src/network/message.rs @@ -486,7 +486,7 @@ mod test { use crate::network::message_bloom::{FilterAdd, FilterLoad, BloomFlags}; use crate::MerkleBlock; use crate::network::message_compact_blocks::{GetBlockTxn, SendCmpct}; - use crate::util::bip152::BlockTransactionsRequest; + use crate::bip152::BlockTransactionsRequest; fn hash(slice: [u8;32]) -> Hash { Hash::from_slice(&slice).unwrap() diff --git a/bitcoin/src/network/message_compact_blocks.rs b/bitcoin/src/network/message_compact_blocks.rs index 19fe42d7..6a92a15d 100644 --- a/bitcoin/src/network/message_compact_blocks.rs +++ b/bitcoin/src/network/message_compact_blocks.rs @@ -3,7 +3,7 @@ //! use crate::internal_macros::impl_consensus_encoding; -use crate::util::bip152; +use crate::bip152; /// sendcmpct message #[derive(PartialEq, Eq, Clone, Debug, Copy, PartialOrd, Ord, Hash)] diff --git a/bitcoin/src/util/mod.rs b/bitcoin/src/util/mod.rs index acd1668c..a34b8212 100644 --- a/bitcoin/src/util/mod.rs +++ b/bitcoin/src/util/mod.rs @@ -11,7 +11,6 @@ pub mod ecdsa; pub mod schnorr; pub mod amount; pub mod base58; -pub mod bip152; pub mod hash; pub mod merkleblock; pub mod psbt; diff --git a/fuzz/fuzz_targets/deserialize_prefilled_transaction.rs b/fuzz/fuzz_targets/deserialize_prefilled_transaction.rs index 1da8ec48..fce2f03e 100644 --- a/fuzz/fuzz_targets/deserialize_prefilled_transaction.rs +++ b/fuzz/fuzz_targets/deserialize_prefilled_transaction.rs @@ -2,7 +2,7 @@ extern crate bitcoin; fn do_test(data: &[u8]) { // We already fuzz Transactions in `./deserialize_transaction.rs`. - let tx_result: Result = bitcoin::consensus::encode::deserialize(data); + let tx_result: Result = bitcoin::consensus::encode::deserialize(data); match tx_result { Err(_) => {}, From 4057c268297f5c1dc5a5e63ef8757b9351f3bb04 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 19 Oct 2022 06:41:10 +1100 Subject: [PATCH 2/2] Run formmater on bip152 Run the formmater on the newly moved `bip152` module. No changes other than those introduced by `cargo +nightly fmt`. --- bitcoin/examples/ecdsa-psbt.rs | 2 +- bitcoin/src/bip152.rs | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/bitcoin/examples/ecdsa-psbt.rs b/bitcoin/examples/ecdsa-psbt.rs index 242c9c05..96a6e049 100644 --- a/bitcoin/examples/ecdsa-psbt.rs +++ b/bitcoin/examples/ecdsa-psbt.rs @@ -382,7 +382,7 @@ mod psbt_sign { use std::ops::Deref; use bitcoin::psbt::{Input, Prevouts, Psbt, PsbtSighashType}; - use bitcoin::sighash::{self, SighashCache, EcdsaSighashType, SchnorrSighashType}; + use bitcoin::sighash::{self, EcdsaSighashType, SchnorrSighashType, SighashCache}; use bitcoin::util::taproot::TapLeafHash; use bitcoin::{EcdsaSig, EcdsaSigError, PrivateKey, Script, Transaction, TxOut}; use secp256k1::{Message, Secp256k1, Signing}; diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs index 8072db59..dc0ae928 100644 --- a/bitcoin/src/bip152.rs +++ b/bitcoin/src/bip152.rs @@ -5,18 +5,17 @@ //! Implementation of compact blocks data structure and algorithms. //! -use crate::prelude::*; - -use crate::io; -use core::{convert, convert::TryFrom, fmt, mem}; +use core::convert::TryFrom; +use core::{convert, fmt, mem}; #[cfg(feature = "std")] use std::error; use crate::consensus::encode::{self, Decodable, Encodable, VarInt}; use crate::hashes::{sha256, siphash24, Hash}; use crate::internal_macros::{impl_array_newtype, impl_bytes_newtype, impl_consensus_encoding}; +use crate::prelude::*; use crate::util::endian; -use crate::{Block, BlockHash, BlockHeader, Transaction}; +use crate::{io, Block, BlockHash, BlockHeader, Transaction}; /// A BIP-152 error #[derive(Clone, PartialEq, Eq, Debug, Copy, PartialOrd, Ord, Hash)] @@ -69,9 +68,7 @@ pub struct PrefilledTransaction { } impl convert::AsRef for PrefilledTransaction { - fn as_ref(&self) -> &Transaction { - &self.tx - } + fn as_ref(&self) -> &Transaction { &self.tx } } impl Encodable for PrefilledTransaction { @@ -376,8 +373,8 @@ mod test { use crate::consensus::encode::{deserialize, serialize}; use crate::hashes::hex::FromHex; use crate::{ - Block, BlockHash, BlockHeader, BlockVersion, OutPoint, Script, Sequence, Transaction, TxIn, - TxMerkleNode, TxOut, Txid, Witness, CompactTarget, + Block, BlockHash, BlockHeader, BlockVersion, CompactTarget, OutPoint, Script, Sequence, + Transaction, TxIn, TxMerkleNode, TxOut, Txid, Witness, }; fn dummy_tx(nonce: &[u8]) -> Transaction {