Skip to content

Commit

Permalink
Merge rust-bitcoin#3495: Automated nightly rustfmt (2024-10-20)
Browse files Browse the repository at this point in the history
2a08b29 2024-10-20 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:
  tcharding:
    ACK 2a08b29

Tree-SHA512: f44713f322724cc7e8823efaa5619197478a0927cd11806777ea9ec4d87a8d0fddf25c3bd58e0a23dc8f60baa18c80a63db2b56196523f616943c6e1497060f6
  • Loading branch information
tcharding committed Oct 21, 2024
2 parents bceb5b4 + 2a08b29 commit 9854854
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 38 deletions.
3 changes: 2 additions & 1 deletion bitcoin/src/blockdata/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ impl Block {
.iter()
.rposition(|o| o.script_pubkey.len() >= 38 && o.script_pubkey.as_bytes()[0..6] == MAGIC)
{
let bytes = <[u8; 32]>::try_from(&coinbase.output[pos].script_pubkey.as_bytes()[6..38]).unwrap();
let bytes = <[u8; 32]>::try_from(&coinbase.output[pos].script_pubkey.as_bytes()[6..38])
.unwrap();
let commitment = WitnessCommitment::from_byte_array(bytes);
// Witness reserved value is in coinbase input witness.
let witness_vec: Vec<_> = coinbase.input[0].witness.iter().collect();
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ crate::internal_macros::define_extension_trait! {
fn push_ecdsa_signature(&mut self, signature: ecdsa::Signature) {
self.push(signature.serialize())
}

/// Get Tapscript following BIP341 rules regarding accounting for an annex.
///
/// This does not guarantee that this represents a P2TR [`Witness`]. It
Expand Down
3 changes: 2 additions & 1 deletion bitcoin/src/psbt/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ macro_rules! impl_psbt_hash_deserialize {
impl $crate::psbt::serialize::Deserialize for $hash_type {
fn deserialize(bytes: &[u8]) -> core::result::Result<Self, $crate::psbt::Error> {
const LEN: usize = <$hash_type as hashes::Hash>::LEN;
let bytes = <[u8; LEN]>::try_from(bytes).map_err(|e| $crate::psbt::Error::from(e))?;
let bytes =
<[u8; LEN]>::try_from(bytes).map_err(|e| $crate::psbt::Error::from(e))?;
Ok(<$hash_type>::from_byte_array(bytes))
}
}
Expand Down
6 changes: 3 additions & 3 deletions bitcoin/src/psbt/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use core::fmt;

use internals::{ToU64 as _};
use internals::ToU64 as _;
use io::{BufRead, Write};

use super::serialize::{Deserialize, Serialize};
use crate::consensus::encode::{
self, deserialize, serialize, Decodable, Encodable, MAX_VEC_SIZE, ReadExt, WriteExt,
self, deserialize, serialize, Decodable, Encodable, ReadExt, WriteExt, MAX_VEC_SIZE,
};
use crate::prelude::{DisplayHex, Vec};
use crate::psbt::Error;
Expand All @@ -24,7 +24,7 @@ use crate::psbt::Error;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Key {
/// The type of this PSBT key.
pub type_value: u64, // Encoded as a compact size.
pub type_value: u64, // Encoded as a compact size.
/// The key data itself in raw byte form.
#[cfg_attr(feature = "serde", serde(with = "crate::serde_utils::hex_bytes"))]
pub key_data: Vec<u8>,
Expand Down
3 changes: 2 additions & 1 deletion bitcoin/src/taproot/merkle_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ impl TaprootMerkleBranch {
let inner = sl
.chunks_exact(TAPROOT_CONTROL_NODE_SIZE)
.map(|chunk| {
let bytes = <[u8; 32]>::try_from(chunk).expect("chunks_exact always returns the correct size");
let bytes = <[u8; 32]>::try_from(chunk)
.expect("chunks_exact always returns the correct size");
TapNodeHash::from_byte_array(bytes)
})
.collect();
Expand Down
12 changes: 10 additions & 2 deletions bitcoin/src/taproot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1854,8 +1854,16 @@ mod test {
#[test]
#[cfg(feature = "serde")]
fn test_merkle_branch_serde() {
let hash1 = TapNodeHash("03ba2a4dcd914fed29a1c630c7e811271b081a0e2f2f52cf1c197583dfd46c1b".parse::<sha256t::Hash<TapBranchTag>>().unwrap());
let hash2 = TapNodeHash("8d79dedc2fa0b55167b5d28c61dbad9ce1191a433f3a1a6c8ee291631b2c94c9".parse::<sha256t::Hash<TapBranchTag>>().unwrap());
let hash1 = TapNodeHash(
"03ba2a4dcd914fed29a1c630c7e811271b081a0e2f2f52cf1c197583dfd46c1b"
.parse::<sha256t::Hash<TapBranchTag>>()
.unwrap(),
);
let hash2 = TapNodeHash(
"8d79dedc2fa0b55167b5d28c61dbad9ce1191a433f3a1a6c8ee291631b2c94c9"
.parse::<sha256t::Hash<TapBranchTag>>()
.unwrap(),
);
let merkle_branch = TaprootMerkleBranch::from([hash1, hash2]);
// use serde_test to test serialization and deserialization
serde_test::assert_tokens(
Expand Down
11 changes: 4 additions & 7 deletions chacha20_poly1305/src/chacha20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ pub struct Key([u8; 32]);

impl Key {
/// Create a new key.
pub const fn new(key: [u8; 32]) -> Self {
Key(key)
}
pub const fn new(key: [u8; 32]) -> Self { Key(key) }
}

/// A 96-bit initialization vector (IV), or nonce.
Expand All @@ -30,9 +28,7 @@ pub struct Nonce([u8; 12]);

impl Nonce {
/// Create a new nonce.
pub const fn new(nonce: [u8; 12]) -> Self {
Nonce(nonce)
}
pub const fn new(nonce: [u8; 12]) -> Self { Nonce(nonce) }
}

/// A SIMD-friendly structure which holds 25% of the cipher state.
Expand Down Expand Up @@ -330,9 +326,10 @@ fn keystream_at_slice(key: Key, nonce: Nonce, count: u32, seek: usize) -> [u8; 6
#[cfg(test)]
#[cfg(feature = "alloc")]
mod tests {
use super::*;
use hex::prelude::*;

use super::*;

#[test]
fn test_chacha_block() {
let mut state = State {
Expand Down
11 changes: 5 additions & 6 deletions chacha20_poly1305/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
pub mod chacha20;
pub mod poly1305;

use core::fmt;

use chacha20::ChaCha20;
use poly1305::Poly1305;

use core::fmt;

pub use self::chacha20::{Key, Nonce};

/// Zero array for padding slices.
Expand Down Expand Up @@ -48,9 +48,7 @@ pub struct ChaCha20Poly1305 {

impl ChaCha20Poly1305 {
/// Make a new instance of a ChaCha20Poly1305 AEAD.
pub const fn new(key: Key, nonce: Nonce) -> Self {
ChaCha20Poly1305 { key, nonce }
}
pub const fn new(key: Key, nonce: Nonce) -> Self { ChaCha20Poly1305 { key, nonce } }

/// Encrypt content in place and return the Poly1305 16-byte authentication tag.
///
Expand Down Expand Up @@ -145,9 +143,10 @@ fn encode_lengths(aad_len: u64, content_len: u64) -> [u8; 16] {
#[cfg(test)]
#[cfg(feature = "alloc")]
mod tests {
use super::*;
use hex::prelude::*;

use super::*;

#[test]
fn test_rfc7539() {
let mut message = *b"Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
Expand Down
3 changes: 2 additions & 1 deletion chacha20_poly1305/src/poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ fn _print_acc(num: &[u32; 5]) {
#[cfg(test)]
#[cfg(feature = "alloc")]
mod tests {
use super::*;
use hex::prelude::*;

use super::*;

#[test]
fn test_rfc7539() {
let key = Vec::from_hex("85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b")
Expand Down
12 changes: 6 additions & 6 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ pub mod witness;
#[doc(inline)]
pub use units::*;

#[doc(inline)]
#[cfg(feature = "alloc")]
pub use self::{
locktime::{absolute, relative},
witness::Witness,
};
#[doc(inline)]
pub use self::{
block::{BlockHash, WitnessCommitment},
pow::CompactTarget,
sequence::Sequence,
transaction::{Txid, Wtxid},
};
#[doc(inline)]
#[cfg(feature = "alloc")]
pub use self::{
locktime::{absolute, relative},
witness::Witness,
};

#[rustfmt::skip]
#[allow(unused_imports)]
Expand Down
17 changes: 8 additions & 9 deletions primitives/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ impl Witness {
/// UNSTABLE: This function may change, break, or disappear in any release.
#[inline]
#[doc(hidden)]
#[allow(non_snake_case)] // Because of `__unstable`.
pub fn from_parts__unstable(content: Vec<u8>, witness_elements: usize, indices_start: usize) -> Self {
#[allow(non_snake_case)] // Because of `__unstable`.
pub fn from_parts__unstable(
content: Vec<u8>,
witness_elements: usize,
indices_start: usize,
) -> Self {
Witness { content, witness_elements, indices_start }
}

Expand Down Expand Up @@ -462,11 +466,7 @@ mod test {
// The last four bytes represent start at index 0.
let content = [0_u8; 5];

Witness {
witness_elements: 1,
content: content.to_vec(),
indices_start: 1,
}
Witness { witness_elements: 1, content: content.to_vec(), indices_start: 1 }
}

#[test]
Expand Down Expand Up @@ -568,7 +568,7 @@ mod test {
#[test]
fn exact_sized_iterator() {
let arbitrary_element = [1_u8, 2, 3];
let num_pushes = 5; // Somewhat arbitrary.
let num_pushes = 5; // Somewhat arbitrary.

let mut witness = Witness::default();

Expand Down Expand Up @@ -623,7 +623,6 @@ mod test {
let ser = serde_json::to_string(&original).unwrap();
let rinsed: Witness = serde_json::from_str(&ser).unwrap();
assert_eq!(rinsed, original);

}

#[test]
Expand Down

0 comments on commit 9854854

Please sign in to comment.