add gas pricing rpc methods
This commit is contained in:
parent
aa50b4cfad
commit
b8c18ab765
|
@ -78,6 +78,18 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_gas_price(&self) -> Result<U256> {
|
||||
let payload = self.consensus.get_execution_payload().await?;
|
||||
let base_fee = U256::from_little_endian(&payload.base_fee_per_gas.to_bytes_le());
|
||||
let tip = U256::from(10_u64.pow(9));
|
||||
Ok(base_fee + tip)
|
||||
}
|
||||
|
||||
pub async fn get_priority_fee(&self) -> Result<U256> {
|
||||
let tip = U256::from(10_u64.pow(9));
|
||||
Ok(tip)
|
||||
}
|
||||
|
||||
pub fn chain_id(&self) -> u64 {
|
||||
self.config.general.chain_id
|
||||
}
|
||||
|
|
|
@ -53,6 +53,10 @@ trait EthRpc {
|
|||
async fn estimate_gas(&self, opts: CallOpts) -> Result<String, Error>;
|
||||
#[method(name = "chainId")]
|
||||
fn chain_id(&self) -> Result<String, Error>;
|
||||
#[method(name = "gasPrice")]
|
||||
async fn gas_price(&self) -> Result<String, Error>;
|
||||
#[method(name = "maxPriorityFeePerGas")]
|
||||
async fn max_priority_fee_per_gas(&self) -> Result<String, Error>;
|
||||
}
|
||||
|
||||
struct RpcInner {
|
||||
|
@ -130,6 +134,16 @@ impl EthRpcServer for RpcInner {
|
|||
let id = self.client.chain_id();
|
||||
Ok(u64_to_hex_string(id))
|
||||
}
|
||||
|
||||
async fn gas_price(&self) -> Result<String, Error> {
|
||||
let gas_price = convert_err(self.client.get_gas_price().await)?;
|
||||
Ok(gas_price.encode_hex())
|
||||
}
|
||||
|
||||
async fn max_priority_fee_per_gas(&self) -> Result<String, Error> {
|
||||
let tip = convert_err(self.client.get_priority_fee().await)?;
|
||||
Ok(tip.encode_hex())
|
||||
}
|
||||
}
|
||||
|
||||
async fn start(rpc: RpcInner) -> Result<(HttpServerHandle, SocketAddr)> {
|
||||
|
|
|
@ -69,7 +69,7 @@ pub struct ExecutionPayload {
|
|||
#[serde(deserialize_with = "extra_data_deserialize")]
|
||||
extra_data: List<u8, 32>,
|
||||
#[serde(deserialize_with = "u256_deserialize")]
|
||||
base_fee_per_gas: U256,
|
||||
pub base_fee_per_gas: U256,
|
||||
#[serde(deserialize_with = "bytes32_deserialize")]
|
||||
pub block_hash: Bytes32,
|
||||
#[serde(deserialize_with = "transactions_deserialize")]
|
||||
|
|
Loading…
Reference in New Issue