use core::{
array::TryFromSliceError,
convert::TryFrom,
fmt::{self, Display, Formatter},
};
#[doc(hidden)]
#[derive(Debug, Eq, PartialEq)]
pub struct TryFromIntError(pub(super) ());
#[derive(Debug)]
#[non_exhaustive]
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)]
#[non_exhaustive]
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(());