Skip to main content

drive/state_transition_action/contract/contract_fee_claim/
mod.rs

1/// transformer
2pub mod transformer;
3/// v0
4pub mod v0;
5
6use crate::state_transition_action::contract::contract_fee_claim::v0::ContractFeeClaimTransitionActionV0;
7use derive_more::From;
8use dpp::block::epoch::EpochIndex;
9use dpp::data_contract::document_type::action_fees::{ContractFeePot, ContractFeePotLastClaim};
10use dpp::fee::Credits;
11use dpp::platform_value::Identifier;
12use dpp::prelude::{IdentityNonce, UserFeeIncrease};
13use std::collections::BTreeMap;
14
15/// The action of a contract fee claim transition: the payout of one of a contract's fee pots,
16/// with what each recipient is paid as settled when the transition was validated.
17#[derive(Debug, Clone, From)]
18pub enum ContractFeeClaimTransitionAction {
19    /// v0
20    V0(ContractFeeClaimTransitionActionV0),
21}
22
23impl ContractFeeClaimTransitionAction {
24    /// The claimant that signed
25    pub fn claimant_id(&self) -> Identifier {
26        match self {
27            ContractFeeClaimTransitionAction::V0(action) => action.claimant_id,
28        }
29    }
30
31    /// The contract whose pot is paid out
32    pub fn data_contract_id(&self) -> Identifier {
33        match self {
34            ContractFeeClaimTransitionAction::V0(action) => action.data_contract_id,
35        }
36    }
37
38    /// The claimant's nonce for the contract
39    pub fn identity_contract_nonce(&self) -> IdentityNonce {
40        match self {
41            ContractFeeClaimTransitionAction::V0(action) => action.identity_contract_nonce,
42        }
43    }
44
45    /// The pot that is paid out
46    pub fn pot(&self) -> ContractFeePot {
47        match self {
48            ContractFeeClaimTransitionAction::V0(action) => action.pot,
49        }
50    }
51
52    /// The epoch of the claim
53    pub fn epoch_index(&self) -> EpochIndex {
54        match self {
55            ContractFeeClaimTransitionAction::V0(action) => action.epoch_index,
56        }
57    }
58
59    /// What the claim records as the pot's last claim: its epoch, the time of its block and
60    /// the claimant
61    pub fn last_claim(&self) -> ContractFeePotLastClaim {
62        match self {
63            ContractFeeClaimTransitionAction::V0(action) => ContractFeePotLastClaim {
64                epoch_index: action.epoch_index,
65                time_ms: action.time_ms,
66                claimant_id: action.claimant_id,
67            },
68        }
69    }
70
71    /// What each recipient is paid
72    pub fn payouts(&self) -> &BTreeMap<Identifier, Credits> {
73        match self {
74            ContractFeeClaimTransitionAction::V0(action) => &action.payouts,
75        }
76    }
77
78    /// The members whose moderation action counts the claim resets
79    pub fn settled_action_counts(&self) -> &[Identifier] {
80        match self {
81            ContractFeeClaimTransitionAction::V0(action) => &action.settled_action_counts,
82        }
83    }
84
85    /// fee multiplier
86    pub fn user_fee_increase(&self) -> UserFeeIncrease {
87        match self {
88            ContractFeeClaimTransitionAction::V0(action) => action.user_fee_increase,
89        }
90    }
91}