Merge rust-bitcoin/rust-bitcoin#4634: Automated nightly rustfmt (2025-06-22)
c060285851
2025-06-22 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: tcharding: ACKc060285851
apoelstra: ACK c06028585189bfb0f76f0e34bf10ec20573d5d71; successfully ran local tests Tree-SHA512: e0eed455b4641522fb1dbdcf57e51cc8328be9be63d01d21e4d4868ad8fe47f11ea449574e85986bbaa7d7dbed89c3d7bce66f84059440c0588c0bde58a36d92
This commit is contained in:
commit
7bbb9085c6
|
@ -1179,7 +1179,7 @@ mod tests {
|
||||||
fn test_upperhex_formatting() {
|
fn test_upperhex_formatting() {
|
||||||
let normal = Normal { index: 42 };
|
let normal = Normal { index: 42 };
|
||||||
let hardened = Hardened { index: 42 };
|
let hardened = Hardened { index: 42 };
|
||||||
|
|
||||||
assert_eq!(format!("{:X}", normal), "2A");
|
assert_eq!(format!("{:X}", normal), "2A");
|
||||||
assert_eq!(format!("{:#X}", normal), "0x2A");
|
assert_eq!(format!("{:#X}", normal), "0x2A");
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ use std::convert::TryFrom;
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||||
|
|
||||||
use bitcoin::consensus::Decodable;
|
use bitcoin::consensus::Decodable;
|
||||||
use p2p::address::AddrV2;
|
|
||||||
use honggfuzz::fuzz;
|
use honggfuzz::fuzz;
|
||||||
|
use p2p::address::AddrV2;
|
||||||
|
|
||||||
fn do_test(data: &[u8]) {
|
fn do_test(data: &[u8]) {
|
||||||
if data.len() < 2 {
|
if data.len() < 2 {
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
use core::{fmt, iter};
|
use core::{fmt, iter};
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
|
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 io::{BufRead, Read, Write};
|
||||||
|
|
||||||
use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
|
|
||||||
use crate::ServiceFlags;
|
use crate::ServiceFlags;
|
||||||
|
|
||||||
/// A message which can be sent on the Bitcoin network
|
/// A message which can be sent on the Bitcoin network
|
||||||
|
@ -206,7 +206,8 @@ impl Encodable for AddrV2 {
|
||||||
network: u8,
|
network: u8,
|
||||||
bytes: &[u8],
|
bytes: &[u8],
|
||||||
) -> Result<usize, io::Error> {
|
) -> 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 {
|
Ok(match *self {
|
||||||
AddrV2::Ipv4(ref addr) => encode_addr(w, 1, &addr.octets())?,
|
AddrV2::Ipv4(ref addr) => encode_addr(w, 1, &addr.octets())?,
|
||||||
|
|
|
@ -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 {
|
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 {
|
macro_rules! impl_consensus_encoding {
|
||||||
|
|
|
@ -16,27 +16,25 @@
|
||||||
#![allow(clippy::uninlined_format_args)] // Allow `format!("{}", x)`instead of enforcing `format!("{x}")`
|
#![allow(clippy::uninlined_format_args)] // Allow `format!("{}", x)`instead of enforcing `format!("{x}")`
|
||||||
|
|
||||||
pub mod address;
|
pub mod address;
|
||||||
|
mod consensus;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod message_blockdata;
|
pub mod message_blockdata;
|
||||||
pub mod message_bloom;
|
pub mod message_bloom;
|
||||||
pub mod message_compact_blocks;
|
pub mod message_compact_blocks;
|
||||||
pub mod message_filter;
|
pub mod message_filter;
|
||||||
pub mod message_network;
|
pub mod message_network;
|
||||||
mod consensus;
|
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use core::str::FromStr;
|
use core::str::FromStr;
|
||||||
use core::{fmt, ops};
|
use core::{fmt, ops};
|
||||||
|
|
||||||
use std::borrow::{Borrow, BorrowMut, ToOwned};
|
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::consensus::encode::{self, Decodable, Encodable};
|
||||||
use bitcoin::network::{Network, Params, TestnetVersion};
|
use bitcoin::network::{Network, Params, TestnetVersion};
|
||||||
|
use hex::FromHex;
|
||||||
|
use internals::impl_to_hex_from_lower_hex;
|
||||||
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
@ -243,7 +241,9 @@ impl Magic {
|
||||||
pub fn to_bytes(self) -> [u8; 4] { self.0 }
|
pub fn to_bytes(self) -> [u8; 4] { self.0 }
|
||||||
|
|
||||||
/// Returns the magic bytes for the network defined by `params`.
|
/// 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 {
|
impl FromStr for Magic {
|
||||||
|
@ -409,9 +409,10 @@ impl std::error::Error for UnknownNetworkError {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use bitcoin::consensus::encode::{deserialize, serialize};
|
use bitcoin::consensus::encode::{deserialize, serialize};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_deserialize() {
|
fn serialize_deserialize() {
|
||||||
assert_eq!(serialize(&Magic::BITCOIN), &[0xf9, 0xbe, 0xb4, 0xd9]);
|
assert_eq!(serialize(&Magic::BITCOIN), &[0xf9, 0xbe, 0xb4, 0xd9]);
|
||||||
|
@ -430,7 +431,10 @@ mod tests {
|
||||||
let magic: Magic = Network::Regtest.try_into().unwrap();
|
let magic: Magic = Network::Regtest.try_into().unwrap();
|
||||||
assert_eq!(serialize(&magic), &[0xfa, 0xbf, 0xb5, 0xda]);
|
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!(
|
assert_eq!(
|
||||||
deserialize::<Magic>(&[0x0b, 0x11, 0x09, 0x07]).ok(),
|
deserialize::<Magic>(&[0x0b, 0x11, 0x09, 0x07]).ok(),
|
||||||
Network::Testnet(TestnetVersion::V3).try_into().ok()
|
Network::Testnet(TestnetVersion::V3).try_into().ok()
|
||||||
|
@ -439,11 +443,16 @@ mod tests {
|
||||||
deserialize::<Magic>(&[0x1c, 0x16, 0x3f, 0x28]).ok(),
|
deserialize::<Magic>(&[0x1c, 0x16, 0x3f, 0x28]).ok(),
|
||||||
Network::Testnet(TestnetVersion::V4).try_into().ok()
|
Network::Testnet(TestnetVersion::V4).try_into().ok()
|
||||||
);
|
);
|
||||||
assert_eq!(deserialize::<Magic>(&[0x0a, 0x03, 0xcf, 0x40]).ok(), Network::Signet.try_into().ok());
|
assert_eq!(
|
||||||
assert_eq!(deserialize::<Magic>(&[0xfa, 0xbf, 0xb5, 0xda]).ok(), Network::Regtest.try_into().ok());
|
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]
|
#[test]
|
||||||
fn service_flags_test() {
|
fn service_flags_test() {
|
||||||
let all = [
|
let all = [
|
||||||
|
|
|
@ -6,23 +6,22 @@
|
||||||
//! are used for (de)serializing Bitcoin objects for transmission on the network.
|
//! are used for (de)serializing Bitcoin objects for transmission on the network.
|
||||||
|
|
||||||
use core::{fmt, iter};
|
use core::{fmt, iter};
|
||||||
use std::borrow::Cow;
|
use std::borrow::{Cow, ToOwned};
|
||||||
use std::boxed::Box;
|
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 hashes::sha256d;
|
||||||
use internals::ToU64 as _;
|
use internals::ToU64 as _;
|
||||||
use io::{BufRead, Write};
|
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::address::{AddrV2Message, Address};
|
||||||
use crate::consensus::impl_vec_wrapper;
|
use crate::consensus::impl_vec_wrapper;
|
||||||
use crate::{
|
use crate::{
|
||||||
message_blockdata, message_bloom, message_compact_blocks, message_filter, message_network,
|
message_blockdata, message_bloom, message_compact_blocks, message_filter, message_network,
|
||||||
Magic,
|
Magic,
|
||||||
};
|
};
|
||||||
use bitcoin::{block, transaction};
|
|
||||||
|
|
||||||
/// The maximum number of [super::message_blockdata::Inventory] items in an `inv` message.
|
/// The maximum number of [super::message_blockdata::Inventory] items in an `inv` message.
|
||||||
///
|
///
|
||||||
|
@ -715,16 +714,16 @@ impl Decodable for V2NetworkMessage {
|
||||||
mod test {
|
mod test {
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
|
|
||||||
use hex_lit::hex;
|
|
||||||
use units::BlockHeight;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use bitcoin::bip152::BlockTransactionsRequest;
|
use bitcoin::bip152::BlockTransactionsRequest;
|
||||||
use bitcoin::bip158::{FilterHash, FilterHeader};
|
use bitcoin::bip158::{FilterHash, FilterHeader};
|
||||||
use bitcoin::block::{Block, BlockHash};
|
use bitcoin::block::{Block, BlockHash};
|
||||||
use bitcoin::consensus::encode::{deserialize, deserialize_partial, serialize};
|
use bitcoin::consensus::encode::{deserialize, deserialize_partial, serialize};
|
||||||
use bitcoin::script::ScriptBuf;
|
use bitcoin::script::ScriptBuf;
|
||||||
use bitcoin::transaction::{Transaction, Txid};
|
use bitcoin::transaction::{Transaction, Txid};
|
||||||
|
use hex_lit::hex;
|
||||||
|
use units::BlockHeight;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
use crate::address::AddrV2;
|
use crate::address::AddrV2;
|
||||||
use crate::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
|
use crate::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
|
||||||
use crate::message_bloom::{BloomFlags, FilterAdd, FilterLoad};
|
use crate::message_bloom::{BloomFlags, FilterAdd, FilterLoad};
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
//! This module describes network messages which are used for passing
|
//! This module describes network messages which are used for passing
|
||||||
//! Bitcoin data (blocks and transactions) around.
|
//! Bitcoin data (blocks and transactions) around.
|
||||||
|
|
||||||
use io::{BufRead, Write};
|
|
||||||
|
|
||||||
use bitcoin::block::BlockHash;
|
use bitcoin::block::BlockHash;
|
||||||
use bitcoin::consensus::encode::{self, Decodable, Encodable};
|
use bitcoin::consensus::encode::{self, Decodable, Encodable};
|
||||||
use bitcoin::transaction::{Txid, Wtxid};
|
use bitcoin::transaction::{Txid, Wtxid};
|
||||||
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
use crate::consensus::impl_consensus_encoding;
|
use crate::consensus::impl_consensus_encoding;
|
||||||
|
|
||||||
/// An inventory item.
|
/// An inventory item.
|
||||||
|
@ -143,10 +143,10 @@ impl_consensus_encoding!(GetHeadersMessage, version, locator_hashes, stop_hash);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use bitcoin::consensus::encode::{deserialize, serialize};
|
||||||
use hex_lit::hex;
|
use hex_lit::hex;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use bitcoin::consensus::encode::{deserialize, serialize};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn getblocks_message() {
|
fn getblocks_message() {
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
//!
|
//!
|
||||||
//! This module describes BIP37 Connection Bloom filtering network messages.
|
//! This module describes BIP37 Connection Bloom filtering network messages.
|
||||||
|
|
||||||
|
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
|
||||||
use io::{BufRead, Write};
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
|
|
||||||
use crate::consensus::impl_consensus_encoding;
|
use crate::consensus::impl_consensus_encoding;
|
||||||
|
|
||||||
/// `filterload` message sets the current bloom filter
|
/// `filterload` message sets the current bloom filter
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
//! BIP152 Compact Blocks network messages
|
//! BIP152 Compact Blocks network messages
|
||||||
|
|
||||||
use bitcoin::bip152;
|
use bitcoin::bip152;
|
||||||
|
|
||||||
use crate::consensus::impl_consensus_encoding;
|
use crate::consensus::impl_consensus_encoding;
|
||||||
|
|
||||||
/// sendcmpct message
|
/// sendcmpct message
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
//!
|
//!
|
||||||
//! This module describes BIP157 Client Side Block Filtering network messages.
|
//! This module describes BIP157 Client Side Block Filtering network messages.
|
||||||
|
|
||||||
use units::BlockHeight;
|
|
||||||
|
|
||||||
use bitcoin::bip158::{FilterHash, FilterHeader};
|
use bitcoin::bip158::{FilterHash, FilterHeader};
|
||||||
use bitcoin::block::BlockHash;
|
use bitcoin::block::BlockHash;
|
||||||
|
use units::BlockHeight;
|
||||||
|
|
||||||
use crate::consensus::impl_consensus_encoding;
|
use crate::consensus::impl_consensus_encoding;
|
||||||
|
|
||||||
/// getcfilters message
|
/// getcfilters message
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
//! capabilities.
|
//! capabilities.
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
|
||||||
use hashes::sha256d;
|
use hashes::sha256d;
|
||||||
use io::{BufRead, Write};
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
|
|
||||||
use crate::address::Address;
|
use crate::address::Address;
|
||||||
use crate::consensus::impl_consensus_encoding;
|
use crate::consensus::impl_consensus_encoding;
|
||||||
use crate::ServiceFlags;
|
use crate::ServiceFlags;
|
||||||
|
@ -147,10 +147,10 @@ impl_consensus_encoding!(Reject, message, ccode, reason, hash);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use bitcoin::consensus::encode::{deserialize, serialize};
|
||||||
use hex_lit::hex;
|
use hex_lit::hex;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use bitcoin::consensus::encode::{deserialize, serialize};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn version_message_test() {
|
fn version_message_test() {
|
||||||
|
|
|
@ -402,9 +402,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checked_mul() {
|
fn checked_mul() {
|
||||||
let fee_rate = FeeRate::from_sat_per_kwu(10)
|
let fee_rate =
|
||||||
.checked_mul(10)
|
FeeRate::from_sat_per_kwu(10).checked_mul(10).expect("expected feerate in sat/kwu");
|
||||||
.expect("expected feerate in sat/kwu");
|
|
||||||
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(100));
|
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(100));
|
||||||
|
|
||||||
let fee_rate = FeeRate::from_sat_per_kwu(10).checked_mul(u64::MAX);
|
let fee_rate = FeeRate::from_sat_per_kwu(10).checked_mul(u64::MAX);
|
||||||
|
@ -413,9 +412,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checked_div() {
|
fn checked_div() {
|
||||||
let fee_rate = FeeRate::from_sat_per_kwu(10)
|
let fee_rate =
|
||||||
.checked_div(10)
|
FeeRate::from_sat_per_kwu(10).checked_div(10).expect("expected feerate in sat/kwu");
|
||||||
.expect("expected feerate in sat/kwu");
|
|
||||||
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(1));
|
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(1));
|
||||||
|
|
||||||
let fee_rate = FeeRate::from_sat_per_kwu(10).checked_div(0);
|
let fee_rate = FeeRate::from_sat_per_kwu(10).checked_div(0);
|
||||||
|
|
Loading…
Reference in New Issue