Skip to content

Commit

Permalink
feat(ethersdb): basic_ref return none instead of panic
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkr8os committed Dec 28, 2023
1 parent 3a829d3 commit 074740f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions crates/revm/src/db/ethersdb.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -60,19 +61,18 @@ impl<M: Middleware> DatabaseRef for EthersDB<M> {
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,
)))
Expand Down

0 comments on commit 074740f

Please sign in to comment.