drive/util/grove_operations/batch_remove_raw/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;
8
9use dpp::version::drive_versions::DriveVersion;
10
11use grovedb::{Element, TransactionArg};
12use grovedb_path::SubtreePath;
13
14impl Drive {
15 /// Pushes a "delete element" operation to `drive_operations` and returns the current element.
16 /// If the element didn't exist does nothing.
17 /// It is raw, because it does not use references.
18 ///
19 /// # Parameters
20 /// * `path`: The path to the element to delete.
21 /// * `key`: The key of the element to delete.
22 /// * `apply_type`: The delete operation type.
23 /// * `transaction`: The groveDB transaction associated with this operation.
24 /// * `drive_operations`: The list of drive operations to append to.
25 /// * `drive_version`: The drive version to select the correct function version to run.
26 ///
27 /// # Returns
28 /// * `Ok(Some(Element))` if the element was successfully deleted.
29 /// * `Ok(None)` if the element does not exist.
30 /// * `Err(DriveError::UnknownVersionMismatch)` if the drive version does not match known versions.
31 pub fn batch_remove_raw<B: AsRef<[u8]>>(
32 &self,
33 path: SubtreePath<'_, B>,
34 key: &[u8],
35 apply_type: BatchDeleteApplyType,
36 transaction: TransactionArg,
37 drive_operations: &mut Vec<LowLevelDriveOperation>,
38 drive_version: &DriveVersion,
39 ) -> Result<Option<Element>, Error> {
40 match drive_version.grove_methods.batch.batch_remove_raw {
41 0 => self.batch_remove_raw_v0(
42 path,
43 key,
44 apply_type,
45 transaction,
46 drive_operations,
47 drive_version,
48 ),
49 version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
50 method: "batch_remove_raw".to_string(),
51 known_versions: vec![0],
52 received: version,
53 })),
54 }
55 }
56}