Skip to content

Commit

Permalink
review: WithHash -> CustomFmt<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaatif committed Aug 12, 2024
1 parent 0e09bed commit 74d3127
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions trace_decoder/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn update_beacon_block_root_contract_storage(
false => {
storage_trie.insert(slot, val.clone()).context(format!(
"at slot {} with value {}",
WithHash(U512::from_big_endian(slot.bytes_be().as_slice())),
CustomFmt(U512::from_big_endian(slot.bytes_be().as_slice())),
U512::from_big_endian(val.as_slice())
))?;

Expand Down Expand Up @@ -191,7 +191,7 @@ fn update_beacon_block_root_contract_storage(
.insert(addr_nibbles, updated_account_bytes.to_vec())
.context(format!(
"at slot {}",
WithHash(U512::from_big_endian(addr_nibbles.bytes_be().as_slice()))
CustomFmt(U512::from_big_endian(addr_nibbles.bytes_be().as_slice()))
))?;

Ok(())
Expand Down Expand Up @@ -294,7 +294,7 @@ fn apply_deltas_to_trie_state(
match val == &ZERO_STORAGE_SLOT_VAL_RLPED {
false => storage_trie.insert(slot, val.clone()).context(format!(
"at slot {} with value {}",
WithHash(U512::from_big_endian(slot.bytes_be().as_slice())),
CustomFmt(U512::from_big_endian(slot.bytes_be().as_slice())),
U512::from_big_endian(val.as_slice())
))?,
true => {
Expand Down Expand Up @@ -657,9 +657,9 @@ fn eth_to_gwei(eth: U256) -> U256 {
const ZERO_STORAGE_SLOT_VAL_RLPED: [u8; 1] = [128];

/// Formatting aid for error context.
struct WithHash(U512);
struct CustomFmt<T>(T);

impl fmt::Display for WithHash {
impl fmt::Display for CustomFmt<U512> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut buf = [0u8; 64];
self.0.to_big_endian(&mut buf);
Expand Down

0 comments on commit 74d3127

Please sign in to comment.