penumbra_sdk_stake/
changes.rs1use crate::{Delegate, Undelegate};
2use anyhow::Result;
3use penumbra_sdk_proto::{penumbra::core::component::stake::v1 as pb, DomainType};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9#[serde(try_from = "pb::DelegationChanges", into = "pb::DelegationChanges")]
10pub struct DelegationChanges {
11 pub delegations: Vec<Delegate>,
12 pub undelegations: Vec<Undelegate>,
13}
14
15impl DomainType for DelegationChanges {
16 type Proto = pb::DelegationChanges;
17}
18
19impl From<DelegationChanges> for pb::DelegationChanges {
20 fn from(changes: DelegationChanges) -> pb::DelegationChanges {
21 pb::DelegationChanges {
22 delegations: changes.delegations.into_iter().map(Into::into).collect(),
23 undelegations: changes.undelegations.into_iter().map(Into::into).collect(),
24 }
25 }
26}
27
28impl TryFrom<pb::DelegationChanges> for DelegationChanges {
29 type Error = anyhow::Error;
30 fn try_from(changes: pb::DelegationChanges) -> Result<DelegationChanges> {
31 Ok(DelegationChanges {
32 delegations: changes
33 .delegations
34 .into_iter()
35 .map(TryInto::try_into)
36 .collect::<Result<_>>()?,
37 undelegations: changes
38 .undelegations
39 .into_iter()
40 .map(TryInto::try_into)
41 .collect::<Result<_>>()?,
42 })
43 }
44}