Skip to content

Commit

Permalink
feat(cast): pretty print tx status in cast receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
llllvvuu committed Apr 1, 2024
1 parent d94e3c6 commit e58b296
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/common/src/fmt/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ type {}",
serde_json::to_string(logs).unwrap(),
logs_bloom.pretty(),
root.pretty(),
status.pretty(),
pretty_status(*status),
transaction_hash.pretty(),
transaction_index.pretty(),
transaction_type.pretty()
Expand Down Expand Up @@ -374,6 +374,14 @@ pub fn to_bytes(uint: ethers_core::types::U256) -> [u8; 32] {
buffer
}

pub fn pretty_status(status: Option<ethers_core::types::U64>) -> String {
match status {
Some(ethers_core::types::U64([0])) => "0 (failed)".to_string(),
Some(ethers_core::types::U64([1])) => "1 (success)".to_string(),
_ => status.pretty(),
}
}

/// Returns the `UiFmt::pretty()` formatted attribute of the transactions
pub fn get_pretty_tx_attr(transaction: &Transaction, attr: &str) -> Option<String> {
match attr {
Expand Down Expand Up @@ -419,7 +427,7 @@ pub fn get_pretty_tx_receipt_attr(
"logs" => Some(receipt.receipt.logs.pretty()),
"logsBloom" | "logs_bloom" => Some(receipt.receipt.logs_bloom.pretty()),
"root" => Some(receipt.receipt.root.pretty()),
"status" => Some(receipt.receipt.status.pretty()),
"status" => Some(pretty_status(receipt.receipt.status)),
"transactionHash" | "transaction_hash" => Some(receipt.receipt.transaction_hash.pretty()),
"transactionIndex" | "transaction_index" => {
Some(receipt.receipt.transaction_index.pretty())
Expand Down

0 comments on commit e58b296

Please sign in to comment.