feat(rpc): get_account (#10369)

This commit is contained in:
greged93
2024-08-19 04:29:17 -07:00
committed by GitHub
parent e27ad1a2be
commit 297934fe21
3 changed files with 35 additions and 6 deletions

View File

@@ -650,10 +650,11 @@ where
/// Handler for: `eth_getAccount`
async fn get_account(
&self,
_address: Address,
_block: BlockId,
address: Address,
block: BlockId,
) -> RpcResult<reth_rpc_types::Account> {
Err(internal_rpc_err("unimplemented"))
trace!(target: "rpc::eth", "Serving eth_getAccount");
Ok(EthState::get_account(self, address, block).await?)
}
/// Handler for: `eth_maxPriorityFeePerGas`

View File

@@ -4,12 +4,13 @@
use futures::Future;
use reth_errors::RethError;
use reth_evm::ConfigureEvmEnv;
use reth_primitives::{Address, BlockId, Bytes, Header, B256, U256};
use reth_primitives::{Address, BlockId, Bytes, Header, B256, KECCAK_EMPTY, U256};
use reth_provider::{
BlockIdReader, ChainSpecProvider, StateProvider, StateProviderBox, StateProviderFactory,
StateRootProvider,
};
use reth_rpc_eth_types::{EthApiError, EthStateCache, PendingBlockEnv, RpcInvalidTransactionError};
use reth_rpc_types::{serde_helpers::JsonStorageKey, EIP1186AccountProofResponse};
use reth_rpc_types::{serde_helpers::JsonStorageKey, Account, EIP1186AccountProofResponse};
use reth_rpc_types_compat::proof::from_primitive_account_proof;
use reth_transaction_pool::{PoolTransaction, TransactionPool};
use revm::db::BundleState;
@@ -127,6 +128,33 @@ pub trait EthState: LoadState + SpawnBlocking {
.await
})
}
/// Returns the account at the given address for the provided block identifier.
fn get_account(
&self,
address: Address,
block_id: BlockId,
) -> impl Future<Output = Result<Account, Self::Error>> + Send {
self.spawn_blocking_io(move |this| {
let state = this.state_at_block_id(block_id)?;
let account = state
.basic_account(address)
.map_err(Self::Error::from_eth_err)?
.unwrap_or_default();
let balance = account.balance;
let nonce = account.nonce;
let code_hash = account.bytecode_hash.unwrap_or(KECCAK_EMPTY);
// Provide a default `HashedStorage` value in order to
// get the storage root hash of the current state.
let storage_root = state
.hashed_storage_root(address, Default::default())
.map_err(Self::Error::from_eth_err)?;
Ok(Account { balance, nonce, code_hash, storage_root })
})
}
}
/// Loads state from database.

View File

@@ -136,7 +136,7 @@ impl HashedPostState {
}
/// Representation of in-memory hashed storage.
#[derive(PartialEq, Eq, Clone, Debug)]
#[derive(PartialEq, Eq, Clone, Debug, Default)]
pub struct HashedStorage {
/// Flag indicating whether the storage was wiped or not.
pub wiped: bool,