use std::{error::Error as StdError, fmt, ops::Deref, sync::Arc};
mod convert;
mod internal;
pub mod prelude;
pub mod util;
use derive_more::Display;
pub use internal::{InternalError, InternalErrorKind, OtherError, SilentError};
use prelude::*;
#[derive(Clone)]
pub struct AnyError(Arc<anyhow::Error>);
#[derive(Debug, Clone, Copy, Eq, PartialEq, Display)]
pub enum ErrorKind {
OutPoint,
Transaction,
SubmitTransaction,
Script,
Header,
Block,
Internal,
Dao,
Spec,
}
def_error_base_on_kind!(Error, ErrorKind, "Top-level ckb error type.");
impl<E> From<E> for AnyError
where
E: StdError + Send + Sync + 'static,
{
fn from(error: E) -> Self {
Self(Arc::new(error.into()))
}
}
impl Deref for AnyError {
type Target = Arc<anyhow::Error>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl fmt::Display for AnyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Debug for AnyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}