penumbra_stake/
current_consensus_keys.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
use anyhow::Result;
use penumbra_proto::{penumbra::core::component::stake::v1 as pb, DomainType};
use serde::{Deserialize, Serialize};
use tendermint::PublicKey;

/// Data structure used to track our view of Tendermint's view of the validator set,
/// so we can keep Tendermint from getting confused about duplicate deletions.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(
    try_from = "pb::CurrentConsensusKeys",
    into = "pb::CurrentConsensusKeys"
)]
pub struct CurrentConsensusKeys {
    pub consensus_keys: Vec<PublicKey>,
}

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

impl From<CurrentConsensusKeys> for pb::CurrentConsensusKeys {
    fn from(value: CurrentConsensusKeys) -> pb::CurrentConsensusKeys {
        pb::CurrentConsensusKeys {
            consensus_keys: value.consensus_keys.into_iter().map(Into::into).collect(),
        }
    }
}

impl TryFrom<pb::CurrentConsensusKeys> for CurrentConsensusKeys {
    type Error = anyhow::Error;
    fn try_from(value: pb::CurrentConsensusKeys) -> Result<CurrentConsensusKeys> {
        Ok(CurrentConsensusKeys {
            consensus_keys: value
                .consensus_keys
                .into_iter()
                .map(TryInto::try_into)
                .collect::<Result<_>>()?,
        })
    }
}