Skip to content

Commit 887f9c5

Browse files
Fmt Botgithub-actions[bot]
authored andcommitted
2025-11-30 automated rustfmt nightly
1 parent b084993 commit 887f9c5

40 files changed

Lines changed: 167 additions & 385 deletions

File tree

bitcoin/examples/ecdsa-psbt-simple.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ const SPEND_AMOUNT: Amount = Amount::from_sat_u32(25_000_000);
5454
const CHANGE_AMOUNT: Amount = Amount::from_sat_u32(4_990_000); // 10_000 sat fee.
5555

5656
// Derive the external address xpriv.
57-
fn get_external_address_xpriv(
58-
master_xpriv: Xpriv,
59-
index: u32,
60-
) -> Xpriv {
57+
fn get_external_address_xpriv(master_xpriv: Xpriv, index: u32) -> Xpriv {
6158
let derivation_path =
6259
BIP84_DERIVATION_PATH.into_derivation_path().expect("valid derivation path");
6360
let child_xpriv =
@@ -69,10 +66,7 @@ fn get_external_address_xpriv(
6966
}
7067

7168
// Derive the internal address xpriv.
72-
fn get_internal_address_xpriv(
73-
master_xpriv: Xpriv,
74-
index: u32,
75-
) -> Xpriv {
69+
fn get_internal_address_xpriv(master_xpriv: Xpriv, index: u32) -> Xpriv {
7670
let derivation_path =
7771
BIP84_DERIVATION_PATH.into_derivation_path().expect("valid derivation path");
7872
let child_xpriv =

bitcoin/examples/ecdsa-psbt.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ impl ColdStorage {
113113
// Hardened children require secret data to derive.
114114

115115
let path = "84h/0h/0h".into_derivation_path()?;
116-
let account_0_xpriv =
117-
master_xpriv.derive_xpriv(&path).expect("derivation path is short");
116+
let account_0_xpriv = master_xpriv.derive_xpriv(&path).expect("derivation path is short");
118117
let account_0_xpub = Xpub::from_xpriv(&account_0_xpriv);
119118

120119
let path = INPUT_UTXO_DERIVATION_PATH.into_derivation_path()?;
@@ -131,10 +130,7 @@ impl ColdStorage {
131130
fn master_fingerprint(&self) -> Fingerprint { self.master_xpub.fingerprint() }
132131

133132
/// Signs `psbt` with this signer.
134-
fn sign_psbt(
135-
&self,
136-
mut psbt: Psbt,
137-
) -> Result<Psbt> {
133+
fn sign_psbt(&self, mut psbt: Psbt) -> Result<Psbt> {
138134
match psbt.sign(&self.master_xpriv) {
139135
Ok(keys) => assert_eq!(keys.len(), 1),
140136
Err((_, e)) => {
@@ -249,9 +245,7 @@ impl WatchOnly {
249245
/// "m/84h/0h/0h/1/0"). A real wallet would have access to the chain so could determine if an
250246
/// address has been used or not. We ignore this detail and just re-use the first change address
251247
/// without loss of generality.
252-
fn change_address(
253-
&self,
254-
) -> Result<(CompressedPublicKey, Address, DerivationPath)> {
248+
fn change_address(&self) -> Result<(CompressedPublicKey, Address, DerivationPath)> {
255249
let path = [ChildNumber::ONE_NORMAL, ChildNumber::ZERO_NORMAL];
256250
let derived = self.account_0_xpub.derive_xpub(path)?;
257251

bitcoin/examples/taproot-psbt-simple.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ const SPEND_AMOUNT: Amount = Amount::from_sat_u32(25_000_000);
5252
const CHANGE_AMOUNT: Amount = Amount::from_sat_u32(4_990_000); // 10_000 sat fee.
5353

5454
// Derive the external address xpriv.
55-
fn get_external_address_xpriv(
56-
master_xpriv: Xpriv,
57-
index: u32,
58-
) -> Xpriv {
55+
fn get_external_address_xpriv(master_xpriv: Xpriv, index: u32) -> Xpriv {
5956
let derivation_path =
6057
BIP86_DERIVATION_PATH.into_derivation_path().expect("valid derivation path");
6158
let child_xpriv =
@@ -67,10 +64,7 @@ fn get_external_address_xpriv(
6764
}
6865

6966
// Derive the internal address xpriv.
70-
fn get_internal_address_xpriv(
71-
master_xpriv: Xpriv,
72-
index: u32,
73-
) -> Xpriv {
67+
fn get_internal_address_xpriv(master_xpriv: Xpriv, index: u32) -> Xpriv {
7468
let derivation_path =
7569
BIP86_DERIVATION_PATH.into_derivation_path().expect("valid derivation path");
7670
let child_xpriv =

bitcoin/examples/taproot-psbt.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ fn generate_bip86_key_spend_tx(
291291
.get(&input.tap_internal_key.ok_or("internal key missing in PSBT")?)
292292
.ok_or("missing Taproot key origin")?;
293293

294-
let secret_key =
295-
master_xpriv.derive_xpriv(derivation_path)?.to_private_key().inner;
294+
let secret_key = master_xpriv.derive_xpriv(derivation_path)?.to_private_key().inner;
296295
sign_psbt_taproot(
297296
secret_key,
298297
input.tap_internal_key.unwrap(),
@@ -482,10 +481,8 @@ impl BenefactorWallet {
482481
.derive_xpriv(&new_derivation_path)
483482
.expect("derivation path is short")
484483
.to_keypair();
485-
let beneficiary_key = self
486-
.beneficiary_xpub
487-
.derive_xpub(&new_derivation_path)?
488-
.to_x_only_public_key();
484+
let beneficiary_key =
485+
self.beneficiary_xpub.derive_xpub(&new_derivation_path)?.to_x_only_public_key();
489486

490487
// Build up the leaf script and combine with internal key into a Taproot commitment
491488
let lock_time = absolute::LockTime::from_height(

bitcoin/src/bip152.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,7 @@ impl BlockTransactions {
402402

403403
#[cfg(feature = "arbitrary")]
404404
impl<'a> Arbitrary<'a> for ShortId {
405-
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
406-
Ok(Self(u.arbitrary()?))
407-
}
405+
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> { Ok(Self(u.arbitrary()?)) }
408406
}
409407

410408
#[cfg(feature = "arbitrary")]
@@ -429,20 +427,14 @@ impl<'a> Arbitrary<'a> for HeaderAndShortIds {
429427
#[cfg(feature = "arbitrary")]
430428
impl<'a> Arbitrary<'a> for BlockTransactions {
431429
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
432-
Ok(Self {
433-
block_hash: u.arbitrary()?,
434-
transactions: Vec::<Transaction>::arbitrary(u)?,
435-
})
430+
Ok(Self { block_hash: u.arbitrary()?, transactions: Vec::<Transaction>::arbitrary(u)? })
436431
}
437432
}
438433

439434
#[cfg(feature = "arbitrary")]
440435
impl<'a> Arbitrary<'a> for BlockTransactionsRequest {
441436
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
442-
Ok(Self {
443-
block_hash: u.arbitrary()?,
444-
indexes: Vec::<u64>::arbitrary(u)?,
445-
})
437+
Ok(Self { block_hash: u.arbitrary()?, indexes: Vec::<u64>::arbitrary(u)? })
446438
}
447439
}
448440

bitcoin/src/bip158.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,7 @@ pub struct BitStreamReader<'a, R: ?Sized> {
490490

491491
impl<'a, R: BufRead + ?Sized> BitStreamReader<'a, R> {
492492
/// Constructs a new [`BitStreamReader`] that reads bitwise from a given `reader`.
493-
pub fn new(reader: &'a mut R) -> Self {
494-
BitStreamReader { buffer: [0u8], reader, offset: 8 }
495-
}
493+
pub fn new(reader: &'a mut R) -> Self { BitStreamReader { buffer: [0u8], reader, offset: 8 } }
496494

497495
/// Reads nbit bits, returning the bits in a `u64` starting with the rightmost bit.
498496
///
@@ -538,9 +536,7 @@ pub struct BitStreamWriter<'a, W> {
538536

539537
impl<'a, W: Write> BitStreamWriter<'a, W> {
540538
/// Constructs a new [`BitStreamWriter`] that writes bitwise to a given `writer`.
541-
pub fn new(writer: &'a mut W) -> Self {
542-
BitStreamWriter { buffer: [0u8], writer, offset: 0 }
543-
}
539+
pub fn new(writer: &'a mut W) -> Self { BitStreamWriter { buffer: [0u8], writer, offset: 0 } }
544540

545541
/// Writes nbits bits from data.
546542
pub fn write(&mut self, data: u64, mut nbits: u8) -> Result<usize, io::Error> {

bitcoin/src/bip32.rs

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,7 @@ impl From<base58::Error> for ParseError {
619619
}
620620

621621
impl From<InvalidBase58PayloadLengthError> for ParseError {
622-
fn from(e: InvalidBase58PayloadLengthError) -> Self {
623-
Self::InvalidBase58PayloadLength(e)
624-
}
622+
fn from(e: InvalidBase58PayloadLengthError) -> Self { Self::InvalidBase58PayloadLength(e) }
625623
}
626624

627625
/// A BIP-0032 error
@@ -737,9 +735,7 @@ impl Xpriv {
737735
}
738736

739737
/// Constructs a new extended public key from this extended private key.
740-
pub fn to_xpub(self) -> Xpub {
741-
Xpub::from_xpriv(&self)
742-
}
738+
pub fn to_xpub(self) -> Xpub { Xpub::from_xpriv(&self) }
743739

744740
/// Constructs a new BIP-0340 keypair for Schnorr signatures and Taproot use matching the internal
745741
/// secret key representation.
@@ -752,20 +748,14 @@ impl Xpriv {
752748
///
753749
/// The `path` argument can be both of type `DerivationPath` or `Vec<ChildNumber>`.
754750
#[deprecated(since = "TBD", note = "use `derive_xpriv()` instead")]
755-
pub fn derive_priv<P: AsRef<[ChildNumber]>>(
756-
&self,
757-
path: P,
758-
) -> Result<Self, DerivationError> {
751+
pub fn derive_priv<P: AsRef<[ChildNumber]>>(&self, path: P) -> Result<Self, DerivationError> {
759752
self.derive_xpriv(path)
760753
}
761754

762755
/// Derives an extended private key from a path.
763756
///
764757
/// The `path` argument can be both of type `DerivationPath` or `Vec<ChildNumber>`.
765-
pub fn derive_xpriv<P: AsRef<[ChildNumber]>>(
766-
&self,
767-
path: P,
768-
) -> Result<Self, DerivationError> {
758+
pub fn derive_xpriv<P: AsRef<[ChildNumber]>>(&self, path: P) -> Result<Self, DerivationError> {
769759
let mut sk: Self = *self;
770760
for cnum in path.as_ref() {
771761
sk = sk.ckd_priv(*cnum)?;
@@ -774,10 +764,7 @@ impl Xpriv {
774764
}
775765

776766
/// Private->Private child key derivation
777-
fn ckd_priv(
778-
&self,
779-
i: ChildNumber,
780-
) -> Result<Self, DerivationError> {
767+
fn ckd_priv(&self, i: ChildNumber) -> Result<Self, DerivationError> {
781768
let mut engine = HmacEngine::<sha512::HashEngine>::new(&self.chain_code[..]);
782769
match i {
783770
ChildNumber::Normal { .. } => {
@@ -795,9 +782,10 @@ impl Xpriv {
795782

796783
engine.input(&u32::from(i).to_be_bytes());
797784
let hmac: Hmac<sha512::Hash> = engine.finalize();
798-
let sk =
799-
secp256k1::SecretKey::from_secret_bytes(*hmac.as_byte_array().split_array::<32, 32>().0)
800-
.expect("statistically impossible to hit");
785+
let sk = secp256k1::SecretKey::from_secret_bytes(
786+
*hmac.as_byte_array().split_array::<32, 32>().0,
787+
)
788+
.expect("statistically impossible to hit");
801789
let tweaked =
802790
sk.add_tweak(&self.private_key.into()).expect("statistically impossible to hit");
803791

@@ -854,9 +842,7 @@ impl Xpriv {
854842
}
855843

856844
/// Returns the HASH160 of the public key belonging to the xpriv
857-
pub fn identifier(&self) -> XKeyIdentifier {
858-
Xpub::from_xpriv(self).identifier()
859-
}
845+
pub fn identifier(&self) -> XKeyIdentifier { Xpub::from_xpriv(self).identifier() }
860846

861847
/// Returns the first four bytes of the identifier
862848
pub fn fingerprint(&self) -> Fingerprint {
@@ -867,9 +853,7 @@ impl Xpriv {
867853
impl Xpub {
868854
/// Constructs a new extended public key from an extended private key.
869855
#[deprecated(since = "TBD", note = "use `from_xpriv()` instead")]
870-
pub fn from_priv(sk: &Xpriv) -> Self {
871-
Self::from_xpriv(sk)
872-
}
856+
pub fn from_priv(sk: &Xpriv) -> Self { Self::from_xpriv(sk) }
873857

874858
/// Constructs a new extended public key from an extended private key.
875859
pub fn from_xpriv(xpriv: &Xpriv) -> Self {
@@ -903,20 +887,14 @@ impl Xpub {
903887
///
904888
/// The `path` argument can be any type implementing `AsRef<ChildNumber>`, such as `DerivationPath`, for instance.
905889
#[deprecated(since = "TBD", note = "use `derive_xpub()` instead")]
906-
pub fn derive_pub<P: AsRef<[ChildNumber]>>(
907-
&self,
908-
path: P,
909-
) -> Result<Self, DerivationError> {
890+
pub fn derive_pub<P: AsRef<[ChildNumber]>>(&self, path: P) -> Result<Self, DerivationError> {
910891
self.derive_xpub(path)
911892
}
912893

913894
/// Attempts to derive an extended public key from a path.
914895
///
915896
/// The `path` argument can be any type implementing `AsRef<ChildNumber>`, such as `DerivationPath`, for instance.
916-
pub fn derive_xpub<P: AsRef<[ChildNumber]>>(
917-
&self,
918-
path: P,
919-
) -> Result<Self, DerivationError> {
897+
pub fn derive_xpub<P: AsRef<[ChildNumber]>>(&self, path: P) -> Result<Self, DerivationError> {
920898
let mut pk: Self = *self;
921899
for cnum in path.as_ref() {
922900
pk = pk.ckd_pub(*cnum)?
@@ -948,10 +926,7 @@ impl Xpub {
948926
}
949927

950928
/// Public->Public child key derivation
951-
pub fn ckd_pub(
952-
&self,
953-
i: ChildNumber,
954-
) -> Result<Self, DerivationError> {
929+
pub fn ckd_pub(&self, i: ChildNumber) -> Result<Self, DerivationError> {
955930
let (sk, chain_code) = self.ckd_pub_tweak(i)?;
956931
let tweaked =
957932
self.public_key.add_exp_tweak(&sk.into()).expect("cryptographically unreachable");
@@ -1307,10 +1282,7 @@ mod tests {
13071282
// Check derivation convenience method for Xpub, should error
13081283
// appropriately if any ChildNumber is hardened
13091284
if path.0.iter().any(|cnum| cnum.is_hardened()) {
1310-
assert_eq!(
1311-
pk.derive_xpub(&path),
1312-
Err(DerivationError::CannotDeriveHardenedChild)
1313-
);
1285+
assert_eq!(pk.derive_xpub(&path), Err(DerivationError::CannotDeriveHardenedChild));
13141286
} else {
13151287
assert_eq!(&pk.derive_xpub(&path).unwrap().to_string()[..], expected_pk);
13161288
}
@@ -1325,10 +1297,7 @@ mod tests {
13251297
assert_eq!(pk, pk2);
13261298
}
13271299
Hardened { .. } => {
1328-
assert_eq!(
1329-
pk.ckd_pub(num),
1330-
Err(DerivationError::CannotDeriveHardenedChild)
1331-
);
1300+
assert_eq!(pk.ckd_pub(num), Err(DerivationError::CannotDeriveHardenedChild));
13321301
pk = Xpub::from_xpriv(&sk);
13331302
}
13341303
}
@@ -1389,7 +1358,6 @@ mod tests {
13891358

13901359
#[test]
13911360
fn vector_1() {
1392-
13931361
let seed = hex!("000102030405060708090a0b0c0d0e0f");
13941362

13951363
// m

bitcoin/src/blockdata/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::consensus::encode::{self, Decodable, Encodable, WriteExt as _};
1818
use crate::merkle_tree::{MerkleNode as _, TxMerkleNode, WitnessMerkleNode};
1919
use crate::network::Params;
2020
use crate::prelude::Vec;
21-
use crate::script::{self, ScriptIntError, ScriptExt as _};
21+
use crate::script::{self, ScriptExt as _, ScriptIntError};
2222
use crate::transaction::{Coinbase, Transaction, TransactionExt as _, Wtxid};
2323
use crate::{internal_macros, BlockTime, Target, Weight, Work};
2424

bitcoin/src/blockdata/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub mod locktime {
4545
pub use units::locktime::absolute::{error, Height, LockTime, MedianTimePast};
4646
#[doc(no_inline)]
4747
pub use units::locktime::absolute::{
48-
ConversionError, IncompatibleHeightError, IncompatibleTimeError, ParseHeightError, ParseTimeError,
48+
ConversionError, IncompatibleHeightError, IncompatibleTimeError, ParseHeightError,
49+
ParseTimeError,
4950
};
5051

5152
#[deprecated(since = "TBD", note = "use `MedianTimePast` instead")]
@@ -76,9 +77,7 @@ pub mod locktime {
7677
7778
/// Re-export everything from the `units::locktime::relative` module.
7879
#[doc(inline)]
79-
pub use units::locktime::relative::{
80-
error, LockTime, NumberOf512Seconds, NumberOfBlocks,
81-
};
80+
pub use units::locktime::relative::{error, LockTime, NumberOf512Seconds, NumberOfBlocks};
8281
#[doc(no_inline)]
8382
pub use units::locktime::relative::{
8483
DisabledLockTimeError, InvalidHeightError, InvalidTimeError, IsSatisfiedByError,

bitcoin/src/blockdata/script/push_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
//! Contains `PushBytes` & co
44
5-
use core::ops::{Deref, DerefMut};
65
use core::fmt;
6+
use core::ops::{Deref, DerefMut};
77

88
use crate::prelude::{Borrow, BorrowMut};
99
use crate::script;

0 commit comments

Comments
 (0)