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