From 62e7d5241292c2532cc3574aa4bf247eeabe2911 Mon Sep 17 00:00:00 2001 From: Tony Ke Date: Sat, 29 Jun 2024 22:00:43 +0800 Subject: [PATCH] primitives: add utility function AccountInfo::from_bytecode --- crates/primitives/src/state.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/primitives/src/state.rs b/crates/primitives/src/state.rs index d1f6c9df46..fc4d1e609f 100644 --- a/crates/primitives/src/state.rs +++ b/crates/primitives/src/state.rs @@ -310,6 +310,17 @@ impl AccountInfo { ..Default::default() } } + + pub fn from_bytecode(bytecode: Bytecode) -> Self { + let hash = bytecode.hash_slow(); + + AccountInfo { + balance: U256::ZERO, + nonce: 1, + code: Some(bytecode), + code_hash: hash, + } + } } #[cfg(test)]