drive/util/batch/drive_op_batch/
shielded.rs1use 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#[derive(Clone, Debug)]
13pub enum ShieldedPoolOperationType {
14 InsertNote {
17 nullifier: [u8; 32],
20 cmx: [u8; 32],
22 cv_net: [u8; 32],
25 encrypted_note: Vec<u8>,
27 },
28 InsertNullifiers {
30 nullifiers: Vec<[u8; 32]>,
32 },
33 UpdateTotalBalance {
35 new_total_balance: u64,
37 },
38}
39
40impl DriveLowLevelOperationConverter for ShieldedPoolOperationType {
41 fn into_low_level_drive_operations(
42 self,
43 drive: &Drive,
44 estimated_costs_only_with_layer_info: &mut Option<
45 HashMap<KeyInfoPath, EstimatedLayerInformation>,
46 >,
47 _block_info: &BlockInfo,
48 _transaction: TransactionArg,
49 platform_version: &PlatformVersion,
50 ) -> Result<Vec<LowLevelDriveOperation>, Error> {
51 if let Some(ref mut estimated_costs) = estimated_costs_only_with_layer_info {
52 Drive::add_estimation_costs_for_shielded_pool_operations(estimated_costs);
53 }
54
55 match self {
56 ShieldedPoolOperationType::InsertNote {
57 nullifier,
58 cmx,
59 cv_net,
60 encrypted_note,
61 } => Drive::insert_note_op(nullifier, cmx, cv_net, encrypted_note, platform_version),
62 ShieldedPoolOperationType::InsertNullifiers { nullifiers } => {
63 drive.insert_nullifiers(&nullifiers, platform_version)
64 }
65 ShieldedPoolOperationType::UpdateTotalBalance { new_total_balance } => {
66 Drive::update_total_balance_op(new_total_balance, platform_version)
67 }
68 }
69 }
70}