casper_client/types/
auction_state.rs1mod era_validators;
4mod validator_weight;
5
6use std::{
7 collections::BTreeMap,
8 fmt::{self, Display, Formatter},
9};
10
11use itertools::Itertools;
12use serde::{Deserialize, Serialize};
13use serde_map_to_array::{BTreeMapToArray, KeyValueLabels};
14
15use casper_types::{system::auction::Bid, Digest, PublicKey};
16
17pub use era_validators::EraValidators;
18pub use validator_weight::ValidatorWeight;
19
20#[derive(Clone, PartialEq, Eq, 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 #[serde(with = "BTreeMapToArray::<PublicKey, Bid, BidLabels>")]
29 bids: BTreeMap<PublicKey, Bid>,
30}
31
32impl AuctionState {
33 pub fn state_root_hash(&self) -> &Digest {
35 &self.state_root_hash
36 }
37
38 pub fn block_height(&self) -> u64 {
40 self.block_height
41 }
42
43 pub fn era_validators(&self) -> impl Iterator<Item = &EraValidators> {
45 self.era_validators.iter()
46 }
47
48 pub fn bids(&self) -> impl Iterator<Item = (&PublicKey, &Bid)> {
50 self.bids.iter()
51 }
52}
53
54impl Display for AuctionState {
55 fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
56 write!(
57 formatter,
58 "auction state {{ state root hash {}, block height {}, validators {{{}}}, bids {{{}}} \
59 }}",
60 self.state_root_hash,
61 self.block_height,
62 self.era_validators().format(", "),
63 self.bids.values().format(", "),
64 )
65 }
66}
67
68struct BidLabels;
69
70impl KeyValueLabels for BidLabels {
71 const KEY: &'static str = "public_key";
72 const VALUE: &'static str = "bid";
73}