diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs index 59d47e0db..72a3ec7db 100644 --- a/bitcoin/src/address/mod.rs +++ b/bitcoin/src/address/mod.rs @@ -92,7 +92,7 @@ pub enum AddressType { /// Pay to taproot. P2tr, /// Pay to anchor. - P2a + P2a, } impl fmt::Display for AddressType { @@ -1531,7 +1531,6 @@ mod tests { assert_eq!(rinsed, foo_unchecked); } - #[test] fn pay_to_anchor_address_regtest() { // Verify that p2a uses the expected address for regtest. diff --git a/bitcoin/src/address/script_pubkey.rs b/bitcoin/src/address/script_pubkey.rs index 208b5e846..7c048680e 100644 --- a/bitcoin/src/address/script_pubkey.rs +++ b/bitcoin/src/address/script_pubkey.rs @@ -10,9 +10,8 @@ use crate::key::{ XOnlyPublicKey, }; use crate::opcodes::all::*; -use crate::script::witness_program::WitnessProgram; +use crate::script::witness_program::{WitnessProgram, P2A_PROGRAM}; use crate::script::witness_version::WitnessVersion; -use crate::script::witness_program::P2A_PROGRAM; use crate::script::{ self, Builder, PushBytes, RedeemScriptSizeError, Script, ScriptBuf, ScriptExt as _, ScriptHash, WScriptHash, WitnessScriptSizeError, diff --git a/bitcoin/src/blockdata/script/witness_program.rs b/bitcoin/src/blockdata/script/witness_program.rs index 989f72257..e0fe7bc60 100644 --- a/bitcoin/src/blockdata/script/witness_program.rs +++ b/bitcoin/src/blockdata/script/witness_program.rs @@ -26,7 +26,7 @@ pub const MIN_SIZE: usize = 2; pub const MAX_SIZE: usize = 40; /// The P2A program which is given by 0x4e73. -pub(crate) const P2A_PROGRAM: [u8;2] = [78, 115]; +pub(crate) const P2A_PROGRAM: [u8; 2] = [78, 115]; /// The segregated witness program. /// @@ -110,7 +110,7 @@ impl WitnessProgram { /// Constructs a new pay to anchor address pub const fn p2a() -> Self { - WitnessProgram { version: WitnessVersion::V1, program: ArrayVec::from_slice(&P2A_PROGRAM)} + WitnessProgram { version: WitnessVersion::V1, program: ArrayVec::from_slice(&P2A_PROGRAM) } } /// Returns the witness program version. diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs index d0ac6f526..99d42f316 100644 --- a/bitcoin/src/blockdata/witness.rs +++ b/bitcoin/src/blockdata/witness.rs @@ -13,7 +13,10 @@ use crate::crypto::ecdsa; use crate::prelude::Vec; #[cfg(doc)] use crate::script::ScriptExt as _; -use crate::taproot::{self, LeafScript, LeafVersion, TAPROOT_ANNEX_PREFIX, TAPROOT_CONTROL_BASE_SIZE, TAPROOT_LEAF_MASK}; +use crate::taproot::{ + self, LeafScript, LeafVersion, TAPROOT_ANNEX_PREFIX, TAPROOT_CONTROL_BASE_SIZE, + TAPROOT_LEAF_MASK, +}; use crate::Script; #[rustfmt::skip] // Keep public re-exports separate. @@ -249,14 +252,16 @@ impl<'a> P2TrSpend<'a> { // for the fact that annex is still there. match witness.len() { 0 => None, - 1 => Some(P2TrSpend::Key { /* signature: witness.last().expect("len > 0") ,*/ annex: None }), + 1 => Some(P2TrSpend::Key { + /* signature: witness.last().expect("len > 0") ,*/ annex: None, + }), 2 if witness.last().expect("len > 0").starts_with(&[TAPROOT_ANNEX_PREFIX]) => { let spend = P2TrSpend::Key { // signature: witness.second_to_last().expect("len > 1"), annex: witness.last(), }; Some(spend) - }, + } // 2 => this is script spend without annex - same as when there are 3+ elements and the // last one does NOT start with TAPROOT_ANNEX_PREFIX. This is handled in the catchall // arm. @@ -267,7 +272,7 @@ impl<'a> P2TrSpend<'a> { annex: witness.last(), }; Some(spend) - }, + } _ => { let spend = P2TrSpend::Script { leaf_script: Script::from_bytes(witness.second_to_last().expect("len > 1")), @@ -275,7 +280,7 @@ impl<'a> P2TrSpend<'a> { annex: None, }; Some(spend) - }, + } } } @@ -390,7 +395,8 @@ mod test { #[test] fn get_taproot_leaf_script() { let tapscript = hex!("deadbeef"); - let control_block = hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + let control_block = + hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // annex starting with 0x50 causes the branching logic. let annex = hex!("50"); @@ -403,10 +409,8 @@ mod test { let witness = deserialize::(&witness_serialized[..]).unwrap(); let witness_annex = deserialize::(&witness_serialized_annex[..]).unwrap(); - let expected_leaf_script = LeafScript { - version: LeafVersion::TapScript, - script: Script::from_bytes(&tapscript), - }; + let expected_leaf_script = + LeafScript { version: LeafVersion::TapScript, script: Script::from_bytes(&tapscript) }; // With or without annex, the tapscript should be returned. assert_eq!(witness.taproot_leaf_script().unwrap(), expected_leaf_script); @@ -451,7 +455,8 @@ mod test { let witness = deserialize::(&witness_serialized[..]).unwrap(); let witness_annex = deserialize::(&witness_serialized_annex[..]).unwrap(); - let witness_key_spend_annex = deserialize::(&witness_serialized_key_spend_annex[..]).unwrap(); + let witness_key_spend_annex = + deserialize::(&witness_serialized_key_spend_annex[..]).unwrap(); // With or without annex, the tapscript should be returned. assert_eq!(witness.taproot_control_block(), Some(&control_block[..])); diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs index e1deed7e2..4c608e94f 100644 --- a/bitcoin/src/crypto/sighash.rs +++ b/bitcoin/src/crypto/sighash.rs @@ -435,9 +435,7 @@ impl EcdsaSighashType { /// type (after masking with 0x1f), regardless of the ANYONECANPAY flag. /// /// See: - pub fn is_single(&self) -> bool { - matches!(self, Self::Single | Self::SinglePlusAnyoneCanPay) - } + pub fn is_single(&self) -> bool { matches!(self, Self::Single | Self::SinglePlusAnyoneCanPay) } /// Constructs a new [`EcdsaSighashType`] from a raw `u32`. /// diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs index 22f835412..19a6ef768 100644 --- a/hashes/src/sha256t/mod.rs +++ b/hashes/src/sha256t/mod.rs @@ -129,9 +129,7 @@ impl Default for HashEngine { } impl Clone for HashEngine { - fn clone(&self) -> Self { - Self(self.0.clone(), PhantomData) - } + fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) } } impl crate::HashEngine for HashEngine { diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs index f3c78516e..3ab7b6829 100644 --- a/primitives/src/script/owned.rs +++ b/primitives/src/script/owned.rs @@ -61,7 +61,9 @@ impl ScriptBuf { /// Constructs a new empty script with pre-allocated capacity. #[inline] - pub fn with_capacity(capacity: usize) -> Self { ScriptBuf::from_bytes(Vec::with_capacity(capacity)) } + pub fn with_capacity(capacity: usize) -> Self { + ScriptBuf::from_bytes(Vec::with_capacity(capacity)) + } /// Pre-allocates at least `additional_len` bytes if needed. /// @@ -96,9 +98,7 @@ impl ScriptBuf { /// /// It is guaranteed that `script.capacity() >= script.len()` always holds. #[inline] - pub fn capacity(&self) -> usize { - self.0.capacity() - } + pub fn capacity(&self) -> usize { self.0.capacity() } } impl Deref for ScriptBuf { diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs index cf24946fb..d1ec78b02 100644 --- a/primitives/src/transaction.rs +++ b/primitives/src/transaction.rs @@ -547,7 +547,9 @@ impl Version { /// As of Bitcoin Core 28.0 ([release notes](https://bitcoincore.org/en/releases/28.0/)), /// versions 1, 2, and 3 are considered standard. #[inline] - pub fn is_standard(&self) -> bool { *self == Version::ONE || *self == Version::TWO || *self == Version::THREE } + pub fn is_standard(&self) -> bool { + *self == Version::ONE || *self == Version::TWO || *self == Version::THREE + } } impl fmt::Display for Version {