feat : eth_coinbase implementation #157 (#167)

* ethereum_get_cooinbase

* change return type from CoinbaseAddress to Address

* format
This commit is contained in:
danilowhk 2023-01-12 22:30:15 -03:00 committed by GitHub
parent c7a1bad8e5
commit 819ee702e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -453,4 +453,8 @@ impl<DB: Database> Client<DB> {
pub async fn get_header(&self) -> Result<Header> { pub async fn get_header(&self) -> Result<Header> {
self.node.read().await.get_header() self.node.read().await.get_header()
} }
pub async fn get_coinbase(&self) -> Result<Address> {
self.node.read().await.get_coinbase()
}
} }

View File

@ -291,6 +291,13 @@ impl Node {
Ok(self.consensus.get_header().clone()) Ok(self.consensus.get_header().clone())
} }
pub fn get_coinbase(&self) -> Result<Address> {
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<Vec<u8>> { pub fn get_last_checkpoint(&self) -> Option<Vec<u8>> {
self.consensus.last_checkpoint.clone() self.consensus.last_checkpoint.clone()
} }

View File

@ -112,6 +112,8 @@ trait EthRpc {
slot: H256, slot: H256,
block: BlockTag, block: BlockTag,
) -> Result<String, Error>; ) -> Result<String, Error>;
#[method(name = "getCoinbase")]
async fn get_coinbase(&self) -> Result<Address, Error>;
} }
#[rpc(client, server, namespace = "net")] #[rpc(client, server, namespace = "net")]
@ -270,6 +272,12 @@ impl EthRpcServer for RpcInner {
.await, .await,
) )
} }
async fn get_coinbase(&self) -> Result<Address, Error> {
let node = self.node.read().await;
Ok(node.get_coinbase().unwrap())
}
async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, Error> { async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, Error> {
let node = self.node.read().await; let node = self.node.read().await;
convert_err(node.get_logs(&filter).await) convert_err(node.get_logs(&filter).await)