drive/util/batch/drive_op_batch/
prefunded_specialized_balance.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::identifier::Identifier;
7use grovedb::batch::KeyInfoPath;
8use grovedb::{EstimatedLayerInformation, TransactionArg};
9use platform_version::version::PlatformVersion;
10use std::collections::HashMap;
11
12/// Operations on Prefunded balances
13#[derive(Clone, Debug)]
14pub enum PrefundedSpecializedBalanceOperationType {
15    /// Creates a new prefunded balance
16    CreateNewPrefundedBalance {
17        /// The id of the prefunded balance
18        prefunded_specialized_balance_id: Identifier,
19        /// The added balance
20        add_balance: u64,
21    },
22    /// Deducts from a prefunded balance
23    DeductFromPrefundedBalance {
24        /// The identity id of the identity
25        prefunded_specialized_balance_id: Identifier,
26        /// The removed balance
27        remove_balance: u64,
28    },
29}
30
31impl DriveLowLevelOperationConverter for PrefundedSpecializedBalanceOperationType {
32    fn into_low_level_drive_operations(
33        self,
34        drive: &Drive,
35        estimated_costs_only_with_layer_info: &mut Option<
36            HashMap<KeyInfoPath, EstimatedLayerInformation>,
37        >,
38        _block_info: &BlockInfo,
39        transaction: TransactionArg,
40        platform_version: &PlatformVersion,
41    ) -> Result<Vec<LowLevelDriveOperation>, Error> {
42        match self {
43            PrefundedSpecializedBalanceOperationType::CreateNewPrefundedBalance {
44                prefunded_specialized_balance_id: specialized_balance_id,
45                add_balance: added_balance,
46            } => drive.add_prefunded_specialized_balance_operations(
47                specialized_balance_id,
48                added_balance,
49                estimated_costs_only_with_layer_info,
50                transaction,
51                platform_version,
52            ),
53            PrefundedSpecializedBalanceOperationType::DeductFromPrefundedBalance {
54                prefunded_specialized_balance_id: specialized_balance_id,
55                remove_balance: removed_balance,
56            } => drive.deduct_from_prefunded_specialized_balance_operations(
57                specialized_balance_id,
58                removed_balance,
59                estimated_costs_only_with_layer_info,
60                transaction,
61                platform_version,
62            ),
63        }
64    }
65}