What changed, and why it matters
This commit is a routine automated code-formatting run by the rustfmt tool. It only changes whitespace, import order, line breaks, and other stylistic details across 23 files. No program logic, algorithms, or security-sensitive behavior was altered.
No security action needed. Treat as normal code-style maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff consists entirely of rustfmt-generated style changes: reordering/reformatting use statements, collapsing or expanding function bodies onto single lines, wrapping long signatures, adding/removing blank lines, and reformatting macro invocations. There are no semantic changes to transaction parsing, key handling, sighash computation, PSBT logic, ChaCha20-Poly1305, consensus encoding/decoding, hash implementations, P2P messages, or any other security-relevant code paths.
Changed components
Inspect captured patch +138 / −150
diff --git a/bitcoin/examples/taproot-psbt.rs b/bitcoin/examples/taproot-psbt.rs
index 91966bc2..ceb72475 100644
--- a/bitcoin/examples/taproot-psbt.rs
+++ b/bitcoin/examples/taproot-psbt.rs
@@ -649,8 +649,7 @@ impl BeneficiaryWallet {
for (x_only_pubkey, (leaf_hashes, (_, derivation_path))) in
&psbt.inputs[0].tap_key_origins.clone()
{
- let secret_key =
- self.master_xpriv.derive_xpriv(derivation_path)?.to_private_key();
+ let secret_key = self.master_xpriv.derive_xpriv(derivation_path)?.to_private_key();
for lh in leaf_hashes {
let sighash_type = TapSighashType::All;
let hash = SighashCache::new(&unsigned_tx).taproot_script_spend_signature_hash(
diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs
index 55ab2f73..a2d4e27f 100644
--- a/bitcoin/src/blockdata/transaction.rs
+++ b/bitcoin/src/blockdata/transaction.rs
@@ -1276,8 +1276,8 @@ impl<'a> Arbitrary<'a> for InputWeightPrediction {
mod tests {
use alloc::string::ToString;
- use hex_unstable::FromHex;
use hex_lit::hex;
+ use hex_unstable::FromHex;
use super::*;
use crate::consensus::encode::{deserialize, serialize};
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 17eb1ceb..57bf8f95 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -21,16 +21,16 @@ use crate::crypto::ecdsa;
use crate::internal_macros::impl_asref_push_bytes;
use crate::network::NetworkKind;
use crate::prelude::{DisplayHex, String, Vec};
-#[cfg(feature = "serde")]
-use crate::serde::{Serialize, Serializer, Deserialize, Deserializer};
use crate::script::{self, WitnessScriptBuf};
+#[cfg(feature = "serde")]
+use crate::serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::taproot::{TapNodeHash, TapTweakHash};
#[rustfmt::skip] // Keep public re-exports separate.
pub use secp256k1::{constants, Parity, Verification};
pub use encapsulate::{
- CompressedPublicKey, Keypair, PublicKey, PrivateKey, SerializedXOnlyPublicKey,
- TweakedKeypair, TweakedPublicKey, XOnlyPublicKey,
+ CompressedPublicKey, Keypair, PrivateKey, PublicKey, SerializedXOnlyPublicKey, TweakedKeypair,
+ TweakedPublicKey, XOnlyPublicKey,
};
#[cfg(all(feature = "rand", feature = "std"))]
pub use secp256k1::rand;
@@ -38,6 +38,7 @@ pub use secp256k1::rand;
/// Encapsulation module to provide a clear barrier for construction/destruction of types.
mod encapsulate {
use secp256k1::Parity;
+
use crate::network::NetworkKind;
/// A Bitcoin Schnorr X-only public key used for BIP-0340 signatures.
@@ -159,7 +160,10 @@ mod encapsulate {
/// Constructs a new uncompressed (legacy) ECDSA private key from the provided secp256k1
/// private key and the specified network.
- pub fn from_secp_uncompressed(key: secp256k1::SecretKey, network: impl Into<NetworkKind>) -> Self {
+ pub fn from_secp_uncompressed(
+ key: secp256k1::SecretKey,
+ network: impl Into<NetworkKind>,
+ ) -> Self {
Self { compressed: false, network: network.into(), inner: key }
}
@@ -308,20 +312,14 @@ impl XOnlyPublicKey {
// since XOnlyPublicKey is Copy but we intentionally use &self to remove a copy and
// to_* to indicate the cost of the operation.
#[allow(clippy::wrong_self_convention)]
- pub fn to_public_key(&self) -> PublicKey {
- self.as_inner().public_key(self.parity()).into()
- }
+ pub fn to_public_key(&self) -> PublicKey { self.as_inner().public_key(self.parity()).into() }
/// Verifies that a tweak produced by [`XOnlyPublicKey::add_tweak`] was computed correctly.
///
/// Should be called on the original untweaked key. Takes the tweaked key with its output parity from
/// [`XOnlyPublicKey::add_tweak`] as input.
#[inline]
- pub fn tweak_add_check(
- &self,
- tweaked_key: &Self,
- tweak: secp256k1::Scalar,
- ) -> bool {
+ pub fn tweak_add_check(&self, tweaked_key: &Self, tweak: secp256k1::Scalar) -> bool {
self.as_inner().tweak_add_check(tweaked_key.as_inner(), tweaked_key.parity(), tweak)
}
@@ -337,10 +335,7 @@ impl XOnlyPublicKey {
///
/// If the resulting key would be invalid.
#[inline]
- pub fn add_tweak(
- &self,
- tweak: &secp256k1::Scalar,
- ) -> Result<Self, TweakXOnlyPublicKeyError> {
+ pub fn add_tweak(&self, tweak: &secp256k1::Scalar) -> Result<Self, TweakXOnlyPublicKeyError> {
match self.as_inner().add_tweak(tweak) {
Ok((xonly, parity)) => Ok(Self::from_secp(xonly).with_parity(parity)),
Err(secp256k1::Error::InvalidTweak) => Err(TweakXOnlyPublicKeyError::BadTweak),
@@ -399,7 +394,6 @@ impl<'de> Deserialize<'de> for XOnlyPublicKey {
}
}
-
impl Keypair {
/// Generates a new random key pair.
///
@@ -448,9 +442,7 @@ impl Keypair {
///
/// This is equivalent to using [`XOnlyPublicKey::from_keypair`].
#[inline]
- pub fn to_x_only_public_key(self) -> XOnlyPublicKey {
- XOnlyPublicKey::from_keypair(&self)
- }
+ pub fn to_x_only_public_key(self) -> XOnlyPublicKey { XOnlyPublicKey::from_keypair(&self) }
}
impl FromStr for Keypair {
@@ -471,9 +463,7 @@ impl From<Keypair> for secp256k1::PublicKey {
impl PublicKey {
/// Constructs a new compressed ECDSA public key from the provided generic secp256k1 public key.
#[deprecated(since = "TBD", note = "use `from_secp` instead")]
- pub fn new(key: impl Into<secp256k1::PublicKey>) -> Self {
- Self::from_secp(key)
- }
+ pub fn new(key: impl Into<secp256k1::PublicKey>) -> Self { Self::from_secp(key) }
/// Constructs a new uncompressed (legacy) ECDSA public key from the provided generic secp256k1
/// public key.
@@ -850,7 +840,9 @@ impl PrivateKey {
pub fn public_key(&self) -> PublicKey {
match self.compressed() {
true => PublicKey::from_secp(secp256k1::PublicKey::from_secret_key(self.as_inner())),
- false => PublicKey::from_secp_uncompressed(secp256k1::PublicKey::from_secret_key(self.as_inner())),
+ false => PublicKey::from_secp_uncompressed(secp256k1::PublicKey::from_secret_key(
+ self.as_inner(),
+ )),
}
}
@@ -930,7 +922,10 @@ impl PrivateKey {
Ok(match compressed {
true => Self::from_secp(secp256k1::SecretKey::from_secret_bytes(*key)?, network),
- false => Self::from_secp_uncompressed(secp256k1::SecretKey::from_secret_bytes(*key)?, network),
+ false => Self::from_secp_uncompressed(
+ secp256k1::SecretKey::from_secret_bytes(*key)?,
+ network,
+ ),
})
}
diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs
index 652b5873..1220d99f 100644
--- a/bitcoin/src/crypto/sighash.rs
+++ b/bitcoin/src/crypto/sighash.rs
@@ -1516,11 +1516,12 @@ impl<'a> Arbitrary<'a> for TapSighashType {
#[cfg(test)]
mod tests {
- use alloc::{string::ToString, vec::Vec};
+ use alloc::string::ToString;
+ use alloc::vec::Vec;
use hashes::HashEngine;
- use hex_unstable::FromHex;
use hex_lit::hex;
+ use hex_unstable::FromHex;
use super::*;
use crate::consensus::deserialize;
diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs
index 47264f8b..b949574f 100644
--- a/bitcoin/src/psbt/mod.rs
+++ b/bitcoin/src/psbt/mod.rs
@@ -1299,8 +1299,8 @@ mod tests {
use core::str::FromStr;
use hashes::{hash160, ripemd160, sha256};
- use hex_unstable::FromHex;
use hex_lit::hex;
+ use hex_unstable::FromHex;
#[cfg(all(feature = "rand", feature = "std"))]
use {
crate::bip32::Fingerprint, crate::locktime, crate::script::ScriptPubKeyBufExt as _,
diff --git a/bitcoin/src/psbt/raw.rs b/bitcoin/src/psbt/raw.rs
index 7773f78e..00e40715 100644
--- a/bitcoin/src/psbt/raw.rs
+++ b/bitcoin/src/psbt/raw.rs
@@ -70,9 +70,7 @@ impl Key {
// Convert compact size to usize, saturating at max.
// If this value exceeds MAX_VEC_SIZE (a usize), we'll error down below, so it's fine
// to discard any higher value.
- let byte_size: usize = r.read_compact_size()?
- .try_into()
- .unwrap_or(usize::MAX);
+ let byte_size: usize = r.read_compact_size()?.try_into().unwrap_or(usize::MAX);
if byte_size == 0 {
return Err(Error::NoMorePairs);
@@ -119,7 +117,8 @@ impl Serialize for Key {
0x10000..=0xFFFF_FFFF => 5,
_ => 9,
};
- buf.emit_compact_size(self.key_data.len() + type_size).expect("in-memory writers don't error");
+ buf.emit_compact_size(self.key_data.len() + type_size)
+ .expect("in-memory writers don't error");
buf.emit_compact_size(self.type_value).expect("in-memory writers don't error");
diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs
index e8de5cc4..ce0b8073 100644
--- a/bitcoin/src/taproot/mod.rs
+++ b/bitcoin/src/taproot/mod.rs
@@ -2054,7 +2054,10 @@ mod test {
let spk = addr.script_pubkey();
// Compare just the key bytes, not the parity
- assert_eq!(expected_output_key.serialize().0, output_key.to_x_only_public_key().serialize().0);
+ assert_eq!(
+ expected_output_key.serialize().0,
+ output_key.to_x_only_public_key().serialize().0
+ );
assert_eq!(expected_tweak, tweak);
assert_eq!(expected_addr, addr);
assert_eq!(expected_spk, spk);
diff --git a/bitcoin/tests/psbt-sign-taproot.rs b/bitcoin/tests/psbt-sign-taproot.rs
index e61d85c6..f18ef978 100644
--- a/bitcoin/tests/psbt-sign-taproot.rs
+++ b/bitcoin/tests/psbt-sign-taproot.rs
@@ -84,7 +84,10 @@ fn psbt_sign_taproot() {
//
let keystore = Keystore {
mfp: mfp.parse::<Fingerprint>().unwrap(),
- sk: PrivateKey::from_secp(kp.to_secret_key(), Network::Testnet(bitcoin::TestnetVersion::V3)),
+ sk: PrivateKey::from_secp(
+ kp.to_secret_key(),
+ Network::Testnet(bitcoin::TestnetVersion::V3),
+ ),
};
let _ = psbt_key_path_spend.sign(&keystore);
@@ -114,7 +117,10 @@ fn psbt_sign_taproot() {
let keystore = Keystore {
mfp: mfp.parse::<Fingerprint>().unwrap(),
- sk: PrivateKey::from_secp(kp.to_secret_key(), Network::Testnet(bitcoin::TestnetVersion::V3)),
+ sk: PrivateKey::from_secp(
+ kp.to_secret_key(),
+ Network::Testnet(bitcoin::TestnetVersion::V3),
+ ),
};
//
diff --git a/chacha20_poly1305/src/lib.rs b/chacha20_poly1305/src/lib.rs
index 4a3095b5..117d69e4 100644
--- a/chacha20_poly1305/src/lib.rs
+++ b/chacha20_poly1305/src/lib.rs
@@ -64,9 +64,7 @@ pub struct ChaCha20Poly1305 {
impl ChaCha20Poly1305 {
/// Make a new instance of a `ChaCha20Poly1305` AEAD.
- pub const fn new(key: Key, nonce: Nonce) -> Self {
- Self { key, nonce }
- }
+ pub const fn new(key: Key, nonce: Nonce) -> Self { Self { key, nonce } }
/// Encrypt content in place and return the `Poly1305` 16-byte authentication tag.
///
diff --git a/consensus_encoding/src/decode/decoders.rs b/consensus_encoding/src/decode/decoders.rs
index 087ada07..662ab96d 100644
--- a/consensus_encoding/src/decode/decoders.rs
+++ b/consensus_encoding/src/decode/decoders.rs
@@ -78,7 +78,8 @@ impl Decoder for ByteVecDecoder {
type Error = ByteVecDecoderError;
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- use {ByteVecDecoderError as E, ByteVecDecoderErrorInner as Inner};
+ use ByteVecDecoderError as E;
+ use ByteVecDecoderErrorInner as Inner;
if let Some(mut decoder) = self.prefix_decoder.take() {
if decoder.push_bytes(bytes).map_err(|e| E(Inner::LengthPrefixDecode(e)))? {
@@ -106,7 +107,8 @@ impl Decoder for ByteVecDecoder {
}
fn end(self) -> Result<Self::Output, Self::Error> {
- use {ByteVecDecoderError as E, ByteVecDecoderErrorInner as Inner};
+ use ByteVecDecoderError as E;
+ use ByteVecDecoderErrorInner as Inner;
if let Some(ref prefix_decoder) = self.prefix_decoder {
return Err(E(Inner::UnexpectedEof(UnexpectedEofError {
@@ -189,7 +191,8 @@ impl<T: Decodable> Decoder for VecDecoder<T> {
type Error = VecDecoderError<<<T as Decodable>::Decoder as Decoder>::Error>;
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- use {VecDecoderError as E, VecDecoderErrorInner as Inner};
+ use VecDecoderError as E;
+ use VecDecoderErrorInner as Inner;
if let Some(mut decoder) = self.prefix_decoder.take() {
if decoder.push_bytes(bytes).map_err(|e| E(Inner::LengthPrefixDecode(e)))? {
diff --git a/consensus_encoding/src/encode/encoders.rs b/consensus_encoding/src/encode/encoders.rs
index 59a68418..dc06913e 100644
--- a/consensus_encoding/src/encode/encoders.rs
+++ b/consensus_encoding/src/encode/encoders.rs
@@ -79,16 +79,12 @@ pub struct ArrayRefEncoder<'e, const N: usize> {
impl<'e, const N: usize> ArrayRefEncoder<'e, N> {
/// Constructs an encoder which encodes the array reference with no length prefix.
- pub const fn without_length_prefix(arr: &'e [u8; N]) -> Self {
- Self { arr: Some(arr) }
- }
+ pub const fn without_length_prefix(arr: &'e [u8; N]) -> Self { Self { arr: Some(arr) } }
}
impl<const N: usize> Encoder for ArrayRefEncoder<'_, N> {
#[inline]
- fn current_chunk(&self) -> &[u8] {
- self.arr.map(|x| &x[..]).unwrap_or_default()
- }
+ fn current_chunk(&self) -> &[u8] { self.arr.map(|x| &x[..]).unwrap_or_default() }
#[inline]
fn advance(&mut self) -> bool {
@@ -99,9 +95,7 @@ impl<const N: usize> Encoder for ArrayRefEncoder<'_, N> {
impl<const N: usize> ExactSizeEncoder for ArrayRefEncoder<'_, N> {
#[inline]
- fn len(&self) -> usize {
- self.arr.map_or(0, |a| a.len())
- }
+ fn len(&self) -> usize { self.arr.map_or(0, |a| a.len()) }
}
/// An encoder for a list of encodable types.
diff --git a/hashes/src/sha256/crypto.rs b/hashes/src/sha256/crypto.rs
index aa7cc935..96b33990 100644
--- a/hashes/src/sha256/crypto.rs
+++ b/hashes/src/sha256/crypto.rs
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: CC0-1.0
+#[cfg(all(target_arch = "aarch64", any(feature = "std", feature = "cpufeatures")))]
+use core::arch::aarch64::*;
#[cfg(all(target_arch = "x86", any(feature = "std", feature = "cpufeatures")))]
use core::arch::x86::*;
#[cfg(all(target_arch = "x86_64", any(feature = "std", feature = "cpufeatures")))]
use core::arch::x86_64::*;
-#[cfg(all(target_arch = "aarch64", any(feature = "std", feature = "cpufeatures")))]
-use core::arch::aarch64::*;
use internals::slice::SliceExt;
@@ -288,7 +288,6 @@ impl HashEngine {
}
}
-
#[cfg(all(feature = "std", target_arch = "aarch64"))]
{
if std::arch::is_aarch64_feature_detected!("sha2") {
@@ -307,7 +306,10 @@ impl HashEngine {
self.software_process_block()
}
- #[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), any(feature = "std", feature = "cpufeatures")))]
+ #[cfg(all(
+ any(target_arch = "x86", target_arch = "x86_64"),
+ any(feature = "std", feature = "cpufeatures")
+ ))]
#[target_feature(enable = "sha,sse2,ssse3,sse4.1")]
unsafe fn process_block_simd_x86_intrinsics(&mut self) {
// Code translated and based on from
diff --git a/io/src/error.rs b/io/src/error.rs
index daad7732..ec9262b3 100644
--- a/io/src/error.rs
+++ b/io/src/error.rs
@@ -2,9 +2,9 @@
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::boxed::Box;
+use core::fmt;
#[cfg(feature = "std")]
use std::boxed::Box;
-use core::fmt;
/// The `io` crate error type.
#[derive(Debug)]
diff --git a/io/src/hash.rs b/io/src/hash.rs
index 044562bf..36fedf0b 100644
--- a/io/src/hash.rs
+++ b/io/src/hash.rs
@@ -160,8 +160,7 @@ where
#[cfg(test)]
#[cfg(feature = "alloc")]
mod tests {
- use alloc::format;
- use alloc::vec;
+ use alloc::{format, vec};
use hashes::hmac;
diff --git a/io/src/lib.rs b/io/src/lib.rs
index d2bd0e0a..8321fc3d 100644
--- a/io/src/lib.rs
+++ b/io/src/lib.rs
@@ -38,9 +38,9 @@ mod hash;
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::vec::Vec;
+use core::cmp;
#[cfg(feature = "std")]
use std::vec::Vec;
-use core::cmp;
use encoding::{Decodable, Decoder, Encoder};
diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs
index b4068a29..33386bbb 100644
--- a/p2p/src/lib.rs
+++ b/p2p/src/lib.rs
@@ -38,7 +38,7 @@ use core::{fmt, ops};
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
use bitcoin::consensus::encode::{self, Decodable, Encodable};
-use encoding::{ArrayEncoder, ArrayDecoder};
+use encoding::{ArrayDecoder, ArrayEncoder};
use hex::FromHex;
use internals::{impl_to_hex_from_lower_hex, write_err};
use io::{BufRead, Write};
@@ -552,9 +552,7 @@ impl encoding::Decoder for MagicDecoder {
impl encoding::Decodable for Magic {
type Decoder = MagicDecoder;
- fn decoder() -> Self::Decoder {
- MagicDecoder(ArrayDecoder::new())
- }
+ fn decoder() -> Self::Decoder { MagicDecoder(ArrayDecoder::new()) }
}
/// Errors occuring when decoding a network [`Magic`].
@@ -573,9 +571,7 @@ impl fmt::Display for MagicDecoderError {
#[cfg(feature = "std")]
impl std::error::Error for MagicDecoderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- Some(&self.0)
- }
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
impl AsRef<[u8]> for Magic {
diff --git a/p2p/src/merkle_tree.rs b/p2p/src/merkle_tree.rs
index 7472d132..35efd03d 100644
--- a/p2p/src/merkle_tree.rs
+++ b/p2p/src/merkle_tree.rs
@@ -17,9 +17,11 @@ use core::fmt;
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt, MAX_VEC_SIZE};
-use encoding::{ArrayDecoder, ArrayEncoder, ByteVecDecoder, CompactSizeEncoder, Decoder2, Decoder3, Encoder2, Encoder3, SliceEncoder, VecDecoder};
-use internals::ToU64 as _;
-use internals::write_err;
+use encoding::{
+ ArrayDecoder, ArrayEncoder, ByteVecDecoder, CompactSizeEncoder, Decoder2, Decoder3, Encoder2,
+ Encoder3, SliceEncoder, VecDecoder,
+};
+use internals::{write_err, ToU64 as _};
use io::{BufRead, Write};
use primitives::block::{self, Block, Checked, HeaderDecoder, HeaderEncoder};
use primitives::merkle_tree::TxMerkleNode;
@@ -134,9 +136,7 @@ impl encoding::Encodable for MerkleBlock {
type Encoder<'e> = MerkleBlockEncoder<'e>;
fn encoder(&self) -> Self::Encoder<'_> {
- MerkleBlockEncoder::new(
- Encoder2::new(self.header.encoder(), self.txn.encoder())
- )
+ MerkleBlockEncoder::new(Encoder2::new(self.header.encoder(), self.txn.encoder()))
}
}
@@ -491,10 +491,7 @@ impl BitVecEncoder {
}
buffer.push(byte);
}
- Self {
- buffer,
- exhausted: false,
- }
+ Self { buffer, exhausted: false }
}
}
@@ -528,23 +525,22 @@ impl encoding::Encodable for PartialMerkleTree {
type Encoder<'e> = PartialMerkleTreeEncoder<'e>;
fn encoder(&self) -> Self::Encoder<'_> {
- PartialMerkleTreeEncoder::new(
- Encoder3::new(
- ArrayEncoder::without_length_prefix(self.num_transactions.to_le_bytes()),
- Encoder2::new(
- CompactSizeEncoder::new(self.hashes.len()),
- SliceEncoder::without_length_prefix(&self.hashes),
- ),
- Encoder2::new(
- CompactSizeEncoder::new(self.bits.len().div_ceil(8)),
- BitVecEncoder::new(&self.bits)
- ),
- )
- )
+ PartialMerkleTreeEncoder::new(Encoder3::new(
+ ArrayEncoder::without_length_prefix(self.num_transactions.to_le_bytes()),
+ Encoder2::new(
+ CompactSizeEncoder::new(self.hashes.len()),
+ SliceEncoder::without_length_prefix(&self.hashes),
+ ),
+ Encoder2::new(
+ CompactSizeEncoder::new(self.bits.len().div_ceil(8)),
+ BitVecEncoder::new(&self.bits),
+ ),
+ ))
}
}
-type PartialMerkleTreeInnerDecoder = Decoder3<ArrayDecoder<4>, VecDecoder<TxMerkleNode>, ByteVecDecoder>;
+type PartialMerkleTreeInnerDecoder =
+ Decoder3<ArrayDecoder<4>, VecDecoder<TxMerkleNode>, ByteVecDecoder>;
/// The decoder type for a [`PartialMerkleTree`].
pub struct PartialMerkleTreeDecoder(PartialMerkleTreeInnerDecoder);
@@ -560,7 +556,8 @@ impl encoding::Decoder for PartialMerkleTreeDecoder {
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
- let (num_transactions, hashes, compress_bit_vec) = self.0.end().map_err(PartialMerkleTreeDecoderError)?;
+ let (num_transactions, hashes, compress_bit_vec) =
+ self.0.end().map_err(PartialMerkleTreeDecoderError)?;
let num_transactions = u32::from_le_bytes(num_transactions);
let mut bits = Vec::with_capacity(compress_bit_vec.len());
for byte in compress_bit_vec {
@@ -568,11 +565,7 @@ impl encoding::Decoder for PartialMerkleTreeDecoder {
bits.push((byte & (1 << i)) != 0);
}
}
- Ok(PartialMerkleTree {
- num_transactions,
- bits,
- hashes
- })
+ Ok(PartialMerkleTree { num_transactions, bits, hashes })
}
#[inline]
@@ -583,15 +576,19 @@ impl encoding::Decodable for PartialMerkleTree {
type Decoder = PartialMerkleTreeDecoder;
fn decoder() -> Self::Decoder {
- PartialMerkleTreeDecoder(
- Decoder3::new(ArrayDecoder::new(),VecDecoder::new(), ByteVecDecoder::new())
- )
+ PartialMerkleTreeDecoder(Decoder3::new(
+ ArrayDecoder::new(),
+ VecDecoder::new(),
+ ByteVecDecoder::new(),
+ ))
}
}
/// An error occuring when decoding a [`PartialMerkleTree`].
#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct PartialMerkleTreeDecoderError(<PartialMerkleTreeInnerDecoder as encoding::Decoder>::Error);
+pub struct PartialMerkleTreeDecoderError(
+ <PartialMerkleTreeInnerDecoder as encoding::Decoder>::Error,
+);
impl From<Infallible> for PartialMerkleTreeDecoderError {
fn from(never: Infallible) -> Self { match never {} }
diff --git a/p2p/src/message.rs b/p2p/src/message.rs
index 89a84311..2b8de0d0 100644
--- a/p2p/src/message.rs
+++ b/p2p/src/message.rs
@@ -16,11 +16,15 @@ use core::{cmp, fmt};
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
-use encoding::{self, ArrayDecoder, ArrayEncoder, CompactSizeEncoder, Decoder2, Encoder2, SliceEncoder, VecDecoder};
+use encoding::{
+ self, ArrayDecoder, ArrayEncoder, CompactSizeEncoder, Decoder2, Encoder2, SliceEncoder,
+ VecDecoder,
+};
use hashes::sha256d;
use internals::{write_err, ToU64 as _};
use io::{self, BufRead, Read, Write};
-use primitives::{block::{self, HeaderDecoder, HeaderEncoder}, transaction};
+use primitives::block::{self, HeaderDecoder, HeaderEncoder};
+use primitives::transaction;
use units::FeeRate;
use crate::address::{AddrV2Message, Address};
@@ -1382,9 +1386,7 @@ pub struct NetworkHeader {
impl NetworkHeader {
/// Create a new [`NetworkHeader`] from underlying block header.
- pub const fn from_header(header: block::Header) -> Self {
- Self { header, length: 0 }
- }
+ pub const fn from_header(header: block::Header) -> Self { Self { header, length: 0 } }
}
encoding::encoder_newtype! {
@@ -1420,10 +1422,7 @@ impl encoding::Decoder for NetworkHeaderDecoder {
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
let (header, length) = self.0.end().map_err(NetworkHeaderDecoderError)?;
- Ok(NetworkHeader {
- header,
- length: u8::from_le_bytes(length),
- })
+ Ok(NetworkHeader { header, length: u8::from_le_bytes(length) })
}
#[inline]
@@ -1434,9 +1433,7 @@ impl encoding::Decodable for NetworkHeader {
type Decoder = NetworkHeaderDecoder;
fn decoder() -> Self::Decoder {
- NetworkHeaderDecoder(
- Decoder2::new(block::Header::decoder(), ArrayDecoder::new()),
- )
+ NetworkHeaderDecoder(Decoder2::new(block::Header::decoder(), ArrayDecoder::new()))
}
}
@@ -1460,13 +1457,8 @@ impl std::error::Error for NetworkHeaderDecoderError {
}
impl Decodable for NetworkHeader {
- fn consensus_decode<R: BufRead + ?Sized>(
- reader: &mut R,
- ) -> Result<Self, encode::Error> {
- Ok(Self {
- header: Decodable::consensus_decode(reader)?,
- length: reader.read_u8()?,
- })
+ fn consensus_decode<R: BufRead + ?Sized>(reader: &mut R) -> Result<Self, encode::Error> {
+ Ok(Self { header: Decodable::consensus_decode(reader)?, length: reader.read_u8()? })
}
}
@@ -1508,12 +1500,10 @@ impl encoding::Encodable for HeadersMessage {
type Encoder<'e> = HeadersMessageEncoder<'e>;
fn encoder(&self) -> Self::Encoder<'_> {
- HeadersMessageEncoder::new(
- Encoder2::new(
- CompactSizeEncoder::new(self.0.len()),
- SliceEncoder::without_length_prefix(&self.0)
- )
- )
+ HeadersMessageEncoder::new(Encoder2::new(
+ CompactSizeEncoder::new(self.0.len()),
+ SliceEncoder::without_length_prefix(&self.0),
+ ))
}
}
@@ -1544,9 +1534,7 @@ impl encoding::Decoder for HeadersMessageDecoder {
impl encoding::Decodable for HeadersMessage {
type Decoder = HeadersMessageDecoder;
- fn decoder() -> Self::Decoder {
- HeadersMessageDecoder(VecDecoder::new())
- }
+ fn decoder() -> Self::Decoder { HeadersMessageDecoder(VecDecoder::new()) }
}
/// An error decoding a [`HeadersMessage`] message.
diff --git a/primitives/src/hash_types/block_hash.rs b/primitives/src/hash_types/block_hash.rs
index 0bd98500..14a71806 100644
--- a/primitives/src/hash_types/block_hash.rs
+++ b/primitives/src/hash_types/block_hash.rs
@@ -39,7 +39,9 @@ encoding::encoder_newtype_exact! {
impl Encodable for BlockHash {
type Encoder<'e> = BlockHashEncoder<'e>;
fn encoder(&self) -> Self::Encoder<'_> {
- BlockHashEncoder::new(encoding::ArrayRefEncoder::without_length_prefix(self.as_byte_array()))
+ BlockHashEncoder::new(encoding::ArrayRefEncoder::without_length_prefix(
+ self.as_byte_array(),
+ ))
}
}
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 890cd4e0..45cf7dff 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -452,10 +452,9 @@ impl Decoder for TransactionDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- use {
- TransactionDecoderError as E, TransactionDecoderErrorInner as Inner,
- TransactionDecoderState as State,
- };
+ use TransactionDecoderError as E;
+ use TransactionDecoderErrorInner as Inner;
+ use TransactionDecoderState as State;
loop {
// Attempt to push to the currently-active decoder and return early on success.
@@ -578,10 +577,9 @@ impl Decoder for TransactionDecoder {
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
- use {
- TransactionDecoderError as E, TransactionDecoderErrorInner as Inner,
- TransactionDecoderState as State,
- };
+ use TransactionDecoderError as E;
+ use TransactionDecoderErrorInner as Inner;
+ use TransactionDecoderState as State;
match self.state {
State::Version(_) => Err(E(Inner::EarlyEnd("version"))),
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index df4ba897..fc114b50 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -352,7 +352,8 @@ impl Decoder for WitnessDecoder {
type Error = WitnessDecoderError;
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- use {WitnessDecoderError as E, WitnessDecoderErrorInner as Inner};
+ use WitnessDecoderError as E;
+ use WitnessDecoderErrorInner as Inner;
// Read initial witness element count.
if self.witness_elements.is_none() {
@@ -462,7 +463,8 @@ impl Decoder for WitnessDecoder {
}
fn end(mut self) -> Result<Self::Output, Self::Error> {
- use {WitnessDecoderError as E, WitnessDecoderErrorInner as Inner};
+ use WitnessDecoderError as E;
+ use WitnessDecoderErrorInner as Inner;
let Some(witness_elements) = self.witness_elements else {
// Never read the witness element count.
@@ -683,9 +685,7 @@ impl<T: AsRef<[u8]>> FromIterator<T> for Witness {
let _ = decoder.push_bytes(&mut buffer.as_slice());
- decoder
- .end()
- .expect("witness_elements in decoder is equal to number of provided elements")
+ decoder.end().expect("witness_elements in decoder is equal to number of provided elements")
}
}
diff --git a/units/src/pow.rs b/units/src/pow.rs
index c80dea06..e1040fa6 100644
--- a/units/src/pow.rs
+++ b/units/src/pow.rs
@@ -56,7 +56,7 @@ impl CompactTarget {
/// - If the input string is not a valid hex encoding of a `u32`.
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError>
where
- Self: Sized
+ Self: Sized,
{
let target = parse_int::hex_u32_prefixed(s)?;
Ok(Self::from_consensus(target))
@@ -70,7 +70,7 @@ impl CompactTarget {
/// - If the input string is not a valid hex encoding of a `u32`.
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError>
where
- Self: Sized
+ Self: Sized,
{
let target = parse_int::hex_u32_unprefixed(s)?;
Ok(Self::from_consensus(target))
diff --git a/units/tests/api.rs b/units/tests/api.rs
index 9244e47c..167db030 100644
--- a/units/tests/api.rs
+++ b/units/tests/api.rs
@@ -271,7 +271,9 @@ fn api_can_use_all_types_from_module_parse() {
fn api_can_use_all_types_from_module_pow() {
use bitcoin_units::pow::CompactTarget;
#[cfg(feature = "encoding")]
- use bitcoin_units::pow::{CompactTargetDecoder, CompactTargetDecoderError, CompactTargetEncoder};
+ use bitcoin_units::pow::{
+ CompactTargetDecoder, CompactTargetDecoderError, CompactTargetEncoder,
+ };
}
#[test]
@@ -366,8 +368,14 @@ fn api_all_wrapper_types_fmt_as_inner() {
assert_format_matches!(BlockMtp::from(rand_num), rand_num);
assert_format_matches!(BlockMtpInterval::from(rand_num), rand_num);
assert_format_matches!(BlockTime::from(rand_num), rand_num);
- assert_format_matches!(relative::NumberOfBlocks::from_height(rand_num as u16), rand_num as u16);
- assert_format_matches!(relative::NumberOf512Seconds::from_512_second_intervals(rand_num as u16), rand_num as u16);
+ assert_format_matches!(
+ relative::NumberOfBlocks::from_height(rand_num as u16),
+ rand_num as u16
+ );
+ assert_format_matches!(
+ relative::NumberOf512Seconds::from_512_second_intervals(rand_num as u16),
+ rand_num as u16
+ );
assert_format_matches!(Sequence::from_consensus(rand_num), rand_num);
assert_format_matches!(Weight::from_wu(rand_num.into()), u64::from(rand_num));
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.