Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
dev: use join! macro (#1384)
Browse files Browse the repository at this point in the history
improve the DatabaseRef implementation for EthDatabase
  • Loading branch information
greged93 authored Sep 17, 2024
1 parent 08bca4c commit 67fb6cd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/providers/eth_provider/database/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ impl<P: EthereumProvider + Send + Sync> DatabaseRef for EthDatabase<P> {
fn basic_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
tokio::task::block_in_place(|| {
let account_info = Handle::current().block_on(async {
let bytecode = self.provider.get_code(address, Some(self.block_id)).await?;
let bytecode = Bytecode::new_raw(bytecode);
let code_hash = bytecode.hash_slow();
let bytecode = self.provider.get_code(address, Some(self.block_id));
let nonce = self.provider.transaction_count(address, Some(self.block_id));
let balance = self.provider.balance(address, Some(self.block_id));

let (bytecode, nonce, balance) = tokio::join!(bytecode, nonce, balance);

let nonce = self.provider.transaction_count(address, Some(self.block_id)).await?.to();
let balance = self.provider.balance(address, Some(self.block_id)).await?;
let bytecode = Bytecode::new_raw(bytecode?);
let code_hash = bytecode.hash_slow();

Result::<_, EthApiError>::Ok(AccountInfo { nonce, balance, code: Some(bytecode), code_hash })
Result::<_, EthApiError>::Ok(AccountInfo {
nonce: nonce?.to(),
balance: balance?,
code: Some(bytecode),
code_hash,
})
})?;

Ok(Some(account_info))
Expand Down

0 comments on commit 67fb6cd

Please sign in to comment.