From 819ee702e8552db88c167325c7a560b193d2ae2b Mon Sep 17 00:00:00 2001 From: danilowhk Date: Thu, 12 Jan 2023 22:30:15 -0300 Subject: [PATCH] feat : eth_coinbase implementation #157 (#167) * ethereum_get_cooinbase * change return type from CoinbaseAddress to Address * format --- client/src/client.rs | 4 ++++ client/src/node.rs | 7 +++++++ client/src/rpc.rs | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index ea9e04f..0f87a82 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -453,4 +453,8 @@ impl Client { pub async fn get_header(&self) -> Result
{ self.node.read().await.get_header() } + + pub async fn get_coinbase(&self) -> Result
{ + self.node.read().await.get_coinbase() + } } diff --git a/client/src/node.rs b/client/src/node.rs index b9308f8..9987413 100644 --- a/client/src/node.rs +++ b/client/src/node.rs @@ -291,6 +291,13 @@ impl Node { Ok(self.consensus.get_header().clone()) } + pub fn get_coinbase(&self) -> Result
{ + self.check_head_age()?; + let payload = self.get_payload(BlockTag::Latest)?; + let coinbase_address = Address::from_slice(&payload.fee_recipient); + Ok(coinbase_address) + } + pub fn get_last_checkpoint(&self) -> Option> { self.consensus.last_checkpoint.clone() } diff --git a/client/src/rpc.rs b/client/src/rpc.rs index 43b867d..8044da2 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -112,6 +112,8 @@ trait EthRpc { slot: H256, block: BlockTag, ) -> Result; + #[method(name = "getCoinbase")] + async fn get_coinbase(&self) -> Result; } #[rpc(client, server, namespace = "net")] @@ -270,6 +272,12 @@ impl EthRpcServer for RpcInner { .await, ) } + + async fn get_coinbase(&self) -> Result { + let node = self.node.read().await; + Ok(node.get_coinbase().unwrap()) + } + async fn get_logs(&self, filter: Filter) -> Result, Error> { let node = self.node.read().await; convert_err(node.get_logs(&filter).await)