use core::convert::Infallible;
use core::str::Utf8Error;
use displaydoc::Display;
use ibc_core::channel::types::acknowledgement::StatusValue;
use ibc_core::channel::types::channel::Order;
use ibc_core::handler::types::error::ContextError;
use ibc_core::host::types::error::IdentifierError;
use ibc_core::host::types::identifiers::{ChannelId, PortId};
use ibc_core::primitives::prelude::*;
use uint::FromDecStrErr;
#[derive(Display, Debug)]
pub enum TokenTransferError {
ContextError(ContextError),
InvalidIdentifier(IdentifierError),
InsufficientFunds {
send_attempt: String,
available_funds: String,
},
DestinationChannelNotFound {
port_id: PortId,
channel_id: ChannelId,
},
EmptyBaseDenom,
InvalidTracePortId {
pos: u64,
validation_error: IdentifierError,
},
InvalidTraceChannelId {
pos: u64,
validation_error: IdentifierError,
},
MalformedTrace(String),
InvalidTraceLength { len: u64 },
InvalidAmount(FromDecStrErr),
InvalidToken,
ChannelNotUnordered {
expect_order: Order,
got_order: Order,
},
CantCloseChannel,
PacketDataDeserialization,
AckDeserialization,
ReceiveDisabled { reason: String },
SendDisabled { reason: String },
ParseAccountFailure,
InvalidPort {
port_id: PortId,
exp_port_id: PortId,
},
DecodeRawMsg { reason: String },
UnknownMsgType { msg_type: String },
InvalidCoin { coin: String },
Utf8Decode(Utf8Error),
Other(String),
}
#[cfg(feature = "std")]
impl std::error::Error for TokenTransferError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self {
Self::ContextError(e) => Some(e),
Self::InvalidIdentifier(e)
| Self::InvalidTracePortId {
validation_error: e,
..
}
| Self::InvalidTraceChannelId {
validation_error: e,
..
} => Some(e),
Self::InvalidAmount(e) => Some(e),
Self::Utf8Decode(e) => Some(e),
_ => None,
}
}
}
impl From<Infallible> for TokenTransferError {
fn from(e: Infallible) -> Self {
match e {}
}
}
impl From<ContextError> for TokenTransferError {
fn from(err: ContextError) -> TokenTransferError {
Self::ContextError(err)
}
}
impl From<IdentifierError> for TokenTransferError {
fn from(err: IdentifierError) -> TokenTransferError {
Self::InvalidIdentifier(err)
}
}
impl From<TokenTransferError> for StatusValue {
fn from(err: TokenTransferError) -> Self {
StatusValue::new(err.to_string()).expect("error message must not be empty")
}
}