use crate::tracking_copy::TrackingCopyError;
use casper_types::{system::auction::EraValidators, Digest};
use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EraValidatorsRequest {
state_hash: Digest,
}
impl EraValidatorsRequest {
pub fn new(state_hash: Digest) -> Self {
EraValidatorsRequest { state_hash }
}
pub fn state_hash(&self) -> Digest {
self.state_hash
}
}
#[derive(Debug)]
pub enum EraValidatorsResult {
AuctionNotFound,
RootNotFound,
ValueNotFound(String),
Failure(TrackingCopyError),
Success {
era_validators: EraValidators,
},
}
impl EraValidatorsResult {
pub fn is_success(&self) -> bool {
matches!(self, EraValidatorsResult::Success { .. })
}
pub fn take_era_validators(self) -> Option<EraValidators> {
match self {
EraValidatorsResult::AuctionNotFound
| EraValidatorsResult::RootNotFound
| EraValidatorsResult::ValueNotFound(_)
| EraValidatorsResult::Failure(_) => None,
EraValidatorsResult::Success { era_validators } => Some(era_validators),
}
}
}
impl Display for EraValidatorsResult {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
EraValidatorsResult::AuctionNotFound => write!(f, "system auction not found"),
EraValidatorsResult::RootNotFound => write!(f, "state root not found"),
EraValidatorsResult::ValueNotFound(msg) => write!(f, "value not found: {}", msg),
EraValidatorsResult::Failure(tce) => write!(f, "{}", tce),
EraValidatorsResult::Success { .. } => {
write!(f, "success")
}
}
}
}