use celestia_proto::celestia::core::v1::gas_estimation::{
EstimateGasPriceAndUsageRequest, EstimateGasPriceAndUsageResponse, EstimateGasPriceRequest,
EstimateGasPriceResponse,
};
use crate::grpc::{FromGrpcResponse, IntoGrpcParam};
use crate::Result;
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen::prelude::wasm_bindgen
)]
#[repr(i32)]
pub enum TxPriority {
Low = 1,
#[default]
Medium = 2,
High = 3,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen::prelude::wasm_bindgen
)]
pub struct GasEstimate {
pub price: f64,
pub usage: u64,
}
impl IntoGrpcParam<EstimateGasPriceRequest> for TxPriority {
fn into_parameter(self) -> EstimateGasPriceRequest {
EstimateGasPriceRequest {
tx_priority: self as i32,
}
}
}
impl FromGrpcResponse<f64> for EstimateGasPriceResponse {
fn try_from_response(self) -> Result<f64> {
Ok(self.estimated_gas_price)
}
}
impl IntoGrpcParam<EstimateGasPriceAndUsageRequest> for (TxPriority, Vec<u8>) {
fn into_parameter(self) -> EstimateGasPriceAndUsageRequest {
EstimateGasPriceAndUsageRequest {
tx_priority: self.0 as i32,
tx_bytes: self.1,
}
}
}
impl FromGrpcResponse<GasEstimate> for EstimateGasPriceAndUsageResponse {
fn try_from_response(self) -> Result<GasEstimate> {
Ok(GasEstimate {
price: self.estimated_gas_price,
usage: self.estimated_gas_used,
})
}
}