#[derive(Debug)]
pub enum Error {
InvalidAccountData,
Winternitz(winterwallet_core::WinternitzError),
RootMismatch,
SignerPositionMismatch {
expected: (u32, u32, u32),
actual: (u32, u32, u32),
},
PositionOverflow,
PayloadTooLarge(&'static str),
TransactionTooLarge { estimated: usize, limit: usize },
UnsupportedTransaction(&'static str),
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidAccountData => write!(f, "invalid account data"),
Self::Winternitz(e) => write!(f, "winternitz error: {e}"),
Self::RootMismatch => write!(f, "on-chain root does not match local state"),
Self::SignerPositionMismatch { expected, actual } => write!(
f,
"signer position mismatch: expected ({}, {}, {}), got ({}, {}, {})",
expected.0, expected.1, expected.2, actual.0, actual.1, actual.2
),
Self::PositionOverflow => write!(f, "signing position overflow"),
Self::PayloadTooLarge(reason) => write!(f, "payload too large: {reason}"),
Self::TransactionTooLarge { estimated, limit } => {
write!(
f,
"transaction too large: {estimated} bytes (limit {limit})"
)
}
Self::UnsupportedTransaction(reason) => write!(f, "unsupported transaction: {reason}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Winternitz(e) => Some(e),
_ => None,
}
}
}
impl From<winterwallet_core::WinternitzError> for Error {
fn from(e: winterwallet_core::WinternitzError) -> Self {
Self::Winternitz(e)
}
}