drive/util/batch/drive_op_batch/
system.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::fee::Credits;
7use dpp::platform_value::Bytes36;
8
9use dpp::asset_lock::reduced_asset_lock_value::AssetLockValue;
10
11use dpp::version::PlatformVersion;
12use grovedb::batch::KeyInfoPath;
13use grovedb::{EstimatedLayerInformation, TransactionArg};
14use std::collections::HashMap;
15
16/// Operations on the System
17#[derive(Clone, Debug)]
18pub enum SystemOperationType {
19    /// We want to add credits to the system.
20    AddToSystemCredits {
21        /// The amount of credits we are seeking to add
22        amount: Credits,
23    },
24    /// We want to remove credits from the system.
25    RemoveFromSystemCredits {
26        /// The amount of credits we are seeking to remove
27        amount: Credits,
28    },
29    /// Adding a used asset lock, if it is only partially used the asset_lock_value
30    /// will have a non 0 remaining_credit_value
31    AddUsedAssetLock {
32        /// The asset lock outpoint that should be added
33        asset_lock_outpoint: Bytes36,
34        /// The asset lock value, both initial and remaining
35        asset_lock_value: AssetLockValue,
36    },
37}
38
39impl DriveLowLevelOperationConverter for SystemOperationType {
40    fn into_low_level_drive_operations(
41        self,
42        drive: &Drive,
43        estimated_costs_only_with_layer_info: &mut Option<
44            HashMap<KeyInfoPath, EstimatedLayerInformation>,
45        >,
46        _block_info: &BlockInfo,
47        transaction: TransactionArg,
48        platform_version: &PlatformVersion,
49    ) -> Result<Vec<LowLevelDriveOperation>, Error> {
50        match self {
51            SystemOperationType::AddToSystemCredits { amount } => drive
52                .add_to_system_credits_operations(
53                    amount,
54                    estimated_costs_only_with_layer_info,
55                    transaction,
56                    platform_version,
57                ),
58            SystemOperationType::RemoveFromSystemCredits { amount } => drive
59                .remove_from_system_credits_operations(
60                    amount,
61                    estimated_costs_only_with_layer_info,
62                    transaction,
63                    platform_version,
64                ),
65            SystemOperationType::AddUsedAssetLock {
66                asset_lock_outpoint,
67                asset_lock_value,
68            } => drive.add_asset_lock_outpoint_operations(
69                &asset_lock_outpoint,
70                asset_lock_value,
71                estimated_costs_only_with_layer_info,
72                platform_version,
73            ),
74        }
75    }
76}