penumbra_sdk_funding/
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
use anyhow::{anyhow, Context};
use penumbra_sdk_num::Amount;
use penumbra_sdk_proto::{penumbra::core::component::funding::v1 as pb, DomainType, Name as _};

#[derive(Clone, Debug)]
pub struct EventFundingStreamReward {
    pub recipient: String,
    pub epoch_index: u64,
    pub reward_amount: Amount,
}

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

    fn try_from(value: pb::EventFundingStreamReward) -> Result<Self, Self::Error> {
        fn inner(value: pb::EventFundingStreamReward) -> anyhow::Result<EventFundingStreamReward> {
            Ok(EventFundingStreamReward {
                recipient: value.recipient,
                epoch_index: value.epoch_index,
                reward_amount: value
                    .reward_amount
                    .ok_or(anyhow!("missing `reward_amount`"))?
                    .try_into()?,
            })
        }
        inner(value).context(format!("parsing {}", pb::EventFundingStreamReward::NAME))
    }
}

impl From<EventFundingStreamReward> for pb::EventFundingStreamReward {
    fn from(value: EventFundingStreamReward) -> Self {
        Self {
            recipient: value.recipient,
            epoch_index: value.epoch_index,
            reward_amount: Some(value.reward_amount.into()),
        }
    }
}

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