1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use casper_types::{system::auction::Bids, Key};

use crate::{
    core::tracking_copy::TrackingCopyQueryResult,
    shared::{newtypes::Blake2bHash, stored_value::StoredValue},
    storage::trie::merkle_proof::TrieMerkleProof,
};

#[derive(Debug)]
pub enum QueryResult {
    RootNotFound,
    ValueNotFound(String),
    CircularReference(String),
    Success {
        value: Box<StoredValue>,
        proofs: Vec<TrieMerkleProof<Key, StoredValue>>,
    },
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryRequest {
    state_hash: Blake2bHash,
    key: Key,
    path: Vec<String>,
}

impl QueryRequest {
    pub fn new(state_hash: Blake2bHash, key: Key, path: Vec<String>) -> Self {
        QueryRequest {
            state_hash,
            key,
            path,
        }
    }

    pub fn state_hash(&self) -> Blake2bHash {
        self.state_hash
    }

    pub fn key(&self) -> Key {
        self.key
    }

    pub fn path(&self) -> &[String] {
        &self.path
    }
}

impl From<TrackingCopyQueryResult> for QueryResult {
    fn from(tracking_copy_query_result: TrackingCopyQueryResult) -> Self {
        match tracking_copy_query_result {
            TrackingCopyQueryResult::ValueNotFound(message) => QueryResult::ValueNotFound(message),
            TrackingCopyQueryResult::CircularReference(message) => {
                QueryResult::CircularReference(message)
            }
            TrackingCopyQueryResult::Success { value, proofs } => {
                let value = Box::new(value);
                QueryResult::Success { value, proofs }
            }
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GetBidsRequest {
    state_hash: Blake2bHash,
}

impl GetBidsRequest {
    pub fn new(state_hash: Blake2bHash) -> Self {
        GetBidsRequest { state_hash }
    }

    pub fn state_hash(&self) -> Blake2bHash {
        self.state_hash
    }
}

#[derive(Debug)]
pub enum GetBidsResult {
    RootNotFound,
    Success { bids: Bids },
}

impl GetBidsResult {
    pub fn success(bids: Bids) -> Self {
        GetBidsResult::Success { bids }
    }

    pub fn bids(&self) -> Option<&Bids> {
        match self {
            GetBidsResult::RootNotFound => None,
            GetBidsResult::Success { bids } => Some(bids),
        }
    }
}