drive/util/grove_operations/grove_get_raw_optional/
mod.rs

1mod v0;
2
3use crate::drive::Drive;
4use crate::error::drive::DriveError;
5use crate::error::Error;
6use crate::fees::op::LowLevelDriveOperation;
7use crate::util::grove_operations::DirectQueryType;
8
9use dpp::version::drive_versions::DriveVersion;
10
11use grovedb::{Element, TransactionArg};
12use grovedb_path::SubtreePath;
13
14impl Drive {
15    /// Handles the retrieval of a raw element from GroveDB at the specified path and key,
16    /// if it exists, without causing an error if the element is not found.
17    ///
18    /// The operation cost is added to `drive_operations` for later processing.
19    ///
20    /// # Parameters
21    /// * `path`: The groveDB hierarchical authenticated structure path from where the element is to be retrieved.
22    /// * `key`: The key of the element to be retrieved from the subtree.
23    /// * `direct_query_type`: The type of query to perform, whether stateless or stateful.
24    /// * `transaction`: The groveDB transaction associated with this operation.
25    /// * `drive_operations`: A vector to collect the costs of operations for later computation.
26    /// * `platform_version`: The platform version to select the correct function version to run.
27    ///
28    /// # Returns
29    /// * `Ok(Some(Element))` if the operation was successful and the element was found.
30    /// * `Ok(None)` if the operation was successful but the element was not found.
31    /// * `Err(DriveError::UnknownVersionMismatch)` if the platform version does not match known versions.
32    pub fn grove_get_raw_optional<B: AsRef<[u8]>>(
33        &self,
34        path: SubtreePath<'_, B>,
35        key: &[u8],
36        direct_query_type: DirectQueryType,
37        transaction: TransactionArg,
38        drive_operations: &mut Vec<LowLevelDriveOperation>,
39        drive_version: &DriveVersion,
40    ) -> Result<Option<Element>, Error> {
41        match drive_version.grove_methods.basic.grove_get_raw_optional {
42            0 => self.grove_get_raw_optional_v0(
43                path,
44                key,
45                direct_query_type,
46                transaction,
47                drive_operations,
48                drive_version,
49            ),
50            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
51                method: "grove_get_raw_optional".to_string(),
52                known_versions: vec![0],
53                received: version,
54            })),
55        }
56    }
57}