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 {
16 nullifier: [u8; 32],
19 cmx: [u8; 32],
21 encrypted_note: Vec<u8>,
23 },
24 InsertNullifiers {
27 nullifiers: Vec<[u8; 32]>,
29 },
30 UpdateTotalBalance {
32 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}