Skip to content

Commit c5a3b62

Browse files
committed
Merge #1390: Make Wallet require a change descriptor
8bc3d35 fix(wallet): `LoadError::MissingDescriptor` includes the missing KeychainKind (valued mammal) 412dee1 ref(wallet)!: Make `Wallet::public_descriptor` infallible (valued mammal) c2513e1 test(wallet): Clarify docs for get_funded_wallet (valued mammal) 9d954cf 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 8bc3d35 Tree-SHA512: f0621deb75d8e1e484b18b40d850f64e26314e39c4778f56c627763ddbffd376288bf6f0f37b61ba2ba744c7083683497d2dfef42bc4ef7d3ed7b374a54d813a
2 parents 8eef350 + 8bc3d35 commit c5a3b62

File tree

16 files changed

+435
-374
lines changed

16 files changed

+435
-374
lines changed

crates/hwi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//!
2121
//! # let mut wallet = Wallet::new_no_persist(
2222
//! # "",
23-
//! # None,
23+
//! # "",
2424
//! # Network::Testnet,
2525
//! # )?;
2626
//! #

crates/wallet/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ fn main() {
7474
let db = bdk_file_store::Store::<ChangeSet>::open_or_create_new(b"magic_bytes", "path/to/my_wallet.db").expect("create store");
7575
7676
let descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/0/*)";
77-
let mut wallet = Wallet::new_or_load(descriptor, None, db, Network::Testnet).expect("create or load wallet");
77+
let change_descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/1/*)";
78+
let mut wallet = Wallet::new_or_load(descriptor, change_descriptor, db, Network::Testnet).expect("create or load wallet");
7879
7980
// Insert a single `TxOut` at `OutPoint` into the wallet.
8081
let _ = wallet.insert_txout(outpoint, txout);

crates/wallet/examples/compiler.rs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,52 @@ use bdk_wallet::{KeychainKind, Wallet};
3232
/// This example demonstrates the interaction between a bdk wallet and miniscript policy.
3333
3434
fn main() -> Result<(), Box<dyn Error>> {
35-
// We start with a generic miniscript policy string
36-
let policy_str = "or(10@thresh(4,pk(029ffbe722b147f3035c87cb1c60b9a5947dd49c774cc31e94773478711a929ac0),pk(025f05815e3a1a8a83bfbb03ce016c9a2ee31066b98f567f6227df1d76ec4bd143),pk(025625f41e4a065efc06d5019cbbd56fe8c07595af1231e7cbc03fafb87ebb71ec),pk(02a27c8b850a00f67da3499b60562673dcf5fdfb82b7e17652a7ac54416812aefd),pk(03e618ec5f384d6e19ca9ebdb8e2119e5bef978285076828ce054e55c4daf473e2)),1@and(older(4209713),thresh(2,pk(03deae92101c790b12653231439f27b8897264125ecb2f46f48278603102573165),pk(033841045a531e1adf9910a6ec279589a90b3b8a904ee64ffd692bd08a8996c1aa),pk(02aebf2d10b040eb936a6f02f44ee82f8b34f5c1ccb20ff3949c2b28206b7c1068))))";
35+
// We start with a miniscript policy string
36+
let policy_str = "or(
37+
10@thresh(4,
38+
pk(029ffbe722b147f3035c87cb1c60b9a5947dd49c774cc31e94773478711a929ac0),pk(025f05815e3a1a8a83bfbb03ce016c9a2ee31066b98f567f6227df1d76ec4bd143),pk(025625f41e4a065efc06d5019cbbd56fe8c07595af1231e7cbc03fafb87ebb71ec),pk(02a27c8b850a00f67da3499b60562673dcf5fdfb82b7e17652a7ac54416812aefd),pk(03e618ec5f384d6e19ca9ebdb8e2119e5bef978285076828ce054e55c4daf473e2)
39+
),1@and(
40+
older(4209713),
41+
thresh(2,
42+
pk(03deae92101c790b12653231439f27b8897264125ecb2f46f48278603102573165),pk(033841045a531e1adf9910a6ec279589a90b3b8a904ee64ffd692bd08a8996c1aa),pk(02aebf2d10b040eb936a6f02f44ee82f8b34f5c1ccb20ff3949c2b28206b7c1068)
43+
)
44+
)
45+
)"
46+
.replace(&[' ', '\n', '\t'][..], "");
47+
3748
println!("Compiling policy: \n{}", policy_str);
3849

3950
// Parse the string as a [`Concrete`] type miniscript policy.
40-
let policy = Concrete::<String>::from_str(policy_str)?;
51+
let policy = Concrete::<String>::from_str(&policy_str)?;
4152

4253
// Create a `wsh` type descriptor from the policy.
4354
// `policy.compile()` returns the resulting miniscript from the policy.
44-
let descriptor = Descriptor::new_wsh(policy.compile()?)?;
55+
let descriptor = Descriptor::new_wsh(policy.compile()?)?.to_string();
56+
57+
println!("Compiled into Descriptor: \n{}", descriptor);
58+
59+
// Do the same for another (internal) keychain
60+
let policy_str = "or(
61+
10@thresh(2,
62+
pk(029ffbe722b147f3035c87cb1c60b9a5947dd49c774cc31e94773478711a929ac0),pk(025f05815e3a1a8a83bfbb03ce016c9a2ee31066b98f567f6227df1d76ec4bd143),pk(025625f41e4a065efc06d5019cbbd56fe8c07595af1231e7cbc03fafb87ebb71ec)
63+
),1@and(
64+
pk(03deae92101c790b12653231439f27b8897264125ecb2f46f48278603102573165),
65+
older(12960)
66+
)
67+
)"
68+
.replace(&[' ', '\n', '\t'][..], "");
4569

46-
println!("Compiled into following Descriptor: \n{}", descriptor);
70+
println!("Compiling internal policy: \n{}", policy_str);
71+
72+
let policy = Concrete::<String>::from_str(&policy_str)?;
73+
let internal_descriptor = Descriptor::new_wsh(policy.compile()?)?.to_string();
74+
println!(
75+
"Compiled into internal Descriptor: \n{}",
76+
internal_descriptor
77+
);
4778

48-
// Create a new wallet from this descriptor
49-
let mut wallet = Wallet::new_no_persist(&format!("{}", descriptor), None, Network::Regtest)?;
79+
// Create a new wallet from descriptors
80+
let mut wallet = Wallet::new_no_persist(&descriptor, &internal_descriptor, Network::Regtest)?;
5081

5182
println!(
5283
"First derived address from the descriptor: \n{}",

crates/wallet/src/descriptor/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub enum Error {
4242
Miniscript(miniscript::Error),
4343
/// Hex decoding error
4444
Hex(bitcoin::hex::HexToBytesError),
45+
/// The provided wallet descriptors are identical
46+
ExternalAndInternalAreTheSame,
4547
}
4648

4749
impl From<crate::keys::KeyError> for Error {
@@ -79,6 +81,9 @@ impl fmt::Display for Error {
7981
Self::Pk(err) => write!(f, "Key-related error: {}", err),
8082
Self::Miniscript(err) => write!(f, "Miniscript error: {}", err),
8183
Self::Hex(err) => write!(f, "Hex decoding error: {}", err),
84+
Self::ExternalAndInternalAreTheSame => {
85+
write!(f, "External and internal descriptors are the same")
86+
}
8287
}
8388
}
8489
}

crates/wallet/src/descriptor/template.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ impl<T: DescriptorTemplate> IntoWalletDescriptor for T {
7777
/// # use bdk_wallet::KeychainKind;
7878
/// use bdk_wallet::template::P2Pkh;
7979
///
80-
/// let key =
80+
/// let key_external =
8181
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
82-
/// let mut wallet = Wallet::new_no_persist(P2Pkh(key), None, Network::Testnet)?;
82+
/// let key_internal =
83+
/// bitcoin::PrivateKey::from_wif("cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW")?;
84+
/// let mut wallet =
85+
/// Wallet::new_no_persist(P2Pkh(key_external), P2Pkh(key_internal), Network::Testnet)?;
8386
///
8487
/// assert_eq!(
8588
/// wallet
@@ -107,9 +110,15 @@ impl<K: IntoDescriptorKey<Legacy>> DescriptorTemplate for P2Pkh<K> {
107110
/// # use bdk_wallet::KeychainKind;
108111
/// use bdk_wallet::template::P2Wpkh_P2Sh;
109112
///
110-
/// let key =
113+
/// let key_external =
111114
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
112-
/// let mut wallet = Wallet::new_no_persist(P2Wpkh_P2Sh(key), None, Network::Testnet)?;
115+
/// let key_internal =
116+
/// bitcoin::PrivateKey::from_wif("cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW")?;
117+
/// let mut wallet = Wallet::new_no_persist(
118+
/// P2Wpkh_P2Sh(key_external),
119+
/// P2Wpkh_P2Sh(key_internal),
120+
/// Network::Testnet,
121+
/// )?;
113122
///
114123
/// assert_eq!(
115124
/// wallet
@@ -138,9 +147,12 @@ impl<K: IntoDescriptorKey<Segwitv0>> DescriptorTemplate for P2Wpkh_P2Sh<K> {
138147
/// # use bdk_wallet::KeychainKind;
139148
/// use bdk_wallet::template::P2Wpkh;
140149
///
141-
/// let key =
150+
/// let key_external =
142151
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
143-
/// let mut wallet = Wallet::new_no_persist(P2Wpkh(key), None, Network::Testnet)?;
152+
/// let key_internal =
153+
/// bitcoin::PrivateKey::from_wif("cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW")?;
154+
/// let mut wallet =
155+
/// Wallet::new_no_persist(P2Wpkh(key_external), P2Wpkh(key_internal), Network::Testnet)?;
144156
///
145157
/// assert_eq!(
146158
/// wallet
@@ -168,9 +180,12 @@ impl<K: IntoDescriptorKey<Segwitv0>> DescriptorTemplate for P2Wpkh<K> {
168180
/// # use bdk_wallet::KeychainKind;
169181
/// use bdk_wallet::template::P2TR;
170182
///
171-
/// let key =
183+
/// let key_external =
172184
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
173-
/// let mut wallet = Wallet::new_no_persist(P2TR(key), None, Network::Testnet)?;
185+
/// let key_internal =
186+
/// bitcoin::PrivateKey::from_wif("cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW")?;
187+
/// let mut wallet =
188+
/// Wallet::new_no_persist(P2TR(key_external), P2TR(key_internal), Network::Testnet)?;
174189
///
175190
/// assert_eq!(
176191
/// wallet
@@ -205,12 +220,12 @@ impl<K: IntoDescriptorKey<Tap>> DescriptorTemplate for P2TR<K> {
205220
/// let key = bitcoin::bip32::Xpriv::from_str("tprv8ZgxMBicQKsPeZRHk4rTG6orPS2CRNFX3njhUXx5vj9qGog5ZMH4uGReDWN5kCkY3jmWEtWause41CDvBRXD1shKknAMKxT99o9qUTRVC6m")?;
206221
/// let mut wallet = Wallet::new_no_persist(
207222
/// Bip44(key.clone(), KeychainKind::External),
208-
/// Some(Bip44(key, KeychainKind::Internal)),
223+
/// Bip44(key, KeychainKind::Internal),
209224
/// Network::Testnet,
210225
/// )?;
211226
///
212227
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "mmogjc7HJEZkrLqyQYqJmxUqFaC7i4uf89");
213-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "pkh([c55b303f/44'/1'/0']tpubDCuorCpzvYS2LCD75BR46KHE8GdDeg1wsAgNZeNr6DaB5gQK1o14uErKwKLuFmeemkQ6N2m3rNgvctdJLyr7nwu2yia7413Hhg8WWE44cgT/0/*)#5wrnv0xt");
228+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "pkh([c55b303f/44'/1'/0']tpubDCuorCpzvYS2LCD75BR46KHE8GdDeg1wsAgNZeNr6DaB5gQK1o14uErKwKLuFmeemkQ6N2m3rNgvctdJLyr7nwu2yia7413Hhg8WWE44cgT/0/*)#5wrnv0xt");
214229
/// # Ok::<_, Box<dyn std::error::Error>>(())
215230
/// ```
216231
pub struct Bip44<K: DerivableKey<Legacy>>(pub K, pub KeychainKind);
@@ -242,12 +257,12 @@ impl<K: DerivableKey<Legacy>> DescriptorTemplate for Bip44<K> {
242257
/// let fingerprint = bitcoin::bip32::Fingerprint::from_str("c55b303f")?;
243258
/// let mut wallet = Wallet::new_no_persist(
244259
/// Bip44Public(key.clone(), fingerprint, KeychainKind::External),
245-
/// Some(Bip44Public(key, fingerprint, KeychainKind::Internal)),
260+
/// Bip44Public(key, fingerprint, KeychainKind::Internal),
246261
/// Network::Testnet,
247262
/// )?;
248263
///
249264
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "miNG7dJTzJqNbFS19svRdTCisC65dsubtR");
250-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "pkh([c55b303f/44'/1'/0']tpubDDDzQ31JkZB7VxUr9bjvBivDdqoFLrDPyLWtLapArAi51ftfmCb2DPxwLQzX65iNcXz1DGaVvyvo6JQ6rTU73r2gqdEo8uov9QKRb7nKCSU/0/*)#cfhumdqz");
265+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "pkh([c55b303f/44'/1'/0']tpubDDDzQ31JkZB7VxUr9bjvBivDdqoFLrDPyLWtLapArAi51ftfmCb2DPxwLQzX65iNcXz1DGaVvyvo6JQ6rTU73r2gqdEo8uov9QKRb7nKCSU/0/*)#cfhumdqz");
251266
/// # Ok::<_, Box<dyn std::error::Error>>(())
252267
/// ```
253268
pub struct Bip44Public<K: DerivableKey<Legacy>>(pub K, pub bip32::Fingerprint, pub KeychainKind);
@@ -278,12 +293,12 @@ impl<K: DerivableKey<Legacy>> DescriptorTemplate for Bip44Public<K> {
278293
/// let key = bitcoin::bip32::Xpriv::from_str("tprv8ZgxMBicQKsPeZRHk4rTG6orPS2CRNFX3njhUXx5vj9qGog5ZMH4uGReDWN5kCkY3jmWEtWause41CDvBRXD1shKknAMKxT99o9qUTRVC6m")?;
279294
/// let mut wallet = Wallet::new_no_persist(
280295
/// Bip49(key.clone(), KeychainKind::External),
281-
/// Some(Bip49(key, KeychainKind::Internal)),
296+
/// Bip49(key, KeychainKind::Internal),
282297
/// Network::Testnet,
283298
/// )?;
284299
///
285300
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "2N4zkWAoGdUv4NXhSsU8DvS5MB36T8nKHEB");
286-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "sh(wpkh([c55b303f/49'/1'/0']tpubDDYr4kdnZgjjShzYNjZUZXUUtpXaofdkMaipyS8ThEh45qFmhT4hKYways7UXmg6V7het1QiFo9kf4kYUXyDvV4rHEyvSpys9pjCB3pukxi/0/*))#s9vxlc8e");
301+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "sh(wpkh([c55b303f/49'/1'/0']tpubDDYr4kdnZgjjShzYNjZUZXUUtpXaofdkMaipyS8ThEh45qFmhT4hKYways7UXmg6V7het1QiFo9kf4kYUXyDvV4rHEyvSpys9pjCB3pukxi/0/*))#s9vxlc8e");
287302
/// # Ok::<_, Box<dyn std::error::Error>>(())
288303
/// ```
289304
pub struct Bip49<K: DerivableKey<Segwitv0>>(pub K, pub KeychainKind);
@@ -315,12 +330,12 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip49<K> {
315330
/// let fingerprint = bitcoin::bip32::Fingerprint::from_str("c55b303f")?;
316331
/// let mut wallet = Wallet::new_no_persist(
317332
/// Bip49Public(key.clone(), fingerprint, KeychainKind::External),
318-
/// Some(Bip49Public(key, fingerprint, KeychainKind::Internal)),
333+
/// Bip49Public(key, fingerprint, KeychainKind::Internal),
319334
/// Network::Testnet,
320335
/// )?;
321336
///
322337
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "2N3K4xbVAHoiTQSwxkZjWDfKoNC27pLkYnt");
323-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "sh(wpkh([c55b303f/49'/1'/0']tpubDC49r947KGK52X5rBWS4BLs5m9SRY3pYHnvRrm7HcybZ3BfdEsGFyzCMzayi1u58eT82ZeyFZwH7DD6Q83E3fM9CpfMtmnTygnLfP59jL9L/0/*))#3tka9g0q");
338+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "sh(wpkh([c55b303f/49'/1'/0']tpubDC49r947KGK52X5rBWS4BLs5m9SRY3pYHnvRrm7HcybZ3BfdEsGFyzCMzayi1u58eT82ZeyFZwH7DD6Q83E3fM9CpfMtmnTygnLfP59jL9L/0/*))#3tka9g0q");
324339
/// # Ok::<_, Box<dyn std::error::Error>>(())
325340
/// ```
326341
pub struct Bip49Public<K: DerivableKey<Segwitv0>>(pub K, pub bip32::Fingerprint, pub KeychainKind);
@@ -351,12 +366,12 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip49Public<K> {
351366
/// let key = bitcoin::bip32::Xpriv::from_str("tprv8ZgxMBicQKsPeZRHk4rTG6orPS2CRNFX3njhUXx5vj9qGog5ZMH4uGReDWN5kCkY3jmWEtWause41CDvBRXD1shKknAMKxT99o9qUTRVC6m")?;
352367
/// let mut wallet = Wallet::new_no_persist(
353368
/// Bip84(key.clone(), KeychainKind::External),
354-
/// Some(Bip84(key, KeychainKind::Internal)),
369+
/// Bip84(key, KeychainKind::Internal),
355370
/// Network::Testnet,
356371
/// )?;
357372
///
358373
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "tb1qhl85z42h7r4su5u37rvvw0gk8j2t3n9y7zsg4n");
359-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "wpkh([c55b303f/84'/1'/0']tpubDDc5mum24DekpNw92t6fHGp8Gr2JjF9J7i4TZBtN6Vp8xpAULG5CFaKsfugWa5imhrQQUZKXe261asP5koDHo5bs3qNTmf3U3o4v9SaB8gg/0/*)#6kfecsmr");
374+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "wpkh([c55b303f/84'/1'/0']tpubDDc5mum24DekpNw92t6fHGp8Gr2JjF9J7i4TZBtN6Vp8xpAULG5CFaKsfugWa5imhrQQUZKXe261asP5koDHo5bs3qNTmf3U3o4v9SaB8gg/0/*)#6kfecsmr");
360375
/// # Ok::<_, Box<dyn std::error::Error>>(())
361376
/// ```
362377
pub struct Bip84<K: DerivableKey<Segwitv0>>(pub K, pub KeychainKind);
@@ -388,12 +403,12 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip84<K> {
388403
/// let fingerprint = bitcoin::bip32::Fingerprint::from_str("c55b303f")?;
389404
/// let mut wallet = Wallet::new_no_persist(
390405
/// Bip84Public(key.clone(), fingerprint, KeychainKind::External),
391-
/// Some(Bip84Public(key, fingerprint, KeychainKind::Internal)),
406+
/// Bip84Public(key, fingerprint, KeychainKind::Internal),
392407
/// Network::Testnet,
393408
/// )?;
394409
///
395410
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "tb1qedg9fdlf8cnnqfd5mks6uz5w4kgpk2pr6y4qc7");
396-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "wpkh([c55b303f/84'/1'/0']tpubDC2Qwo2TFsaNC4ju8nrUJ9mqVT3eSgdmy1yPqhgkjwmke3PRXutNGRYAUo6RCHTcVQaDR3ohNU9we59brGHuEKPvH1ags2nevW5opEE9Z5Q/0/*)#dhu402yv");
411+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "wpkh([c55b303f/84'/1'/0']tpubDC2Qwo2TFsaNC4ju8nrUJ9mqVT3eSgdmy1yPqhgkjwmke3PRXutNGRYAUo6RCHTcVQaDR3ohNU9we59brGHuEKPvH1ags2nevW5opEE9Z5Q/0/*)#dhu402yv");
397412
/// # Ok::<_, Box<dyn std::error::Error>>(())
398413
/// ```
399414
pub struct Bip84Public<K: DerivableKey<Segwitv0>>(pub K, pub bip32::Fingerprint, pub KeychainKind);
@@ -424,12 +439,12 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip84Public<K> {
424439
/// let key = bitcoin::bip32::Xpriv::from_str("tprv8ZgxMBicQKsPeZRHk4rTG6orPS2CRNFX3njhUXx5vj9qGog5ZMH4uGReDWN5kCkY3jmWEtWause41CDvBRXD1shKknAMKxT99o9qUTRVC6m")?;
425440
/// let mut wallet = Wallet::new_no_persist(
426441
/// Bip86(key.clone(), KeychainKind::External),
427-
/// Some(Bip86(key, KeychainKind::Internal)),
442+
/// Bip86(key, KeychainKind::Internal),
428443
/// Network::Testnet,
429444
/// )?;
430445
///
431446
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "tb1p5unlj09djx8xsjwe97269kqtxqpwpu2epeskgqjfk4lnf69v4tnqpp35qu");
432-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "tr([c55b303f/86'/1'/0']tpubDCiHofpEs47kx358bPdJmTZHmCDqQ8qw32upCSxHrSEdeeBs2T5Mq6QMB2ukeMqhNBiyhosBvJErteVhfURPGXPv3qLJPw5MVpHUewsbP2m/0/*)#dkgvr5hm");
447+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "tr([c55b303f/86'/1'/0']tpubDCiHofpEs47kx358bPdJmTZHmCDqQ8qw32upCSxHrSEdeeBs2T5Mq6QMB2ukeMqhNBiyhosBvJErteVhfURPGXPv3qLJPw5MVpHUewsbP2m/0/*)#dkgvr5hm");
433448
/// # Ok::<_, Box<dyn std::error::Error>>(())
434449
/// ```
435450
pub struct Bip86<K: DerivableKey<Tap>>(pub K, pub KeychainKind);
@@ -461,12 +476,12 @@ impl<K: DerivableKey<Tap>> DescriptorTemplate for Bip86<K> {
461476
/// let fingerprint = bitcoin::bip32::Fingerprint::from_str("c55b303f")?;
462477
/// let mut wallet = Wallet::new_no_persist(
463478
/// Bip86Public(key.clone(), fingerprint, KeychainKind::External),
464-
/// Some(Bip86Public(key, fingerprint, KeychainKind::Internal)),
479+
/// Bip86Public(key, fingerprint, KeychainKind::Internal),
465480
/// Network::Testnet,
466481
/// )?;
467482
///
468483
/// assert_eq!(wallet.next_unused_address(KeychainKind::External)?.to_string(), "tb1pwjp9f2k5n0xq73ecuu0c5njvgqr3vkh7yaylmpqvsuuaafymh0msvcmh37");
469-
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).unwrap().to_string(), "tr([c55b303f/86'/1'/0']tpubDC2Qwo2TFsaNC4ju8nrUJ9mqVT3eSgdmy1yPqhgkjwmke3PRXutNGRYAUo6RCHTcVQaDR3ohNU9we59brGHuEKPvH1ags2nevW5opEE9Z5Q/0/*)#2p65srku");
484+
/// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "tr([c55b303f/86'/1'/0']tpubDC2Qwo2TFsaNC4ju8nrUJ9mqVT3eSgdmy1yPqhgkjwmke3PRXutNGRYAUo6RCHTcVQaDR3ohNU9we59brGHuEKPvH1ags2nevW5opEE9Z5Q/0/*)#2p65srku");
470485
/// # Ok::<_, Box<dyn std::error::Error>>(())
471486
/// ```
472487
pub struct Bip86Public<K: DerivableKey<Tap>>(pub K, pub bip32::Fingerprint, pub KeychainKind);

crates/wallet/src/wallet/error.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ pub enum CreateTxError {
9090
NoUtxosSelected,
9191
/// Output created is under the dust limit, 546 satoshis
9292
OutputBelowDustLimit(usize),
93-
/// The `change_policy` was set but the wallet does not have a change_descriptor
94-
ChangePolicyDescriptor,
9593
/// There was an error with coin selection
9694
CoinSelection(coin_selection::Error),
9795
/// Wallet's UTXO set is not enough to cover recipient's requested plus fee
@@ -177,12 +175,6 @@ impl fmt::Display for CreateTxError {
177175
CreateTxError::OutputBelowDustLimit(limit) => {
178176
write!(f, "Output below the dust limit: {}", limit)
179177
}
180-
CreateTxError::ChangePolicyDescriptor => {
181-
write!(
182-
f,
183-
"The `change_policy` can be set only if the wallet has a change_descriptor"
184-
)
185-
}
186178
CreateTxError::CoinSelection(e) => e.fmt(f),
187179
CreateTxError::InsufficientFunds { needed, available } => {
188180
write!(

0 commit comments

Comments
 (0)