diff --git a/core/src/client/mod.rs b/core/src/client/mod.rs index dcf49efb..a43c38b1 100644 --- a/core/src/client/mod.rs +++ b/core/src/client/mod.rs @@ -153,8 +153,8 @@ impl> Client { self.node.get_block_number().await } - pub async fn get_client_version(&self) -> Result { - self.node.get_client_version().await + pub async fn client_version(&self) -> Result { + self.node.client_version().await } pub async fn get_block_by_number( diff --git a/core/src/client/node.rs b/core/src/client/node.rs index 96dda2bc..147ff66a 100644 --- a/core/src/client/node.rs +++ b/core/src/client/node.rs @@ -140,7 +140,7 @@ impl> Node { self.execution.get_logs(filter).await } - pub async fn get_client_version(&self) -> Result { + pub async fn client_version(&self) -> Result { self.execution.get_client_version().await } diff --git a/core/src/client/rpc.rs b/core/src/client/rpc.rs index 82ddc6ae..5c126616 100644 --- a/core/src/client/rpc.rs +++ b/core/src/client/rpc.rs @@ -74,8 +74,6 @@ trait EthRpc Result; #[method(name = "getCode")] async fn get_code(&self, address: Address, block: BlockTag) -> Result; - #[method(name = "getClientVersion")] - async fn get_client_version(&self) -> Result; #[method(name = "call")] async fn call(&self, tx: TXR, block: BlockTag) -> Result; #[method(name = "estimateGas")] @@ -143,6 +141,12 @@ trait NetRpc { async fn version(&self) -> Result; } +#[rpc(client, server, namespace = "web3")] +trait Web3Rpc { + #[method(name = "clientVersion")] + async fn client_version(&self) -> Result; +} + struct RpcInner> { node: Arc>, address: SocketAddr, @@ -196,10 +200,6 @@ impl> convert_err(self.node.get_code(address, block).await) } - async fn get_client_version(&self) -> Result { - convert_err(self.node.get_client_version().await) - } - async fn call( &self, tx: N::TransactionRequest, @@ -324,6 +324,14 @@ impl> NetRpcServer for RpcI } } +#[async_trait] +impl> Web3RpcServer for RpcInner { + async fn client_version(&self) -> Result { + convert_err(self.node.client_version().await) + } +} + + async fn start>( rpc: RpcInner, ) -> Result<(ServerHandle, SocketAddr)> { @@ -332,10 +340,12 @@ async fn start>( let mut methods = Methods::new(); let eth_methods: Methods = EthRpcServer::into_rpc(rpc.clone()).into(); - let net_methods: Methods = NetRpcServer::into_rpc(rpc).into(); + let net_methods: Methods = NetRpcServer::into_rpc(rpc.clone()).into(); + let web3_methods: Methods = Web3RpcServer::into_rpc(rpc).into(); methods.merge(eth_methods)?; methods.merge(net_methods)?; + methods.merge(web3_methods)?; let handle = server.start(methods); diff --git a/examples/basic.rs b/examples/basic.rs index 9e501faa..ec648e51 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -46,7 +46,7 @@ async fn main() -> Result<()> { client.start().await?; client.wait_synced().await; - let client_version = client.get_client_version().await?; + let client_version = client.client_version().await?; let head_block_num = client.get_block_number().await?; let addr = Address::from_str("0x00000000219ab540356cBB839Cbe05303d7705Fa")?; let block = BlockTag::Latest; diff --git a/rpc.md b/rpc.md index ae81107c..5cbb1f77 100644 --- a/rpc.md +++ b/rpc.md @@ -25,4 +25,4 @@ Helios provides a variety of RPC methods for interacting with the Ethereum netwo | `eth_getBlockTransactionCountByNumber` | `get_block_transaction_count_by_number` | Returns the number of transactions in a block from a block matching the block number. | `client.get_block_transaction_count_by_number(&self, block: BlockTag)` | | `eth_coinbase` | `get_coinbase` | Returns the client coinbase address. | `client.get_coinbase(&self)` | | `eth_syncing` | `syncing` | Returns an object with data about the sync status or false. | `client.syncing(&self)` | -| `web3_getClientVersion` | `get_client_version` | Returns the current version of the chain client. | `client.get_client_version(&self)` | +| `web3_clientVersion` | `client_version` | Returns the current version of the chain client. | `client.client_version(&self)` |