2025-06-22 automated rustfmt nightly

This commit is contained in:
Fmt Bot 2025-06-22 01:46:07 +00:00 committed by github-actions[bot]
parent 51f78bbb4c
commit c060285851
12 changed files with 50 additions and 40 deletions

View File

@ -1179,7 +1179,7 @@ mod tests {
fn test_upperhex_formatting() {
let normal = Normal { index: 42 };
let hardened = Hardened { index: 42 };
assert_eq!(format!("{:X}", normal), "2A");
assert_eq!(format!("{:#X}", normal), "0x2A");

View File

@ -2,8 +2,8 @@ use std::convert::TryFrom;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use bitcoin::consensus::Decodable;
use p2p::address::AddrV2;
use honggfuzz::fuzz;
use p2p::address::AddrV2;
fn do_test(data: &[u8]) {
if data.len() < 2 {

View File

@ -8,9 +8,9 @@
use core::{fmt, iter};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
use io::{BufRead, Read, Write};
use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
use crate::ServiceFlags;
/// A message which can be sent on the Bitcoin network
@ -206,7 +206,8 @@ impl Encodable for AddrV2 {
network: u8,
bytes: &[u8],
) -> Result<usize, io::Error> {
Ok(network.consensus_encode(w)? + crate::consensus::consensus_encode_with_size(bytes, w)?)
Ok(network.consensus_encode(w)?
+ crate::consensus::consensus_encode_with_size(bytes, w)?)
}
Ok(match *self {
AddrV2::Ipv4(ref addr) => encode_addr(w, 1, &addr.octets())?,

View File

@ -9,7 +9,9 @@ pub(crate) fn consensus_encode_with_size<W: Write + ?Sized>(
}
pub(crate) fn parse_failed_error(msg: &'static str) -> bitcoin::consensus::encode::Error {
bitcoin::consensus::encode::Error::Parse(bitcoin::consensus::encode::ParseError::ParseFailed(msg))
bitcoin::consensus::encode::Error::Parse(bitcoin::consensus::encode::ParseError::ParseFailed(
msg,
))
}
macro_rules! impl_consensus_encoding {

View File

@ -16,27 +16,25 @@
#![allow(clippy::uninlined_format_args)] // Allow `format!("{}", x)`instead of enforcing `format!("{x}")`
pub mod address;
mod consensus;
pub mod message;
pub mod message_blockdata;
pub mod message_bloom;
pub mod message_compact_blocks;
pub mod message_filter;
pub mod message_network;
mod consensus;
extern crate alloc;
use core::str::FromStr;
use core::{fmt, ops};
use std::borrow::{Borrow, BorrowMut, ToOwned};
use hex::FromHex;
use internals::impl_to_hex_from_lower_hex;
use io::{BufRead, Write};
use bitcoin::consensus::encode::{self, Decodable, Encodable};
use bitcoin::network::{Network, Params, TestnetVersion};
use hex::FromHex;
use internals::impl_to_hex_from_lower_hex;
use io::{BufRead, Write};
#[rustfmt::skip]
#[doc(inline)]
@ -243,7 +241,9 @@ impl Magic {
pub fn to_bytes(self) -> [u8; 4] { self.0 }
/// Returns the magic bytes for the network defined by `params`.
pub fn from_params(params: impl AsRef<Params>) -> Option<Self> { params.as_ref().network.try_into().ok() }
pub fn from_params(params: impl AsRef<Params>) -> Option<Self> {
params.as_ref().network.try_into().ok()
}
}
impl FromStr for Magic {
@ -409,9 +409,10 @@ impl std::error::Error for UnknownNetworkError {
#[cfg(test)]
mod tests {
use super::*;
use bitcoin::consensus::encode::{deserialize, serialize};
use super::*;
#[test]
fn serialize_deserialize() {
assert_eq!(serialize(&Magic::BITCOIN), &[0xf9, 0xbe, 0xb4, 0xd9]);
@ -430,7 +431,10 @@ mod tests {
let magic: Magic = Network::Regtest.try_into().unwrap();
assert_eq!(serialize(&magic), &[0xfa, 0xbf, 0xb5, 0xda]);
assert_eq!(deserialize::<Magic>(&[0xf9, 0xbe, 0xb4, 0xd9]).ok(), Network::Bitcoin.try_into().ok());
assert_eq!(
deserialize::<Magic>(&[0xf9, 0xbe, 0xb4, 0xd9]).ok(),
Network::Bitcoin.try_into().ok()
);
assert_eq!(
deserialize::<Magic>(&[0x0b, 0x11, 0x09, 0x07]).ok(),
Network::Testnet(TestnetVersion::V3).try_into().ok()
@ -439,11 +443,16 @@ mod tests {
deserialize::<Magic>(&[0x1c, 0x16, 0x3f, 0x28]).ok(),
Network::Testnet(TestnetVersion::V4).try_into().ok()
);
assert_eq!(deserialize::<Magic>(&[0x0a, 0x03, 0xcf, 0x40]).ok(), Network::Signet.try_into().ok());
assert_eq!(deserialize::<Magic>(&[0xfa, 0xbf, 0xb5, 0xda]).ok(), Network::Regtest.try_into().ok());
assert_eq!(
deserialize::<Magic>(&[0x0a, 0x03, 0xcf, 0x40]).ok(),
Network::Signet.try_into().ok()
);
assert_eq!(
deserialize::<Magic>(&[0xfa, 0xbf, 0xb5, 0xda]).ok(),
Network::Regtest.try_into().ok()
);
}
#[test]
fn service_flags_test() {
let all = [

View File

@ -6,23 +6,22 @@
//! are used for (de)serializing Bitcoin objects for transmission on the network.
use core::{fmt, iter};
use std::borrow::Cow;
use std::borrow::{Cow, ToOwned};
use std::boxed::Box;
use std::borrow::ToOwned;
use bitcoin::consensus::encode::{self, CheckedData, Decodable, Encodable, ReadExt, WriteExt};
use bitcoin::merkle_tree::MerkleBlock;
use bitcoin::{block, transaction};
use hashes::sha256d;
use internals::ToU64 as _;
use io::{BufRead, Write};
use bitcoin::consensus::encode::{self, CheckedData, Decodable, Encodable, ReadExt, WriteExt};
use bitcoin::merkle_tree::MerkleBlock;
use crate::address::{AddrV2Message, Address};
use crate::consensus::impl_vec_wrapper;
use crate::{
message_blockdata, message_bloom, message_compact_blocks, message_filter, message_network,
Magic,
};
use bitcoin::{block, transaction};
/// The maximum number of [super::message_blockdata::Inventory] items in an `inv` message.
///
@ -715,16 +714,16 @@ impl Decodable for V2NetworkMessage {
mod test {
use std::net::Ipv4Addr;
use hex_lit::hex;
use units::BlockHeight;
use super::*;
use bitcoin::bip152::BlockTransactionsRequest;
use bitcoin::bip158::{FilterHash, FilterHeader};
use bitcoin::block::{Block, BlockHash};
use bitcoin::consensus::encode::{deserialize, deserialize_partial, serialize};
use bitcoin::script::ScriptBuf;
use bitcoin::transaction::{Transaction, Txid};
use hex_lit::hex;
use units::BlockHeight;
use super::*;
use crate::address::AddrV2;
use crate::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
use crate::message_bloom::{BloomFlags, FilterAdd, FilterLoad};

View File

@ -5,11 +5,11 @@
//! This module describes network messages which are used for passing
//! Bitcoin data (blocks and transactions) around.
use io::{BufRead, Write};
use bitcoin::block::BlockHash;
use bitcoin::consensus::encode::{self, Decodable, Encodable};
use bitcoin::transaction::{Txid, Wtxid};
use io::{BufRead, Write};
use crate::consensus::impl_consensus_encoding;
/// An inventory item.
@ -143,10 +143,10 @@ impl_consensus_encoding!(GetHeadersMessage, version, locator_hashes, stop_hash);
#[cfg(test)]
mod tests {
use bitcoin::consensus::encode::{deserialize, serialize};
use hex_lit::hex;
use super::*;
use bitcoin::consensus::encode::{deserialize, serialize};
#[test]
fn getblocks_message() {

View File

@ -4,9 +4,9 @@
//!
//! This module describes BIP37 Connection Bloom filtering network messages.
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
use io::{BufRead, Write};
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
use crate::consensus::impl_consensus_encoding;
/// `filterload` message sets the current bloom filter

View File

@ -4,6 +4,7 @@
//! BIP152 Compact Blocks network messages
use bitcoin::bip152;
use crate::consensus::impl_consensus_encoding;
/// sendcmpct message

View File

@ -4,10 +4,10 @@
//!
//! This module describes BIP157 Client Side Block Filtering network messages.
use units::BlockHeight;
use bitcoin::bip158::{FilterHash, FilterHeader};
use bitcoin::block::BlockHash;
use units::BlockHeight;
use crate::consensus::impl_consensus_encoding;
/// getcfilters message

View File

@ -6,10 +6,10 @@
//! capabilities.
use std::borrow::Cow;
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
use hashes::sha256d;
use io::{BufRead, Write};
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
use crate::address::Address;
use crate::consensus::impl_consensus_encoding;
use crate::ServiceFlags;
@ -147,10 +147,10 @@ impl_consensus_encoding!(Reject, message, ccode, reason, hash);
#[cfg(test)]
mod tests {
use bitcoin::consensus::encode::{deserialize, serialize};
use hex_lit::hex;
use super::*;
use bitcoin::consensus::encode::{deserialize, serialize};
#[test]
fn version_message_test() {

View File

@ -399,9 +399,8 @@ mod tests {
#[test]
fn checked_mul() {
let fee_rate = FeeRate::from_sat_per_kwu(10)
.checked_mul(10)
.expect("expected feerate in sat/kwu");
let fee_rate =
FeeRate::from_sat_per_kwu(10).checked_mul(10).expect("expected feerate in sat/kwu");
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(100));
let fee_rate = FeeRate::from_sat_per_kwu(10).checked_mul(u64::MAX);
@ -410,9 +409,8 @@ mod tests {
#[test]
fn checked_div() {
let fee_rate = FeeRate::from_sat_per_kwu(10)
.checked_div(10)
.expect("expected feerate in sat/kwu");
let fee_rate =
FeeRate::from_sat_per_kwu(10).checked_div(10).expect("expected feerate in sat/kwu");
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(1));
let fee_rate = FeeRate::from_sat_per_kwu(10).checked_div(0);