Skip to main content

slip132_parser/
error.rs

1//! Error
2
3use std::fmt;
4
5use bitcoin::{base58, bip32};
6
7/// SKIP-132 error
8#[derive(Debug, PartialEq, Eq)]
9pub enum Error {
10    /// Base58 error
11    Base58(base58::Error),
12    /// BIP-32 error
13    Bip32(bip32::Error),
14    /// Missing SLIP-32 prefix
15    MissingPrefix,
16    /// Unknown SLIP-32 prefix
17    UnknownPrefix,
18}
19
20impl std::error::Error for Error {}
21
22impl fmt::Display for Error {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Self::Base58(e) => write!(f, "{e}"),
26            Self::Bip32(e) => write!(f, "{e}"),
27            Self::MissingPrefix => write!(f, "Missing SLIP-32 prefix"),
28            Self::UnknownPrefix => write!(f, "Unknown SLIP-32 prefix"),
29        }
30    }
31}
32
33impl From<base58::Error> for Error {
34    fn from(e: base58::Error) -> Self {
35        Self::Base58(e)
36    }
37}
38
39impl From<bip32::Error> for Error {
40    fn from(e: bip32::Error) -> Self {
41        Self::Bip32(e)
42    }
43}