Skip to content

Commit d4642e0

Browse files
committed
Merge #309: Cherrypick #306 onto release/2.2
f73596e docs: add wording on required use of xpub for multipath constructor (thunderbiscuit) Pull request description: This is just a cherry pick of my #306 PR onto the 2.2 release branch. ACKs for top commit: ValuedMammal: ACK f73596e oleonardolima: ACK f73596e Tree-SHA512: f1e0f2acf9ab832e33fcf071b880de8df09b40bc755236c80f0045c48f667c10e4b38133f50f210acafe6d335e6a62b77037b6a5068d16d44a25dd46e138307c
2 parents e43e597 + f73596e commit d4642e0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

wallet/src/wallet/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,17 @@ impl Wallet {
399399
/// Build a new [`Wallet`] from a two-path descriptor.
400400
///
401401
/// This function parses a multipath descriptor with exactly 2 paths and creates a wallet
402-
/// using the existing receive and change wallet creation logic.
402+
/// using the existing receive and change wallet creation logic. Note that you can only use this
403+
/// method with public extended keys (`xpub` prefix) to create watch-only wallets.
403404
///
404405
/// Multipath descriptors follow [BIP 389] and allow defining both receive and change
405406
/// derivation paths in a single descriptor using the `<0;1>` syntax.
406407
///
407408
/// If you have previously created a wallet, use [`load`](Self::load) instead.
408409
///
409410
/// # Errors
410-
/// Returns an error if the descriptor is invalid or not a 2-path multipath descriptor.
411+
/// Returns an error if the descriptor is invalid, not a 2-path multipath descriptor, or if
412+
/// the descriptor provided contains an extended private key (`xprv` prefix).
411413
///
412414
/// # Synopsis
413415
///
@@ -1224,7 +1226,7 @@ impl Wallet {
12241226
txs
12251227
}
12261228

1227-
/// Return the balance, separated into available, trusted-pending, untrusted-pending and
1229+
/// Return the balance, separated into available, trusted-pending, untrusted-pending, and
12281230
/// immature values.
12291231
pub fn balance(&self) -> Balance {
12301232
self.indexed_graph.graph().balance(
@@ -2794,6 +2796,7 @@ macro_rules! doctest_wallet {
27942796
#[cfg(test)]
27952797
mod test {
27962798
use super::*;
2799+
use crate::miniscript::Error::Unexpected;
27972800
use crate::test_utils::get_test_tr_single_sig_xprv_and_change_desc;
27982801
use crate::test_utils::insert_tx;
27992802

@@ -2894,6 +2897,17 @@ mod test {
28942897
let wallet = params.network(Network::Testnet).create_wallet_no_persist();
28952898
assert!(matches!(wallet, Err(DescriptorError::MultiPath)));
28962899

2900+
// Test with a private descriptor
2901+
// You get a Miniscript(Unexpected("Can't make an extended private key with multiple paths
2902+
// into a public key.")) error.
2903+
let private_multipath_descriptor = "wpkh(tprv8ZgxMBicQKsPdWAHbugK2tjtVtRjKGixYVZUdL7xLHMgXZS6BFbFi1UDb1CHT25Z5PU1F9j7wGxwUiRhqz9E3nZRztikGUV6HoRDYcqPhM4/84'/1'/0'/<0;1>/*)";
2904+
let params = Wallet::create_from_two_path_descriptor(private_multipath_descriptor);
2905+
let wallet = params.network(Network::Testnet).create_wallet_no_persist();
2906+
assert!(matches!(
2907+
wallet,
2908+
Err(DescriptorError::Miniscript(Unexpected(..)))
2909+
));
2910+
28972911
// Test with invalid 3-path multipath descriptor
28982912
let three_path_descriptor = "wpkh([9a6a2580/84'/1'/0']tpubDDnGNapGEY6AZAdQbfRJgMg9fvz8pUBrLwvyvUqEgcUfgzM6zc2eVK4vY9x9L5FJWdX8WumXuLEDV5zDZnTfbn87vLe9XceCFwTu9so9Kks/<0;1;2>/*)";
28992913
let params = Wallet::create_from_two_path_descriptor(three_path_descriptor);

0 commit comments

Comments
 (0)