casper_storage/data_access_layer/
bids.rs

1//! Support for obtaining current bids from the auction system.
2use crate::tracking_copy::TrackingCopyError;
3
4use casper_types::{system::auction::BidKind, Digest};
5
6/// Represents a request to obtain current bids in the auction system.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct BidsRequest {
9    state_hash: Digest,
10}
11
12impl BidsRequest {
13    /// Creates new request.
14    pub fn new(state_hash: Digest) -> Self {
15        BidsRequest { state_hash }
16    }
17
18    /// Returns state root hash.
19    pub fn state_hash(&self) -> Digest {
20        self.state_hash
21    }
22}
23
24/// Represents a result of a `get_bids` request.
25#[derive(Debug)]
26pub enum BidsResult {
27    /// Invalid state root hash.
28    RootNotFound,
29    /// Contains current bids returned from the global state.
30    Success {
31        /// Current bids.
32        bids: Vec<BidKind>,
33    },
34    /// Failure.
35    Failure(TrackingCopyError),
36}
37
38impl BidsResult {
39    /// Returns wrapped [`Vec<BidKind>`] if this represents a successful query result.
40    pub fn into_option(self) -> Option<Vec<BidKind>> {
41        if let Self::Success { bids } = self {
42            Some(bids)
43        } else {
44            None
45        }
46    }
47}