1use cosmrs::Gas as CosmrsGas;
2use nym_validator_client::nyxd::cosmwasm_client::types::GasInfo as ValidatorClientGasInfo;
3use serde::{Deserialize, Serialize};
4
5#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
6#[cfg_attr(
7 feature = "generate-ts",
8 ts(export, export_to = "ts-packages/types/src/types/rust/Gas.ts")
9)]
10#[derive(Deserialize, Serialize, Copy, Clone, Debug)]
11pub struct Gas {
12 pub gas_units: u64,
14}
15
16impl Gas {
17 pub fn from_u64(value: u64) -> Gas {
18 Gas { gas_units: value }
19 }
20}
21
22impl From<CosmrsGas> for Gas {
23 fn from(gas: CosmrsGas) -> Self {
24 Gas { gas_units: gas }
25 }
26}
27
28impl From<i64> for Gas {
29 fn from(value: i64) -> Self {
30 Gas {
31 gas_units: value.try_into().unwrap_or_default(),
32 }
33 }
34}
35
36#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
37#[cfg_attr(
38 feature = "generate-ts",
39 ts(export, export_to = "ts-packages/types/src/types/rust/GasInfo.ts")
40)]
41#[derive(Deserialize, Serialize, Copy, Clone, Debug)]
42pub struct GasInfo {
43 pub gas_wanted: Gas,
45
46 pub gas_used: Gas,
48}
49
50impl From<ValidatorClientGasInfo> for GasInfo {
51 fn from(info: ValidatorClientGasInfo) -> Self {
52 GasInfo {
53 gas_wanted: info.gas_wanted.into(),
54 gas_used: info.gas_used.into(),
55 }
56 }
57}
58
59impl GasInfo {
60 pub fn from_u64(gas_wanted: u64, gas_used: u64) -> GasInfo {
61 GasInfo {
62 gas_wanted: Gas::from_u64(gas_wanted),
63 gas_used: Gas::from_u64(gas_used),
64 }
65 }
66}