drive/util/grove_operations/grove_insert_empty_tree/mod.rs
1mod v0;
2
3use crate::drive::Drive;
4use crate::error::drive::DriveError;
5use crate::error::Error;
6use crate::fees::op::LowLevelDriveOperation;
7use dpp::version::drive_versions::DriveVersion;
8use grovedb::operations::insert::InsertOptions;
9use grovedb::{TransactionArg, TreeType};
10use grovedb_path::SubtreePath;
11
12impl Drive {
13 /// Inserts an empty tree into groveDB at the specified path and key.
14 /// The operation's cost is then added to `drive_operations` for later processing.
15 ///
16 /// # Parameters
17 /// * `path`: The groveDB hierarchical authenticated structure path where the new element is to be inserted.
18 /// * `key`: The key where the new element should be inserted in the subtree.
19 /// * `transaction`: The groveDB transaction associated with this operation.
20 /// * `tree_type`: The type of tree (normal - sum tree - count tree - count sum tree)
21 /// * `options`: Optional insert options to further configure the operation.
22 /// * `drive_operations`: A vector to collect the costs of operations for later computation.
23 /// * `platform_version`: The platform version to select the correct function version to run.
24 ///
25 /// # Returns
26 /// * `Ok(())` if the operation was successful.
27 /// * `Err(DriveError::UnknownVersionMismatch)` if the platform version does not match known versions.
28 #[allow(clippy::too_many_arguments)]
29 pub fn grove_insert_empty_tree<B: AsRef<[u8]>>(
30 &self,
31 path: SubtreePath<'_, B>,
32 key: &[u8],
33 tree_type: TreeType,
34 transaction: TransactionArg,
35 options: Option<InsertOptions>,
36 drive_operations: &mut Vec<LowLevelDriveOperation>,
37 drive_version: &DriveVersion,
38 ) -> Result<(), Error> {
39 match drive_version.grove_methods.basic.grove_insert_empty_tree {
40 0 => self.grove_insert_empty_tree_v0(
41 path,
42 key,
43 tree_type,
44 transaction,
45 options,
46 drive_operations,
47 drive_version,
48 ),
49 version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
50 method: "grove_insert_empty_tree".to_string(),
51 known_versions: vec![0],
52 received: version,
53 })),
54 }
55 }
56}