Skip to content

Commit

Permalink
Change unwrap to ? to propagate errors (bluealloy#1207)
Browse files Browse the repository at this point in the history
* Change unwrap to ? to propagate errors

* Make clippy happy
  • Loading branch information
wtdcode authored and fubuloubu committed Apr 11, 2024
1 parent e7870a1 commit 69426c1
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions crates/revm/src/db/ethersdb.rs
Expand Up @@ -96,27 +96,22 @@ impl<M: Middleware> DatabaseRef for EthersDB<M> {
let storage = self
.client
.get_storage_at(add, index, self.block_number)
.await
.unwrap();
U256::from_be_bytes(storage.to_fixed_bytes())
.await?;
Ok(U256::from_be_bytes(storage.to_fixed_bytes()))
};
Ok(self.block_on(f))
self.block_on(f)
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
// saturate usize
if number > U256::from(u64::MAX) {
return Ok(KECCAK_EMPTY);
}
// We known number <= u64::MAX so unwrap is safe
let number = eU64::from(u64::try_from(number).unwrap());
let f = async {
self.client
.get_block(BlockId::from(number))
.await
.ok()
.flatten()
};
Ok(B256::new(self.block_on(f).unwrap().hash.unwrap().0))
let f = async { self.client.get_block(BlockId::from(number)).await };
// If number is given, the block is supposed to be finalized so unwrap is safe too.
Ok(B256::new(self.block_on(f)?.unwrap().hash.unwrap().0))
}
}

Expand Down

0 comments on commit 69426c1

Please sign in to comment.