small refactor for Account implementation (#6143)

This commit is contained in:
Thomas Coratger
2024-01-22 06:59:22 +01:00
committed by GitHub
parent 734109e968
commit ccafe0f2df

View File

@ -29,12 +29,9 @@ impl Account {
/// After SpuriousDragon empty account is defined as account with nonce == 0 && balance == 0 && /// After SpuriousDragon empty account is defined as account with nonce == 0 && balance == 0 &&
/// bytecode = None. /// bytecode = None.
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
let is_bytecode_empty = match self.bytecode_hash { self.nonce == 0 &&
None => true, self.balance.is_zero() &&
Some(hash) => hash == KECCAK_EMPTY, self.bytecode_hash.map_or(true, |hash| hash == KECCAK_EMPTY)
};
self.nonce == 0 && self.balance.is_zero() && is_bytecode_empty
} }
/// Converts [GenesisAccount] to [Account] type /// Converts [GenesisAccount] to [Account] type
@ -50,10 +47,7 @@ impl Account {
/// Returns an account bytecode's hash. /// Returns an account bytecode's hash.
/// In case of no bytecode, returns [`KECCAK_EMPTY`]. /// In case of no bytecode, returns [`KECCAK_EMPTY`].
pub fn get_bytecode_hash(&self) -> B256 { pub fn get_bytecode_hash(&self) -> B256 {
match self.bytecode_hash { self.bytecode_hash.unwrap_or(KECCAK_EMPTY)
Some(hash) => hash,
None => KECCAK_EMPTY,
}
} }
} }