drive/util/batch/drive_op_batch/
identity.rs1use 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::identity::{Identity, IdentityPublicKey, KeyID, TimestampMillis};
8use dpp::prelude::{IdentityNonce, Revision};
9
10use crate::drive::identity::update::methods::merge_identity_nonce::MergeIdentityContractNonceResultToResult;
11use crate::drive::votes::resolved::votes::ResolvedVote;
12use crate::state_transition_action::identity::masternode_vote::v0::PreviousVoteCount;
13use dpp::version::PlatformVersion;
14use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice;
15use grovedb::batch::KeyInfoPath;
16use grovedb::{EstimatedLayerInformation, TransactionArg};
17use std::collections::HashMap;
18
19#[allow(clippy::large_enum_variant)]
21#[derive(Clone, Debug)]
22pub enum IdentityOperationType {
23 AddNewIdentity {
28 identity: Identity,
30 is_masternode_identity: bool,
33 },
34 AddToIdentityBalance {
36 identity_id: [u8; 32],
38 added_balance: u64,
40 },
41 RemoveFromIdentityBalance {
43 identity_id: [u8; 32],
45 balance_to_remove: u64,
48 },
49 AddNewKeysToIdentity {
51 identity_id: [u8; 32],
53 unique_keys_to_add: Vec<IdentityPublicKey>,
55 non_unique_keys_to_add: Vec<IdentityPublicKey>,
57 },
58 DisableIdentityKeys {
60 identity_id: [u8; 32],
62 keys_ids: Vec<KeyID>,
64 },
65
66 UpdateIdentityKeyLimits {
69 identity_id: [u8; 32],
71 key: IdentityPublicKey,
73 total_budget: Option<Credits>,
75 expires_at: Option<TimestampMillis>,
77 },
78
79 ReEnableIdentityKeys {
82 identity_id: [u8; 32],
84 keys_ids: Vec<KeyID>,
86 },
87
88 UpdateIdentityRevision {
90 identity_id: [u8; 32],
92 revision: Revision,
94 },
95 MasternodeCastVote {
97 voter_pro_tx_hash: [u8; 32],
99 strength: u8,
101 vote: ResolvedVote,
103 previous_resource_vote_choice_to_remove: Option<(ResourceVoteChoice, PreviousVoteCount)>,
105 },
106 UpdateIdentityNonce {
108 identity_id: [u8; 32],
110 nonce: IdentityNonce,
112 },
113
114 UpdateIdentityContractNonce {
116 identity_id: [u8; 32],
118 contract_id: [u8; 32],
120 nonce: IdentityNonce,
122 },
123}
124
125impl DriveLowLevelOperationConverter for IdentityOperationType {
126 fn into_low_level_drive_operations(
127 self,
128 drive: &Drive,
129 estimated_costs_only_with_layer_info: &mut Option<
130 HashMap<KeyInfoPath, EstimatedLayerInformation>,
131 >,
132 block_info: &BlockInfo,
133 transaction: TransactionArg,
134 platform_version: &PlatformVersion,
135 ) -> Result<Vec<LowLevelDriveOperation>, Error> {
136 match self {
137 IdentityOperationType::AddNewIdentity {
138 identity,
139 is_masternode_identity,
140 } => drive.add_new_identity_operations(
141 identity,
142 is_masternode_identity,
143 block_info,
144 &mut None,
145 estimated_costs_only_with_layer_info,
146 transaction,
147 platform_version,
148 ),
149 IdentityOperationType::AddToIdentityBalance {
150 identity_id,
151 added_balance,
152 } => drive.add_to_identity_balance_operations(
153 identity_id,
154 added_balance,
155 estimated_costs_only_with_layer_info,
156 transaction,
157 platform_version,
158 ),
159 IdentityOperationType::RemoveFromIdentityBalance {
160 identity_id,
161 balance_to_remove,
162 } => drive.remove_from_identity_balance_operations(
163 identity_id,
164 balance_to_remove,
165 estimated_costs_only_with_layer_info,
166 transaction,
167 platform_version,
168 ),
169 IdentityOperationType::AddNewKeysToIdentity {
170 identity_id,
171 unique_keys_to_add,
172 non_unique_keys_to_add,
173 } => drive.add_new_keys_to_identity_operations(
174 identity_id,
175 unique_keys_to_add,
176 non_unique_keys_to_add,
177 true,
178 &block_info.epoch,
179 estimated_costs_only_with_layer_info,
180 transaction,
181 platform_version,
182 ),
183 IdentityOperationType::DisableIdentityKeys {
184 identity_id,
185 keys_ids,
186 } => drive.disable_identity_keys_operations(
187 identity_id,
188 keys_ids,
189 block_info.time_ms,
190 &block_info.epoch,
191 estimated_costs_only_with_layer_info,
192 transaction,
193 platform_version,
194 ),
195 IdentityOperationType::UpdateIdentityKeyLimits {
196 identity_id,
197 key,
198 total_budget,
199 expires_at,
200 } => drive.update_identity_key_limits_operations(
201 identity_id,
202 key,
203 total_budget,
204 expires_at,
205 &block_info.epoch,
206 estimated_costs_only_with_layer_info,
207 transaction,
208 platform_version,
209 ),
210 IdentityOperationType::ReEnableIdentityKeys {
211 identity_id,
212 keys_ids,
213 } => drive.re_enable_identity_keys_operations(
214 identity_id,
215 keys_ids,
216 &block_info.epoch,
217 estimated_costs_only_with_layer_info,
218 transaction,
219 platform_version,
220 ),
221 IdentityOperationType::UpdateIdentityRevision {
222 identity_id,
223 revision,
224 } => Ok(vec![drive.update_identity_revision_operation(
225 identity_id,
226 revision,
227 estimated_costs_only_with_layer_info,
228 platform_version,
229 )?]),
230 IdentityOperationType::MasternodeCastVote {
231 voter_pro_tx_hash,
232 strength,
233 vote,
234 previous_resource_vote_choice_to_remove,
235 } => {
236 drive.register_identity_vote_operations(
239 voter_pro_tx_hash,
240 strength,
241 vote,
242 previous_resource_vote_choice_to_remove,
243 transaction,
244 platform_version,
245 )
246 }
247 IdentityOperationType::UpdateIdentityContractNonce {
248 identity_id,
249 contract_id,
250 nonce,
251 } => {
252 let (result, operations) = drive.merge_identity_contract_nonce_operations(
253 identity_id,
254 contract_id,
255 nonce,
256 block_info,
257 estimated_costs_only_with_layer_info,
258 transaction,
259 platform_version,
260 )?;
261 result.to_result()?;
262 Ok(operations)
263 }
264 IdentityOperationType::UpdateIdentityNonce { identity_id, nonce } => {
265 let (result, operations) = drive.merge_identity_nonce_operations(
266 identity_id,
267 nonce,
268 block_info,
269 estimated_costs_only_with_layer_info,
270 transaction,
271 platform_version,
272 )?;
273 result.to_result()?;
274 Ok(operations)
275 }
276 }
277 }
278}