2024-10-20 automated rustfmt nightly

This commit is contained in:
Fmt Bot 2024-10-20 01:21:52 +00:00 committed by github-actions[bot]
parent 51d503730d
commit 2a08b29232
11 changed files with 45 additions and 38 deletions

View File

@ -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();

View File

@ -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))
}
}

View File

@ -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;

View File

@ -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();

View File

@ -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(

View File

@ -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.
@ -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.
@ -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 {

View File

@ -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.
@ -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.
///
@ -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.";

View File

@ -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")

View File

@ -46,12 +46,6 @@ 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},
@ -59,6 +53,12 @@ pub use self::{
sequence::Sequence,
transaction::{Txid, Wtxid},
};
#[doc(inline)]
#[cfg(feature = "alloc")]
pub use self::{
locktime::{absolute, relative},
witness::Witness,
};
#[rustfmt::skip]
#[allow(unused_imports)]

View File

@ -64,7 +64,11 @@ impl Witness {
#[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 {
pub fn from_parts__unstable(
content: Vec<u8>,
witness_elements: usize,
indices_start: usize,
) -> Self {
Witness { content, witness_elements, indices_start }
}
@ -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]
@ -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]