-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move formatting logic to foundry-macros (#4936)
* chore: move formatting logic to foundry-macros * fixes
- Loading branch information
Showing
10 changed files
with
94 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Helpers for formatting ethereum types | ||
|
||
use crate::TransactionReceiptWithRevertReason; | ||
|
||
pub use foundry_macros::fmt::*; | ||
|
||
impl UIfmt for TransactionReceiptWithRevertReason { | ||
fn pretty(&self) -> String { | ||
if let Some(revert_reason) = &self.revert_reason { | ||
format!( | ||
"{} | ||
revertReason {}", | ||
self.receipt.pretty(), | ||
revert_reason | ||
) | ||
} else { | ||
self.receipt.pretty() | ||
} | ||
} | ||
} | ||
|
||
/// Returns the ``UiFmt::pretty()` formatted attribute of the transaction receipt | ||
pub fn get_pretty_tx_receipt_attr( | ||
receipt: &TransactionReceiptWithRevertReason, | ||
attr: &str, | ||
) -> Option<String> { | ||
match attr { | ||
"blockHash" | "block_hash" => Some(receipt.receipt.block_hash.pretty()), | ||
"blockNumber" | "block_number" => Some(receipt.receipt.block_number.pretty()), | ||
"contractAddress" | "contract_address" => Some(receipt.receipt.contract_address.pretty()), | ||
"cumulativeGasUsed" | "cumulative_gas_used" => { | ||
Some(receipt.receipt.cumulative_gas_used.pretty()) | ||
} | ||
"effectiveGasPrice" | "effective_gas_price" => { | ||
Some(receipt.receipt.effective_gas_price.pretty()) | ||
} | ||
"gasUsed" | "gas_used" => Some(receipt.receipt.gas_used.pretty()), | ||
"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()), | ||
"transactionHash" | "transaction_hash" => Some(receipt.receipt.transaction_hash.pretty()), | ||
"transactionIndex" | "transaction_index" => { | ||
Some(receipt.receipt.transaction_index.pretty()) | ||
} | ||
"type" | "transaction_type" => Some(receipt.receipt.transaction_type.pretty()), | ||
"revertReason" | "revert_reason" => Some(receipt.revert_reason.pretty()), | ||
_ => None, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
//! Foundry's procedural macros. | ||
//! | ||
//! Also includes traits and other utilities used by the macros. | ||
|
||
// TODO: Remove dependency on foundry-common (currently only used for the UIfmt trait). | ||
|
||
mod console_fmt; | ||
pub use console_fmt::{console_format, ConsoleFmt, FormatSpec}; | ||
pub mod fmt; | ||
pub use fmt::{console_format, ConsoleFmt, FormatSpec, TokenDisplay, UIfmt}; | ||
|
||
#[doc(inline)] | ||
pub use foundry_macros_impl::ConsoleFmt; |