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
use casper_hashing::Digest;
use casper_types::{Key, StoredValue};
use crate::{
core::tracking_copy::TrackingCopyQueryResult, storage::trie::merkle_proof::TrieMerkleProof,
};
#[derive(Debug)]
pub enum QueryResult {
RootNotFound,
ValueNotFound(String),
CircularReference(String),
DepthLimit {
depth: u64,
},
Success {
value: Box<StoredValue>,
proofs: Vec<TrieMerkleProof<Key, StoredValue>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryRequest {
state_hash: Digest,
key: Key,
path: Vec<String>,
}
impl QueryRequest {
pub fn new(state_hash: Digest, key: Key, path: Vec<String>) -> Self {
QueryRequest {
state_hash,
key,
path,
}
}
pub fn state_hash(&self) -> Digest {
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 }
}
TrackingCopyQueryResult::DepthLimit { depth } => QueryResult::DepthLimit { depth },
}
}
}