Skip to main content

stratum_apps/config_helpers/coinbase_output/
errors.rs

1use core::fmt;
2
3use miniscript::bitcoin::{address, hex};
4
5/// Error enum
6#[derive(Debug)]
7pub enum Error {
8    /// Error parsing a Bitcoin address
9    Address(address::ParseError),
10    /// Error parsing a raw descriptor as hex.
11    Hex(hex::HexToBytesError),
12    /// Invalid `output_script_value` for script type. It must be a valid public key/script
13    InvalidOutputScript,
14    /// Unknown script type in config
15    UnknownOutputScriptType,
16    /// Error from the `miniscript` crate.
17    Miniscript(miniscript::Error),
18}
19
20impl fmt::Display for Error {
21    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22        use Error::*;
23        match self {
24            Address(e) => write!(f, "Bitcoin address: {e}"),
25            Hex(e) => write!(f, "Decoding hex-formatted script: {e}"),
26            UnknownOutputScriptType => write!(f, "Unknown script type in config"),
27            InvalidOutputScript => write!(
28                f,
29                "Invalid output_script_value for your script type. It must be a valid public key/script"
30            ),
31            Miniscript(e) => write!(f, "Miniscript: {e}"),
32        }
33    }
34}
35
36impl From<address::ParseError> for Error {
37    fn from(e: address::ParseError) -> Self {
38        Error::Address(e)
39    }
40}
41
42impl From<hex::HexToBytesError> for Error {
43    fn from(e: hex::HexToBytesError) -> Self {
44        Error::Hex(e)
45    }
46}
47
48impl From<miniscript::Error> for Error {
49    fn from(e: miniscript::Error) -> Self {
50        Error::Miniscript(e)
51    }
52}