Skip to main content

drive/state_transition_action/contract/contract_user_moderation/
mod.rs

1/// transformer
2pub mod transformer;
3/// v0
4pub mod v0;
5
6use crate::state_transition_action::contract::contract_user_moderation::v0::{
7    ContractDocumentDeletionContext, ContractTeamActionContext,
8    ContractUserModerationTransitionActionV0, ContractWarningContext,
9};
10use derive_more::From;
11use dpp::platform_value::Identifier;
12use dpp::prelude::{IdentityNonce, UserFeeIncrease};
13use dpp::state_transition::contract_user_moderation_transition::ContractUserModerationAction;
14
15/// The action of a contract user moderation transition: one edit of a moderated contract's
16/// banlist, suspension list or warning list, with the target's status as it was read when the
17/// transition was validated, or the deletion of one document, with what was read about it.
18#[derive(Debug, Clone, From)]
19pub enum ContractUserModerationTransitionAction {
20    /// v0
21    V0(ContractUserModerationTransitionActionV0),
22}
23
24impl ContractUserModerationTransitionAction {
25    /// The moderator that signed
26    pub fn moderator_id(&self) -> Identifier {
27        match self {
28            ContractUserModerationTransitionAction::V0(action) => action.moderator_id,
29        }
30    }
31
32    /// The moderated contract
33    pub fn data_contract_id(&self) -> Identifier {
34        match self {
35            ContractUserModerationTransitionAction::V0(action) => action.data_contract_id,
36        }
37    }
38
39    /// The moderator's nonce for the contract
40    pub fn identity_contract_nonce(&self) -> IdentityNonce {
41        match self {
42            ContractUserModerationTransitionAction::V0(action) => action.identity_contract_nonce,
43        }
44    }
45
46    /// What is done, to whom
47    pub fn action(&self) -> &ContractUserModerationAction {
48        match self {
49            ContractUserModerationTransitionAction::V0(action) => &action.action,
50        }
51    }
52
53    /// Whether the target carried a suspension when the transition was validated
54    pub fn target_is_suspended(&self) -> bool {
55        match self {
56            ContractUserModerationTransitionAction::V0(action) => action.target_is_suspended,
57        }
58    }
59
60    /// What a warn read when the transition was validated, `None` for every other action
61    pub fn warning(&self) -> Option<&ContractWarningContext> {
62        match self {
63            ContractUserModerationTransitionAction::V0(action) => action.warning.as_ref(),
64        }
65    }
66
67    /// What a document deletion read when the transition was validated, `None` for an action
68    /// on an identity
69    pub fn document_deletion(&self) -> Option<&ContractDocumentDeletionContext> {
70        match self {
71            ContractUserModerationTransitionAction::V0(action) => action.document_deletion.as_ref(),
72        }
73    }
74
75    /// What the proposal of a settled document's deletion or the approval of a team action
76    /// read and decided when the transition was validated, `None` for every other action
77    pub fn team_action(&self) -> Option<&ContractTeamActionContext> {
78        match self {
79            ContractUserModerationTransitionAction::V0(action) => action.team_action.as_ref(),
80        }
81    }
82
83    /// The signer's moderation action count on the elected contract after this action, when
84    /// the action counts for a member of the seated team
85    pub fn moderation_action_count(&self) -> Option<u32> {
86        match self {
87            ContractUserModerationTransitionAction::V0(action) => action.moderation_action_count,
88        }
89    }
90
91    /// The same action, counted for its signer, a member of the elected contract's seated team:
92    /// `count` is the signer's moderation action count since the moderators pot was last
93    /// settled, this action included
94    pub fn with_moderation_action_count(self, count: u32) -> Self {
95        match self {
96            ContractUserModerationTransitionAction::V0(mut action) => {
97                action.moderation_action_count = Some(count);
98                ContractUserModerationTransitionAction::V0(action)
99            }
100        }
101    }
102
103    /// fee multiplier
104    pub fn user_fee_increase(&self) -> UserFeeIncrease {
105        match self {
106            ContractUserModerationTransitionAction::V0(action) => action.user_fee_increase,
107        }
108    }
109}