penumbra_stake/validator/
status.rsuse penumbra_num::Amount;
use penumbra_proto::{penumbra::core::component::stake::v1 as pb, DomainType};
use serde::{Deserialize, Serialize};
use crate::{validator::BondingState, validator::State, IdentityKey};
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(try_from = "pb::ValidatorStatus", into = "pb::ValidatorStatus")]
pub struct Status {
pub identity_key: IdentityKey,
pub voting_power: Amount,
pub state: State,
pub bonding_state: BondingState,
}
impl DomainType for Status {
type Proto = pb::ValidatorStatus;
}
impl From<Status> for pb::ValidatorStatus {
fn from(v: Status) -> Self {
pb::ValidatorStatus {
identity_key: Some(v.identity_key.into()),
voting_power: Some(v.voting_power.into()),
bonding_state: Some(v.bonding_state.into()),
state: Some(v.state.into()),
}
}
}
impl TryFrom<pb::ValidatorStatus> for Status {
type Error = anyhow::Error;
fn try_from(v: pb::ValidatorStatus) -> Result<Self, Self::Error> {
Ok(Status {
identity_key: v
.identity_key
.ok_or_else(|| anyhow::anyhow!("missing identity key field in proto"))?
.try_into()?,
voting_power: v
.voting_power
.ok_or_else(|| anyhow::anyhow!("missing voting power field in proto"))?
.try_into()?,
state: v
.state
.ok_or_else(|| anyhow::anyhow!("missing state field in proto"))?
.try_into()?,
bonding_state: v
.bonding_state
.expect("expected bonding state to be set on validator status")
.try_into()?,
})
}
}