drive/util/batch/drive_op_batch/
shielded.rs

1use crate::drive::Drive;
2use crate::error::Error;
3use crate::fees::op::LowLevelDriveOperation;
4use crate::util::batch::drive_op_batch::DriveLowLevelOperationConverter;
5use dpp::block::block_info::BlockInfo;
6use dpp::version::PlatformVersion;
7use grovedb::batch::KeyInfoPath;
8use grovedb::{EstimatedLayerInformation, TransactionArg};
9use std::collections::HashMap;
10
11/// Operations on the Shielded Pool
12#[derive(Clone, Debug)]
13pub enum ShieldedPoolOperationType {
14    /// Insert a note into the CommitmentTree (appends cmx to frontier + stores cmx||rho||encrypted_note as item)
15    InsertNote {
16        /// The 32-byte nullifier (rho) of the spent note in this action, stored alongside
17        /// the ciphertext so light clients can derive Rho for trial decryption
18        nullifier: [u8; 32],
19        /// The 32-byte note commitment (cmx)
20        cmx: [u8; 32],
21        /// The encrypted note payload (216 bytes)
22        encrypted_note: Vec<u8>,
23    },
24    /// Insert nullifiers into the permanent tree (double-spend prevention) and
25    /// per-block sync storage (catch-up RPCs).
26    InsertNullifiers {
27        /// The 32-byte nullifiers to insert
28        nullifiers: Vec<[u8; 32]>,
29    },
30    /// Update the shielded pool total balance
31    UpdateTotalBalance {
32        /// The new total balance value
33        new_total_balance: u64,
34    },
35}
36
37impl DriveLowLevelOperationConverter for ShieldedPoolOperationType {
38    fn into_low_level_drive_operations(
39        self,
40        drive: &Drive,
41        estimated_costs_only_with_layer_info: &mut Option<
42            HashMap<KeyInfoPath, EstimatedLayerInformation>,
43        >,
44        block_info: &BlockInfo,
45        transaction: TransactionArg,
46        platform_version: &PlatformVersion,
47    ) -> Result<Vec<LowLevelDriveOperation>, Error> {
48        if let Some(ref mut estimated_costs) = estimated_costs_only_with_layer_info {
49            Drive::add_estimation_costs_for_shielded_pool_operations(estimated_costs);
50        }
51
52        match self {
53            ShieldedPoolOperationType::InsertNote {
54                nullifier,
55                cmx,
56                encrypted_note,
57            } => Drive::insert_note_op(nullifier, cmx, encrypted_note, platform_version),
58            ShieldedPoolOperationType::InsertNullifiers { nullifiers } => drive.insert_nullifiers(
59                &nullifiers,
60                block_info.height,
61                block_info.time_ms,
62                transaction,
63                platform_version,
64            ),
65            ShieldedPoolOperationType::UpdateTotalBalance { new_total_balance } => {
66                Drive::update_total_balance_op(new_total_balance, platform_version)
67            }
68        }
69    }
70}