drive/util/grove_operations/grove_batch_operations_costs/
mod.rs

1mod v0;
2
3use crate::util::batch::GroveDbOpBatch;
4
5use crate::drive::Drive;
6use crate::error::drive::DriveError;
7use crate::error::Error;
8use crate::fees::op::LowLevelDriveOperation;
9
10use dpp::version::drive_versions::DriveVersion;
11
12use grovedb::batch::KeyInfoPath;
13use grovedb::EstimatedLayerInformation;
14use std::collections::HashMap;
15
16impl Drive {
17    /// Retrieves the costs for the given batch of groveDB operations.
18    /// The costs are then added to `drive_operations` for later processing.
19    ///
20    /// # Parameters
21    /// * `ops`: The batch of groveDB operations to retrieve costs for.
22    /// * `estimated_layer_info`: A map with estimated layer information.
23    /// * `validate`: Specifies whether to validate that insertions do not override existing entries.
24    /// * `drive_operations`: A vector to collect the costs of operations for later computation.
25    /// * `drive_version`: The drive version to select the correct function version to run.
26    ///
27    /// # Returns
28    /// * `Ok(())` if the operation was successful.
29    /// * `Err(DriveError::UnknownVersionMismatch)` if the drive version does not match known versions.
30    pub fn grove_batch_operations_costs(
31        &self,
32        ops: GroveDbOpBatch,
33        estimated_layer_info: HashMap<KeyInfoPath, EstimatedLayerInformation>,
34        validate: bool,
35        drive_operations: &mut Vec<LowLevelDriveOperation>,
36        drive_version: &DriveVersion,
37    ) -> Result<(), Error> {
38        match drive_version
39            .grove_methods
40            .costs
41            .grove_batch_operations_costs
42        {
43            0 => self.grove_batch_operations_costs_v0(
44                ops,
45                estimated_layer_info,
46                validate,
47                drive_operations,
48                drive_version,
49            ),
50            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
51                method: "grove_batch_operations_costs".to_string(),
52                known_versions: vec![0],
53                received: version,
54            })),
55        }
56    }
57}