chore: use fmt::Formatter helpers (#6775)

This commit is contained in:
DaniPopes
2024-02-24 13:40:19 +02:00
committed by GitHub
parent 12b3bae53d
commit b7ac2d6fd2
4 changed files with 28 additions and 19 deletions

1
Cargo.lock generated
View File

@ -6956,6 +6956,7 @@ dependencies = [
"criterion",
"fnv",
"futures-util",
"itertools 0.12.1",
"metrics",
"parking_lot 0.12.1",
"paste",

View File

@ -49,6 +49,7 @@ fnv = "1.0.7"
bitflags.workspace = true
auto_impl = "1.0"
smallvec.workspace = true
itertools.workspace = true
# testing
rand = { workspace = true, optional = true }

View File

@ -19,6 +19,7 @@ use crate::{
ValidPoolTransaction, U256,
};
use fnv::FnvHashMap;
use itertools::Itertools;
use reth_primitives::{
constants::{
eip4844::BLOB_TX_MIN_BLOB_GASPRICE, ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE,
@ -1819,21 +1820,21 @@ pub struct PruneResult<T: PoolTransaction> {
}
impl<T: PoolTransaction> fmt::Debug for PruneResult<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "PruneResult {{ ")?;
write!(
fmt,
"promoted: {:?}, ",
self.promoted.iter().map(|tx| *tx.hash()).collect::<Vec<_>>()
)?;
write!(fmt, "failed: {:?}, ", self.failed)?;
write!(
fmt,
"pruned: {:?}, ",
self.pruned.iter().map(|tx| *tx.transaction.hash()).collect::<Vec<_>>()
)?;
write!(fmt, "}}")?;
Ok(())
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PruneResult")
.field(
"promoted",
&format_args!("[{}]", self.promoted.iter().map(|tx| tx.hash()).format(", ")),
)
.field("failed", &self.failed)
.field(
"pruned",
&format_args!(
"[{}]",
self.pruned.iter().map(|tx| tx.transaction.hash()).format(", ")
),
)
.finish()
}
}

View File

@ -568,7 +568,7 @@ impl TransactionOrigin {
/// known block hash.
///
/// This is used to update the pool state accordingly.
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct CanonicalStateUpdate<'a> {
/// Hash of the tip block.
pub new_tip: &'a SealedBlock,
@ -613,10 +613,16 @@ impl<'a> CanonicalStateUpdate<'a> {
}
}
impl<'a> fmt::Display for CanonicalStateUpdate<'a> {
impl fmt::Display for CanonicalStateUpdate<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{{ hash: {}, number: {}, pending_block_base_fee: {}, pending_block_blob_fee: {:?}, changed_accounts: {}, mined_transactions: {} }}",
self.hash(), self.number(), self.pending_block_base_fee, self.pending_block_blob_fee, self.changed_accounts.len(), self.mined_transactions.len())
f.debug_struct("CanonicalStateUpdate")
.field("hash", &self.hash())
.field("number", &self.number())
.field("pending_block_base_fee", &self.pending_block_base_fee)
.field("pending_block_blob_fee", &self.pending_block_blob_fee)
.field("changed_accounts", &self.changed_accounts.len())
.field("mined_transactions", &self.mined_transactions.len())
.finish()
}
}