Skip to content

Commit

Permalink
feat(ethersdb): propagate errors instead of panicking in basic_ref (#935
Browse files Browse the repository at this point in the history
)
  • Loading branch information
0xkr8os authored Dec 29, 2023
1 parent b97bbf7 commit eff379d
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions crates/revm/src/db/ethersdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<M: Middleware> EthersDB<M> {
}

impl<M: Middleware> DatabaseRef for EthersDB<M> {
type Error = ();
type Error = M::Error;

fn basic_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
let add = eH160::from(address.0 .0);
Expand All @@ -60,22 +60,12 @@ 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:?}"));
let bytecode = Bytecode::new_raw(bytecode.0.into());

let balance = U256::from_limbs(balance?.0);
let nonce = nonce?.as_u64();
let bytecode = Bytecode::new_raw(code?.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(),
code_hash,
bytecode,
)))
Ok(Some(AccountInfo::new(balance, nonce, code_hash, bytecode)))
}

fn code_by_hash_ref(&self, _code_hash: B256) -> Result<Bytecode, Self::Error> {
Expand Down Expand Up @@ -115,7 +105,7 @@ impl<M: Middleware> DatabaseRef for EthersDB<M> {
}

impl<M: Middleware> Database for EthersDB<M> {
type Error = ();
type Error = M::Error;

#[inline]
fn basic(&mut self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
Expand Down

0 comments on commit eff379d

Please sign in to comment.