use std::error;
use std::fmt::{self, Debug, Display};
use crate::scanning::ScanError;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error<WalletError, BlockSourceError> {
Wallet(WalletError),
BlockSource(BlockSourceError),
Scan(ScanError),
}
impl<WE: fmt::Display, BE: fmt::Display> fmt::Display for Error<WE, BE> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
Error::Wallet(e) => {
write!(
f,
"The underlying datasource produced the following error: {e}"
)
}
Error::BlockSource(e) => {
write!(
f,
"The underlying block store produced the following error: {e}"
)
}
Error::Scan(e) => {
write!(f, "Scanning produced the following error: {e}")
}
}
}
}
impl<WE, BE> error::Error for Error<WE, BE>
where
WE: Debug + Display + error::Error + 'static,
BE: Debug + Display + error::Error + 'static,
{
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match &self {
Error::Wallet(e) => Some(e),
Error::BlockSource(e) => Some(e),
_ => None,
}
}
}
impl<WE, BSE> From<ScanError> for Error<WE, BSE> {
fn from(e: ScanError) -> Self {
Error::Scan(e)
}
}