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

bitcoindevkit / bdk / 10348217438

12 Aug 2024 08:10AM UTC coverage: 81.794% (-0.02%) from 81.813%
10348217438

Pull #1535

github

web-flow
Merge 2c0bc45ec into 98c49592d
Pull Request #1535: test(electrum): Test sync in reorg and no-reorg situations

19 of 25 new or added lines in 1 file covered. (76.0%)

1 existing line in 1 file now uncovered.

10908 of 13336 relevant lines covered (81.79%)

12995.15 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, PartialEq)]
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
    /// Error thrown while working with [`keys`](crate::keys)
27
    Key(crate::keys::KeyError),
28
    /// Error while extracting and manipulating policies
29
    Policy(crate::descriptor::policy::PolicyError),
30

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

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

48
impl From<crate::keys::KeyError> for Error {
49
    fn from(key_error: crate::keys::KeyError) -> Error {
×
50
        match key_error {
×
51
            crate::keys::KeyError::Miniscript(inner) => Error::Miniscript(inner),
×
52
            crate::keys::KeyError::Bip32(inner) => Error::Bip32(inner),
×
53
            e => Error::Key(e),
×
54
        }
55
    }
×
56
}
57

58
impl fmt::Display for Error {
59
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
60
        match self {
×
61
            Self::InvalidHdKeyPath => write!(f, "Invalid HD key path"),
×
62
            Self::InvalidDescriptorChecksum => {
63
                write!(f, "The provided descriptor doesn't match its checksum")
×
64
            }
65
            Self::HardenedDerivationXpub => write!(
×
66
                f,
×
67
                "The descriptor contains hardened derivation steps on public extended keys"
×
68
            ),
×
69
            Self::MultiPath => write!(
×
70
                f,
×
71
                "The descriptor contains multipath keys, which are not supported yet"
×
72
            ),
×
73
            Self::Key(err) => write!(f, "Key error: {}", err),
×
74
            Self::Policy(err) => write!(f, "Policy error: {}", err),
×
75
            Self::InvalidDescriptorCharacter(char) => {
×
76
                write!(f, "Invalid descriptor character: {}", char)
×
77
            }
78
            Self::Bip32(err) => write!(f, "BIP32 error: {}", err),
×
79
            Self::Base58(err) => write!(f, "Base58 error: {}", err),
×
80
            Self::Pk(err) => write!(f, "Key-related error: {}", err),
×
81
            Self::Miniscript(err) => write!(f, "Miniscript error: {}", err),
×
82
            Self::Hex(err) => write!(f, "Hex decoding error: {}", err),
×
83
            Self::ExternalAndInternalAreTheSame => {
84
                write!(f, "External and internal descriptors are the same")
×
85
            }
86
        }
87
    }
×
88
}
89

90
#[cfg(feature = "std")]
91
impl std::error::Error for Error {}
92

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

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

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

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

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

123
impl From<crate::descriptor::policy::PolicyError> for Error {
124
    fn from(err: crate::descriptor::policy::PolicyError) -> Self {
×
125
        Error::Policy(err)
×
126
    }
×
127
}
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