Merge rust-bitcoin/rust-bitcoin#4155: Automated nightly rustfmt (2025-03-02)

166e37161a 2025-03-02 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  apoelstra:
    ACK 166e37161a2412c716e82f7046da304d4788a3c9; successfully ran local tests

Tree-SHA512: 630978ca16f514379e0851254f2b7137f2612e98d8614e9d2c1170bda805ece5936371a2b1fb4b846f3ec906c5c72c9dc1bf9a4239cc6c3336e8f456108a826f
This commit is contained in:
merge-script 2025-03-02 17:27:48 +00:00
commit 58baee62ca
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
8 changed files with 29 additions and 28 deletions

View File

@ -92,7 +92,7 @@ pub enum AddressType {
/// Pay to taproot. /// Pay to taproot.
P2tr, P2tr,
/// Pay to anchor. /// Pay to anchor.
P2a P2a,
} }
impl fmt::Display for AddressType { impl fmt::Display for AddressType {
@ -1531,7 +1531,6 @@ mod tests {
assert_eq!(rinsed, foo_unchecked); assert_eq!(rinsed, foo_unchecked);
} }
#[test] #[test]
fn pay_to_anchor_address_regtest() { fn pay_to_anchor_address_regtest() {
// Verify that p2a uses the expected address for regtest. // Verify that p2a uses the expected address for regtest.

View File

@ -10,9 +10,8 @@ use crate::key::{
XOnlyPublicKey, XOnlyPublicKey,
}; };
use crate::opcodes::all::*; 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_version::WitnessVersion;
use crate::script::witness_program::P2A_PROGRAM;
use crate::script::{ use crate::script::{
self, Builder, PushBytes, RedeemScriptSizeError, Script, ScriptBuf, ScriptExt as _, ScriptHash, self, Builder, PushBytes, RedeemScriptSizeError, Script, ScriptBuf, ScriptExt as _, ScriptHash,
WScriptHash, WitnessScriptSizeError, WScriptHash, WitnessScriptSizeError,

View File

@ -26,7 +26,7 @@ pub const MIN_SIZE: usize = 2;
pub const MAX_SIZE: usize = 40; pub const MAX_SIZE: usize = 40;
/// The P2A program which is given by 0x4e73. /// 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. /// The segregated witness program.
/// ///
@ -110,7 +110,7 @@ impl WitnessProgram {
/// Constructs a new pay to anchor address /// Constructs a new pay to anchor address
pub const fn p2a() -> Self { 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. /// Returns the witness program version.

View File

@ -13,7 +13,10 @@ use crate::crypto::ecdsa;
use crate::prelude::Vec; use crate::prelude::Vec;
#[cfg(doc)] #[cfg(doc)]
use crate::script::ScriptExt as _; 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; use crate::Script;
#[rustfmt::skip] // Keep public re-exports separate. #[rustfmt::skip] // Keep public re-exports separate.
@ -249,14 +252,16 @@ impl<'a> P2TrSpend<'a> {
// for the fact that annex is still there. // for the fact that annex is still there.
match witness.len() { match witness.len() {
0 => None, 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]) => { 2 if witness.last().expect("len > 0").starts_with(&[TAPROOT_ANNEX_PREFIX]) => {
let spend = P2TrSpend::Key { let spend = P2TrSpend::Key {
// signature: witness.second_to_last().expect("len > 1"), // signature: witness.second_to_last().expect("len > 1"),
annex: witness.last(), annex: witness.last(),
}; };
Some(spend) Some(spend)
}, }
// 2 => this is script spend without annex - same as when there are 3+ elements and the // 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 // last one does NOT start with TAPROOT_ANNEX_PREFIX. This is handled in the catchall
// arm. // arm.
@ -267,7 +272,7 @@ impl<'a> P2TrSpend<'a> {
annex: witness.last(), annex: witness.last(),
}; };
Some(spend) Some(spend)
}, }
_ => { _ => {
let spend = P2TrSpend::Script { let spend = P2TrSpend::Script {
leaf_script: Script::from_bytes(witness.second_to_last().expect("len > 1")), leaf_script: Script::from_bytes(witness.second_to_last().expect("len > 1")),
@ -275,7 +280,7 @@ impl<'a> P2TrSpend<'a> {
annex: None, annex: None,
}; };
Some(spend) Some(spend)
}, }
} }
} }
@ -390,7 +395,8 @@ mod test {
#[test] #[test]
fn get_taproot_leaf_script() { fn get_taproot_leaf_script() {
let tapscript = hex!("deadbeef"); let tapscript = hex!("deadbeef");
let control_block = hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); let control_block =
hex!("c0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// annex starting with 0x50 causes the branching logic. // annex starting with 0x50 causes the branching logic.
let annex = hex!("50"); let annex = hex!("50");
@ -403,10 +409,8 @@ mod test {
let witness = deserialize::<Witness>(&witness_serialized[..]).unwrap(); let witness = deserialize::<Witness>(&witness_serialized[..]).unwrap();
let witness_annex = deserialize::<Witness>(&witness_serialized_annex[..]).unwrap(); let witness_annex = deserialize::<Witness>(&witness_serialized_annex[..]).unwrap();
let expected_leaf_script = LeafScript { let expected_leaf_script =
version: LeafVersion::TapScript, LeafScript { version: LeafVersion::TapScript, script: Script::from_bytes(&tapscript) };
script: Script::from_bytes(&tapscript),
};
// With or without annex, the tapscript should be returned. // With or without annex, the tapscript should be returned.
assert_eq!(witness.taproot_leaf_script().unwrap(), expected_leaf_script); assert_eq!(witness.taproot_leaf_script().unwrap(), expected_leaf_script);
@ -451,7 +455,8 @@ mod test {
let witness = deserialize::<Witness>(&witness_serialized[..]).unwrap(); let witness = deserialize::<Witness>(&witness_serialized[..]).unwrap();
let witness_annex = deserialize::<Witness>(&witness_serialized_annex[..]).unwrap(); let witness_annex = deserialize::<Witness>(&witness_serialized_annex[..]).unwrap();
let witness_key_spend_annex = deserialize::<Witness>(&witness_serialized_key_spend_annex[..]).unwrap(); let witness_key_spend_annex =
deserialize::<Witness>(&witness_serialized_key_spend_annex[..]).unwrap();
// With or without annex, the tapscript should be returned. // With or without annex, the tapscript should be returned.
assert_eq!(witness.taproot_control_block(), Some(&control_block[..])); assert_eq!(witness.taproot_control_block(), Some(&control_block[..]));

View File

@ -435,9 +435,7 @@ impl EcdsaSighashType {
/// type (after masking with 0x1f), regardless of the ANYONECANPAY flag. /// type (after masking with 0x1f), regardless of the ANYONECANPAY flag.
/// ///
/// See: <https://github.com/bitcoin/bitcoin/blob/e486597/src/script/interpreter.cpp#L1618-L1619> /// See: <https://github.com/bitcoin/bitcoin/blob/e486597/src/script/interpreter.cpp#L1618-L1619>
pub fn is_single(&self) -> bool { pub fn is_single(&self) -> bool { matches!(self, Self::Single | Self::SinglePlusAnyoneCanPay) }
matches!(self, Self::Single | Self::SinglePlusAnyoneCanPay)
}
/// Constructs a new [`EcdsaSighashType`] from a raw `u32`. /// Constructs a new [`EcdsaSighashType`] from a raw `u32`.
/// ///

View File

@ -129,9 +129,7 @@ impl<T: Tag> Default for HashEngine<T> {
} }
impl<T: Tag> Clone for HashEngine<T> { impl<T: Tag> Clone for HashEngine<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) }
Self(self.0.clone(), PhantomData)
}
} }
impl<T: Tag> crate::HashEngine for HashEngine<T> { impl<T: Tag> crate::HashEngine for HashEngine<T> {

View File

@ -61,7 +61,9 @@ impl ScriptBuf {
/// Constructs a new empty script with pre-allocated capacity. /// Constructs a new empty script with pre-allocated capacity.
#[inline] #[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. /// 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. /// It is guaranteed that `script.capacity() >= script.len()` always holds.
#[inline] #[inline]
pub fn capacity(&self) -> usize { pub fn capacity(&self) -> usize { self.0.capacity() }
self.0.capacity()
}
} }
impl Deref for ScriptBuf { impl Deref for ScriptBuf {

View File

@ -547,7 +547,9 @@ impl Version {
/// As of Bitcoin Core 28.0 ([release notes](https://bitcoincore.org/en/releases/28.0/)), /// As of Bitcoin Core 28.0 ([release notes](https://bitcoincore.org/en/releases/28.0/)),
/// versions 1, 2, and 3 are considered standard. /// versions 1, 2, and 3 are considered standard.
#[inline] #[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 { impl fmt::Display for Version {