penumbra_fee/
params.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use penumbra_proto::penumbra::core::component::fee::v1 as pb;

use penumbra_proto::DomainType;
use serde::{Deserialize, Serialize};

use crate::GasPrices;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(try_from = "pb::FeeParameters", into = "pb::FeeParameters")]
pub struct FeeParameters {
    pub fixed_gas_prices: GasPrices,
    pub fixed_alt_gas_prices: Vec<GasPrices>,
}

impl DomainType for FeeParameters {
    type Proto = pb::FeeParameters;
}

impl TryFrom<pb::FeeParameters> for FeeParameters {
    type Error = anyhow::Error;

    fn try_from(msg: pb::FeeParameters) -> anyhow::Result<Self> {
        Ok(FeeParameters {
            fixed_gas_prices: msg.fixed_gas_prices.unwrap_or_default().try_into()?,
            fixed_alt_gas_prices: msg
                .fixed_alt_gas_prices
                .into_iter()
                .map(|p| p.try_into())
                .collect::<Result<_, _>>()?,
        })
    }
}

impl From<FeeParameters> for pb::FeeParameters {
    fn from(params: FeeParameters) -> Self {
        pb::FeeParameters {
            fixed_gas_prices: Some(params.fixed_gas_prices.into()),
            fixed_alt_gas_prices: params
                .fixed_alt_gas_prices
                .into_iter()
                .map(Into::into)
                .collect(),
        }
    }
}