Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add is_empty_code_hash fn #826

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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