casper_storage/data_access_layer/
prefixed_values.rs

1//! Support for obtaining all values with a given key prefix.
2use crate::{tracking_copy::TrackingCopyError, KeyPrefix};
3use casper_types::{Digest, StoredValue};
4
5/// Represents a request to obtain all values with a given key prefix.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct PrefixedValuesRequest {
8    state_hash: Digest,
9    key_prefix: KeyPrefix,
10}
11
12impl PrefixedValuesRequest {
13    /// Creates new request.
14    pub fn new(state_hash: Digest, key_prefix: KeyPrefix) -> Self {
15        Self {
16            state_hash,
17            key_prefix,
18        }
19    }
20
21    /// Returns state root hash.
22    pub fn state_hash(&self) -> Digest {
23        self.state_hash
24    }
25
26    /// Returns key prefix.
27    pub fn key_prefix(&self) -> &KeyPrefix {
28        &self.key_prefix
29    }
30}
31
32/// Represents a result of a `items_by_prefix` request.
33#[derive(Debug)]
34pub enum PrefixedValuesResult {
35    /// Invalid state root hash.
36    RootNotFound,
37    /// Contains values returned from the global state.
38    Success {
39        /// The requested prefix.
40        key_prefix: KeyPrefix,
41        /// Current values.
42        values: Vec<StoredValue>,
43    },
44    /// Failure.
45    Failure(TrackingCopyError),
46}