Skip to content

Commit

Permalink
fix(cast block): ensure to print all fields (#9209)
Browse files Browse the repository at this point in the history
fix(cast block): ensure to print all fields
  • Loading branch information
klkvr authored Oct 27, 2024
1 parent 513ed69 commit 5c69a9d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 24 deletions.
3 changes: 3 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ stateRoot [..]
timestamp [..]
withdrawalsRoot [..]
totalDifficulty [..]
blobGasUsed [..]
excessBlobGas [..]
requestsHash [..]
transactions: [
...
]
Expand Down
89 changes: 65 additions & 24 deletions crates/common/fmt/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_consensus::{AnyReceiptEnvelope, Eip658Value, Receipt, ReceiptWithBloom
use alloy_network::ReceiptResponse;
use alloy_primitives::{hex, Address, Bloom, Bytes, FixedBytes, Uint, B256, I256, U256, U64};
use alloy_rpc_types::{
AccessListItem, AnyNetworkBlock, AnyTransactionReceipt, Block, BlockTransactions, Log,
AccessListItem, AnyNetworkBlock, AnyTransactionReceipt, Block, BlockTransactions, Header, Log,
Transaction, TransactionReceipt,
};
use alloy_serde::{OtherFields, WithOtherFields};
Expand Down Expand Up @@ -597,6 +597,9 @@ pub fn get_pretty_block_attr(block: &AnyNetworkBlock, attr: &str) -> Option<Stri
"stateRoot" | "state_root" => Some(block.header.state_root.pretty()),
"timestamp" => Some(block.header.timestamp.pretty()),
"totalDifficulty" | "total_difficult" => Some(block.header.total_difficulty.pretty()),
"blobGasUsed" | "blob_gas_used" => Some(block.header.blob_gas_used.pretty()),
"excessBlobGas" | "excess_blob_gas" => Some(block.header.excess_blob_gas.pretty()),
"requestsHash" | "requests_hash" => Some(block.header.requests_hash.pretty()),
other => {
if let Some(value) = block.other.get(other) {
let val = EthValue::from(value.clone());
Expand All @@ -608,6 +611,38 @@ pub fn get_pretty_block_attr(block: &AnyNetworkBlock, attr: &str) -> Option<Stri
}

fn pretty_block_basics<T>(block: &Block<T>) -> String {
let Block {
header:
Header {
hash,
parent_hash,
uncles_hash,
miner,
state_root,
transactions_root,
receipts_root,
logs_bloom,
difficulty,
number,
gas_limit,
gas_used,
timestamp,
total_difficulty,
extra_data,
mix_hash,
nonce,
base_fee_per_gas,
withdrawals_root,
blob_gas_used,
excess_blob_gas,
parent_beacon_block_root,
requests_hash,
},
uncles: _,
transactions: _,
size,
withdrawals: _,
} = block;
format!(
"
baseFeePerGas {}
Expand All @@ -630,31 +665,37 @@ size {}
stateRoot {}
timestamp {} ({})
withdrawalsRoot {}
totalDifficulty {}",
block.header.base_fee_per_gas.pretty(),
block.header.difficulty.pretty(),
block.header.extra_data.pretty(),
block.header.gas_limit.pretty(),
block.header.gas_used.pretty(),
block.header.hash.pretty(),
block.header.logs_bloom.pretty(),
block.header.miner.pretty(),
block.header.mix_hash.pretty(),
block.header.nonce.pretty(),
block.header.number.pretty(),
block.header.parent_hash.pretty(),
block.header.parent_beacon_block_root.pretty(),
block.header.transactions_root.pretty(),
block.header.receipts_root.pretty(),
block.header.uncles_hash.pretty(),
block.size.pretty(),
block.header.state_root.pretty(),
block.header.timestamp.pretty(),
chrono::DateTime::from_timestamp(block.header.timestamp as i64, 0)
totalDifficulty {}
blobGasUsed {}
excessBlobGas {}
requestsHash {}",
base_fee_per_gas.pretty(),
difficulty.pretty(),
extra_data.pretty(),
gas_limit.pretty(),
gas_used.pretty(),
hash.pretty(),
logs_bloom.pretty(),
miner.pretty(),
mix_hash.pretty(),
nonce.pretty(),
number.pretty(),
parent_hash.pretty(),
parent_beacon_block_root.pretty(),
transactions_root.pretty(),
receipts_root.pretty(),
uncles_hash.pretty(),
size.pretty(),
state_root.pretty(),
timestamp.pretty(),
chrono::DateTime::from_timestamp(*timestamp as i64, 0)
.expect("block timestamp in range")
.to_rfc2822(),
block.header.withdrawals_root.pretty(),
block.header.total_difficulty.pretty(),
withdrawals_root.pretty(),
total_difficulty.pretty(),
blob_gas_used.pretty(),
excess_blob_gas.pretty(),
requests_hash.pretty(),
)
}

Expand Down

0 comments on commit 5c69a9d

Please sign in to comment.