drive/util/grove_operations/grove_commitment_tree_count/mod.rs
1mod v0;
2
3use crate::drive::Drive;
4use crate::error::drive::DriveError;
5use crate::error::Error;
6use crate::fees::op::LowLevelDriveOperation;
7
8use dpp::version::drive_versions::DriveVersion;
9
10use grovedb::TransactionArg;
11use grovedb_path::SubtreePath;
12
13impl Drive {
14 /// Returns the total number of items in a CommitmentTree.
15 /// The operation's cost is then added to `drive_operations` for later processing.
16 ///
17 /// # Parameters
18 /// * `path`: The path to the CommitmentTree's parent.
19 /// * `key`: The key of the CommitmentTree element.
20 /// * `transaction`: The groveDB transaction associated with this operation.
21 /// * `drive_operations`: A vector to collect the costs of operations for later computation.
22 /// * `drive_version`: The drive version to select the correct function version to run.
23 ///
24 /// # Returns
25 /// * `Ok(u64)` — the total number of items in the CommitmentTree.
26 /// * `Err(DriveError::UnknownVersionMismatch)` if the drive version does not match known versions.
27 pub fn grove_commitment_tree_count<B: AsRef<[u8]>>(
28 &self,
29 path: SubtreePath<'_, B>,
30 key: &[u8],
31 transaction: TransactionArg,
32 drive_operations: &mut Vec<LowLevelDriveOperation>,
33 drive_version: &DriveVersion,
34 ) -> Result<u64, Error> {
35 match drive_version
36 .grove_methods
37 .basic
38 .grove_commitment_tree_count
39 {
40 0 => self.grove_commitment_tree_count_v0(
41 path,
42 key,
43 transaction,
44 drive_operations,
45 drive_version,
46 ),
47 version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
48 method: "grove_commitment_tree_count".to_string(),
49 known_versions: vec![0],
50 received: version,
51 })),
52 }
53 }
54}