Skip to content

Commit 59c2d60

Browse files
Fmt Botgithub-actions[bot]
Fmt Bot
authored andcommitted
2025-03-30 automated rustfmt nightly
1 parent afcfc13 commit 59c2d60

File tree

25 files changed

+198
-230
lines changed

25 files changed

+198
-230
lines changed

base58/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ pub fn decode(data: &str) -> Result<Vec<u8>, InvalidCharacterError> {
113113
/// Decodes a base58check-encoded string into a byte vector verifying the checksum.
114114
pub fn decode_check(data: &str) -> Result<Vec<u8>, Error> {
115115
let mut ret: Vec<u8> = decode(data)?;
116-
let (remaining, &data_check) = ret.split_last_chunk::<4>().ok_or(TooShortError { length: ret.len() })?;
116+
let (remaining, &data_check) =
117+
ret.split_last_chunk::<4>().ok_or(TooShortError { length: ret.len() })?;
117118

118119
let hash_check = *sha256d::Hash::hash(remaining).as_byte_array().sub_array::<0, 4>();
119120

bitcoin/src/address/mod.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ struct DisplayUnchecked<'a, N: NetworkValidation>(&'a Address<N>);
409409

410410
#[cfg(feature = "serde")]
411411
impl<N: NetworkValidation> fmt::Display for DisplayUnchecked<'_, N> {
412-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0.inner(), fmt) }
412+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
413+
fmt::Display::fmt(&self.0.inner(), fmt)
414+
}
413415
}
414416

415417
#[cfg(feature = "serde")]
@@ -459,25 +461,21 @@ impl<V: NetworkValidation> serde::Serialize for Address<V> {
459461
/// Methods on [`Address`] that can be called on both `Address<NetworkChecked>` and
460462
/// `Address<NetworkUnchecked>`.
461463
impl<V: NetworkValidation> Address<V> {
462-
fn from_inner(inner: AddressInner) -> Self {
463-
Address(PhantomData, inner)
464-
}
464+
fn from_inner(inner: AddressInner) -> Self { Address(PhantomData, inner) }
465465

466-
fn into_inner(self) -> AddressInner {
467-
self.1
468-
}
466+
fn into_inner(self) -> AddressInner { self.1 }
469467

470-
fn inner(&self) -> &AddressInner {
471-
&self.1
472-
}
468+
fn inner(&self) -> &AddressInner { &self.1 }
473469

474470
/// Returns a reference to the address as if it was unchecked.
475471
pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> {
476472
Address::from_inner_ref(self.inner())
477473
}
478474

479475
/// Marks the network of this address as unchecked.
480-
pub fn into_unchecked(self) -> Address<NetworkUnchecked> { Address::from_inner(self.into_inner()) }
476+
pub fn into_unchecked(self) -> Address<NetworkUnchecked> {
477+
Address::from_inner(self.into_inner())
478+
}
481479

482480
/// Returns the [`NetworkKind`] of this address.
483481
pub fn network_kind(&self) -> NetworkKind {
@@ -807,9 +805,7 @@ impl Address<NetworkUnchecked> {
807805
/// Returns a reference to the checked address.
808806
///
809807
/// This function is dangerous in case the address is not a valid checked address.
810-
pub fn assume_checked_ref(&self) -> &Address {
811-
Address::from_inner_ref(self.inner())
812-
}
808+
pub fn assume_checked_ref(&self) -> &Address { Address::from_inner_ref(self.inner()) }
813809

814810
/// Parsed addresses do not always have *one* network. The problem is that legacy testnet,
815811
/// regtest and signet addresses use the same prefix instead of multiple different ones. When
@@ -920,7 +916,8 @@ impl Address<NetworkUnchecked> {
920916
return Err(LegacyAddressTooLongError { length: s.len() }.into());
921917
}
922918
let data = base58::decode_check(s)?;
923-
let data: &[u8; 21] = (&*data).try_into().map_err(|_| InvalidBase58PayloadLengthError { length: s.len() })?;
919+
let data: &[u8; 21] =
920+
(&*data).try_into().map_err(|_| InvalidBase58PayloadLengthError { length: s.len() })?;
924921

925922
let (prefix, &data) = data.split_first();
926923

bitcoin/src/bip152.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use core::{convert, fmt, mem};
1010
use std::error;
1111

1212
use hashes::{sha256, siphash24};
13-
use internals::{ToU64 as _, array::ArrayExt as _};
13+
use internals::array::ArrayExt as _;
14+
use internals::ToU64 as _;
1415
use io::{BufRead, Write};
1516

1617
use crate::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};

bitcoin/src/bip158.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ use core::convert::Infallible;
4242
use core::fmt;
4343

4444
use hashes::{sha256d, siphash24, HashEngine as _};
45-
use internals::{write_err, ToU64 as _, array::ArrayExt as _};
45+
use internals::array::ArrayExt as _;
46+
use internals::{write_err, ToU64 as _};
4647
use io::{BufRead, Write};
4748

4849
use crate::block::{Block, BlockHash, Checked};

bitcoin/src/bip32.rs

+11-23
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,9 @@ impl Xpriv {
682682

683683
engine.input(&u32::from(i).to_be_bytes());
684684
let hmac: Hmac<sha512::Hash> = engine.finalize();
685-
let sk = secp256k1::SecretKey::from_byte_array(
686-
hmac.as_byte_array().split_array::<32, 32>().0,
687-
)
688-
.expect("statistically impossible to hit");
685+
let sk =
686+
secp256k1::SecretKey::from_byte_array(hmac.as_byte_array().split_array::<32, 32>().0)
687+
.expect("statistically impossible to hit");
689688
let tweaked =
690689
sk.add_tweak(&self.private_key.into()).expect("statistically impossible to hit");
691690

@@ -701,14 +700,8 @@ impl Xpriv {
701700

702701
/// Decoding extended private key from binary data according to BIP 32
703702
pub fn decode(data: &[u8]) -> Result<Xpriv, Error> {
704-
let Common {
705-
network,
706-
depth,
707-
parent_fingerprint,
708-
child_number,
709-
chain_code,
710-
key,
711-
} = Common::decode(data)?;
703+
let Common { network, depth, parent_fingerprint, child_number, chain_code, key } =
704+
Common::decode(data)?;
712705

713706
let network = match network {
714707
VERSION_BYTES_MAINNET_PRIVATE => NetworkKind::Main,
@@ -834,7 +827,7 @@ impl Xpub {
834827

835828
let hmac = engine.finalize();
836829
let private_key = secp256k1::SecretKey::from_byte_array(
837-
hmac.as_byte_array().split_array::<32, 32>().0
830+
hmac.as_byte_array().split_array::<32, 32>().0,
838831
)?;
839832
let chain_code = ChainCode::from_hmac(hmac);
840833
Ok((private_key, chain_code))
@@ -863,14 +856,8 @@ impl Xpub {
863856

864857
/// Decoding extended public key from binary data according to BIP 32
865858
pub fn decode(data: &[u8]) -> Result<Xpub, Error> {
866-
let Common {
867-
network,
868-
depth,
869-
parent_fingerprint,
870-
child_number,
871-
chain_code,
872-
key,
873-
} = Common::decode(data)?;
859+
let Common { network, depth, parent_fingerprint, child_number, chain_code, key } =
860+
Common::decode(data)?;
874861

875862
let network = match network {
876863
VERSION_BYTES_MAINNET_PUBLIC => NetworkKind::Main,
@@ -994,13 +981,14 @@ struct Common {
994981
parent_fingerprint: Fingerprint,
995982
child_number: ChildNumber,
996983
chain_code: ChainCode,
997-
// public key (compressed) or 0 byte followed by a private key
984+
// public key (compressed) or 0 byte followed by a private key
998985
key: [u8; 33],
999986
}
1000987

1001988
impl Common {
1002989
fn decode(data: &[u8]) -> Result<Self, Error> {
1003-
let data: &[u8; 78] = data.try_into().map_err(|_| Error::WrongExtendedKeyLength(data.len()))?;
990+
let data: &[u8; 78] =
991+
data.try_into().map_err(|_| Error::WrongExtendedKeyLength(data.len()))?;
1004992

1005993
let (&network, data) = data.split_array::<4, 74>();
1006994
let (&depth, data) = data.split_first::<73>();

bitcoin/src/blockdata/script/push_bytes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ mod primitive {
5858
}
5959

6060
impl PushBytes {
61-
6261
/// Constructs an empty `&PushBytes`.
6362
pub fn empty() -> &'static Self { Self::from_slice_unchecked(&[]) }
6463

bitcoin/src/blockdata/witness.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::crypto::key::SerializedXOnlyPublicKey;
1414
use crate::prelude::Vec;
1515
#[cfg(doc)]
1616
use crate::script::ScriptExt as _;
17-
use crate::taproot::{self, ControlBlock, LeafScript, TAPROOT_ANNEX_PREFIX, TaprootMerkleBranch};
17+
use crate::taproot::{self, ControlBlock, LeafScript, TaprootMerkleBranch, TAPROOT_ANNEX_PREFIX};
1818
use crate::Script;
1919

2020
type BorrowedControlBlock<'a> = ControlBlock<&'a TaprootMerkleBranch, &'a SerializedXOnlyPublicKey>;
@@ -387,7 +387,8 @@ mod test {
387387
#[test]
388388
fn get_tapscript() {
389389
let tapscript = hex!("deadbeef");
390-
let control_block = hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
390+
let control_block =
391+
hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
391392
// annex starting with 0x50 causes the branching logic.
392393
let annex = hex!("50");
393394

@@ -435,7 +436,8 @@ mod test {
435436
#[test]
436437
fn get_control_block() {
437438
let tapscript = hex!("deadbeef");
438-
let control_block = hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
439+
let control_block =
440+
hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
439441
let expected_control_block = BorrowedControlBlock::decode_borrowed(&control_block).unwrap();
440442
// annex starting with 0x50 causes the branching logic.
441443
let annex = hex!("50");
@@ -454,7 +456,8 @@ mod test {
454456
#[test]
455457
fn get_annex() {
456458
let tapscript = hex!("deadbeef");
457-
let control_block = hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
459+
let control_block =
460+
hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
458461
// annex starting with 0x50 causes the branching logic.
459462
let annex = hex!("50");
460463

bitcoin/src/crypto/key.rs

+8-23
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ use crate::taproot::{TapNodeHash, TapTweakHash};
2626

2727
#[rustfmt::skip] // Keep public re-exports separate.
2828
pub use secp256k1::{constants, Keypair, Parity, Secp256k1, Verification, XOnlyPublicKey};
29-
pub use serialized_x_only::SerializedXOnlyPublicKey;
30-
3129
#[cfg(feature = "rand-std")]
3230
pub use secp256k1::rand;
31+
pub use serialized_x_only::SerializedXOnlyPublicKey;
3332

3433
/// A Bitcoin ECDSA public key.
3534
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -528,17 +527,13 @@ impl PrivateKey {
528527
}
529528
};
530529

531-
Ok(PrivateKey {
532-
compressed,
533-
network,
534-
inner: secp256k1::SecretKey::from_byte_array(key)?,
535-
})
530+
Ok(PrivateKey { compressed, network, inner: secp256k1::SecretKey::from_byte_array(key)? })
536531
}
537532

538533
/// Returns a new private key with the negated secret value.
539534
///
540535
/// The resulting key corresponds to the same x-only public key (identical x-coordinate)
541-
/// but with the opposite y-coordinate parity. This is useful for ensuring compatibility
536+
/// but with the opposite y-coordinate parity. This is useful for ensuring compatibility
542537
/// with specific public key formats and BIP-340 requirements.
543538
#[inline]
544539
pub fn negate(&self) -> Self {
@@ -1239,19 +1234,13 @@ mod serialized_x_only {
12391234

12401235
impl SerializedXOnlyPublicKey {
12411236
/// Marks the supplied bytes as a serialized x-only public key.
1242-
pub const fn from_byte_array(bytes: [u8; 32]) -> Self {
1243-
Self(bytes)
1244-
}
1237+
pub const fn from_byte_array(bytes: [u8; 32]) -> Self { Self(bytes) }
12451238

12461239
/// Returns the raw bytes.
1247-
pub const fn to_byte_array(self) -> [u8; 32] {
1248-
self.0
1249-
}
1240+
pub const fn to_byte_array(self) -> [u8; 32] { self.0 }
12501241

12511242
/// Returns a reference to the raw bytes.
1252-
pub const fn as_byte_array(&self) -> &[u8; 32] {
1253-
&self.0
1254-
}
1243+
pub const fn as_byte_array(&self) -> &[u8; 32] { &self.0 }
12551244
}
12561245
}
12571246

@@ -1263,15 +1252,11 @@ impl SerializedXOnlyPublicKey {
12631252
}
12641253

12651254
impl AsRef<[u8; 32]> for SerializedXOnlyPublicKey {
1266-
fn as_ref(&self) -> &[u8; 32] {
1267-
self.as_byte_array()
1268-
}
1255+
fn as_ref(&self) -> &[u8; 32] { self.as_byte_array() }
12691256
}
12701257

12711258
impl From<&SerializedXOnlyPublicKey> for SerializedXOnlyPublicKey {
1272-
fn from(borrowed: &SerializedXOnlyPublicKey) -> Self {
1273-
*borrowed
1274-
}
1259+
fn from(borrowed: &SerializedXOnlyPublicKey) -> Self { *borrowed }
12751260
}
12761261

12771262
impl fmt::Debug for SerializedXOnlyPublicKey {

bitcoin/src/crypto/taproot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use core::fmt;
99

1010
#[cfg(feature = "arbitrary")]
1111
use arbitrary::{Arbitrary, Unstructured};
12-
use internals::write_err;
1312
use internals::array::ArrayExt;
13+
use internals::write_err;
1414
use io::Write;
1515

1616
use crate::prelude::Vec;

bitcoin/src/hash_types.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
//!
55
//! This module is deprecated. You can find hash types in their respective, hopefully obvious, modules.
66
7-
#[deprecated(since = "TBD", note = "use `crate::T` instead")]
8-
pub use crate::{
9-
BlockHash, TxMerkleNode, Txid, WitnessCommitment, WitnessMerkleNode,
10-
Wtxid,
11-
};
127
#[deprecated(since = "TBD", note = "use `crate::T` instead")]
138
pub use crate::bip158::{FilterHash, FilterHeader};
9+
#[deprecated(since = "TBD", note = "use `crate::T` instead")]
10+
pub use crate::{BlockHash, TxMerkleNode, Txid, WitnessCommitment, WitnessMerkleNode, Wtxid};
1411

1512
#[cfg(test)]
1613
mod tests {

bitcoin/src/p2p/message.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ mod test {
702702

703703
use super::*;
704704
use crate::bip152::BlockTransactionsRequest;
705-
use crate::bip158::{FilterHeader, FilterHash};
705+
use crate::bip158::{FilterHash, FilterHeader};
706706
use crate::block::{Block, BlockHash};
707707
use crate::consensus::encode::{deserialize, deserialize_partial, serialize};
708708
use crate::p2p::address::AddrV2;
@@ -738,19 +738,25 @@ mod test {
738738
45,
739739
Address::new(&([123, 255, 000, 100], 833).into(), ServiceFlags::NETWORK),
740740
)]),
741-
NetworkMessage::Inv(vec![Inventory::Block(BlockHash::from_byte_array(hash([8u8; 32]).to_byte_array()))]),
742-
NetworkMessage::GetData(vec![Inventory::Transaction(Txid::from_byte_array(hash([45u8; 32]).to_byte_array()))]),
741+
NetworkMessage::Inv(vec![Inventory::Block(BlockHash::from_byte_array(
742+
hash([8u8; 32]).to_byte_array(),
743+
))]),
744+
NetworkMessage::GetData(vec![Inventory::Transaction(Txid::from_byte_array(
745+
hash([45u8; 32]).to_byte_array(),
746+
))]),
743747
NetworkMessage::NotFound(vec![Inventory::Error([0u8; 32])]),
744748
NetworkMessage::GetBlocks(GetBlocksMessage::new(
745749
vec![
746750
BlockHash::from_byte_array(hash([1u8; 32]).to_byte_array()),
747-
BlockHash::from_byte_array(hash([4u8; 32]).to_byte_array())],
751+
BlockHash::from_byte_array(hash([4u8; 32]).to_byte_array()),
752+
],
748753
BlockHash::from_byte_array(hash([5u8; 32]).to_byte_array()),
749754
)),
750755
NetworkMessage::GetHeaders(GetHeadersMessage::new(
751756
vec![
752757
BlockHash::from_byte_array(hash([10u8; 32]).to_byte_array()),
753-
BlockHash::from_byte_array(hash([40u8; 32]).to_byte_array())],
758+
BlockHash::from_byte_array(hash([40u8; 32]).to_byte_array()),
759+
],
754760
BlockHash::from_byte_array(hash([50u8; 32]).to_byte_array()),
755761
)),
756762
NetworkMessage::MemPool,
@@ -791,8 +797,13 @@ mod test {
791797
NetworkMessage::CFHeaders(CFHeaders {
792798
filter_type: 13,
793799
stop_hash: BlockHash::from_byte_array(hash([53u8; 32]).to_byte_array()),
794-
previous_filter_header: FilterHeader::from_byte_array(hash([12u8; 32]).to_byte_array()),
795-
filter_hashes: vec![FilterHash::from_byte_array(hash([4u8; 32]).to_byte_array()), FilterHash::from_byte_array(hash([12u8; 32]).to_byte_array())],
800+
previous_filter_header: FilterHeader::from_byte_array(
801+
hash([12u8; 32]).to_byte_array(),
802+
),
803+
filter_hashes: vec![
804+
FilterHash::from_byte_array(hash([4u8; 32]).to_byte_array()),
805+
FilterHash::from_byte_array(hash([12u8; 32]).to_byte_array()),
806+
],
796807
}),
797808
NetworkMessage::GetCFCheckpt(GetCFCheckpt {
798809
filter_type: 17,
@@ -801,7 +812,10 @@ mod test {
801812
NetworkMessage::CFCheckpt(CFCheckpt {
802813
filter_type: 27,
803814
stop_hash: BlockHash::from_byte_array(hash([77u8; 32]).to_byte_array()),
804-
filter_headers: vec![FilterHeader::from_byte_array(hash([3u8; 32]).to_byte_array()), FilterHeader::from_byte_array(hash([99u8; 32]).to_byte_array())],
815+
filter_headers: vec![
816+
FilterHeader::from_byte_array(hash([3u8; 32]).to_byte_array()),
817+
FilterHeader::from_byte_array(hash([99u8; 32]).to_byte_array()),
818+
],
805819
}),
806820
NetworkMessage::Alert(vec![45, 66, 3, 2, 6, 8, 9, 12, 3, 130]),
807821
NetworkMessage::Reject(Reject {

bitcoin/src/psbt/serialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ impl Serialize for KeySource {
216216

217217
impl Deserialize for KeySource {
218218
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
219-
let (fingerprint, mut d) = bytes.split_first_chunk::<4>()
220-
.ok_or(io::Error::from(io::ErrorKind::UnexpectedEof))?;
219+
let (fingerprint, mut d) =
220+
bytes.split_first_chunk::<4>().ok_or(io::Error::from(io::ErrorKind::UnexpectedEof))?;
221221

222222
let fprint: Fingerprint = fingerprint.into();
223223
let mut dpath: Vec<ChildNumber> = Default::default();

0 commit comments

Comments
 (0)