bdk_wallet/descriptor/
error.rs1use core::fmt;
14
15#[derive(Debug, PartialEq)]
17pub enum Error {
18 InvalidHdKeyPath,
20 InvalidDescriptorChecksum,
22 HardenedDerivationXpub,
24 MultiPath,
27 Key(crate::keys::KeyError),
29 Policy(crate::descriptor::policy::PolicyError),
31
32 InvalidDescriptorCharacter(u8),
34
35 Bip32(bitcoin::bip32::Error),
37 Base58(bitcoin::base58::Error),
39 Pk(bitcoin::key::ParsePublicKeyError),
41 Miniscript(miniscript::Error),
43 Hex(bitcoin::hex::HexToBytesError),
45 ExternalAndInternalAreTheSame,
47}
48
49impl From<crate::keys::KeyError> for Error {
50 fn from(key_error: crate::keys::KeyError) -> Error {
51 match key_error {
52 crate::keys::KeyError::Miniscript(inner) => Error::Miniscript(inner),
53 crate::keys::KeyError::Bip32(inner) => Error::Bip32(inner),
54 e => Error::Key(e),
55 }
56 }
57}
58
59impl fmt::Display for Error {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 match self {
62 Self::InvalidHdKeyPath => write!(f, "Invalid HD key path"),
63 Self::InvalidDescriptorChecksum => {
64 write!(f, "The provided descriptor doesn't match its checksum")
65 }
66 Self::HardenedDerivationXpub => write!(
67 f,
68 "The descriptor contains hardened derivation steps on public extended keys"
69 ),
70 Self::MultiPath => write!(
71 f,
72 "The descriptor contains multipath keys with invalid number of paths (must have exactly 2 paths for receive and change)"
73 ),
74 Self::Key(err) => write!(f, "Key error: {err}"),
75 Self::Policy(err) => write!(f, "Policy error: {err}"),
76 Self::InvalidDescriptorCharacter(char) => {
77 write!(f, "Invalid descriptor character: {char}")
78 }
79 Self::Bip32(err) => write!(f, "BIP32 error: {err}"),
80 Self::Base58(err) => write!(f, "Base58 error: {err}"),
81 Self::Pk(err) => write!(f, "Key-related error: {err}"),
82 Self::Miniscript(err) => write!(f, "Miniscript error: {err}"),
83 Self::Hex(err) => write!(f, "Hex decoding error: {err}"),
84 Self::ExternalAndInternalAreTheSame => {
85 write!(f, "External and internal descriptors are the same")
86 }
87 }
88 }
89}
90
91#[cfg(feature = "std")]
92impl std::error::Error for Error {}
93
94impl From<bitcoin::bip32::Error> for Error {
95 fn from(err: bitcoin::bip32::Error) -> Self {
96 Error::Bip32(err)
97 }
98}
99
100impl From<bitcoin::base58::Error> for Error {
101 fn from(err: bitcoin::base58::Error) -> Self {
102 Error::Base58(err)
103 }
104}
105
106impl From<bitcoin::key::ParsePublicKeyError> for Error {
107 fn from(err: bitcoin::key::ParsePublicKeyError) -> Self {
108 Error::Pk(err)
109 }
110}
111
112impl From<miniscript::Error> for Error {
113 fn from(err: miniscript::Error) -> Self {
114 Error::Miniscript(err)
115 }
116}
117
118impl From<bitcoin::hex::HexToBytesError> for Error {
119 fn from(err: bitcoin::hex::HexToBytesError) -> Self {
120 Error::Hex(err)
121 }
122}
123
124impl From<crate::descriptor::policy::PolicyError> for Error {
125 fn from(err: crate::descriptor::policy::PolicyError) -> Self {
126 Error::Policy(err)
127 }
128}