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