• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bitcoindevkit / bdk / 9475497656

12 Jun 2024 02:00AM UTC coverage: 82.974% (-0.4%) from 83.405%
9475497656

Pull #1468

github

web-flow
Merge 44e446faa into 473ef9714
Pull Request #1468: wip(feat): use `Weight` type instead of `usize`

112 of 190 new or added lines in 19 files covered. (58.95%)

13 existing lines in 3 files now uncovered.

11253 of 13562 relevant lines covered (82.97%)

16764.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.38
/crates/wallet/src/descriptor/error.rs
1
// Bitcoin Dev Kit
2
// Written in 2020 by Alekos Filini <alekos.filini@gmail.com>
3
//
4
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
5
//
6
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
7
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
9
// You may not use this file except in accordance with one or both of these
10
// licenses.
11

12
//! Descriptor errors
13
use core::fmt;
14

15
/// Errors related to the parsing and usage of descriptors
16
#[derive(Debug)]
17
pub enum Error {
18
    /// Invalid HD Key path, such as having a wildcard but a length != 1
19
    InvalidHdKeyPath,
20
    /// The provided descriptor doesn't match its checksum
21
    InvalidDescriptorChecksum,
22
    /// The descriptor contains hardened derivation steps on public extended keys
23
    HardenedDerivationXpub,
24
    /// The descriptor contains multipath keys
25
    MultiPath,
26

27
    /// Error thrown while working with [`keys`](crate::keys)
28
    Key(crate::keys::KeyError),
29
    /// Error while extracting and manipulating policies
30
    Policy(crate::descriptor::policy::PolicyError),
31

32
    /// Invalid byte found in the descriptor checksum
33
    InvalidDescriptorCharacter(u8),
34

35
    /// BIP32 error
36
    Bip32(bitcoin::bip32::Error),
37
    /// Error during base58 decoding
38
    Base58(bitcoin::base58::Error),
39
    /// Key-related error
40
    Pk(bitcoin::key::ParsePublicKeyError),
41
    /// Miniscript error
42
    Miniscript(miniscript::Error),
43
    /// Hex decoding error
44
    Hex(bitcoin::hex::HexToBytesError),
45
    /// The provided wallet descriptors are identical
46
    ExternalAndInternalAreTheSame,
47
}
48

49
impl 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

59
impl 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, which are not supported yet"
×
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")]
92
impl std::error::Error for Error {}
93

94
impl From<bitcoin::bip32::Error> for Error {
95
    fn from(err: bitcoin::bip32::Error) -> Self {
×
96
        Error::Bip32(err)
×
97
    }
×
98
}
99

100
impl From<bitcoin::base58::Error> for Error {
101
    fn from(err: bitcoin::base58::Error) -> Self {
×
102
        Error::Base58(err)
×
103
    }
×
104
}
105

106
impl From<bitcoin::key::ParsePublicKeyError> for Error {
NEW
107
    fn from(err: bitcoin::key::ParsePublicKeyError) -> Self {
×
108
        Error::Pk(err)
×
109
    }
×
110
}
111

112
impl From<miniscript::Error> for Error {
113
    fn from(err: miniscript::Error) -> Self {
2✔
114
        Error::Miniscript(err)
2✔
115
    }
2✔
116
}
117

118
impl From<bitcoin::hex::HexToBytesError> for Error {
119
    fn from(err: bitcoin::hex::HexToBytesError) -> Self {
×
120
        Error::Hex(err)
×
121
    }
×
122
}
123

124
impl From<crate::descriptor::policy::PolicyError> for Error {
125
    fn from(err: crate::descriptor::policy::PolicyError) -> Self {
×
126
        Error::Policy(err)
×
127
    }
×
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc