2024-10-20 automated rustfmt nightly
This commit is contained in:
parent
51d503730d
commit
2a08b29232
|
@ -141,7 +141,8 @@ impl Block {
|
||||||
.iter()
|
.iter()
|
||||||
.rposition(|o| o.script_pubkey.len() >= 38 && o.script_pubkey.as_bytes()[0..6] == MAGIC)
|
.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);
|
let commitment = WitnessCommitment::from_byte_array(bytes);
|
||||||
// Witness reserved value is in coinbase input witness.
|
// Witness reserved value is in coinbase input witness.
|
||||||
let witness_vec: Vec<_> = coinbase.input[0].witness.iter().collect();
|
let witness_vec: Vec<_> = coinbase.input[0].witness.iter().collect();
|
||||||
|
|
|
@ -140,7 +140,7 @@ crate::internal_macros::define_extension_trait! {
|
||||||
fn push_ecdsa_signature(&mut self, signature: ecdsa::Signature) {
|
fn push_ecdsa_signature(&mut self, signature: ecdsa::Signature) {
|
||||||
self.push(signature.serialize())
|
self.push(signature.serialize())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get Tapscript following BIP341 rules regarding accounting for an annex.
|
/// Get Tapscript following BIP341 rules regarding accounting for an annex.
|
||||||
///
|
///
|
||||||
/// This does not guarantee that this represents a P2TR [`Witness`]. It
|
/// This does not guarantee that this represents a P2TR [`Witness`]. It
|
||||||
|
|
|
@ -174,7 +174,8 @@ macro_rules! impl_psbt_hash_deserialize {
|
||||||
impl $crate::psbt::serialize::Deserialize for $hash_type {
|
impl $crate::psbt::serialize::Deserialize for $hash_type {
|
||||||
fn deserialize(bytes: &[u8]) -> core::result::Result<Self, $crate::psbt::Error> {
|
fn deserialize(bytes: &[u8]) -> core::result::Result<Self, $crate::psbt::Error> {
|
||||||
const LEN: usize = <$hash_type as hashes::Hash>::LEN;
|
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))
|
Ok(<$hash_type>::from_byte_array(bytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use internals::{ToU64 as _};
|
use internals::ToU64 as _;
|
||||||
use io::{BufRead, Write};
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
use super::serialize::{Deserialize, Serialize};
|
use super::serialize::{Deserialize, Serialize};
|
||||||
use crate::consensus::encode::{
|
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::prelude::{DisplayHex, Vec};
|
||||||
use crate::psbt::Error;
|
use crate::psbt::Error;
|
||||||
|
@ -24,7 +24,7 @@ use crate::psbt::Error;
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Key {
|
pub struct Key {
|
||||||
/// The type of this PSBT 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.
|
/// The key data itself in raw byte form.
|
||||||
#[cfg_attr(feature = "serde", serde(with = "crate::serde_utils::hex_bytes"))]
|
#[cfg_attr(feature = "serde", serde(with = "crate::serde_utils::hex_bytes"))]
|
||||||
pub key_data: Vec<u8>,
|
pub key_data: Vec<u8>,
|
||||||
|
|
|
@ -53,7 +53,8 @@ impl TaprootMerkleBranch {
|
||||||
let inner = sl
|
let inner = sl
|
||||||
.chunks_exact(TAPROOT_CONTROL_NODE_SIZE)
|
.chunks_exact(TAPROOT_CONTROL_NODE_SIZE)
|
||||||
.map(|chunk| {
|
.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)
|
TapNodeHash::from_byte_array(bytes)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -1854,8 +1854,16 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn test_merkle_branch_serde() {
|
fn test_merkle_branch_serde() {
|
||||||
let hash1 = TapNodeHash("03ba2a4dcd914fed29a1c630c7e811271b081a0e2f2f52cf1c197583dfd46c1b".parse::<sha256t::Hash<TapBranchTag>>().unwrap());
|
let hash1 = TapNodeHash(
|
||||||
let hash2 = TapNodeHash("8d79dedc2fa0b55167b5d28c61dbad9ce1191a433f3a1a6c8ee291631b2c94c9".parse::<sha256t::Hash<TapBranchTag>>().unwrap());
|
"03ba2a4dcd914fed29a1c630c7e811271b081a0e2f2f52cf1c197583dfd46c1b"
|
||||||
|
.parse::<sha256t::Hash<TapBranchTag>>()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let hash2 = TapNodeHash(
|
||||||
|
"8d79dedc2fa0b55167b5d28c61dbad9ce1191a433f3a1a6c8ee291631b2c94c9"
|
||||||
|
.parse::<sha256t::Hash<TapBranchTag>>()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
let merkle_branch = TaprootMerkleBranch::from([hash1, hash2]);
|
let merkle_branch = TaprootMerkleBranch::from([hash1, hash2]);
|
||||||
// use serde_test to test serialization and deserialization
|
// use serde_test to test serialization and deserialization
|
||||||
serde_test::assert_tokens(
|
serde_test::assert_tokens(
|
||||||
|
|
|
@ -19,9 +19,7 @@ pub struct Key([u8; 32]);
|
||||||
|
|
||||||
impl Key {
|
impl Key {
|
||||||
/// Create a new key.
|
/// Create a new key.
|
||||||
pub const fn new(key: [u8; 32]) -> Self {
|
pub const fn new(key: [u8; 32]) -> Self { Key(key) }
|
||||||
Key(key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A 96-bit initialization vector (IV), or nonce.
|
/// A 96-bit initialization vector (IV), or nonce.
|
||||||
|
@ -30,9 +28,7 @@ pub struct Nonce([u8; 12]);
|
||||||
|
|
||||||
impl Nonce {
|
impl Nonce {
|
||||||
/// Create a new nonce.
|
/// Create a new nonce.
|
||||||
pub const fn new(nonce: [u8; 12]) -> Self {
|
pub const fn new(nonce: [u8; 12]) -> Self { Nonce(nonce) }
|
||||||
Nonce(nonce)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A SIMD-friendly structure which holds 25% of the cipher state.
|
/// 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(test)]
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use hex::prelude::*;
|
use hex::prelude::*;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chacha_block() {
|
fn test_chacha_block() {
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
pub mod chacha20;
|
pub mod chacha20;
|
||||||
pub mod poly1305;
|
pub mod poly1305;
|
||||||
|
|
||||||
|
use core::fmt;
|
||||||
|
|
||||||
use chacha20::ChaCha20;
|
use chacha20::ChaCha20;
|
||||||
use poly1305::Poly1305;
|
use poly1305::Poly1305;
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
pub use self::chacha20::{Key, Nonce};
|
pub use self::chacha20::{Key, Nonce};
|
||||||
|
|
||||||
/// Zero array for padding slices.
|
/// Zero array for padding slices.
|
||||||
|
@ -48,9 +48,7 @@ pub struct ChaCha20Poly1305 {
|
||||||
|
|
||||||
impl ChaCha20Poly1305 {
|
impl ChaCha20Poly1305 {
|
||||||
/// Make a new instance of a ChaCha20Poly1305 AEAD.
|
/// Make a new instance of a ChaCha20Poly1305 AEAD.
|
||||||
pub const fn new(key: Key, nonce: Nonce) -> Self {
|
pub const fn new(key: Key, nonce: Nonce) -> Self { ChaCha20Poly1305 { key, nonce } }
|
||||||
ChaCha20Poly1305 { key, nonce }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encrypt content in place and return the Poly1305 16-byte authentication tag.
|
/// 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(test)]
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use hex::prelude::*;
|
use hex::prelude::*;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rfc7539() {
|
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.";
|
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.";
|
||||||
|
|
|
@ -223,9 +223,10 @@ fn _print_acc(num: &[u32; 5]) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use hex::prelude::*;
|
use hex::prelude::*;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rfc7539() {
|
fn test_rfc7539() {
|
||||||
let key = Vec::from_hex("85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b")
|
let key = Vec::from_hex("85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b")
|
||||||
|
|
|
@ -46,12 +46,6 @@ pub mod witness;
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use units::*;
|
pub use units::*;
|
||||||
|
|
||||||
#[doc(inline)]
|
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub use self::{
|
|
||||||
locktime::{absolute, relative},
|
|
||||||
witness::Witness,
|
|
||||||
};
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use self::{
|
pub use self::{
|
||||||
block::{BlockHash, WitnessCommitment},
|
block::{BlockHash, WitnessCommitment},
|
||||||
|
@ -59,6 +53,12 @@ pub use self::{
|
||||||
sequence::Sequence,
|
sequence::Sequence,
|
||||||
transaction::{Txid, Wtxid},
|
transaction::{Txid, Wtxid},
|
||||||
};
|
};
|
||||||
|
#[doc(inline)]
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
pub use self::{
|
||||||
|
locktime::{absolute, relative},
|
||||||
|
witness::Witness,
|
||||||
|
};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
|
|
|
@ -63,8 +63,12 @@ impl Witness {
|
||||||
/// UNSTABLE: This function may change, break, or disappear in any release.
|
/// UNSTABLE: This function may change, break, or disappear in any release.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[allow(non_snake_case)] // Because of `__unstable`.
|
#[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 }
|
Witness { content, witness_elements, indices_start }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,11 +466,7 @@ mod test {
|
||||||
// The last four bytes represent start at index 0.
|
// The last four bytes represent start at index 0.
|
||||||
let content = [0_u8; 5];
|
let content = [0_u8; 5];
|
||||||
|
|
||||||
Witness {
|
Witness { witness_elements: 1, content: content.to_vec(), indices_start: 1 }
|
||||||
witness_elements: 1,
|
|
||||||
content: content.to_vec(),
|
|
||||||
indices_start: 1,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -568,7 +568,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn exact_sized_iterator() {
|
fn exact_sized_iterator() {
|
||||||
let arbitrary_element = [1_u8, 2, 3];
|
let arbitrary_element = [1_u8, 2, 3];
|
||||||
let num_pushes = 5; // Somewhat arbitrary.
|
let num_pushes = 5; // Somewhat arbitrary.
|
||||||
|
|
||||||
let mut witness = Witness::default();
|
let mut witness = Witness::default();
|
||||||
|
|
||||||
|
@ -623,7 +623,6 @@ mod test {
|
||||||
let ser = serde_json::to_string(&original).unwrap();
|
let ser = serde_json::to_string(&original).unwrap();
|
||||||
let rinsed: Witness = serde_json::from_str(&ser).unwrap();
|
let rinsed: Witness = serde_json::from_str(&ser).unwrap();
|
||||||
assert_eq!(rinsed, original);
|
assert_eq!(rinsed, original);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue