From 6aaadb6ba30ab87487dd92fdf55068581fdb794c Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 7 Jan 2025 09:10:39 +0700 Subject: [PATCH] more work --- .../token_configuration/accessors/mod.rs | 24 ++++ .../token_configuration/accessors/v0/mod.rs | 8 ++ .../v0/mod.rs | 42 +++++++ .../token_configuration/v0/accessors.rs | 20 ++++ .../token_configuration/v0/mod.rs | 22 +++- packages/rs-dpp/src/errors/consensus/codes.rs | 1 + .../src/errors/consensus/state/state_error.rs | 5 +- ...identity_token_account_not_frozen_error.rs | 51 ++++++++ .../src/errors/consensus/state/token/mod.rs | 2 + .../batch/action_validation/mod.rs | 1 + .../token_base_transition_action/mod.rs | 2 +- .../state_v0/mod.rs | 2 +- .../structure_v0/mod.rs | 2 +- .../token_burn_transition_action/mod.rs | 2 +- .../state_v0/mod.rs | 2 +- .../structure_v0/mod.rs | 2 +- .../mod.rs | 86 ++++++++++++++ .../state_v0/mod.rs | 109 ++++++++++++++++++ .../structure_v0/mod.rs | 27 +++++ .../token_freeze_transition_action/mod.rs | 2 +- .../state_v0/mod.rs | 2 +- .../structure_v0/mod.rs | 2 +- .../token_mint_transition_action/mod.rs | 2 +- .../state_v0/mod.rs | 4 +- .../structure_v0/mod.rs | 2 +- .../token_transfer_transition_action/mod.rs | 2 +- .../state_v0/mod.rs | 4 +- .../structure_v0/mod.rs | 4 +- .../token_unfreeze_transition_action/mod.rs | 2 +- .../state_v0/mod.rs | 32 ++++- .../structure_v0/mod.rs | 2 +- .../batch/advanced_structure/v0/mod.rs | 8 +- .../batch/transformer/v0/mod.rs | 10 +- .../token_transition/mod.rs | 2 +- 34 files changed, 455 insertions(+), 35 deletions(-) create mode 100644 packages/rs-dpp/src/errors/consensus/state/token/identity_token_account_not_frozen_error.rs create mode 100644 packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/mod.rs create mode 100644 packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/state_v0/mod.rs create mode 100644 packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/structure_v0/mod.rs diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs index 4d528fc16d..12d1f42da9 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs @@ -109,6 +109,18 @@ impl TokenConfigurationV0Getters for TokenConfiguration { } } + fn destroy_frozen_funds_rules(&self) -> &ChangeControlRules { + match self { + TokenConfiguration::V0(v0) => v0.destroy_frozen_funds_rules(), + } + } + + fn emergency_action_rules(&self) -> &ChangeControlRules { + match self { + TokenConfiguration::V0(v0) => v0.emergency_action_rules(), + } + } + /// Returns the main control group. fn main_control_group(&self) -> Option { match self { @@ -196,6 +208,18 @@ impl TokenConfigurationV0Setters for TokenConfiguration { } } + fn set_destroy_frozen_funds_rules(&mut self, rules: ChangeControlRules) { + match self { + TokenConfiguration::V0(v0) => v0.set_destroy_frozen_funds_rules(rules), + } + } + + fn set_emergency_action_rules(&mut self, rules: ChangeControlRules) { + match self { + TokenConfiguration::V0(v0) => v0.set_emergency_action_rules(rules), + } + } + /// Sets the main control group. fn set_main_control_group(&mut self, group: Option) { match self { diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs index dfd34414d6..0d47db8e62 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs @@ -44,6 +44,10 @@ pub trait TokenConfigurationV0Getters { /// Returns the unfreeze rules. fn unfreeze_rules(&self) -> &ChangeControlRules; + /// Returns the destroy frozen funds rules. + fn destroy_frozen_funds_rules(&self) -> &ChangeControlRules; + /// Returns the emergency action rules. + fn emergency_action_rules(&self) -> &ChangeControlRules; /// Returns the main control group. fn main_control_group(&self) -> Option; @@ -83,6 +87,10 @@ pub trait TokenConfigurationV0Setters { /// Sets the unfreeze rules. fn set_unfreeze_rules(&mut self, rules: ChangeControlRules); + /// Sets the `destroy frozen funds` rules. + fn set_destroy_frozen_funds_rules(&mut self, rules: ChangeControlRules); + /// Sets the emergency action rules. + fn set_emergency_action_rules(&mut self, rules: ChangeControlRules); /// Sets the main control group. fn set_main_control_group(&mut self, group: Option); diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/validate_token_configuration_update/v0/mod.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/validate_token_configuration_update/v0/mod.rs index 68eb8c54a9..a11f775a57 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/validate_token_configuration_update/v0/mod.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/validate_token_configuration_update/v0/mod.rs @@ -203,6 +203,48 @@ impl TokenConfiguration { } } + // Check changes to destroy_frozen_funds_rules + if old.destroy_frozen_funds_rules != new.destroy_frozen_funds_rules { + if !old.destroy_frozen_funds_rules.can_change_to( + &new.destroy_frozen_funds_rules, + contract_owner_id, + main_group, + groups, + action_taker, + ) { + return SimpleConsensusValidationResult::new_with_error( + DataContractTokenConfigurationUpdateError::new( + "update".to_string(), + "destroyFrozenFundsRules".to_string(), + self.clone(), + new_config.clone(), + ) + .into(), + ); + } + } + + // Check changes to emergency_action_rules + if old.emergency_action_rules != new.emergency_action_rules { + if !old.emergency_action_rules.can_change_to( + &new.emergency_action_rules, + contract_owner_id, + main_group, + groups, + action_taker, + ) { + return SimpleConsensusValidationResult::new_with_error( + DataContractTokenConfigurationUpdateError::new( + "update".to_string(), + "emergencyActionRules".to_string(), + self.clone(), + new_config.clone(), + ) + .into(), + ); + } + } + // Check changes to main_control_group if old.main_control_group != new.main_control_group { if !old diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs index 55eda9646e..11e0b9ef94 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs @@ -81,6 +81,16 @@ impl TokenConfigurationV0Getters for TokenConfigurationV0 { &self.unfreeze_rules } + /// Returns the `destroy frozen funds` rules. + fn destroy_frozen_funds_rules(&self) -> &ChangeControlRules { + &self.destroy_frozen_funds_rules + } + + /// Returns the emergency action rules. + fn emergency_action_rules(&self) -> &ChangeControlRules { + &self.emergency_action_rules + } + /// Returns the main control group. fn main_control_group(&self) -> Option { self.main_control_group @@ -144,6 +154,16 @@ impl TokenConfigurationV0Setters for TokenConfigurationV0 { self.unfreeze_rules = rules; } + /// Sets the destroy frozen funds rules. + fn set_destroy_frozen_funds_rules(&mut self, rules: ChangeControlRules) { + self.destroy_frozen_funds_rules = rules; + } + + /// Sets the emergency action rules. + fn set_emergency_action_rules(&mut self, rules: ChangeControlRules) { + self.emergency_action_rules = rules; + } + /// Sets the main control group. fn set_main_control_group(&mut self, group: Option) { self.main_control_group = group; diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs index 773f42291c..8e1851018d 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs @@ -64,6 +64,10 @@ pub struct TokenConfigurationV0 { pub freeze_rules: ChangeControlRules, #[serde(default = "default_change_control_rules")] pub unfreeze_rules: ChangeControlRules, + #[serde(default = "default_change_control_rules")] + pub destroy_frozen_funds_rules: ChangeControlRules, + #[serde(default = "default_change_control_rules")] + pub emergency_action_rules: ChangeControlRules, #[serde(default)] pub main_control_group: Option, #[serde(default)] @@ -102,7 +106,7 @@ impl fmt::Display for TokenConfigurationV0 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "TokenConfigurationV0 {{\n conventions: {:?},\n base_supply: {},\n max_supply: {:?},\n max_supply_change_rules: {:?},\n new_tokens_destination_identity: {:?},\n new_tokens_destination_identity_rules: {:?},\n minting_allow_choosing_destination: {},\n minting_allow_choosing_destination_rules: {:?},\n manual_minting_rules: {:?},\n manual_burning_rules: {:?},\n freeze_rules: {:?},\n unfreeze_rules: {:?},\n main_control_group: {:?},\n main_control_group_can_be_modified: {:?}\n}}", + "TokenConfigurationV0 {{\n conventions: {:?},\n base_supply: {},\n max_supply: {:?},\n max_supply_change_rules: {:?},\n new_tokens_destination_identity: {:?},\n new_tokens_destination_identity_rules: {:?},\n minting_allow_choosing_destination: {},\n minting_allow_choosing_destination_rules: {:?},\n manual_minting_rules: {:?},\n manual_burning_rules: {:?},\n freeze_rules: {:?},\n unfreeze_rules: {:?},\n destroy_frozen_funds_rules: {:?},\n emergency_action_rules: {:?},\n main_control_group: {:?},\n main_control_group_can_be_modified: {:?}\n}}", self.conventions, self.base_supply, self.max_supply, @@ -115,6 +119,8 @@ impl fmt::Display for TokenConfigurationV0 { self.manual_burning_rules, self.freeze_rules, self.unfreeze_rules, + self.destroy_frozen_funds_rules, + self.emergency_action_rules, self.main_control_group, self.main_control_group_can_be_modified ) @@ -182,6 +188,20 @@ impl TokenConfigurationV0 { changing_authorized_action_takers_to_contract_owner_allowed: false, } .into(), + destroy_frozen_funds_rules: ChangeControlRulesV0 { + authorized_to_make_change: AuthorizedActionTakers::NoOne, + authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, + changing_authorized_action_takers_to_no_one_allowed: false, + changing_authorized_action_takers_to_contract_owner_allowed: false, + } + .into(), + emergency_action_rules: ChangeControlRulesV0 { + authorized_to_make_change: AuthorizedActionTakers::NoOne, + authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, + changing_authorized_action_takers_to_no_one_allowed: false, + changing_authorized_action_takers_to_contract_owner_allowed: false, + } + .into(), main_control_group: None, main_control_group_can_be_modified: AuthorizedActionTakers::NoOne, } diff --git a/packages/rs-dpp/src/errors/consensus/codes.rs b/packages/rs-dpp/src/errors/consensus/codes.rs index cf7571cfbf..56f38cfaa2 100644 --- a/packages/rs-dpp/src/errors/consensus/codes.rs +++ b/packages/rs-dpp/src/errors/consensus/codes.rs @@ -237,6 +237,7 @@ impl ErrorWithCode for StateError { Self::IdentityDoesNotHaveEnoughTokenBalanceError(_) => 40150, Self::UnauthorizedTokenActionError(_) => 40151, Self::IdentityTokenAccountFrozenError(_) => 40152, + Self::IdentityTokenAccountNotFrozenError(_) => 40153, // Identity Errors: 40200-40299 Self::IdentityAlreadyExistsError(_) => 40200, diff --git a/packages/rs-dpp/src/errors/consensus/state/state_error.rs b/packages/rs-dpp/src/errors/consensus/state/state_error.rs index 9ab79f5e84..9dc0a2938b 100644 --- a/packages/rs-dpp/src/errors/consensus/state/state_error.rs +++ b/packages/rs-dpp/src/errors/consensus/state/state_error.rs @@ -41,7 +41,7 @@ use crate::consensus::state::identity::missing_transfer_key_error::MissingTransf use crate::consensus::state::identity::no_transfer_key_for_core_withdrawal_available_error::NoTransferKeyForCoreWithdrawalAvailableError; use crate::consensus::state::prefunded_specialized_balances::prefunded_specialized_balance_insufficient_error::PrefundedSpecializedBalanceInsufficientError; use crate::consensus::state::prefunded_specialized_balances::prefunded_specialized_balance_not_found_error::PrefundedSpecializedBalanceNotFoundError; -use crate::consensus::state::token::{IdentityDoesNotHaveEnoughTokenBalanceError, IdentityTokenAccountFrozenError, UnauthorizedTokenActionError}; +use crate::consensus::state::token::{IdentityDoesNotHaveEnoughTokenBalanceError, IdentityTokenAccountFrozenError, IdentityTokenAccountNotFrozenError, UnauthorizedTokenActionError}; use crate::consensus::state::voting::masternode_incorrect_voter_identity_id_error::MasternodeIncorrectVoterIdentityIdError; use crate::consensus::state::voting::masternode_incorrect_voting_address_error::MasternodeIncorrectVotingAddressError; use crate::consensus::state::voting::masternode_not_found_error::MasternodeNotFoundError; @@ -212,6 +212,9 @@ pub enum StateError { #[error(transparent)] IdentityTokenAccountFrozenError(IdentityTokenAccountFrozenError), + #[error(transparent)] + IdentityTokenAccountNotFrozenError(IdentityTokenAccountNotFrozenError), + #[error(transparent)] IdentityNotMemberOfGroupError(IdentityNotMemberOfGroupError), diff --git a/packages/rs-dpp/src/errors/consensus/state/token/identity_token_account_not_frozen_error.rs b/packages/rs-dpp/src/errors/consensus/state/token/identity_token_account_not_frozen_error.rs new file mode 100644 index 0000000000..479fcc1a50 --- /dev/null +++ b/packages/rs-dpp/src/errors/consensus/state/token/identity_token_account_not_frozen_error.rs @@ -0,0 +1,51 @@ +use crate::consensus::state::state_error::StateError; +use crate::consensus::ConsensusError; +use crate::ProtocolError; +use bincode::{Decode, Encode}; +use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize}; +use platform_value::Identifier; +use thiserror::Error; + +#[derive( + Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize, +)] +#[error( + "Identity {} account is not frozen for token {}. Action attempted: {}", + identity_id, + token_id, + action +)] +#[platform_serialize(unversioned)] +pub struct IdentityTokenAccountNotFrozenError { + token_id: Identifier, + identity_id: Identifier, + action: String, +} + +impl IdentityTokenAccountNotFrozenError { + pub fn new(token_id: Identifier, identity_id: Identifier, action: String) -> Self { + Self { + token_id, + identity_id, + action, + } + } + + pub fn token_id(&self) -> &Identifier { + &self.token_id + } + + pub fn identity_id(&self) -> &Identifier { + &self.identity_id + } + + pub fn action(&self) -> &str { + &self.action + } +} + +impl From for ConsensusError { + fn from(err: IdentityTokenAccountNotFrozenError) -> Self { + Self::StateError(StateError::IdentityTokenAccountNotFrozenError(err)) + } +} diff --git a/packages/rs-dpp/src/errors/consensus/state/token/mod.rs b/packages/rs-dpp/src/errors/consensus/state/token/mod.rs index 9d084d981b..6838bc261c 100644 --- a/packages/rs-dpp/src/errors/consensus/state/token/mod.rs +++ b/packages/rs-dpp/src/errors/consensus/state/token/mod.rs @@ -1,7 +1,9 @@ mod identity_does_not_have_enough_token_balance_error; mod identity_token_account_frozen_error; +mod identity_token_account_not_frozen_error; mod unauthorized_token_action_error; pub use identity_does_not_have_enough_token_balance_error::*; pub use identity_token_account_frozen_error::*; +pub use identity_token_account_not_frozen_error::*; pub use unauthorized_token_action_error::*; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/mod.rs index 034c8d387b..e0ff14413e 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/mod.rs @@ -6,6 +6,7 @@ pub(crate) mod document_transfer_transition_action; pub(crate) mod document_update_price_transition_action; pub(crate) mod token_base_transition_action; pub(crate) mod token_burn_transition_action; +pub(crate) mod token_destroy_frozen_funds_transition_action; pub(crate) mod token_freeze_transition_action; pub(crate) mod token_mint_transition_action; pub(crate) mod token_transfer_transition_action; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/mod.rs index fb68b51540..ed77bb370d 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/mod.rs @@ -1,7 +1,7 @@ use dpp::block::block_info::BlockInfo; use dpp::identifier::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_base_transition_action::TokenBaseTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_base_transition_action::TokenBaseTransitionAction; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/state_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/state_v0/mod.rs index ace0696ec5..d072a906d3 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/state_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/state_v0/mod.rs @@ -4,7 +4,7 @@ use dpp::consensus::state::group::GroupActionAlreadySignedByIdentityError; use dpp::consensus::state::state_error::StateError; use dpp::prelude::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use drive::query::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/structure_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/structure_v0/mod.rs index adcfec8364..034d208c51 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/structure_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_base_transition_action/structure_v0/mod.rs @@ -4,7 +4,7 @@ use dpp::consensus::basic::token::InvalidTokenPositionError; use dpp::data_contract::accessors::v0::DataContractV0Getters; use dpp::data_contract::accessors::v1::DataContractV1Getters; use dpp::validation::{SimpleConsensusValidationResult}; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/mod.rs index d5ed620981..0ed8bdfb4d 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/mod.rs @@ -1,7 +1,7 @@ use dpp::block::block_info::BlockInfo; use dpp::identifier::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_burn_transition_action::TokenBurnTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_burn_transition_action::TokenBurnTransitionAction; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/state_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/state_v0/mod.rs index d8b8f00e3e..85ad0983ef 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/state_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/state_v0/mod.rs @@ -8,7 +8,7 @@ use dpp::data_contract::associated_token::token_configuration::accessors::v0::To use dpp::multi_identity_events::ActionTaker; use dpp::prelude::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_burn_transition_action::{TokenBurnTransitionAction, TokenBurnTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_burn_transition_action::{TokenBurnTransitionAction, TokenBurnTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use drive::query::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/structure_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/structure_v0/mod.rs index 04a1953093..3529a60558 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/structure_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_burn_transition_action/structure_v0/mod.rs @@ -1,5 +1,5 @@ use dpp::validation::{SimpleConsensusValidationResult}; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_burn_transition_action::{TokenBurnTransitionAction, TokenBurnTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_burn_transition_action::{TokenBurnTransitionAction, TokenBurnTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use crate::error::Error; use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/mod.rs new file mode 100644 index 0000000000..9b8428f51d --- /dev/null +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/mod.rs @@ -0,0 +1,86 @@ +use dpp::block::block_info::BlockInfo; +use dpp::identifier::Identifier; +use dpp::validation::SimpleConsensusValidationResult; +use drive::state_transition_action::batch::batched_transition::token_transition::token_destroy_frozen_funds_transition_action::TokenDestroyFrozenFundsTransitionAction; +use dpp::version::PlatformVersion; +use drive::grovedb::TransactionArg; +use crate::error::Error; +use crate::error::execution::ExecutionError; +use crate::execution::types::state_transition_execution_context::StateTransitionExecutionContext; +use crate::execution::validation::state_transition::batch::action_validation::token_destroy_frozen_funds_transition_action::state_v0::TokenDestroyFrozenFundsTransitionActionStateValidationV0; +use crate::execution::validation::state_transition::batch::action_validation::token_destroy_frozen_funds_transition_action::structure_v0::TokenDestroyFrozenFundsTransitionActionStructureValidationV0; +use crate::platform_types::platform::PlatformStateRef; + +mod state_v0; +mod structure_v0; + +pub trait TokenDestroyFrozenFundsTransitionActionValidation { + fn validate_structure( + &self, + platform_version: &PlatformVersion, + ) -> Result; + + fn validate_state( + &self, + platform: &PlatformStateRef, + owner_id: Identifier, + block_info: &BlockInfo, + execution_context: &mut StateTransitionExecutionContext, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result; +} + +impl TokenDestroyFrozenFundsTransitionActionValidation for TokenDestroyFrozenFundsTransitionAction { + fn validate_structure( + &self, + platform_version: &PlatformVersion, + ) -> Result { + match platform_version + .drive_abci + .validation_and_processing + .state_transitions + .batch_state_transition + .token_destroy_frozen_funds_transition_structure_validation + { + 0 => self.validate_structure_v0(platform_version), + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { + method: "TokenDestroyFrozenFundsTransitionAction::validate_structure".to_string(), + known_versions: vec![0], + received: version, + })), + } + } + + fn validate_state( + &self, + platform: &PlatformStateRef, + owner_id: Identifier, + block_info: &BlockInfo, + execution_context: &mut StateTransitionExecutionContext, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result { + match platform_version + .drive_abci + .validation_and_processing + .state_transitions + .batch_state_transition + .token_destroy_frozen_funds_transition_state_validation + { + 0 => self.validate_state_v0( + platform, + owner_id, + block_info, + execution_context, + transaction, + platform_version, + ), + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { + method: "TokenDestroyFrozenFundsTransitionAction::validate_state".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/state_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/state_v0/mod.rs new file mode 100644 index 0000000000..99bf2b350c --- /dev/null +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/state_v0/mod.rs @@ -0,0 +1,109 @@ +use dpp::block::block_info::BlockInfo; +use dpp::consensus::ConsensusError; +use dpp::consensus::state::state_error::StateError; +use dpp::consensus::state::token::{IdentityTokenAccountNotFrozenError, UnauthorizedTokenActionError}; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contract::accessors::v1::DataContractV1Getters; +use dpp::data_contract::associated_token::token_configuration::accessors::v0::TokenConfigurationV0Getters; +use dpp::multi_identity_events::ActionTaker; +use dpp::prelude::Identifier; +use dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; +use dpp::validation::SimpleConsensusValidationResult; +use drive::state_transition_action::batch::batched_transition::token_transition::token_destroy_frozen_funds_transition_action::{TokenDestroyFrozenFundsTransitionAction, TokenDestroyFrozenFundsTransitionActionAccessorsV0}; +use dpp::version::PlatformVersion; +use drive::query::TransactionArg; +use crate::error::Error; +use crate::execution::types::execution_operation::ValidationOperation; +use crate::execution::types::state_transition_execution_context::{StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0}; +use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; +use crate::platform_types::platform::PlatformStateRef; + +pub(super) trait TokenDestroyFrozenFundsTransitionActionStateValidationV0 { + fn validate_state_v0( + &self, + platform: &PlatformStateRef, + owner_id: Identifier, + block_info: &BlockInfo, + execution_context: &mut StateTransitionExecutionContext, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result; +} +impl TokenDestroyFrozenFundsTransitionActionStateValidationV0 + for TokenDestroyFrozenFundsTransitionAction +{ + fn validate_state_v0( + &self, + platform: &PlatformStateRef, + owner_id: Identifier, + block_info: &BlockInfo, + execution_context: &mut StateTransitionExecutionContext, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result { + let validation_result = self.base().validate_state( + platform, + owner_id, + block_info, + execution_context, + transaction, + platform_version, + )?; + if !validation_result.is_valid() { + return Ok(validation_result); + } + + // We need to validate that we are frozen + + let (info, fee_result) = platform.drive.fetch_identity_token_info_with_costs( + self.token_id().to_buffer(), + self.frozen_identity_id().to_buffer(), + block_info, + true, + transaction, + platform_version, + )?; + execution_context.add_operation(ValidationOperation::PrecalculatedOperation(fee_result)); + + if info.is_none() || !info.unwrap().frozen() { + return Ok(SimpleConsensusValidationResult::new_with_error( + ConsensusError::StateError(StateError::IdentityTokenAccountNotFrozenError( + IdentityTokenAccountNotFrozenError::new( + self.token_id(), + self.frozen_identity_id(), + "destroy_frozen_funds".to_string(), + ), + )), + )); + } + + // Let's first check to see if we are authorized to perform this action + let contract = &self.data_contract_fetch_info_ref().contract; + let token_configuration = contract.expected_token_configuration(self.token_position())?; + let rules = token_configuration.destroy_frozen_funds_rules(); + let main_control_group = token_configuration + .main_control_group() + .map(|position| contract.expected_group(position)) + .transpose()?; + + if !rules.can_make_change( + &contract.owner_id(), + main_control_group, + contract.groups(), + &ActionTaker::SingleIdentity(owner_id), + ) { + return Ok(SimpleConsensusValidationResult::new_with_error( + ConsensusError::StateError(StateError::UnauthorizedTokenActionError( + UnauthorizedTokenActionError::new( + self.token_id(), + owner_id, + "destroy_frozen_funds".to_string(), + rules.authorized_to_make_change_action_takers().clone(), + ), + )), + )); + } + + Ok(SimpleConsensusValidationResult::new()) + } +} diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/structure_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/structure_v0/mod.rs new file mode 100644 index 0000000000..2f0c22d417 --- /dev/null +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_destroy_frozen_funds_transition_action/structure_v0/mod.rs @@ -0,0 +1,27 @@ +use dpp::validation::{SimpleConsensusValidationResult}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_destroy_frozen_funds_transition_action::{TokenDestroyFrozenFundsTransitionAction, TokenDestroyFrozenFundsTransitionActionAccessorsV0}; +use dpp::version::PlatformVersion; +use crate::error::Error; +use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; + +pub(super) trait TokenDestroyFrozenFundsTransitionActionStructureValidationV0 { + fn validate_structure_v0( + &self, + platform_version: &PlatformVersion, + ) -> Result; +} +impl TokenDestroyFrozenFundsTransitionActionStructureValidationV0 + for TokenDestroyFrozenFundsTransitionAction +{ + fn validate_structure_v0( + &self, + platform_version: &PlatformVersion, + ) -> Result { + let validation_result = self.base().validate_structure(platform_version)?; + if !validation_result.is_valid() { + return Ok(validation_result); + } + + Ok(SimpleConsensusValidationResult::default()) + } +} diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/mod.rs index ca1f1cde83..47777b8d73 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/mod.rs @@ -1,7 +1,7 @@ use dpp::block::block_info::BlockInfo; use dpp::identifier::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_freeze_transition_action::TokenFreezeTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_freeze_transition_action::TokenFreezeTransitionAction; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/state_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/state_v0/mod.rs index 49a004f929..507f02c281 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/state_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/state_v0/mod.rs @@ -8,7 +8,7 @@ use dpp::data_contract::associated_token::token_configuration::accessors::v0::To use dpp::multi_identity_events::ActionTaker; use dpp::prelude::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_freeze_transition_action::{TokenFreezeTransitionAction, TokenFreezeTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_freeze_transition_action::{TokenFreezeTransitionAction, TokenFreezeTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use drive::query::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/structure_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/structure_v0/mod.rs index 774dbe37f8..8b754e60e7 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/structure_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_freeze_transition_action/structure_v0/mod.rs @@ -1,5 +1,5 @@ use dpp::validation::{SimpleConsensusValidationResult}; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_freeze_transition_action::{TokenFreezeTransitionAction, TokenFreezeTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_freeze_transition_action::{TokenFreezeTransitionAction, TokenFreezeTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use crate::error::Error; use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/mod.rs index 8a3a5b14ff..f8cd83b7a6 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/mod.rs @@ -1,7 +1,7 @@ use dpp::block::block_info::BlockInfo; use dpp::identifier::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_mint_transition_action::TokenMintTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_mint_transition_action::TokenMintTransitionAction; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/state_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/state_v0/mod.rs index 263d0c588a..7653477deb 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/state_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/state_v0/mod.rs @@ -10,10 +10,10 @@ use dpp::data_contract::change_control_rules::authorized_action_takers::Authoriz use dpp::multi_identity_events::ActionTaker; use dpp::prelude::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_mint_transition_action::{TokenMintTransitionAction, TokenMintTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_mint_transition_action::{TokenMintTransitionAction, TokenMintTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use drive::query::TransactionArg; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_base_transition_action::TokenBaseTransitionActionAccessorsV0; +use drive::state_transition_action::batch::batched_transition::token_transition::token_base_transition_action::TokenBaseTransitionActionAccessorsV0; use crate::error::Error; use crate::execution::types::execution_operation::{RetrieveIdentityInfo, ValidationOperation}; use crate::execution::types::state_transition_execution_context::{StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0}; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/structure_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/structure_v0/mod.rs index 618dfe8032..33648a7e26 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/structure_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_mint_transition_action/structure_v0/mod.rs @@ -1,5 +1,5 @@ use dpp::validation::{SimpleConsensusValidationResult}; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_mint_transition_action::{TokenMintTransitionAction, TokenMintTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_mint_transition_action::{TokenMintTransitionAction, TokenMintTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use crate::error::Error; use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/mod.rs index aabaff973d..2d9754412f 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/mod.rs @@ -1,7 +1,7 @@ use dpp::block::block_info::BlockInfo; use dpp::identifier::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_transfer_transition_action::TokenTransferTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_transfer_transition_action::TokenTransferTransitionAction; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/state_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/state_v0/mod.rs index 41058ffa36..04336501c9 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/state_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/state_v0/mod.rs @@ -5,10 +5,10 @@ use dpp::consensus::state::token::{IdentityDoesNotHaveEnoughTokenBalanceError, I use dpp::prelude::Identifier; use dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_transfer_transition_action::{TokenTransferTransitionAction}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_transfer_transition_action::{TokenTransferTransitionAction}; use dpp::version::PlatformVersion; use drive::query::TransactionArg; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; +use drive::state_transition_action::batch::batched_transition::token_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; use crate::error::Error; use crate::execution::types::execution_operation::ValidationOperation; use crate::execution::types::state_transition_execution_context::{StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0}; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/structure_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/structure_v0/mod.rs index eb4e9ef98a..b575605cfe 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/structure_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_transfer_transition_action/structure_v0/mod.rs @@ -1,8 +1,8 @@ use dpp::identifier::Identifier; use dpp::validation::{SimpleConsensusValidationResult}; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_transfer_transition_action::TokenTransferTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_transfer_transition_action::TokenTransferTransitionAction; use dpp::version::PlatformVersion; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; +use drive::state_transition_action::batch::batched_transition::token_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; use crate::error::Error; use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/mod.rs index 76145d247f..0cb5f563fc 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/mod.rs @@ -1,7 +1,7 @@ use dpp::block::block_info::BlockInfo; use dpp::identifier::Identifier; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_unfreeze_transition_action::TokenUnfreezeTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_unfreeze_transition_action::TokenUnfreezeTransitionAction; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; use crate::error::Error; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/state_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/state_v0/mod.rs index c2f40fbd65..e8ba23d7f4 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/state_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/state_v0/mod.rs @@ -1,18 +1,20 @@ use dpp::block::block_info::BlockInfo; use dpp::consensus::ConsensusError; use dpp::consensus::state::state_error::StateError; -use dpp::consensus::state::token::UnauthorizedTokenActionError; +use dpp::consensus::state::token::{IdentityTokenAccountNotFrozenError, UnauthorizedTokenActionError}; use dpp::data_contract::accessors::v0::DataContractV0Getters; use dpp::data_contract::accessors::v1::DataContractV1Getters; use dpp::data_contract::associated_token::token_configuration::accessors::v0::TokenConfigurationV0Getters; use dpp::multi_identity_events::ActionTaker; use dpp::prelude::Identifier; +use dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; use dpp::validation::SimpleConsensusValidationResult; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_unfreeze_transition_action::{TokenUnfreezeTransitionAction, TokenUnfreezeTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_unfreeze_transition_action::{TokenUnfreezeTransitionAction, TokenUnfreezeTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use drive::query::TransactionArg; use crate::error::Error; -use crate::execution::types::state_transition_execution_context::StateTransitionExecutionContext; +use crate::execution::types::execution_operation::ValidationOperation; +use crate::execution::types::state_transition_execution_context::{StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0}; use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; use crate::platform_types::platform::PlatformStateRef; @@ -49,6 +51,30 @@ impl TokenUnfreezeTransitionActionStateValidationV0 for TokenUnfreezeTransitionA return Ok(validation_result); } + // We need to validate that we are frozen + + let (info, fee_result) = platform.drive.fetch_identity_token_info_with_costs( + self.token_id().to_buffer(), + self.frozen_identity_id().to_buffer(), + block_info, + true, + transaction, + platform_version, + )?; + execution_context.add_operation(ValidationOperation::PrecalculatedOperation(fee_result)); + + if info.is_none() || !info.unwrap().frozen() { + return Ok(SimpleConsensusValidationResult::new_with_error( + ConsensusError::StateError(StateError::IdentityTokenAccountNotFrozenError( + IdentityTokenAccountNotFrozenError::new( + self.token_id(), + self.frozen_identity_id(), + "destroy_frozen_funds".to_string(), + ), + )), + )); + } + // Let's first check to see if we are authorized to perform this action let contract = &self.data_contract_fetch_info_ref().contract; let token_configuration = contract.expected_token_configuration(self.token_position())?; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/structure_v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/structure_v0/mod.rs index 66289fc23b..ba729c1f5e 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/structure_v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token_unfreeze_transition_action/structure_v0/mod.rs @@ -1,5 +1,5 @@ use dpp::validation::{SimpleConsensusValidationResult}; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_unfreeze_transition_action::{TokenUnfreezeTransitionAction, TokenUnfreezeTransitionActionAccessorsV0}; +use drive::state_transition_action::batch::batched_transition::token_transition::token_unfreeze_transition_action::{TokenUnfreezeTransitionAction, TokenUnfreezeTransitionActionAccessorsV0}; use dpp::version::PlatformVersion; use crate::error::Error; use crate::execution::validation::state_transition::batch::action_validation::token_base_transition_action::TokenBaseTransitionActionValidation; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v0/mod.rs index 267fb12d38..b8d77035b3 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v0/mod.rs @@ -28,10 +28,10 @@ use drive::state_transition_action::document::batch::batched_transition::documen use drive::state_transition_action::document::batch::batched_transition::document_transition::document_replace_transition_action::DocumentReplaceTransitionActionAccessorsV0; use drive::state_transition_action::document::batch::batched_transition::document_transition::document_transfer_transition_action::DocumentTransferTransitionActionAccessorsV0; use drive::state_transition_action::document::batch::batched_transition::document_transition::document_update_price_transition_action::DocumentUpdatePriceTransitionActionAccessorsV0; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_freeze_transition_action::TokenFreezeTransitionActionAccessorsV0; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_mint_transition_action::TokenMintTransitionActionAccessorsV0; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_unfreeze_transition_action::TokenUnfreezeTransitionActionAccessorsV0; +use drive::state_transition_action::batch::batched_transition::token_transition::token_freeze_transition_action::TokenFreezeTransitionActionAccessorsV0; +use drive::state_transition_action::batch::batched_transition::token_transition::token_mint_transition_action::TokenMintTransitionActionAccessorsV0; +use drive::state_transition_action::batch::batched_transition::token_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; +use drive::state_transition_action::batch::batched_transition::token_transition::token_unfreeze_transition_action::TokenUnfreezeTransitionActionAccessorsV0; use drive::state_transition_action::StateTransitionAction; use drive::state_transition_action::system::bump_identity_data_contract_nonce_action::BumpIdentityDataContractNonceAction; use crate::error::execution::ExecutionError; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/transformer/v0/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/transformer/v0/mod.rs index a2594a1150..9c98dd44c3 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/transformer/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/transformer/v0/mod.rs @@ -53,11 +53,11 @@ use drive::drive::Drive; use drive::state_transition_action::document::batch::batched_transition::document_transition::document_purchase_transition_action::DocumentPurchaseTransitionAction; use drive::state_transition_action::document::batch::batched_transition::document_transition::document_transfer_transition_action::DocumentTransferTransitionAction; use drive::state_transition_action::document::batch::batched_transition::document_transition::document_update_price_transition_action::DocumentUpdatePriceTransitionAction; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_burn_transition_action::TokenBurnTransitionAction; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_freeze_transition_action::TokenFreezeTransitionAction; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_mint_transition_action::TokenMintTransitionAction; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_transfer_transition_action::TokenTransferTransitionAction; -use drive::state_transition_action::document::batch::batched_transition::document_transition::token_unfreeze_transition_action::TokenUnfreezeTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_burn_transition_action::TokenBurnTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_freeze_transition_action::TokenFreezeTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_mint_transition_action::TokenMintTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_transfer_transition_action::TokenTransferTransitionAction; +use drive::state_transition_action::batch::batched_transition::token_transition::token_unfreeze_transition_action::TokenUnfreezeTransitionAction; use drive::state_transition_action::system::bump_identity_data_contract_nonce_action::BumpIdentityDataContractNonceAction; use crate::execution::types::execution_operation::ValidationOperation; use crate::execution::types::state_transition_execution_context::{StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0}; diff --git a/packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs b/packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs index 79defafe13..4a457e1043 100644 --- a/packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs +++ b/packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs @@ -19,7 +19,7 @@ pub mod token_destroy_frozen_funds_transition_action; pub mod token_emergency_action_transition_action; use derive_more::From; -use crate::state_transition_action::batch::batched_transition::token_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; +use crate::state_transition_action::batch::batched_transition::token_transition::token_base_transition_action::TokenBaseTransitionAction; use crate::state_transition_action::batch::batched_transition::token_transition::token_burn_transition_action::{TokenBurnTransitionAction, TokenBurnTransitionActionAccessorsV0}; use crate::state_transition_action::batch::batched_transition::token_transition::token_freeze_transition_action::{TokenFreezeTransitionAction, TokenFreezeTransitionActionAccessorsV0}; use crate::state_transition_action::batch::batched_transition::token_transition::token_unfreeze_transition_action::{TokenUnfreezeTransitionAction, TokenUnfreezeTransitionActionAccessorsV0};