penumbra_fee/
event.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
46
47
48
use crate::Fee;
use anyhow::{anyhow, Context};
use penumbra_proto::{core::component::fee::v1 as pb, DomainType, Name as _};

#[derive(Clone, Debug)]
pub struct EventBlockFees {
    pub swapped_fee_total: Fee,
    pub swapped_base_fee_total: Fee,
    pub swapped_tip_total: Fee,
}

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

    fn try_from(value: pb::EventBlockFees) -> Result<Self, Self::Error> {
        fn inner(value: pb::EventBlockFees) -> anyhow::Result<EventBlockFees> {
            Ok(EventBlockFees {
                swapped_fee_total: value
                    .swapped_fee_total
                    .ok_or(anyhow!("missing `swapped_fee_total`"))?
                    .try_into()?,
                swapped_base_fee_total: value
                    .swapped_base_fee_total
                    .ok_or(anyhow!("missing `swapped_base_fee_total`"))?
                    .try_into()?,
                swapped_tip_total: value
                    .swapped_tip_total
                    .ok_or(anyhow!("missing `swapped_tip_total`"))?
                    .try_into()?,
            })
        }
        inner(value).context(format!("parsing {}", pb::EventBlockFees::NAME))
    }
}

impl From<EventBlockFees> for pb::EventBlockFees {
    fn from(value: EventBlockFees) -> Self {
        Self {
            swapped_fee_total: Some(value.swapped_fee_total.into()),
            swapped_base_fee_total: Some(value.swapped_base_fee_total.into()),
            swapped_tip_total: Some(value.swapped_tip_total.into()),
        }
    }
}

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