use anyhow::Error as AError;
use gsdk::{Error as GearSDKError, ext::subxt::error::Error as SubxtError};
use std::{io::Error as IOError, result::Result as StdResult};
pub type Result<T = (), E = Error> = StdResult<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Anyhow(#[from] AError),
#[error(transparent)]
GearSDK(#[from] GearSDKError),
#[error("An attempt to iter events without subscription")]
EventsSubscriptionNotFound,
#[error("Events stopped (unreachable")]
EventsStopped,
#[error("Expected event wasn't found")]
EventNotFound,
#[error(transparent)]
IO(#[from] IOError),
#[error("An attempt to upload invalid binary")]
WrongBinaryExtension,
#[error("Funds overcame u128::MAX")]
BalanceOverflow,
#[error("Block data not found")]
BlockDataNotFound,
#[error("Block hash not found")]
BlockHashNotFound,
#[error("Some of extrinsics wasn't processed within the batch")]
IncompleteBatchResult(usize, usize),
#[error("Max depth reached, but queried block wasn't found")]
MaxDepthReached,
#[error("Event not found in pre-queried events")]
EventNotFoundInIterator,
#[error("Storage not found.")]
StorageNotFound,
#[error("Timestamp not found in storage.")]
TimestampNotFound,
#[error(transparent)]
Codec(#[from] parity_scale_codec::Error),
#[error(transparent)]
Hex(#[from] hex::FromHexError),
#[error("Program {0} already exists")]
ProgramAlreadyExists(String),
#[error("Failed to parse WebSocket domain.")]
WSDomainInvalid,
#[error(transparent)]
Url(#[from] url::ParseError),
}
impl From<gsdk::ext::subxt_core::Error> for Error {
fn from(err: gsdk::ext::subxt_core::Error) -> Self {
Self::GearSDK(SubxtError::from(err).into())
}
}
impl From<SubxtError> for Error {
fn from(err: SubxtError) -> Self {
Self::GearSDK(err.into())
}
}
impl From<Box<SubxtError>> for Error {
fn from(err: Box<SubxtError>) -> Self {
Self::GearSDK(err.into())
}
}