2025-03-16 automated rustfmt nightly

This commit is contained in:
Fmt Bot 2025-03-16 01:25:25 +00:00 committed by github-actions[bot]
parent 0ca9fcfd0e
commit a74e08a53d
24 changed files with 87 additions and 91 deletions

View File

@ -413,7 +413,7 @@ mod test {
use crate::merkle_tree::TxMerkleNode;
use crate::transaction::OutPointExt;
use crate::{
transaction, Amount, BlockChecked, CompactTarget, OutPoint, ScriptBuf, Sequence, BlockTime,
transaction, Amount, BlockChecked, BlockTime, CompactTarget, OutPoint, ScriptBuf, Sequence,
TxIn, TxOut, Txid, Witness,
};

View File

@ -16,7 +16,7 @@ use crate::opcodes::all::*;
use crate::pow::CompactTarget;
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
use crate::witness::Witness;
use crate::{script, Amount, BlockHash, Sequence, TestnetVersion, BlockTime};
use crate::{script, Amount, BlockHash, BlockTime, Sequence, TestnetVersion};
/// How many seconds between blocks we expect on average.
pub const TARGET_BLOCK_SPACING: u32 = 600;

View File

@ -21,10 +21,10 @@ pub use self::{
/// Implements `FeeRate` and assoctiated features.
pub mod fee_rate {
/// Re-export everything from the [`units::fee_rate`] module.
pub use units::fee_rate::FeeRate;
#[cfg(feature = "serde")]
pub use units::fee_rate::serde;
/// Re-export everything from the [`units::fee_rate`] module.
pub use units::fee_rate::FeeRate;
}
/// Provides absolute and relative locktimes.

View File

@ -8,7 +8,7 @@ use crate::address::script_pubkey::{
};
use crate::consensus::encode::{deserialize, serialize};
use crate::crypto::key::{PublicKey, XOnlyPublicKey};
use crate::{Amount, FeeRate, opcodes};
use crate::{opcodes, Amount, FeeRate};
#[test]
#[rustfmt::skip]

View File

@ -462,7 +462,7 @@ impl PrivateKey {
/// Deserializes a private key from a byte array.
pub fn from_byte_array(
data: [u8; 32],
network: impl Into<NetworkKind>
network: impl Into<NetworkKind>,
) -> Result<PrivateKey, secp256k1::Error> {
Ok(PrivateKey::new(secp256k1::SecretKey::from_byte_array(&data)?, network))
}

View File

@ -164,9 +164,7 @@ pub use crate::{
blockdata::script::witness_program::{self, WitnessProgram},
blockdata::script::witness_version::{self, WitnessVersion},
// These modules also re-export all the respective `primitives` types.
blockdata::{
block, constants, fee_rate, locktime, script, transaction, weight, witness,
},
blockdata::{block, constants, fee_rate, locktime, script, transaction, weight, witness},
};
#[rustfmt::skip]

View File

@ -135,7 +135,7 @@ impl Psbt {
/// An alias for [`extract_tx_fee_rate_limit`].
///
/// [`extract_tx_fee_rate_limit`]: Psbt::extract_tx_fee_rate_limit
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
pub fn extract_tx(self) -> Result<Transaction, ExtractTxError> {
self.internal_extract_tx_with_fee_rate_limit(Self::DEFAULT_MAX_FEE_RATE)
}
@ -147,7 +147,7 @@ impl Psbt {
/// [`ExtractTxError`] variants will contain either the [`Psbt`] itself or the [`Transaction`]
/// that was extracted. These can be extracted from the Errors in order to recover.
/// See the error documentation for info on the variants. In general, it covers large fees.
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
pub fn extract_tx_fee_rate_limit(self) -> Result<Transaction, ExtractTxError> {
self.internal_extract_tx_with_fee_rate_limit(Self::DEFAULT_MAX_FEE_RATE)
}
@ -159,7 +159,7 @@ impl Psbt {
/// See [`extract_tx`].
///
/// [`extract_tx`]: Psbt::extract_tx
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
pub fn extract_tx_with_fee_rate_limit(
self,
max_fee_rate: FeeRate,
@ -187,7 +187,7 @@ impl Psbt {
}
#[inline]
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
fn internal_extract_tx_with_fee_rate_limit(
self,
max_fee_rate: FeeRate,

View File

@ -260,10 +260,8 @@ impl Serialize for XOnlyPublicKey {
impl Deserialize for XOnlyPublicKey {
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
XOnlyPublicKey::from_byte_array(
bytes.try_into().map_err(|_| Error::InvalidXOnlyPublicKey)?,
)
.map_err(|_| Error::InvalidXOnlyPublicKey)
XOnlyPublicKey::from_byte_array(bytes.try_into().map_err(|_| Error::InvalidXOnlyPublicKey)?)
.map_err(|_| Error::InvalidXOnlyPublicKey)
}
}

View File

@ -52,11 +52,7 @@ impl TaprootMerkleBranch {
} else if node_hashes.len() > TAPROOT_CONTROL_MAX_NODE_COUNT {
Err(InvalidMerkleTreeDepthError(sl.len() / TAPROOT_CONTROL_NODE_SIZE).into())
} else {
let inner = node_hashes
.iter()
.copied()
.map(TapNodeHash::from_byte_array)
.collect();
let inner = node_hashes.iter().copied().map(TapNodeHash::from_byte_array).collect();
Ok(TaprootMerkleBranch(inner))
}

View File

@ -109,8 +109,7 @@ fn serde_regression_txin() {
#[test]
fn serde_regression_txout() {
let txout =
TxOut { value: Amount::MAX, script_pubkey: ScriptBuf::from(vec![0u8, 1u8, 2u8]) };
let txout = TxOut { value: Amount::MAX, script_pubkey: ScriptBuf::from(vec![0u8, 1u8, 2u8]) };
let got = serialize(&txout).unwrap();
let want = include_bytes!("data/serde/txout_bincode") as &[_];
assert_eq!(got, want)

View File

@ -1,6 +1,5 @@
use honggfuzz::fuzz;
use bitcoin_fuzz::fuzz_utils::consume_random_bytes;
use honggfuzz::fuzz;
fn do_test(data: &[u8]) {
let mut new_data = data;

View File

@ -2,9 +2,8 @@ use bitcoin::address::Address;
use bitcoin::consensus::encode;
use bitcoin::script::{self, ScriptExt as _};
use bitcoin::{FeeRate, Network};
use honggfuzz::fuzz;
use bitcoin_fuzz::fuzz_utils::{consume_random_bytes, consume_u64};
use honggfuzz::fuzz;
fn do_test(data: &[u8]) {
let mut new_data = data;

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: CC0-1.0
use internals::slice::SliceExt;
use super::{HashEngine, BLOCK_SIZE};
#[cfg(feature = "small-hash")]

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: CC0-1.0
use internals::slice::SliceExt;
use super::{HashEngine, BLOCK_SIZE};
impl HashEngine {

View File

@ -6,6 +6,7 @@ use core::arch::x86::*;
use core::arch::x86_64::*;
use internals::slice::SliceExt;
use super::{HashEngine, Midstate, BLOCK_SIZE};
#[allow(non_snake_case)]

View File

@ -9,6 +9,7 @@ mod crypto;
mod tests;
use core::{cmp, convert, fmt};
use internals::slice::SliceExt;
use crate::{incomplete_block_len, sha256d, HashEngine as _};
@ -80,7 +81,8 @@ impl HashEngine {
/// Please see docs on [`Midstate`] before using this function.
pub fn from_midstate(midstate: Midstate) -> HashEngine {
let mut ret = [0; 8];
for (ret_val, midstate_bytes) in ret.iter_mut().zip(midstate.as_ref().bitcoin_as_chunks().0) {
for (ret_val, midstate_bytes) in ret.iter_mut().zip(midstate.as_ref().bitcoin_as_chunks().0)
{
*ret_val = u32::from_be_bytes(*midstate_bytes);
}

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: CC0-1.0
use internals::slice::SliceExt;
use super::{HashEngine, BLOCK_SIZE};
#[allow(non_snake_case)]

View File

@ -23,7 +23,9 @@ pub trait SliceExt {
/// let mut slice = [1, 2, 3];
/// let fail = slice.as_chunks_mut::<0>();
/// ```
fn bitcoin_as_chunks_mut<const N: usize>(&mut self) -> (&mut [[Self::Item; N]], &mut [Self::Item]);
fn bitcoin_as_chunks_mut<const N: usize>(
&mut self,
) -> (&mut [[Self::Item; N]], &mut [Self::Item]);
}
impl<T> SliceExt for [T] {
@ -40,11 +42,15 @@ impl<T> SliceExt for [T] {
// we're merely casting, so no aliasing issues here
// arrays of T have same alignment as T
// the resulting slice points within the obtained slice as was computed above
let left = unsafe { core::slice::from_raw_parts(left.as_ptr().cast::<[Self::Item; N]>(), chunks_count) };
let left = unsafe {
core::slice::from_raw_parts(left.as_ptr().cast::<[Self::Item; N]>(), chunks_count)
};
(left, right)
}
fn bitcoin_as_chunks_mut<const N: usize>(&mut self) -> (&mut [[Self::Item; N]], &mut [Self::Item]) {
fn bitcoin_as_chunks_mut<const N: usize>(
&mut self,
) -> (&mut [[Self::Item; N]], &mut [Self::Item]) {
#[allow(clippy::let_unit_value)]
let _ = Hack::<N>::IS_NONZERO;
@ -55,7 +61,12 @@ impl<T> SliceExt for [T] {
// we're merely casting, so no aliasing issues here
// arrays of T have same alignment as T
// the resulting slice points within the obtained slice as was computed above
let left = unsafe { core::slice::from_raw_parts_mut(left.as_mut_ptr().cast::<[Self::Item; N]>(), chunks_count) };
let left = unsafe {
core::slice::from_raw_parts_mut(
left.as_mut_ptr().cast::<[Self::Item; N]>(),
chunks_count,
)
};
(left, right)
}
}
@ -63,7 +74,9 @@ impl<T> SliceExt for [T] {
struct Hack<const N: usize>;
impl<const N: usize> Hack<N> {
const IS_NONZERO: () = { assert!(N != 0); };
const IS_NONZERO: () = {
assert!(N != 0);
};
}
#[cfg(test)]

View File

@ -6,7 +6,7 @@
//! all of the opcodes for that language.
#![allow(non_camel_case_types)]
#![allow(dead_code)] // This module is private and is duplicated in `bitcoin`.
#![allow(dead_code)] // This module is private and is duplicated in `bitcoin`.
use core::fmt;

View File

@ -670,7 +670,10 @@ mod tests {
witness: Witness::new(),
};
let txout = TxOut { value: Amount::from_sat(123_456_789).unwrap(), script_pubkey: ScriptBuf::new() };
let txout = TxOut {
value: Amount::from_sat(123_456_789).unwrap(),
script_pubkey: ScriptBuf::new(),
};
let tx_orig = Transaction {
version: Version::ONE,

View File

@ -355,8 +355,7 @@ impl<'de> serde::Deserialize<'de> for Witness {
self,
mut a: A,
) -> Result<Self::Value, A::Error> {
use hex::FromHex;
use hex::HexToBytesError as E;
use hex::{FromHex, HexToBytesError as E};
use serde::de::{self, Unexpected};
let mut ret = match a.size_hint() {
@ -366,16 +365,17 @@ impl<'de> serde::Deserialize<'de> for Witness {
while let Some(elem) = a.next_element::<String>()? {
let vec = Vec::<u8>::from_hex(&elem).map_err(|e| match e {
E::InvalidChar(ref e) => match core::char::from_u32(e.invalid_char().into()) {
Some(c) => de::Error::invalid_value(
Unexpected::Char(c),
&"a valid hex character",
),
None => de::Error::invalid_value(
Unexpected::Unsigned(e.invalid_char().into()),
&"a valid hex character",
),
},
E::InvalidChar(ref e) =>
match core::char::from_u32(e.invalid_char().into()) {
Some(c) => de::Error::invalid_value(
Unexpected::Char(c),
&"a valid hex character",
),
None => de::Error::invalid_value(
Unexpected::Unsigned(e.invalid_char().into()),
&"a valid hex character",
),
},
E::OddLengthString(ref e) =>
de::Error::invalid_length(e.length(), &"an even length string"),
})?;

View File

@ -115,7 +115,7 @@ impl Denomination {
Denomination::MicroBitcoin => -2,
Denomination::Bit => -2,
Denomination::Satoshi => 0,
Denomination::_DoNotUse(infallible) => match infallible {}
Denomination::_DoNotUse(infallible) => match infallible {},
}
}
@ -128,7 +128,7 @@ impl Denomination {
Denomination::MicroBitcoin => "uBTC",
Denomination::Bit => "bits",
Denomination::Satoshi => "satoshi",
Denomination::_DoNotUse(infallible) => match infallible {}
Denomination::_DoNotUse(infallible) => match infallible {},
}
}

View File

@ -345,14 +345,8 @@ fn parsing() {
assert_eq!(p("1.1", den_btc), Ok(sat(1_100_000_00)));
assert_eq!(p("100", den_sat), Ok(sat(100)));
assert_eq!(p("55", den_sat), Ok(sat(55)));
assert_eq!(
p("2100000000000000", den_sat),
Ok(sat(21_000_000__000_000_00))
);
assert_eq!(
p("2100000000000000.", den_sat),
Ok(sat(21_000_000__000_000_00))
);
assert_eq!(p("2100000000000000", den_sat), Ok(sat(21_000_000__000_000_00)));
assert_eq!(p("2100000000000000.", den_sat), Ok(sat(21_000_000__000_000_00)));
assert_eq!(p("21000000", den_btc), Ok(sat(21_000_000__000_000_00)));
// exactly 50 chars.
@ -702,28 +696,15 @@ fn to_from_string_in() {
assert_eq!(ua_str(&ua_sat(21_000_000).to_string_in(D::Bit), D::Bit), Ok(ua_sat(21_000_000)));
assert_eq!(ua_str(&ua_sat(0).to_string_in(D::Satoshi), D::Satoshi), Ok(ua_sat(0)));
assert!(
ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Bitcoin), D::Bitcoin).is_ok()
);
assert!(ua_str(
&ua_sat(Amount::MAX.to_sat()).to_string_in(D::CentiBitcoin),
D::CentiBitcoin
)
.is_ok());
assert!(ua_str(
&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MilliBitcoin),
D::MilliBitcoin
)
.is_ok());
assert!(ua_str(
&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MicroBitcoin),
D::MicroBitcoin
)
.is_ok());
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Bitcoin), D::Bitcoin).is_ok());
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::CentiBitcoin), D::CentiBitcoin)
.is_ok());
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MilliBitcoin), D::MilliBitcoin)
.is_ok());
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MicroBitcoin), D::MicroBitcoin)
.is_ok());
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Bit), D::Bit).is_ok());
assert!(
ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Satoshi), D::Satoshi).is_ok()
);
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Satoshi), D::Satoshi).is_ok());
assert_eq!(
sa_str(&SignedAmount::MAX.to_string_in(D::Satoshi), D::MicroBitcoin),
@ -970,11 +951,19 @@ fn sum_amounts() {
assert_eq!([].iter().sum::<NumOpResult<Amount>>(), Amount::ZERO.into());
assert_eq!([].iter().sum::<NumOpResult<SignedAmount>>(), SignedAmount::ZERO.into());
let results = [NumOpResult::Valid(sat(42)), NumOpResult::Valid(sat(1337)), NumOpResult::Valid(sat(21))];
let results =
[NumOpResult::Valid(sat(42)), NumOpResult::Valid(sat(1337)), NumOpResult::Valid(sat(21))];
assert_eq!(results.iter().sum::<NumOpResult<Amount>>(), NumOpResult::Valid(sat(1400)));
let signed_results = [NumOpResult::Valid(ssat(42)), NumOpResult::Valid(ssat(1337)), NumOpResult::Valid(ssat(21))];
assert_eq!(signed_results.iter().sum::<NumOpResult<SignedAmount>>(), NumOpResult::Valid(ssat(1400)));
let signed_results = [
NumOpResult::Valid(ssat(42)),
NumOpResult::Valid(ssat(1337)),
NumOpResult::Valid(ssat(21)),
];
assert_eq!(
signed_results.iter().sum::<NumOpResult<SignedAmount>>(),
NumOpResult::Valid(ssat(1400))
);
let amounts = [sat(42), sat(1337), sat(21)];
assert_eq!(
@ -1240,9 +1229,7 @@ fn unsigned_amount_div_by_amount() {
#[test]
#[should_panic(expected = "attempt to divide by zero")]
fn unsigned_amount_div_by_amount_zero() {
let _ = sat(1897) / Amount::ZERO;
}
fn unsigned_amount_div_by_amount_zero() { let _ = sat(1897) / Amount::ZERO; }
#[test]
fn signed_amount_div_by_amount() {
@ -1256,9 +1243,7 @@ fn signed_amount_div_by_amount() {
#[test]
#[should_panic(expected = "attempt to divide by zero")]
fn signed_amount_div_by_amount_zero() {
let _ = ssat(1897) / SignedAmount::ZERO;
}
fn signed_amount_div_by_amount_zero() { let _ = ssat(1897) / SignedAmount::ZERO; }
#[test]
fn check_const() {

View File

@ -14,8 +14,8 @@ use arbitrary::{Arbitrary, Unstructured};
// These imports test "typical" usage by user code.
use bitcoin_units::locktime::{absolute, relative}; // Typical usage is `absolute::Height`.
use bitcoin_units::{
amount, block, fee_rate, locktime, parse, weight, Amount, BlockHeight, BlockInterval, FeeRate,
SignedAmount, BlockTime, Weight,
amount, block, fee_rate, locktime, parse, weight, Amount, BlockHeight, BlockInterval,
BlockTime, FeeRate, SignedAmount, Weight,
};
/// A struct that includes all public non-error enums.
@ -147,7 +147,7 @@ fn api_can_use_modules_from_crate_root() {
#[test]
fn api_can_use_types_from_crate_root() {
use bitcoin_units::{
Amount, BlockHeight, BlockInterval, FeeRate, SignedAmount, BlockTime, Weight,
Amount, BlockHeight, BlockInterval, BlockTime, FeeRate, SignedAmount, Weight,
};
}