add eth_blockNumber to rpc

This commit is contained in:
Noah Citron 2022-08-29 12:06:50 -04:00
parent b8c18ab765
commit 57ecba8fd2
2 changed files with 12 additions and 0 deletions

View File

@ -90,6 +90,11 @@ impl Client {
Ok(tip)
}
pub async fn get_block_number(&self) -> Result<u64> {
let payload = self.consensus.get_execution_payload().await?;
Ok(payload.block_number)
}
pub fn chain_id(&self) -> u64 {
self.config.general.chain_id
}

View File

@ -57,6 +57,8 @@ trait EthRpc {
async fn gas_price(&self) -> Result<String, Error>;
#[method(name = "maxPriorityFeePerGas")]
async fn max_priority_fee_per_gas(&self) -> Result<String, Error>;
#[method(name = "blockNumber")]
async fn block_number(&self) -> Result<String, Error>;
}
struct RpcInner {
@ -144,6 +146,11 @@ impl EthRpcServer for RpcInner {
let tip = convert_err(self.client.get_priority_fee().await)?;
Ok(tip.encode_hex())
}
async fn block_number(&self) -> Result<String, Error> {
let num = convert_err(self.client.get_block_number().await)?;
Ok(u64_to_hex_string(num))
}
}
async fn start(rpc: RpcInner) -> Result<(HttpServerHandle, SocketAddr)> {