Skip to main content

drive/util/batch/drive_op_batch/
contract_group.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::contract_group::{ContractGroupInfo, ContractGroupMembership};
7use dpp::identifier::Identifier;
8use grovedb::batch::KeyInfoPath;
9use grovedb::{EstimatedLayerInformation, TransactionArg};
10use platform_version::version::PlatformVersion;
11use std::collections::HashMap;
12
13/// Operations on contract groups: identity-owned sets of contracts, contract document types and
14/// contract tokens.
15#[derive(Clone, Debug)]
16pub enum ContractGroupOperationType {
17    /// Registers a new contract group.
18    RegisterContractGroup {
19        /// The group id, derived from the registering identity and its nonce.
20        contract_group_id: Identifier,
21        /// The stored information: owner, name, description.
22        info: ContractGroupInfo,
23    },
24    /// Records the contract group memberships of a newly created contract.
25    AddContractGroupMemberships {
26        /// The created contract.
27        contract_id: Identifier,
28        /// The memberships it declares.
29        memberships: Vec<ContractGroupMembership>,
30    },
31}
32
33impl DriveLowLevelOperationConverter for ContractGroupOperationType {
34    fn into_low_level_drive_operations(
35        self,
36        drive: &Drive,
37        estimated_costs_only_with_layer_info: &mut Option<
38            HashMap<KeyInfoPath, EstimatedLayerInformation>,
39        >,
40        _block_info: &BlockInfo,
41        transaction: TransactionArg,
42        platform_version: &PlatformVersion,
43    ) -> Result<Vec<LowLevelDriveOperation>, Error> {
44        match self {
45            ContractGroupOperationType::RegisterContractGroup {
46                contract_group_id,
47                info,
48            } => drive.insert_contract_group_operations(
49                contract_group_id,
50                &info,
51                estimated_costs_only_with_layer_info,
52                transaction,
53                platform_version,
54            ),
55            ContractGroupOperationType::AddContractGroupMemberships {
56                contract_id,
57                memberships,
58            } => drive.insert_contract_group_memberships_operations(
59                contract_id,
60                &memberships,
61                estimated_costs_only_with_layer_info,
62                transaction,
63                platform_version,
64            ),
65        }
66    }
67}