chore: use Display when formatting addresses and hashes (#6245)

This commit is contained in:
DaniPopes
2024-01-26 15:57:08 +01:00
committed by GitHub
parent 556741abb0
commit 0aa22466d2
8 changed files with 16 additions and 20 deletions

View File

@ -57,7 +57,7 @@ impl fmt::Display for Head {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, 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 self.number, self.hash, self.difficulty, self.total_difficulty, self.timestamp
) )
} }

View File

@ -151,7 +151,7 @@ impl std::fmt::Display for InsertBlockErrorData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!( write!(
f, 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 self.block.hash, self.block.number, self.block.parent_hash, self.kind
) )
} }

View File

@ -683,7 +683,7 @@ where
debug_assert!( debug_assert!(
self.peers.contains_key(&peer_id), 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`, "a dead peer has been returned as idle by `@pop_any_idle_peer`, broken invariant `@peers` and `@transaction_fetcher`,
`%peer_id`: {:?}, `%peer_id`: {},
`@peers`: {:?}, `@peers`: {:?},
`@transaction_fetcher`: {:?}", `@transaction_fetcher`: {:?}",
peer_id, self.peers, self.transaction_fetcher peer_id, self.peers, self.transaction_fetcher

View File

@ -55,7 +55,7 @@ where
let peers = peers let peers = peers
.into_iter() .into_iter()
.map(|peer| PeerInfo { .map(|peer| PeerInfo {
id: Some(format!("{:?}", peer.remote_id)), id: Some(peer.remote_id.to_string()),
name: peer.client_version.to_string(), name: peer.client_version.to_string(),
caps: peer.capabilities.capabilities().iter().map(|cap| cap.to_string()).collect(), caps: peer.capabilities.capabilities().iter().map(|cap| cap.to_string()).collect(),
network: PeerNetworkInfo { network: PeerNetworkInfo {
@ -68,7 +68,7 @@ where
protocols: PeerProtocolsInfo { protocols: PeerProtocolsInfo {
eth: Some(PeerEthProtocolInfo { eth: Some(PeerEthProtocolInfo {
difficulty: Some(peer.status.total_difficulty), difficulty: Some(peer.status.total_difficulty),
head: format!("{:?}", peer.status.blockhash), head: peer.status.blockhash.to_string(),
version: peer.status.version as u32, version: peer.status.version as u32,
}), }),
pip: None, pip: None,

View File

@ -211,7 +211,7 @@ impl DiskFileBlobStoreInner {
/// Returns the path to the blob file for the given transaction hash. /// Returns the path to the blob file for the given transaction hash.
#[inline] #[inline]
fn blob_disk_file(&self, tx: B256) -> PathBuf { 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. /// Retries the blob data for the given transaction hash.

View File

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

View File

@ -73,7 +73,7 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
// Waiting for new transactions // Waiting for new transactions
while let Some(event) = pending_transactions.next().await { while let Some(event) = pending_transactions.next().await {
let tx = event.transaction; let tx = event.transaction;
println!("Transaction received: {:?}", tx); println!("Transaction received: {tx:?}");
if let Some(tx_recipient_address) = tx.to() { if let Some(tx_recipient_address) = tx.to() {
if recipients.is_empty() || recipients.contains(&tx_recipient_address) { if recipients.is_empty() || recipients.contains(&tx_recipient_address) {
@ -83,11 +83,8 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
let tracerequest = let tracerequest =
TraceCallRequest::new(callrequest).with_trace_type(TraceType::Trace); TraceCallRequest::new(callrequest).with_trace_type(TraceType::Trace);
if let Ok(trace_result) = traceapi.trace_call(tracerequest).await { if let Ok(trace_result) = traceapi.trace_call(tracerequest).await {
println!( let hash = tx.hash();
"trace result for transaction : {:?} is {:?}", println!("trace result for transaction {hash}: {trace_result:?}");
tx.hash(),
trace_result
);
} }
} }
} }

View File

@ -210,7 +210,7 @@ impl Account {
/// In case of a mismatch, `Err(Error::Assertion)` is returned. /// In case of a mismatch, `Err(Error::Assertion)` is returned.
pub fn assert_db(&self, address: Address, tx: &impl DbTx) -> Result<(), Error> { pub fn assert_db(&self, address: Address, tx: &impl DbTx) -> Result<(), Error> {
let account = tx.get::<tables::PlainAccountState>(address)?.ok_or_else(|| { 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")?; assert_equal(self.balance.into(), account.balance, "Balance does not match")?;