use casper_types::{global_state::TrieMerkleProof, Digest, Key, StoredValue};
use crate::tracking_copy::{TrackingCopyError, TrackingCopyQueryResult};
#[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::Failure(TrackingCopyError::CircularReference(message))
}
TrackingCopyQueryResult::Success { value, proofs } => {
let value = Box::new(value);
QueryResult::Success { value, proofs }
}
TrackingCopyQueryResult::DepthLimit { depth } => {
QueryResult::Failure(TrackingCopyError::QueryDepthLimit { depth })
}
TrackingCopyQueryResult::RootNotFound => QueryResult::RootNotFound,
}
}
}
#[derive(Debug)]
pub enum QueryResult {
RootNotFound,
ValueNotFound(String),
Success {
value: Box<StoredValue>,
proofs: Vec<TrieMerkleProof<Key, StoredValue>>,
},
Failure(TrackingCopyError),
}