Skip to content

Commit

Permalink
Merge rust-bitcoin#3361: Automated nightly rustfmt (2024-09-15)
Browse files Browse the repository at this point in the history
7990724 2024-09-15 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 7990724 successfully ran local tests; nothing too offensive this week

Tree-SHA512: 41edd16a7cea096757a1fba815b48b0791d4d03050303efb60aa68595e947b40e1d7ec7c32e4d2f115f2628cb1471474ed9caa699bde5ab0ed4cd0245b48de17
  • Loading branch information
apoelstra committed Sep 15, 2024
2 parents 7360c3c + 7990724 commit fe2985b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 36 deletions.
4 changes: 1 addition & 3 deletions bitcoin/src/blockdata/script/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

use internals::script::{self, PushDataLenLen};

use super::{
Error, PushBytes, Script, ScriptBuf, ScriptBufExtPriv as _,
};
use super::{Error, PushBytes, Script, ScriptBuf, ScriptBufExtPriv as _};
use crate::opcodes::{self, Opcode};

/// A "parsed opcode" which allows iterating over a [`Script`] in a more sensible way.
Expand Down
8 changes: 3 additions & 5 deletions bitcoin/src/blockdata/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use core::fmt;
use core::ops::{Deref, DerefMut};

use hashes::{hash160, sha256};
use internals::{impl_to_hex_from_lower_hex};
use internals::impl_to_hex_from_lower_hex;
use internals::script::{self, PushDataLenLen};
use io::{BufRead, Write};

Expand Down Expand Up @@ -643,15 +643,13 @@ pub(super) fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn fmt::Write) -> fmt::Re
macro_rules! read_push_data_len {
($iter:expr, $size:path, $formatter:expr) => {
match script::read_push_data_len($iter, $size) {
Ok(n) => {
n
},
Ok(n) => n,
Err(_) => {
$formatter.write_str("<unexpected end>")?;
break;
}
}
}
};
}

let mut iter = script.iter();
Expand Down
15 changes: 3 additions & 12 deletions bitcoin/src/blockdata/script/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,10 @@ fn script_asm() {
"OP_0 OP_PUSHBYTES_71 304402202457e78cc1b7f50d0543863c27de75d07982bde8359b9e3316adec0aec165f2f02200203fd331c4e4a4a02f48cf1c291e2c0d6b2f7078a784b5b3649fca41f8794d401 OP_0 OP_PUSHDATA1 552103244e602b46755f24327142a0517288cebd159eccb6ccf41ea6edf1f601e9af952103bbbacc302d19d29dbfa62d23f37944ae19853cf260c745c2bea739c95328fcb721039227e83246bd51140fe93538b2301c9048be82ef2fb3c7fc5d78426ed6f609ad210229bf310c379b90033e2ecb07f77ecf9b8d59acb623ab7be25a0caed539e2e6472103703e2ed676936f10b3ce9149fa2d4a32060fb86fa9a70a4efe3f21d7ab90611921031e9b7c6022400a6bb0424bbcde14cff6c016b91ee3803926f3440abf5c146d05210334667f975f55a8455d515a2ef1c94fdfa3315f12319a14515d2a13d82831f62f57ae");
// Various weird scripts found in transaction 6d7ed9914625c73c0288694a6819196a27ef6c08f98e1270d975a8e65a3dc09a
// which triggerred overflow bugs on 32-bit machines in script formatting in the past.
assert_eq!(
ScriptBuf::from_hex("01").unwrap().to_string(),
"OP_PUSHBYTES_1 <push past end>"
);
assert_eq!(
ScriptBuf::from_hex("0201").unwrap().to_string(),
"OP_PUSHBYTES_2 <push past end>"
);
assert_eq!(ScriptBuf::from_hex("01").unwrap().to_string(), "OP_PUSHBYTES_1 <push past end>");
assert_eq!(ScriptBuf::from_hex("0201").unwrap().to_string(), "OP_PUSHBYTES_2 <push past end>");
assert_eq!(ScriptBuf::from_hex("4c").unwrap().to_string(), "<unexpected end>");
assert_eq!(
ScriptBuf::from_hex("4c0201").unwrap().to_string(),
"OP_PUSHDATA1 <push past end>"
);
assert_eq!(ScriptBuf::from_hex("4c0201").unwrap().to_string(), "OP_PUSHDATA1 <push past end>");
assert_eq!(ScriptBuf::from_hex("4d").unwrap().to_string(), "<unexpected end>");
assert_eq!(
ScriptBuf::from_hex("4dffff01").unwrap().to_string(),
Expand Down
8 changes: 5 additions & 3 deletions bitcoin/src/blockdata/script/witness_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ mod tests {

if size == 20 {
assert!(program.expect("valid witness program").is_p2wpkh());
continue
continue;
}
if size == 32 {
assert!(program.expect("valid witness program").is_p2wsh());
continue
continue;
}
assert!(program.is_err());
}
Expand All @@ -203,6 +203,8 @@ mod tests {
#[test]
fn valid_v1_witness_programs() {
let arbitrary_bytes = [0x00; 32];
assert!(WitnessProgram::new(WitnessVersion::V1, &arbitrary_bytes).expect("valid witness program").is_p2tr());
assert!(WitnessProgram::new(WitnessVersion::V1, &arbitrary_bytes)
.expect("valid witness program")
.is_p2tr());
}
}
4 changes: 1 addition & 3 deletions bitcoin/src/blockdata/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ impl Witness {
let index_size = witness_elements * 4;
let content_size = slice
.iter()
.map(|elem| {
elem.as_ref().len() + compact_size::encoded_size(elem.as_ref().len())
})
.map(|elem| elem.as_ref().len() + compact_size::encoded_size(elem.as_ref().len()))
.sum();

let mut content = vec![0u8; content_size + index_size];
Expand Down
6 changes: 5 additions & 1 deletion hashes/src/siphash24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ macro_rules! compress {
macro_rules! load_int_le {
($buf:expr, $i:expr, $int_ty:ident) => {{
debug_assert!($i + mem::size_of::<$int_ty>() <= $buf.len());
$int_ty::from_le_bytes($buf.get_unchecked($i..($i + mem::size_of::<$int_ty>())).try_into().expect("len is correctly computed using size_of"))
$int_ty::from_le_bytes(
$buf.get_unchecked($i..($i + mem::size_of::<$int_ty>()))
.try_into()
.expect("len is correctly computed using size_of"),
)
}};
}

Expand Down
7 changes: 4 additions & 3 deletions hashes/tests/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

#![cfg(feature = "bitcoin-io")]

use bitcoin_hashes::{
hash160, hmac, ripemd160, sha1, sha256, sha256d, sha384, sha512, sha512_256, siphash24,
GeneralHash as _,
};
use bitcoin_io::Write;

use bitcoin_hashes::{hash160, hmac, ripemd160, sha1, sha256, sha256d, sha384, sha512, sha512_256, siphash24, GeneralHash as _};

macro_rules! write_test {
($mod:ident, $exp_empty:expr, $exp_256:expr, $exp_64k:expr,) => {
#[test]
Expand Down Expand Up @@ -124,4 +126,3 @@ fn siphash24() {
engine.write_all(&[99; 64000]).unwrap();
assert_eq!(format!("{}", siphash24::Hash::from_engine(engine)), "ce456e4e4ecbc5bf");
}

12 changes: 6 additions & 6 deletions units/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,10 +1167,10 @@ impl FromStr for Amount {
if d == Ok(Amount::ZERO) {
Ok(Amount::ZERO)
} else {
result
result
}
},
_ => result
}
_ => result,
}
}
}
Expand Down Expand Up @@ -1605,10 +1605,10 @@ impl FromStr for SignedAmount {
if d == Ok(SignedAmount::ZERO) {
Ok(SignedAmount::ZERO)
} else {
result
result
}
},
_ => result
}
_ => result,
}
}
}
Expand Down

0 comments on commit fe2985b

Please sign in to comment.