Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jan 7, 2025
1 parent 084f722 commit 6aaadb6
Show file tree
Hide file tree
Showing 34 changed files with 455 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupContractPosition> {
match self {
Expand Down Expand Up @@ -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<GroupContractPosition>) {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupContractPosition>;
Expand Down Expand Up @@ -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<GroupContractPosition>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupContractPosition> {
self.main_control_group
Expand Down Expand Up @@ -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<GroupContractPosition>) {
self.main_control_group = group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupContractPosition>,
#[serde(default)]
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/src/errors/consensus/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion packages/rs-dpp/src/errors/consensus/state/state_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,6 +212,9 @@ pub enum StateError {
#[error(transparent)]
IdentityTokenAccountFrozenError(IdentityTokenAccountFrozenError),

#[error(transparent)]
IdentityTokenAccountNotFrozenError(IdentityTokenAccountNotFrozenError),

#[error(transparent)]
IdentityNotMemberOfGroupError(IdentityNotMemberOfGroupError),

Expand Down
Original file line number Diff line number Diff line change
@@ -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<IdentityTokenAccountNotFrozenError> for ConsensusError {
fn from(err: IdentityTokenAccountNotFrozenError) -> Self {
Self::StateError(StateError::IdentityTokenAccountNotFrozenError(err))
}
}
2 changes: 2 additions & 0 deletions packages/rs-dpp/src/errors/consensus/state/token/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit 6aaadb6

Please sign in to comment.