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

feat(provider): eth_getAccount support #760

Merged
merged 4 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use alloy_primitives::{
};
use alloy_rpc_client::{ClientRef, PollerBuilder, RpcCall, WeakClient};
use alloy_rpc_types::{
AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, EIP1186AccountProofResponse,
FeeHistory, Filter, FilterChanges, Log, SyncStatus,
AccessListWithGasUsed, AccountResponse, Block, BlockId, BlockNumberOrTag,
EIP1186AccountProofResponse, FeeHistory, Filter, FilterChanges, Log, SyncStatus,
};
use alloy_rpc_types_trace::parity::{LocalizedTransactionTrace, TraceResults, TraceType};
use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResult};
Expand Down Expand Up @@ -574,6 +574,16 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
self.client().request("eth_getLogs", (filter,)).await
}

/// Retrieves account information ([AccountResponse]) for the given [Address] at the particular
/// [BlockId].
async fn get_account(
&self,
address: Address,
block: BlockId,
mattsse marked this conversation as resolved.
Show resolved Hide resolved
) -> TransportResult<Option<AccountResponse>> {
self.client().request("eth_getAccount", (address, block)).await
}

/// Gets the accounts in the remote node. This is usually empty unless you're using a local
/// node.
async fn get_accounts(&self) -> TransportResult<Vec<Address>> {
Expand Down
14 changes: 14 additions & 0 deletions crates/rpc-types/src/eth/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ pub struct EIP1186AccountProofResponse {
pub storage_proof: Vec<EIP1186StorageProof>,
}

/// Response for `eth_getAccount`
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have an Account struct in alloy-consensus? if not i would prefer to push this down and ensure it has RLP encoding

pub struct AccountResponse {
/// The account's balance.
pub balance: U256,
/// The hash of the code of the account.
pub code_hash: B256,
/// The account's nonce.
pub nonce: U64,
/// The hash of the storage account data.
pub storage_root: B256,
}

/// Extended account information (used by `parity_allAccountInfo`).
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct ExtAccountInfo {
Expand Down
Loading