casper_storage/data_access_layer/
addressable_entity.rs

1use crate::tracking_copy::TrackingCopyError;
2use casper_types::{AddressableEntity, Digest, Key};
3
4/// Represents a request to obtain an addressable entity.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct AddressableEntityRequest {
7    state_hash: Digest,
8    key: Key,
9}
10
11impl AddressableEntityRequest {
12    /// Creates new request.
13    pub fn new(state_hash: Digest, key: Key) -> Self {
14        AddressableEntityRequest { state_hash, key }
15    }
16
17    /// Returns state root hash.
18    pub fn state_hash(&self) -> Digest {
19        self.state_hash
20    }
21
22    /// Returns key.
23    pub fn key(&self) -> Key {
24        self.key
25    }
26}
27
28/// Represents a result of a `addressable_entity` request.
29#[derive(Debug)]
30pub enum AddressableEntityResult {
31    /// Invalid state root hash.
32    RootNotFound,
33    /// Value not found.
34    ValueNotFound(String),
35    /// Contains an addressable entity from global state.
36    Success {
37        /// An addressable entity.
38        entity: AddressableEntity,
39    },
40    /// Failure.
41    Failure(TrackingCopyError),
42}
43
44impl AddressableEntityResult {
45    /// Returns wrapped addressable entity if this represents a successful query result.
46    pub fn into_option(self) -> Option<AddressableEntity> {
47        if let Self::Success { entity } = self {
48            Some(entity)
49        } else {
50            None
51        }
52    }
53}