casper_types/account/
error.rs1use core::{
2 array::TryFromSliceError,
3 convert::TryFrom,
4 fmt::{self, Display, Formatter},
5};
6
7#[doc(hidden)]
9#[derive(Debug, Eq, PartialEq)]
10pub struct TryFromIntError(pub(super) ());
11
12#[derive(Debug)]
14#[non_exhaustive]
15pub enum FromStrError {
16 InvalidPrefix,
18 Hex(base16::DecodeError),
20 Hash(TryFromSliceError),
22}
23
24impl From<base16::DecodeError> for FromStrError {
25 fn from(error: base16::DecodeError) -> Self {
26 FromStrError::Hex(error)
27 }
28}
29
30impl From<TryFromSliceError> for FromStrError {
31 fn from(error: TryFromSliceError) -> Self {
32 FromStrError::Hash(error)
33 }
34}
35
36impl Display for FromStrError {
37 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
38 match self {
39 FromStrError::InvalidPrefix => write!(f, "prefix is not 'account-hash-'"),
40 FromStrError::Hex(error) => {
41 write!(f, "failed to decode address portion from hex: {}", error)
42 }
43 FromStrError::Hash(error) => write!(f, "address portion is wrong length: {}", error),
44 }
45 }
46}
47
48#[repr(i32)]
52#[derive(Debug, PartialEq, Eq, Copy, Clone)]
53#[non_exhaustive]
54pub enum SetThresholdFailure {
55 KeyManagementThreshold = 1,
58 DeploymentThreshold = 2,
60 PermissionDeniedError = 3,
62 InsufficientTotalWeight = 4,
65}
66
67#[doc(hidden)]
69impl TryFrom<i32> for SetThresholdFailure {
70 type Error = TryFromIntError;
71
72 fn try_from(value: i32) -> Result<Self, Self::Error> {
73 match value {
74 d if d == SetThresholdFailure::KeyManagementThreshold as i32 => {
75 Ok(SetThresholdFailure::KeyManagementThreshold)
76 }
77 d if d == SetThresholdFailure::DeploymentThreshold as i32 => {
78 Ok(SetThresholdFailure::DeploymentThreshold)
79 }
80 d if d == SetThresholdFailure::PermissionDeniedError as i32 => {
81 Ok(SetThresholdFailure::PermissionDeniedError)
82 }
83 d if d == SetThresholdFailure::InsufficientTotalWeight as i32 => {
84 Ok(SetThresholdFailure::InsufficientTotalWeight)
85 }
86 _ => Err(TryFromIntError(())),
87 }
88 }
89}
90
91impl Display for SetThresholdFailure {
92 fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
93 match self {
94 SetThresholdFailure::KeyManagementThreshold => formatter
95 .write_str("New threshold should be greater than or equal to deployment threshold"),
96 SetThresholdFailure::DeploymentThreshold => formatter.write_str(
97 "New threshold should be lower than or equal to key management threshold",
98 ),
99 SetThresholdFailure::PermissionDeniedError => formatter
100 .write_str("Unable to set action threshold due to insufficient permissions"),
101 SetThresholdFailure::InsufficientTotalWeight => formatter.write_str(
102 "New threshold should be lower or equal than total weight of associated keys",
103 ),
104 }
105 }
106}
107
108#[derive(Debug)]
110pub struct TryFromSliceForAccountHashError(());