Skip to content

Commit 6bcfb82

Browse files
authored
fix: specialize eth_getAccountInfo in fork mode (#11634)
* fix: specialize eth_getAccountInfo in fork mode * typo
1 parent a8dc5ae commit 6bcfb82

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/anvil/src/eth/api.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,12 +766,31 @@ impl EthApi {
766766
}
767767

768768
/// Returns the account information including balance, nonce, code and storage
769+
///
770+
/// Note: This isn't support by all providers
769771
pub async fn get_account_info(
770772
&self,
771773
address: Address,
772774
block_number: Option<BlockId>,
773775
) -> Result<alloy_rpc_types::eth::AccountInfo> {
774776
node_info!("eth_getAccountInfo");
777+
778+
if let Some(fork) = self.get_fork() {
779+
// check if the number predates the fork, if in fork mode
780+
if let BlockRequest::Number(number) = self.block_request(block_number).await?
781+
&& fork.predates_fork(number)
782+
{
783+
// if this predates the fork we need to fetch balance, nonce, code individually
784+
// because the provider might not support this endpoint
785+
let balance = self.balance(address, Some(number.into()));
786+
let code = self.get_code(address, Some(number.into()));
787+
let nonce = self.get_transaction_count(address, Some(number.into()));
788+
let (balance, code, nonce) = try_join!(balance, code, nonce)?;
789+
790+
return Ok(alloy_rpc_types::eth::AccountInfo { balance, nonce, code });
791+
}
792+
}
793+
775794
let account = self.get_account(address, block_number);
776795
let code = self.get_code(address, block_number);
777796
let (account, code) = try_join!(account, code)?;

0 commit comments

Comments
 (0)