casper_client/types/
auction_state.rs

1//! Types associated with reporting auction state.
2
3mod bid;
4mod delegator;
5mod era_validators;
6mod validator_weight;
7
8use std::fmt::{self, Display, Formatter};
9
10use itertools::Itertools;
11use serde::{Deserialize, Serialize};
12
13use casper_hashing::Digest;
14
15pub use bid::{Bid, BidderAndBid};
16pub use delegator::Delegator;
17pub use era_validators::EraValidators;
18pub use validator_weight::ValidatorWeight;
19
20/// The state associated with the auction system contract as at the given block height and
21/// corresponding state root hash.
22#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize, Debug)]
23#[serde(deny_unknown_fields)]
24pub struct AuctionState {
25    state_root_hash: Digest,
26    block_height: u64,
27    era_validators: Vec<EraValidators>,
28    bids: Vec<BidderAndBid>,
29}
30
31impl AuctionState {
32    /// Returns the state root hash applicable to this auction state.
33    pub fn state_root_hash(&self) -> &Digest {
34        &self.state_root_hash
35    }
36
37    /// Returns the block height applicable to this auction state.
38    pub fn block_height(&self) -> u64 {
39        self.block_height
40    }
41
42    /// Returns the validators for the applicable era.
43    pub fn era_validators(&self) -> impl Iterator<Item = &EraValidators> {
44        self.era_validators.iter()
45    }
46
47    /// Returns the bids for the applicable era.
48    pub fn bids(&self) -> impl Iterator<Item = &BidderAndBid> {
49        self.bids.iter()
50    }
51}
52
53impl Display for AuctionState {
54    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
55        write!(
56            formatter,
57            "auction state {{ state root hash {}, block height {}, validators {{{}}}, bids {{{}}} \
58            }}",
59            self.state_root_hash,
60            self.block_height,
61            self.era_validators().format(", "),
62            self.bids().format(", "),
63        )
64    }
65}