drive/util/batch/drive_op_batch/
system.rs1use crate::drive::Drive;
2use crate::error::{drive::DriveError, 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#[derive(Clone, Debug)]
25pub enum SystemOperationType {
26 AddToCurrentEpochProcessingPool {
29 amount: Credits,
31 },
32 AddToSystemCredits {
34 amount: Credits,
36 },
37 RemoveFromSystemCredits {
39 amount: Credits,
41 },
42 AddUsedAssetLock {
45 asset_lock_outpoint: Bytes36,
47 asset_lock_value: AssetLockValue,
49 },
50}
51
52impl DriveLowLevelOperationConverter for SystemOperationType {
53 fn into_low_level_drive_operations(
54 self,
55 drive: &Drive,
56 estimated_costs_only_with_layer_info: &mut Option<
57 HashMap<KeyInfoPath, EstimatedLayerInformation>,
58 >,
59 _block_info: &BlockInfo,
60 transaction: TransactionArg,
61 platform_version: &PlatformVersion,
62 ) -> Result<Vec<LowLevelDriveOperation>, Error> {
63 match self {
64 SystemOperationType::AddToCurrentEpochProcessingPool { .. } => {
65 Err(Error::Drive(DriveError::NotSupported(
66 "processing pool credits require apply_drive_operations generation 1",
67 )))
68 }
69 SystemOperationType::AddToSystemCredits { amount } => drive
70 .add_to_system_credits_operations(
71 amount,
72 estimated_costs_only_with_layer_info,
73 transaction,
74 platform_version,
75 ),
76 SystemOperationType::RemoveFromSystemCredits { amount } => drive
77 .remove_from_system_credits_operations(
78 amount,
79 estimated_costs_only_with_layer_info,
80 transaction,
81 platform_version,
82 ),
83 SystemOperationType::AddUsedAssetLock {
84 asset_lock_outpoint,
85 asset_lock_value,
86 } => drive.add_asset_lock_outpoint_operations(
87 &asset_lock_outpoint,
88 asset_lock_value,
89 estimated_costs_only_with_layer_info,
90 platform_version,
91 ),
92 }
93 }
94}