From fe6110c6e46435e57f7a3836aa8b871dba530fa6 Mon Sep 17 00:00:00 2001 From: Fmt Bot Date: Sun, 20 Jul 2025 02:29:04 +0000 Subject: [PATCH] 2025-07-20 automated rustfmt nightly --- bitcoin/src/blockdata/block.rs | 3 +- bitcoin/src/blockdata/transaction.rs | 16 +++-------- bitcoin/src/network/mod.rs | 1 - bitcoin/tests/network.rs | 17 +++-------- primitives/src/locktime/relative.rs | 3 +- units/src/amount/serde.rs | 42 +++++++++++++++------------- units/src/amount/tests.rs | 19 +++---------- 7 files changed, 37 insertions(+), 64 deletions(-) diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index f74ebfb15..3411a4a09 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -535,8 +535,7 @@ mod tests { use crate::pow::test_utils::{u128_to_work, u64_to_work}; use crate::script::ScriptBuf; use crate::transaction::{OutPoint, Transaction, TxIn, TxOut, Txid}; - use crate::{block, CompactTarget, Network, TestnetVersion}; - use crate::{Amount, Sequence, Witness}; + use crate::{block, Amount, CompactTarget, Network, Sequence, TestnetVersion, Witness}; #[test] fn static_vector() { diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 296dd213f..3b1c19a90 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -1175,17 +1175,13 @@ impl Coinbase { /// /// This method does not validate that the transaction is actually a coinbase transaction. /// The caller must ensure that this transaction is indeed a valid coinbase transaction. - pub fn assume_coinbase(tx: Transaction) -> Self { - Self(tx) - } + pub fn assume_coinbase(tx: Transaction) -> Self { Self(tx) } /// Returns the first input of this coinbase transaction. /// /// This method is infallible because a valid coinbase transaction is guaranteed /// to have exactly one input. - pub fn first_input(&self) -> &TxIn { - &self.0.input[0] - } + pub fn first_input(&self) -> &TxIn { &self.0.input[0] } /// Returns a reference to the underlying transaction. /// @@ -1200,17 +1196,13 @@ impl Coinbase { pub fn into_transaction(self) -> Transaction { self.0 } /// Computes the [`Txid`] of this coinbase transaction. - pub fn compute_txid(&self) -> Txid { - self.0.compute_txid() - } + pub fn compute_txid(&self) -> Txid { self.0.compute_txid() } /// Returns the wtxid of this coinbase transaction. /// /// For coinbase transactions, this is always `Wtxid::COINBASE`. #[doc(alias = "compute_wtxid")] - pub const fn wtxid(&self) -> Wtxid { - Wtxid::COINBASE - } + pub const fn wtxid(&self) -> Wtxid { Wtxid::COINBASE } } mod sealed { diff --git a/bitcoin/src/network/mod.rs b/bitcoin/src/network/mod.rs index 6751117d8..214e95bd3 100644 --- a/bitcoin/src/network/mod.rs +++ b/bitcoin/src/network/mod.rs @@ -59,7 +59,6 @@ pub enum TestnetVersion { V4, } - /// The cryptocurrency network to act on. /// /// This is an exhaustive enum, meaning that we cannot add any future networks without defining a diff --git a/bitcoin/tests/network.rs b/bitcoin/tests/network.rs index 025912d08..921a29f06 100644 --- a/bitcoin/tests/network.rs +++ b/bitcoin/tests/network.rs @@ -5,9 +5,7 @@ use bitcoin::network::{Network, NetworkKind, TestnetVersion}; #[test] fn can_match_exhaustively_on_network() { // Returns true if `n` is mainnet. - fn is_mainnet(n: Network) -> bool { - matches!(n, Network::Bitcoin) - } + fn is_mainnet(n: Network) -> bool { matches!(n, Network::Bitcoin) } assert!(is_mainnet(Network::Bitcoin)); } @@ -15,9 +13,7 @@ fn can_match_exhaustively_on_network() { #[test] fn can_match_exhaustively_on_testnet() { // Returns true if `n` is any testnet. - fn is_testnet(n: Network) -> bool { - matches!(n, Network::Testnet(_)) - } + fn is_testnet(n: Network) -> bool { matches!(n, Network::Testnet(_)) } assert!(is_testnet(Network::Testnet(TestnetVersion::V3))); } @@ -25,21 +21,16 @@ fn can_match_exhaustively_on_testnet() { #[test] fn can_use_network_kind() { // Returns true if `n` is any mainnet. - fn is_mainnet(n: Network) -> bool { - NetworkKind::from(n).is_mainnet() - } + fn is_mainnet(n: Network) -> bool { NetworkKind::from(n).is_mainnet() } // Returns true if `n` is a any testnet. - fn is_testnet(n: Network) -> bool { - !NetworkKind::from(n).is_mainnet() - } + fn is_testnet(n: Network) -> bool { !NetworkKind::from(n).is_mainnet() } assert!(is_mainnet(Network::Bitcoin)); assert!(!is_testnet(Network::Bitcoin)); assert!(is_testnet(Network::Testnet(TestnetVersion::V3))); assert!(!is_mainnet(Network::Testnet(TestnetVersion::V3))); - } #[test] diff --git a/primitives/src/locktime/relative.rs b/primitives/src/locktime/relative.rs index effcd882d..cdfcd8216 100644 --- a/primitives/src/locktime/relative.rs +++ b/primitives/src/locktime/relative.rs @@ -9,7 +9,6 @@ use core::{convert, fmt}; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; - use internals::write_err; use crate::Sequence; @@ -525,7 +524,7 @@ impl<'a> Arbitrary<'a> for LockTime { fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { match bool::arbitrary(u)? { true => Ok(LockTime::Blocks(NumberOfBlocks::arbitrary(u)?)), - false => Ok(LockTime::Time(NumberOf512Seconds::arbitrary(u)?)) + false => Ok(LockTime::Time(NumberOf512Seconds::arbitrary(u)?)), } } } diff --git a/units/src/amount/serde.rs b/units/src/amount/serde.rs index 93d75fded..76d8ad599 100644 --- a/units/src/amount/serde.rs +++ b/units/src/amount/serde.rs @@ -74,11 +74,11 @@ pub mod as_sat { pub fn deserialize<'d, A, D: Deserializer<'d>>(d: D) -> Result where - A: TryFrom, >::Error: core::fmt::Display + A: TryFrom, + >::Error: core::fmt::Display, { let sat = i64::deserialize(d)?; - let amount = SignedAmount::from_sat(sat) - .map_err(serde::de::Error::custom)?; + let amount = SignedAmount::from_sat(sat).map_err(serde::de::Error::custom)?; A::try_from(amount).map_err(serde::de::Error::custom) } @@ -112,13 +112,15 @@ pub mod as_sat { pub fn deserialize<'d, A, D: Deserializer<'d>>(d: D) -> Result, D::Error> where - A: TryFrom, >::Error: core::fmt::Display + A: TryFrom, + >::Error: core::fmt::Display, { struct VisitOptAmt(PhantomData); impl<'de, X> de::Visitor<'de> for VisitOptAmt where - X: TryFrom, >::Error: core::fmt::Display + X: TryFrom, + >::Error: core::fmt::Display, { type Value = Option; @@ -169,7 +171,8 @@ pub mod as_btc { pub fn deserialize<'d, A, D: Deserializer<'d>>(d: D) -> Result where - A: TryFrom, >::Error: core::fmt::Display + A: TryFrom, + >::Error: core::fmt::Display, { let btc = f64::deserialize(d)?; let amount = SignedAmount::from_btc(btc) @@ -208,13 +211,15 @@ pub mod as_btc { pub fn deserialize<'d, A, D: Deserializer<'d>>(d: D) -> Result, D::Error> where - A: TryFrom, >::Error: core::fmt::Display + A: TryFrom, + >::Error: core::fmt::Display, { struct VisitOptAmt(PhantomData); impl<'de, X> de::Visitor<'de> for VisitOptAmt where - X: TryFrom, >::Error: core::fmt::Display + X: TryFrom, + >::Error: core::fmt::Display, { type Value = Option; @@ -251,6 +256,7 @@ pub mod as_str { //! [`SignedAmount`]: crate::SignedAmount use alloc::string::String; + use serde::{Deserialize, Deserializer, Serialize, Serializer}; use super::DisplayFullError; @@ -266,7 +272,8 @@ pub mod as_str { pub fn deserialize<'d, A, D: Deserializer<'d>>(d: D) -> Result where - A: TryFrom, >::Error: core::fmt::Display + A: TryFrom, + >::Error: core::fmt::Display, { let btc = String::deserialize(d)?; let amount = SignedAmount::from_str_in(&btc, Denomination::Bitcoin) @@ -290,10 +297,7 @@ pub mod as_str { use crate::amount::{Denomination, SignedAmount}; #[allow(clippy::ref_option)] // API forced by serde. - pub fn serialize( - a: &Option, - s: S, - ) -> Result + pub fn serialize(a: &Option, s: S) -> Result where A: Into + Copy, { @@ -306,17 +310,17 @@ pub mod as_str { } } - pub fn deserialize<'d, A, D: Deserializer<'d>>( - d: D, - ) -> Result, D::Error> + pub fn deserialize<'d, A, D: Deserializer<'d>>(d: D) -> Result, D::Error> where - A: TryFrom, >::Error: core::fmt::Display + A: TryFrom, + >::Error: core::fmt::Display, { struct VisitOptAmt(PhantomData); impl<'de, X> de::Visitor<'de> for VisitOptAmt where - X: TryFrom, >::Error: core::fmt::Display + X: TryFrom, + >::Error: core::fmt::Display, { type Value = Option; @@ -346,7 +350,7 @@ pub mod as_str { #[cfg(test)] mod tests { - use serde::{Serialize, Deserialize}; + use serde::{Deserialize, Serialize}; use crate::amount::{self, Amount, SignedAmount}; diff --git a/units/src/amount/tests.rs b/units/src/amount/tests.rs index 1e55219e5..110977d16 100644 --- a/units/src/amount/tests.rs +++ b/units/src/amount/tests.rs @@ -847,19 +847,11 @@ fn sum_amounts() { assert_eq!(empty.into_iter().sum::>(), NumOpResult::Valid(SignedAmount::ZERO)); let amounts = [sat(42), sat(1337), sat(21)]; - let sum = amounts - .into_iter() - .map(NumOpResult::from) - .sum::>() - .unwrap(); + let sum = amounts.into_iter().map(NumOpResult::from).sum::>().unwrap(); assert_eq!(sum, sat(1400)); let amounts = [Amount::MAX_MONEY, sat(1337), sat(21)]; - assert!(amounts - .into_iter() - .map(NumOpResult::from) - .sum::>() - .is_error()); + assert!(amounts.into_iter().map(NumOpResult::from).sum::>().is_error()); let amounts = [SignedAmount::MIN, ssat(-1), ssat(21)]; assert!(amounts @@ -876,11 +868,8 @@ fn sum_amounts() { .is_error()); let amounts = [ssat(42), ssat(3301), ssat(21)]; - let sum = amounts - .into_iter() - .map(NumOpResult::from) - .sum::>() - .unwrap(); + let sum = + amounts.into_iter().map(NumOpResult::from).sum::>().unwrap(); assert_eq!(sum, ssat(3364)); }