casper_storage/data_access_layer/
entry_points.rs

1use crate::tracking_copy::TrackingCopyError;
2use casper_types::{Digest, EntryPointValue, HashAddr};
3
4/// Represents a request to obtain entry point.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct EntryPointRequest {
7    state_hash: Digest,
8    entry_point_name: String,
9    contract_hash: HashAddr,
10}
11
12impl EntryPointRequest {
13    /// ctor
14    pub fn new(state_hash: Digest, entry_point_name: String, contract_hash: HashAddr) -> Self {
15        EntryPointRequest {
16            state_hash,
17            entry_point_name,
18            contract_hash,
19        }
20    }
21
22    /// Returns state root hash.
23    pub fn state_hash(&self) -> Digest {
24        self.state_hash
25    }
26
27    /// Returns entry_point_name.
28    pub fn entry_point_name(&self) -> &str {
29        &self.entry_point_name
30    }
31
32    /// Returns contract_hash.
33    pub fn contract_hash(&self) -> HashAddr {
34        self.contract_hash
35    }
36}
37
38impl From<EntryPointExistsRequest> for EntryPointRequest {
39    fn from(value: EntryPointExistsRequest) -> Self {
40        EntryPointRequest {
41            state_hash: value.state_hash,
42            entry_point_name: value.entry_point_name,
43            contract_hash: value.contract_hash,
44        }
45    }
46}
47
48/// Represents a result of a `entry_point` request.
49#[derive(Debug)]
50pub enum EntryPointResult {
51    /// Invalid state root hash.
52    RootNotFound,
53    /// Value not found.
54    ValueNotFound(String),
55    /// Contains an addressable entity from global state.
56    Success {
57        /// An addressable entity.
58        entry_point: EntryPointValue,
59    },
60    /// Failure result.
61    Failure(TrackingCopyError),
62}
63
64/// Represents a request to check entry point existence.
65#[derive(Debug, Clone, PartialEq, Eq)]
66pub struct EntryPointExistsRequest {
67    state_hash: Digest,
68    entry_point_name: String,
69    contract_hash: HashAddr,
70}
71
72impl EntryPointExistsRequest {
73    /// ctor
74    pub fn new(state_hash: Digest, entry_point_name: String, contract_hash: HashAddr) -> Self {
75        EntryPointExistsRequest {
76            state_hash,
77            entry_point_name,
78            contract_hash,
79        }
80    }
81
82    /// Returns state root hash.
83    pub fn state_hash(&self) -> Digest {
84        self.state_hash
85    }
86
87    /// Returns entry_point_name.
88    pub fn entry_point_name(&self) -> &str {
89        &self.entry_point_name
90    }
91
92    /// Returns contract_hash.
93    pub fn contract_hash(&self) -> HashAddr {
94        self.contract_hash
95    }
96}
97
98/// Represents a result of `entry_point_exists` request.
99#[derive(Debug)]
100pub enum EntryPointExistsResult {
101    /// Invalid state root hash.
102    RootNotFound,
103    /// Value not found.
104    ValueNotFound(String),
105    /// This variant will be returned if the entry point was found.
106    Success,
107    /// Failure result.
108    Failure(TrackingCopyError),
109}
110
111impl EntryPointExistsResult {
112    /// Returns `true` if the result is `Success`.
113    pub fn is_success(self) -> bool {
114        matches!(self, Self::Success { .. })
115    }
116}