Skip to content

Commit

Permalink
feat: add is_empty_code_hash fn (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 23, 2023
1 parent df44297 commit 2293ad7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/primitives/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl AccountInfo {
/// - balance is zero
/// - nonce is zero
pub fn is_empty(&self) -> bool {
let code_empty = self.code_hash == KECCAK_EMPTY || self.code_hash == B256::ZERO;
let code_empty = self.is_empty_code_hash() || self.code_hash == B256::ZERO;
self.balance == U256::ZERO && self.nonce == 0 && code_empty
}

Expand All @@ -252,6 +252,12 @@ impl AccountInfo {
self.code_hash
}

/// Returns true if the code hash is the Keccak256 hash of the empty string `""`.
#[inline]
pub fn is_empty_code_hash(&self) -> bool {
self.code_hash == KECCAK_EMPTY
}

/// Take bytecode from account. Code will be set to None.
pub fn take_bytecode(&mut self) -> Option<Bytecode> {
self.code.take()
Expand Down

0 comments on commit 2293ad7

Please sign in to comment.