drive/util/batch/drive_op_batch/
contract_fee_pot.rs1use crate::drive::Drive;
2use crate::error::Error;
3use crate::fees::op::LowLevelDriveOperation;
4use crate::util::batch::drive_op_batch::DriveLowLevelOperationConverter;
5use dpp::balances::credits::Credits;
6use dpp::block::block_info::BlockInfo;
7use dpp::data_contract::document_type::action_fees::{ContractFeePot, ContractFeePotLastClaim};
8use dpp::identifier::Identifier;
9use grovedb::batch::KeyInfoPath;
10use grovedb::{EstimatedLayerInformation, TransactionArg};
11use platform_version::version::PlatformVersion;
12use std::collections::HashMap;
13
14#[derive(Clone, Debug)]
19pub enum ContractFeePotOperationType {
20 AddToPot {
23 contract_id: Identifier,
25 pot: ContractFeePot,
27 amount: Credits,
29 },
30 DeductFromPot {
32 contract_id: Identifier,
34 pot: ContractFeePot,
36 amount: Credits,
38 },
39 SetLastClaim {
41 contract_id: Identifier,
43 pot: ContractFeePot,
45 last_claim: ContractFeePotLastClaim,
47 },
48}
49
50impl DriveLowLevelOperationConverter for ContractFeePotOperationType {
51 fn into_low_level_drive_operations(
52 self,
53 drive: &Drive,
54 estimated_costs_only_with_layer_info: &mut Option<
55 HashMap<KeyInfoPath, EstimatedLayerInformation>,
56 >,
57 _block_info: &BlockInfo,
58 transaction: TransactionArg,
59 platform_version: &PlatformVersion,
60 ) -> Result<Vec<LowLevelDriveOperation>, Error> {
61 match self {
62 ContractFeePotOperationType::AddToPot {
63 contract_id,
64 pot,
65 amount,
66 } => drive.add_to_contract_fee_pot_operations(
67 contract_id,
68 pot,
69 amount,
70 estimated_costs_only_with_layer_info,
71 transaction,
72 platform_version,
73 ),
74 ContractFeePotOperationType::DeductFromPot {
75 contract_id,
76 pot,
77 amount,
78 } => drive.deduct_from_contract_fee_pot_operations(
79 contract_id,
80 pot,
81 amount,
82 estimated_costs_only_with_layer_info,
83 transaction,
84 platform_version,
85 ),
86 ContractFeePotOperationType::SetLastClaim {
87 contract_id,
88 pot,
89 last_claim,
90 } => drive.set_contract_last_fee_claim_operations(
91 contract_id,
92 pot,
93 &last_claim,
94 estimated_costs_only_with_layer_info,
95 platform_version,
96 ),
97 }
98 }
99}