From 074740fdbb760a8f6deeb84df613c8842773a876 Mon Sep 17 00:00:00 2001 From: 0xkr8os Date: Thu, 28 Dec 2023 11:55:21 -0600 Subject: [PATCH] feat(ethersdb): basic_ref return none instead of panic --- crates/revm/src/db/ethersdb.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/revm/src/db/ethersdb.rs b/crates/revm/src/db/ethersdb.rs index a82107fac22..9d5bb59bed0 100644 --- a/crates/revm/src/db/ethersdb.rs +++ b/crates/revm/src/db/ethersdb.rs @@ -1,6 +1,7 @@ use crate::primitives::{AccountInfo, Address, Bytecode, B256, KECCAK_EMPTY, U256}; use crate::{Database, DatabaseRef}; -use ethers_core::types::{BlockId, H160 as eH160, H256, U64 as eU64}; +use core::str::FromStr; +use ethers_core::types::{BlockId, Bytes, H160 as eH160, H256, U64 as eU64}; use ethers_providers::Middleware; use std::sync::Arc; use tokio::runtime::{Handle, Runtime}; @@ -60,19 +61,18 @@ impl DatabaseRef for EthersDB { tokio::join!(nonce, balance, code) }; let (nonce, balance, code) = self.block_on(f); - // panic on not getting data? - let bytecode = code.unwrap_or_else(|e| panic!("ethers get code error: {e:?}")); + + if nonce.is_err() || balance.is_err() { + // If we can't get nonce or balance, we can't get the account + return Ok(None); + } + + let bytecode = code.unwrap_or(Bytes::from_str("").unwrap()); let bytecode = Bytecode::new_raw(bytecode.0.into()); let code_hash = bytecode.hash_slow(); Ok(Some(AccountInfo::new( - U256::from_limbs( - balance - .unwrap_or_else(|e| panic!("ethers get balance error: {e:?}")) - .0, - ), - nonce - .unwrap_or_else(|e| panic!("ethers get nonce error: {e:?}")) - .as_u64(), + U256::from_limbs(balance.unwrap().0), + nonce.unwrap().as_u64(), code_hash, bytecode, )))