Skip to content

Commit

Permalink
chore: use Display when formatting addresses and hashes (paradigmxyz#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jan 26, 2024
1 parent 556741a commit 0aa2246
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/ethereum-forks/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl fmt::Display for Head {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Head Block:\n Number: {}\n Hash: {:?}\n Difficulty: {:?}\n Total Difficulty: {:?}\n Timestamp: {}",
"Head Block:\n Number: {}\n Hash: {}\n Difficulty: {:?}\n Total Difficulty: {:?}\n Timestamp: {}",
self.number, self.hash, self.difficulty, self.total_difficulty, self.timestamp
)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/interfaces/src/blockchain_tree/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl std::fmt::Display for InsertBlockErrorData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Failed to insert block (hash={:?}, number={}, parent_hash={:?}): {}",
"Failed to insert block (hash={}, number={}, parent_hash={}): {}",
self.block.hash, self.block.number, self.block.parent_hash, self.kind
)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ where
debug_assert!(
self.peers.contains_key(&peer_id),
"a dead peer has been returned as idle by `@pop_any_idle_peer`, broken invariant `@peers` and `@transaction_fetcher`,
`%peer_id`: {:?},
`%peer_id`: {},
`@peers`: {:?},
`@transaction_fetcher`: {:?}",
peer_id, self.peers, self.transaction_fetcher
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
let peers = peers
.into_iter()
.map(|peer| PeerInfo {
id: Some(format!("{:?}", peer.remote_id)),
id: Some(peer.remote_id.to_string()),
name: peer.client_version.to_string(),
caps: peer.capabilities.capabilities().iter().map(|cap| cap.to_string()).collect(),
network: PeerNetworkInfo {
Expand All @@ -68,7 +68,7 @@ where
protocols: PeerProtocolsInfo {
eth: Some(PeerEthProtocolInfo {
difficulty: Some(peer.status.total_difficulty),
head: format!("{:?}", peer.status.blockhash),
head: peer.status.blockhash.to_string(),
version: peer.status.version as u32,
}),
pip: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/blobstore/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl DiskFileBlobStoreInner {
/// Returns the path to the blob file for the given transaction hash.
#[inline]
fn blob_disk_file(&self, tx: B256) -> PathBuf {
self.blob_dir.join(format!("{:x}", tx))
self.blob_dir.join(format!("{tx:x}"))
}

/// Retries the blob data for the given transaction hash.
Expand Down
13 changes: 6 additions & 7 deletions crates/transaction-pool/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,12 @@ impl<T: PoolTransaction + Clone> Clone for ValidPoolTransaction<T> {
}

impl<T: PoolTransaction> fmt::Debug for ValidPoolTransaction<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "Transaction {{ ")?;
write!(fmt, "hash: {:?}, ", &self.transaction.hash())?;
write!(fmt, "provides: {:?}, ", &self.transaction_id)?;
write!(fmt, "raw tx: {:?}", &self.transaction)?;
write!(fmt, "}}")?;
Ok(())
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ValidPoolTransaction")
.field("hash", self.transaction.hash())
.field("provides", &self.transaction_id)
.field("raw_tx", &self.transaction)
.finish()
}
}

Expand Down
9 changes: 3 additions & 6 deletions examples/trace-transaction-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
// Waiting for new transactions
while let Some(event) = pending_transactions.next().await {
let tx = event.transaction;
println!("Transaction received: {:?}", tx);
println!("Transaction received: {tx:?}");

if let Some(tx_recipient_address) = tx.to() {
if recipients.is_empty() || recipients.contains(&tx_recipient_address) {
Expand All @@ -83,11 +83,8 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
let tracerequest =
TraceCallRequest::new(callrequest).with_trace_type(TraceType::Trace);
if let Ok(trace_result) = traceapi.trace_call(tracerequest).await {
println!(
"trace result for transaction : {:?} is {:?}",
tx.hash(),
trace_result
);
let hash = tx.hash();
println!("trace result for transaction {hash}: {trace_result:?}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion testing/ef-tests/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Account {
/// In case of a mismatch, `Err(Error::Assertion)` is returned.
pub fn assert_db(&self, address: Address, tx: &impl DbTx) -> Result<(), Error> {
let account = tx.get::<tables::PlainAccountState>(address)?.ok_or_else(|| {
Error::Assertion(format!("Expected account ({address:?}) is missing from DB: {self:?}"))
Error::Assertion(format!("Expected account ({address}) is missing from DB: {self:?}"))
})?;

assert_equal(self.balance.into(), account.balance, "Balance does not match")?;
Expand Down

0 comments on commit 0aa2246

Please sign in to comment.