bitcoin_bosd/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Error types for the Bitcoin BOSD library.

use hex::error::HexToBytesError;
use thiserror::Error;

use crate::DescriptorType;

#[cfg(feature = "address")]
use bitcoin::script::witness_program::Error as WitnessProgramError;
#[cfg(feature = "address")]
use bitcoin::secp256k1::Error as Secp256k1Error;

/// Errors related to [`Descriptor`](crate::Descriptor).
#[derive(Error, Debug, PartialEq, Eq)]
pub enum DescriptorError {
    /// Missing type tag
    #[error("missing type tag")]
    MissingTypeTag,

    /// Invalid descriptor type tag.
    #[error("invalid descriptor type tag: {0}")]
    InvalidDescriptorType(u8),

    /// Invalid payload length.
    #[error("invalid payload length: {0}")]
    InvalidPayloadLength(usize),

    /// Hex decoding error.
    #[error("hex decoding error: {0}")]
    HexDecodingError(#[from] HexToBytesError),

    /// Invalid [`Address`](bitcoin::Address) conversion.
    ///
    /// Currently only susceptible for `OP_RETURN` descriptors
    /// being converted to a bitcoin address.
    #[cfg(feature = "address")]
    #[error("{0:?} cannot be converted to a bitcoin address")]
    InvalidAddressConversion(DescriptorType),

    /// [`secp256k1`](bitcoin::secp256k1) errors.
    #[cfg(feature = "address")]
    #[error("secp256k1 error: {0}")]
    Secp256k1Error(#[from] Secp256k1Error),

    /// [`WitnessProgram`](bitcoin::WitnessProgram) errors.
    #[cfg(feature = "address")]
    #[error("witness program error: {0}")]
    WitnessProgramError(#[from] WitnessProgramError),
}