Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unwrap to ? to propagate errors #1207

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions crates/revm/src/db/ethersdb.rs
Original file line number Diff line number Diff line change
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
Loading