diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index 97170fbf1..80f48ebe8 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -30,7 +30,7 @@ use crate::{ OtherBlockData, TrieRootHash, TxnIdx, EMPTY_ACCOUNT_BYTES_RLPED, ZERO_STORAGE_SLOT_VAL_RLPED, }, - utils::{hash, optional_field, optional_field_hex, update_val_if_some}, + utils::{eth_to_gwei, hash, optional_field, optional_field_hex, update_val_if_some}, }; /// Stores the result of parsing tries. Returns a [TraceParsingError] upon @@ -617,7 +617,7 @@ impl ProcessedBlockTrace { })?; let mut acc_data = account_from_rlped_bytes(acc_bytes)?; - acc_data.balance += amt; + acc_data.balance += eth_to_gwei(amt); state .insert(h_addr_nibs, rlp::encode(&acc_data).to_vec()) @@ -721,7 +721,7 @@ impl StateTrieWrites { } }; - update_val_if_some(&mut state_node.balance, self.balance); + update_val_i_some(&mut state_node.balance, self.balance); update_val_if_some(&mut state_node.nonce, self.nonce); update_val_if_some(&mut state_node.storage_root, storage_root_hash_change); update_val_if_some(&mut state_node.code_hash, self.code_hash); diff --git a/trace_decoder/src/utils.rs b/trace_decoder/src/utils.rs index 7abfe00df..2995ca68d 100644 --- a/trace_decoder/src/utils.rs +++ b/trace_decoder/src/utils.rs @@ -1,4 +1,4 @@ -use ethereum_types::H256; +use ethereum_types::{H256, U256}; use keccak_hash::keccak; use log::trace; use mpt_trie::{ @@ -8,6 +8,11 @@ use mpt_trie::{ use crate::types::HashedStorageAddr; +pub(crate) fn eth_to_gwei(eth: U256) -> U256 { + // 1 ether = 10^9 gwei. + eth * U256::from(10).pow(9.into()) +} + pub(crate) fn hash(bytes: &[u8]) -> H256 { H256::from(keccak(bytes).0) }