casper_storage/data_access_layer/
era_validators.rs1use crate::tracking_copy::TrackingCopyError;
4use casper_types::{system::auction::EraValidators, Digest};
5use std::fmt::{Display, Formatter};
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct EraValidatorsRequest {
10 state_hash: Digest,
11}
12
13impl EraValidatorsRequest {
14 pub fn new(state_hash: Digest) -> Self {
16 EraValidatorsRequest { state_hash }
17 }
18
19 pub fn state_hash(&self) -> Digest {
21 self.state_hash
22 }
23}
24
25#[derive(Debug)]
27pub enum EraValidatorsResult {
28 AuctionNotFound,
30 RootNotFound,
32 ValueNotFound(String),
34 Failure(TrackingCopyError),
36 Success {
38 era_validators: EraValidators,
40 },
41}
42
43impl EraValidatorsResult {
44 pub fn is_success(&self) -> bool {
46 matches!(self, EraValidatorsResult::Success { .. })
47 }
48
49 pub fn take_era_validators(self) -> Option<EraValidators> {
51 match self {
52 EraValidatorsResult::AuctionNotFound
53 | EraValidatorsResult::RootNotFound
54 | EraValidatorsResult::ValueNotFound(_)
55 | EraValidatorsResult::Failure(_) => None,
56 EraValidatorsResult::Success { era_validators } => Some(era_validators),
57 }
58 }
59}
60
61impl Display for EraValidatorsResult {
62 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
63 match self {
64 EraValidatorsResult::AuctionNotFound => write!(f, "system auction not found"),
65 EraValidatorsResult::RootNotFound => write!(f, "state root not found"),
66 EraValidatorsResult::ValueNotFound(msg) => write!(f, "value not found: {}", msg),
67 EraValidatorsResult::Failure(tce) => write!(f, "{}", tce),
68 EraValidatorsResult::Success { .. } => {
69 write!(f, "success")
70 }
71 }
72 }
73}