1use penumbra_sdk_num::Amount;
2use penumbra_sdk_proto::{penumbra::core::component::stake::v1 as pb, DomainType};
3use serde::{Deserialize, Serialize};
45use crate::{validator::BondingState, validator::State, IdentityKey};
67/// The current status of a validator, including its identity, voting power, and state in the
8/// validator state machine.
9#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
10#[serde(try_from = "pb::ValidatorStatus", into = "pb::ValidatorStatus")]
11pub struct Status {
12/// The validator's identity.
13pub identity_key: IdentityKey,
14/// The validator's voting power.
15pub voting_power: Amount,
16/// The validator's current state.
17pub state: State,
18/// Represents the bonding status of the validator's stake pool.
19pub bonding_state: BondingState,
20}
2122impl DomainType for Status {
23type Proto = pb::ValidatorStatus;
24}
2526impl From<Status> for pb::ValidatorStatus {
27fn from(v: Status) -> Self {
28 pb::ValidatorStatus {
29 identity_key: Some(v.identity_key.into()),
30 voting_power: Some(v.voting_power.into()),
31 bonding_state: Some(v.bonding_state.into()),
32 state: Some(v.state.into()),
33 }
34 }
35}
3637impl TryFrom<pb::ValidatorStatus> for Status {
38type Error = anyhow::Error;
39fn try_from(v: pb::ValidatorStatus) -> Result<Self, Self::Error> {
40Ok(Status {
41 identity_key: v
42 .identity_key
43 .ok_or_else(|| anyhow::anyhow!("missing identity key field in proto"))?
44.try_into()?,
45 voting_power: v
46 .voting_power
47 .ok_or_else(|| anyhow::anyhow!("missing voting power field in proto"))?
48.try_into()?,
49 state: v
50 .state
51 .ok_or_else(|| anyhow::anyhow!("missing state field in proto"))?
52.try_into()?,
53 bonding_state: v
54 .bonding_state
55 .expect("expected bonding state to be set on validator status")
56 .try_into()?,
57 })
58 }
59}