celestia_grpc/grpc/
gas_estimation.rs1use celestia_proto::celestia::core::v1::gas_estimation::{
2 EstimateGasPriceAndUsageRequest, EstimateGasPriceAndUsageResponse, EstimateGasPriceRequest,
3 EstimateGasPriceResponse,
4};
5use serde::{Deserialize, Serialize};
6
7use crate::Result;
8use crate::grpc::{FromGrpcResponse, IntoGrpcParam};
9
10#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize)]
12#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
13#[cfg_attr(
14 all(feature = "wasm-bindgen", target_arch = "wasm32"),
15 wasm_bindgen::prelude::wasm_bindgen
16)]
17#[repr(i32)]
18pub enum TxPriority {
19 Low = 1,
21 #[default]
23 Medium = 2,
24 High = 3,
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
30#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
31#[cfg_attr(
32 all(feature = "wasm-bindgen", target_arch = "wasm32"),
33 wasm_bindgen::prelude::wasm_bindgen
34)]
35pub struct GasEstimate {
36 pub price: f64,
38 pub usage: u64,
40}
41
42impl IntoGrpcParam<EstimateGasPriceRequest> for TxPriority {
43 fn into_parameter(self) -> EstimateGasPriceRequest {
44 EstimateGasPriceRequest {
45 tx_priority: self as i32,
46 }
47 }
48}
49
50impl FromGrpcResponse<f64> for EstimateGasPriceResponse {
51 fn try_from_response(self) -> Result<f64> {
52 Ok(self.estimated_gas_price)
53 }
54}
55
56impl IntoGrpcParam<EstimateGasPriceAndUsageRequest> for (TxPriority, Vec<u8>) {
57 fn into_parameter(self) -> EstimateGasPriceAndUsageRequest {
58 EstimateGasPriceAndUsageRequest {
59 tx_priority: self.0 as i32,
60 tx_bytes: self.1,
61 }
62 }
63}
64
65impl FromGrpcResponse<GasEstimate> for EstimateGasPriceAndUsageResponse {
66 fn try_from_response(self) -> Result<GasEstimate> {
67 Ok(GasEstimate {
68 price: self.estimated_gas_price,
69 usage: self.estimated_gas_used,
70 })
71 }
72}