drive/util/grove_operations/batch_delete/
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::BatchDeleteApplyType;
8use grovedb::operations::delete::DeleteOptions;
9
10use dpp::version::drive_versions::DriveVersion;
11
12use grovedb::TransactionArg;
13use grovedb_path::SubtreePath;
14
15impl Drive {
16    /// Pushes a "delete element" operation to `drive_operations`.
17    ///
18    /// # Parameters
19    /// * `path`: The path to delete.
20    /// * `key`: The key of the item to delete.
21    /// * `apply_type`: The apply type for the delete operation.
22    /// * `transaction`: The transaction argument.
23    /// * `drive_operations`: The vector containing low-level drive operations.
24    /// * `drive_version`: The drive version to select the correct function version to run.
25    ///
26    /// # Returns
27    /// * `Ok(())` if the operation was successful.
28    /// * `Err(DriveError::UnknownVersionMismatch)` if the drive version does not match known versions.
29    pub fn batch_delete<B: AsRef<[u8]>>(
30        &self,
31        path: SubtreePath<'_, B>,
32        key: &[u8],
33        apply_type: BatchDeleteApplyType,
34        transaction: TransactionArg,
35        drive_operations: &mut Vec<LowLevelDriveOperation>,
36        drive_version: &DriveVersion,
37    ) -> Result<(), Error> {
38        match drive_version.grove_methods.batch.batch_delete {
39            0 => self.batch_delete_v0(
40                path,
41                key,
42                apply_type,
43                transaction,
44                drive_operations,
45                drive_version,
46            ),
47            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
48                method: "batch_delete".to_string(),
49                known_versions: vec![0],
50                received: version,
51            })),
52        }
53    }
54
55    /// Pushes a "delete element" operation to `drive_operations`.
56    ///
57    /// # Parameters
58    /// * `path`: The path to delete.
59    /// * `key`: The key of the item to delete.
60    /// * `apply_type`: The apply type for the delete operation.
61    /// * `options`: The delete options.
62    /// * `transaction`: The transaction argument.
63    /// * `drive_operations`: The vector containing low-level drive operations.
64    /// * `drive_version`: The drive version to select the correct function version to run.
65    ///
66    /// # Returns
67    /// * `Ok(())` if the operation was successful.
68    /// * `Err(DriveError::UnknownVersionMismatch)` if the drive version does not match known versions.
69    #[allow(clippy::too_many_arguments)]
70    pub fn batch_delete_with_options<B: AsRef<[u8]>>(
71        &self,
72        path: SubtreePath<'_, B>,
73        key: &[u8],
74        apply_type: BatchDeleteApplyType,
75        options: DeleteOptions,
76        transaction: TransactionArg,
77        drive_operations: &mut Vec<LowLevelDriveOperation>,
78        drive_version: &DriveVersion,
79    ) -> Result<(), Error> {
80        match drive_version.grove_methods.batch.batch_delete {
81            0 => self.batch_delete_with_options_v0(
82                path,
83                key,
84                apply_type,
85                options,
86                transaction,
87                drive_operations,
88                drive_version,
89            ),
90            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
91                method: "batch_delete".to_string(),
92                known_versions: vec![0],
93                received: version,
94            })),
95        }
96    }
97}