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

bitcoindevkit / bdk / 9394987004

06 Jun 2024 04:11AM UTC coverage: 83.368% (+0.2%) from 83.157%
9394987004

push

github

notmandatory
Merge bitcoindevkit/bdk#1390: Make Wallet require a change descriptor

<a class=hub.com/bitcoindevkit/bdk/commit/8bc3d35f6c83d078551c4bc57f72f13324865486">8bc3d35f6<a href="https://github.com/bitcoindevkit/bdk/commit/c5a3b62d633fc1fa0ebda144237de96dbe1636d6"> fix(wallet): `LoadError::MissingDescriptor` includes the missing KeychainKind (valued mammal)
<a class="double-link" href="https://github.com/bitcoindevkit/bdk/commit/412dee1f5b027af7800ee155717d47f4ab4b60e0">412dee1f5</a><a href="https://github.com/bitcoindevkit/bdk/commit/c5a3b62d633fc1fa0ebda144237de96dbe1636d6"> ref(wallet)!: Make `Wallet::public_descriptor` infallible (valued mammal)
</a><a class="double-link" href="https://github.com/bitcoindevkit/bdk/commit/c2513e1090374d7871a8623845bd10757e6ab0b3">c2513e109</a><a href="https://github.com/bitcoindevkit/bdk/commit/c5a3b62d633fc1fa0ebda144237de96dbe1636d6"> test(wallet): Clarify docs for get_funded_wallet (valued mammal)
</a><a class="double-link" href="https://github.com/bitcoindevkit/bdk/commit/9d954cf7d25d43c77115cd931407005a09365389">9d954cf7d</a> refactor(wallet)!: Make Wallet require a change descriptor (valued mammal)

Pull request description:

  All `Wallet` constructors are modified to require a change descriptor, where previously it was optional. Additionally we enforce uniqueness of the change descriptor to avoid ambiguity when deriving scripts and ensure the wallet will always have two distinct keystores.

  Notable changes

  * Add error `DescriptorError::ExternalAndInternalAreTheSame`
  * Remove error `CreateTxError::ChangePolicyDescriptor`
  * No longer rely on `map_keychain`

  fixes #1383

  ### Notes to the reviewers

  ### Changelog notice

  Changed:

  Constructing a Wallet now requires two distinct descriptors.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  notmandatory:
    re-ACK 8bc3d35f6c83d078551c4bc57f72f13324865486

Tree-SHA512: f0621deb7c4778f56c2ba744c70a54d813a

99 of 114 new or added lines in 3 files covered. (86.84%)

1 existing line in 1 file now uncovered.

11253 of 13498 relevant lines covered (83.37%)

16529.36 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::Error),
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 => {
NEW
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::Error> for Error {
107
    fn from(err: bitcoin::key::Error) -> 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