Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub enum EthRequest {
#[serde(rename = "web3_sha3", with = "sequence")]
Web3Sha3(Bytes),

/// Returns the current Ethereum protocol version.
#[serde(rename = "eth_protocolVersion", with = "empty_params")]
EthProtocolVersion(()),

#[serde(rename = "eth_chainId", with = "empty_params")]
EthChainId(()),

Expand All @@ -52,6 +56,10 @@ pub enum EthRequest {
#[serde(rename = "net_listening", with = "empty_params")]
NetListening(()),

/// Returns the number of hashes per second with which the node is mining.
#[serde(rename = "eth_hashrate", with = "empty_params")]
EthHashrate(()),

#[serde(rename = "eth_gasPrice", with = "empty_params")]
EthGasPrice(()),

Expand All @@ -67,6 +75,10 @@ pub enum EthRequest {
#[serde(rename = "eth_blockNumber", with = "empty_params")]
EthBlockNumber(()),

/// Returns the client coinbase address.
#[serde(rename = "eth_coinbase", with = "empty_params")]
EthCoinbase(()),

#[serde(rename = "eth_getBalance")]
EthGetBalance(Address, Option<BlockId>),

Expand Down
3 changes: 3 additions & 0 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl EthApi {
pub async fn execute(&self, request: EthRequest) -> ResponseResult {
trace!(target: "rpc::api", "executing eth request");
let response = match request.clone() {
EthRequest::EthProtocolVersion(()) => self.protocol_version().to_rpc_result(),
EthRequest::Web3ClientVersion(()) => self.client_version().to_rpc_result(),
EthRequest::Web3Sha3(content) => self.sha3(content).to_rpc_result(),
EthRequest::EthGetAccount(addr, block) => {
Expand All @@ -195,13 +196,15 @@ impl EthApi {
EthRequest::EthChainId(_) => self.eth_chain_id().to_rpc_result(),
EthRequest::EthNetworkId(_) => self.network_id().to_rpc_result(),
EthRequest::NetListening(_) => self.net_listening().to_rpc_result(),
EthRequest::EthHashrate(()) => self.hashrate().to_rpc_result(),
EthRequest::EthGasPrice(_) => self.eth_gas_price().to_rpc_result(),
EthRequest::EthMaxPriorityFeePerGas(_) => {
self.gas_max_priority_fee_per_gas().to_rpc_result()
}
EthRequest::EthBlobBaseFee(_) => self.blob_base_fee().to_rpc_result(),
EthRequest::EthAccounts(_) => self.accounts().to_rpc_result(),
EthRequest::EthBlockNumber(_) => self.block_number().to_rpc_result(),
EthRequest::EthCoinbase(()) => self.author().to_rpc_result(),
EthRequest::EthGetStorageAt(addr, slot, block) => {
self.storage_at(addr, slot, block).await.to_rpc_result()
}
Expand Down
Loading