casper_types/account/
action_type.rs

1use core::convert::TryFrom;
2
3use crate::addressable_entity::TryFromIntError;
4
5/// The various types of action which can be performed in the context of a given account.
6#[repr(u32)]
7pub enum ActionType {
8    /// Represents performing a deploy.
9    Deployment = 0,
10    /// Represents changing the associated keys (i.e. map of [`AccountHash`](super::AccountHash)s
11    /// to [`Weight`](super::Weight)s) or action thresholds (i.e. the total
12    /// [`Weight`](super::Weight)s of signing [`AccountHash`](super::AccountHash)s required to
13    /// perform various actions).
14    KeyManagement = 1,
15}
16
17// This conversion is not intended to be used by third party crates.
18#[doc(hidden)]
19impl TryFrom<u32> for ActionType {
20    type Error = TryFromIntError;
21
22    fn try_from(value: u32) -> Result<Self, Self::Error> {
23        // This doesn't use `num_derive` traits such as FromPrimitive and ToPrimitive
24        // that helps to automatically create `from_u32` and `to_u32`. This approach
25        // gives better control over generated code.
26        match value {
27            d if d == ActionType::Deployment as u32 => Ok(ActionType::Deployment),
28            d if d == ActionType::KeyManagement as u32 => Ok(ActionType::KeyManagement),
29            _ => Err(TryFromIntError(())),
30        }
31    }
32}