Skip to content

Commit 2bb29fb

Browse files
authored
feat(anvil): wire eth_protocolVersion, eth_hashrate, eth_coinbase RPCs (#11934)
* feat(anvil): wire eth_protocolVersion, eth_hashrate, eth_coinbase RPCs * Wire protocolVersion/hashrate/coinbase in execute and return hex from protocol_version
1 parent 807036b commit 2bb29fb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

crates/anvil/core/src/eth/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub enum EthRequest {
4343
#[serde(rename = "web3_sha3", with = "sequence")]
4444
Web3Sha3(Bytes),
4545

46+
/// Returns the current Ethereum protocol version.
47+
#[serde(rename = "eth_protocolVersion", with = "empty_params")]
48+
EthProtocolVersion(()),
49+
4650
#[serde(rename = "eth_chainId", with = "empty_params")]
4751
EthChainId(()),
4852

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

59+
/// Returns the number of hashes per second with which the node is mining.
60+
#[serde(rename = "eth_hashrate", with = "empty_params")]
61+
EthHashrate(()),
62+
5563
#[serde(rename = "eth_gasPrice", with = "empty_params")]
5664
EthGasPrice(()),
5765

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

78+
/// Returns the client coinbase address.
79+
#[serde(rename = "eth_coinbase", with = "empty_params")]
80+
EthCoinbase(()),
81+
7082
#[serde(rename = "eth_getBalance")]
7183
EthGetBalance(Address, Option<BlockId>),
7284

crates/anvil/src/eth/api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl EthApi {
172172
pub async fn execute(&self, request: EthRequest) -> ResponseResult {
173173
trace!(target: "rpc::api", "executing eth request");
174174
let response = match request.clone() {
175+
EthRequest::EthProtocolVersion(()) => self.protocol_version().to_rpc_result(),
175176
EthRequest::Web3ClientVersion(()) => self.client_version().to_rpc_result(),
176177
EthRequest::Web3Sha3(content) => self.sha3(content).to_rpc_result(),
177178
EthRequest::EthGetAccount(addr, block) => {
@@ -195,13 +196,15 @@ impl EthApi {
195196
EthRequest::EthChainId(_) => self.eth_chain_id().to_rpc_result(),
196197
EthRequest::EthNetworkId(_) => self.network_id().to_rpc_result(),
197198
EthRequest::NetListening(_) => self.net_listening().to_rpc_result(),
199+
EthRequest::EthHashrate(()) => self.hashrate().to_rpc_result(),
198200
EthRequest::EthGasPrice(_) => self.eth_gas_price().to_rpc_result(),
199201
EthRequest::EthMaxPriorityFeePerGas(_) => {
200202
self.gas_max_priority_fee_per_gas().to_rpc_result()
201203
}
202204
EthRequest::EthBlobBaseFee(_) => self.blob_base_fee().to_rpc_result(),
203205
EthRequest::EthAccounts(_) => self.accounts().to_rpc_result(),
204206
EthRequest::EthBlockNumber(_) => self.block_number().to_rpc_result(),
207+
EthRequest::EthCoinbase(()) => self.author().to_rpc_result(),
205208
EthRequest::EthGetStorageAt(addr, slot, block) => {
206209
self.storage_at(addr, slot, block).await.to_rpc_result()
207210
}

0 commit comments

Comments
 (0)