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