Skip to content

Automated nightly rustfmt (2025-06-22) #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitcoin/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/bitcoin/p2p_address_roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions p2p/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())?,
Expand Down
4 changes: 3 additions & 1 deletion p2p/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 20 additions & 11 deletions p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,26 @@
#![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 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};

use bitcoin::consensus::encode::{self, Decodable, Encodable};
use bitcoin::network::{Network, Params, TestnetVersion};

#[rustfmt::skip]
#[doc(inline)]
pub use self::address::Address;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]);
Expand All @@ -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()
Expand All @@ -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 = [
Expand Down
17 changes: 8 additions & 9 deletions p2p/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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};
Expand Down
6 changes: 3 additions & 3 deletions p2p/src/message_blockdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion p2p/src/message_bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions p2p/src/message_compact_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! BIP152 Compact Blocks network messages

use bitcoin::bip152;

use crate::consensus::impl_consensus_encoding;

/// sendcmpct message
Expand Down
4 changes: 2 additions & 2 deletions p2p/src/message_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions p2p/src/message_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 4 additions & 6 deletions units/src/fee_rate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down