Skip to content

Commit e7d9d44

Browse files
committed
Merge #250: feat!: use NetworkKind
881df71 chore: rename `merge_network_kinds` to `intersect_network_kinds` (Luis Schwab) fdb9d13 fix: GeneratableKey options for PrivateKey, Xpriv (valued mammal) b1d384f feat!(examples,test): use `NetworkKind` (Luis Schwab) 944274a feat!(wallet): use `NetworkKind` (Luis Schwab) c22aa13 feat!(keys): use `NetworkKind` (Luis Schwab) ade83b4 feat!(descriptor): use `NetworkKind` (Luis Schwab) Pull request description: ### Description Closes #22. Closes #94. This PR replaces `bitcoin::Network` for `bitcoin::NetworkKind` where it applies. I also took the liberty of fixing up and adding comments on the files I touched. ### Changelog - `wallet_name_from_descriptor()` takes `NetworkKind` instead of `Network`. - `DescriptorToExtract` takes `NetworkKind` instead of `Network`. - `impl IntoWalletDescriptor for <T>` takes `Network` instead `NetworkKind`. - `DescriptorTemplate::build()` takes `NetworkKind` instead of `Network`. - `ExtendedKey::into_xprv()` takes `NetworkKind` instead of `Network`. - `ExtendedKey::into_xpub()` takes `NetworkKind` instead of `Network`. - `DerivableKey::into_extended_key()` examples updated to use `NetworkKind` instead of `Network`. - `any_network()` renamed to `any_network_kind()`. - `mainnet_network()` renamed to `mainnet_network_kind()`. - `test_networks()` renamed to `test_network_kind()`. - `merge_networks()` renamed to `intersect_network_kinds()`. - `ValidNetworks` type alias renamed to `ValidNetworkKinds`. - `GeneratedKey::new()` takes `ValidNetworkKinds` instead of `ValidNetworks`. - `DescriptorKey::from_public()` takes `ValidNetworkKinds` instead of `ValidNetworks`. - `DescriptorKey::from_secret()` takes `ValidNetworkKinds` instead of `ValidNetworks`. - `KeyError::InvalidNetwork` renamed to `KeyError::InvalidNetworkKind`. - `DescriptorKey::override_valid_networks()` renamed to `override_valid_network_kinds()`. - Network validation logic updated to use `NetworkKind` instead of `Network`. - Test network validation now uses `NetworkKind::Test` instead of `Network::{Regtest, Signet, Testnet, Testnet4}`. - Examples and comments updated to use `NetworkKind` instead of `Network`. ### 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 +nightly fmt` and `cargo clippy` before committing #### New Features: * [ ] I've added tests for the new feature * [X] I've added docs for the new feature #### Bugfixes: * [X] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [X] I'm linking the issue being fixed by this PR ACKs for top commit: ValuedMammal: ACK 881df71 oleonardolima: ACK 881df71 Tree-SHA512: 9da33233db1409764d75fd688c8343f01c624b359df389acbafbab818114b2ffb1d0f1a977ff60ff5f850b8d8de4b74827360a4740954c0d751ce5a60d1cc5af
2 parents 321c8a0 + 881df71 commit e7d9d44

File tree

13 files changed

+818
-669
lines changed

13 files changed

+818
-669
lines changed

examples/mnemonic_to_descriptors.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
1+
// Copyright (c) 2020-2025 Bitcoin Dev Kit Developers
22
//
33
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
44
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
@@ -9,7 +9,7 @@
99
use anyhow::anyhow;
1010
use bdk_wallet::bitcoin::bip32::DerivationPath;
1111
use bdk_wallet::bitcoin::secp256k1::Secp256k1;
12-
use bdk_wallet::bitcoin::Network;
12+
use bdk_wallet::bitcoin::NetworkKind;
1313
use bdk_wallet::descriptor;
1414
use bdk_wallet::descriptor::IntoWalletDescriptor;
1515
use bdk_wallet::keys::bip39::{Language, Mnemonic, WordCount};
@@ -18,32 +18,32 @@ use bdk_wallet::miniscript::Tap;
1818
use std::str::FromStr;
1919

2020
/// This example demonstrates how to generate a mnemonic phrase
21-
/// using BDK and use that to generate a descriptor string.
21+
/// using BDK and use that mnemonic phrase to generate a descriptor string.
2222
#[allow(clippy::print_stdout)]
2323
fn main() -> Result<(), anyhow::Error> {
2424
let secp = Secp256k1::new();
2525

26-
// In this example we are generating a 12 words mnemonic phrase
26+
// In this example we are generating a 12 word mnemonic phrase
2727
// but it is also possible generate 15, 18, 21 and 24 words
28-
// using their respective `WordCount` variant.
28+
// using the respective `WordCount` variant.
2929
let mnemonic: GeneratedKey<_, Tap> =
3030
Mnemonic::generate((WordCount::Words12, Language::English))
3131
.map_err(|_| anyhow!("Mnemonic generation error"))?;
3232

3333
println!("Mnemonic phrase: {}", *mnemonic);
3434
let mnemonic_with_passphrase = (mnemonic, None);
3535

36-
// define external and internal derivation key path
36+
// Define the external and internal derivation key path.
3737
let external_path = DerivationPath::from_str("m/86h/1h/0h/0").unwrap();
3838
let internal_path = DerivationPath::from_str("m/86h/1h/0h/1").unwrap();
3939

40-
// generate external and internal descriptor from mnemonic
40+
// Generate external and internal descriptors from the mnemonic phrase.
4141
let (external_descriptor, ext_keymap) =
4242
descriptor!(tr((mnemonic_with_passphrase.clone(), external_path)))?
43-
.into_wallet_descriptor(&secp, Network::Testnet)?;
43+
.into_wallet_descriptor(&secp, NetworkKind::Test)?;
4444
let (internal_descriptor, int_keymap) =
4545
descriptor!(tr((mnemonic_with_passphrase, internal_path)))?
46-
.into_wallet_descriptor(&secp, Network::Testnet)?;
46+
.into_wallet_descriptor(&secp, NetworkKind::Test)?;
4747

4848
println!("tpub external descriptor: {external_descriptor}");
4949
println!("tpub internal descriptor: {internal_descriptor}");

examples/policy.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Bitcoin Dev Kit
22
// Written in 2020 by Alekos Filini <alekos.filini@gmail.com>
33
//
4-
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
4+
// Copyright (c) 2020-2025 Bitcoin Dev Kit Developers
55
//
66
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
77
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
@@ -10,11 +10,12 @@
1010
// licenses.
1111

1212
extern crate bdk_wallet;
13+
1314
use std::error::Error;
1415

15-
use bdk_wallet::bitcoin::Network;
1616
use bdk_wallet::descriptor::{policy::BuildSatisfaction, ExtractPolicy, IntoWalletDescriptor};
1717
use bdk_wallet::signer::SignersContainer;
18+
use bitcoin::NetworkKind;
1819

1920
/// This example describes the use of the BDK's [`bdk_wallet::descriptor::policy`] module.
2021
///
@@ -29,18 +30,17 @@ use bdk_wallet::signer::SignersContainer;
2930
fn main() -> Result<(), Box<dyn Error>> {
3031
let secp = bitcoin::secp256k1::Secp256k1::new();
3132

32-
// The descriptor used in the example
33-
// The form is "wsh(multi(2, <privkey>, <pubkey>))"
33+
// The descriptor used in the example. The form is "wsh(multi(2, <privkey>, <pubkey>))".
3434
let desc = "wsh(multi(2,tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcLNfjdi5qUvw3VDfgYiH5mNsj5izuiu2N/1/*,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/1/*))";
3535

3636
// Use the descriptor string to derive the full descriptor and a keymap.
3737
// The wallet descriptor can be used to create a new bdk_wallet::wallet.
3838
// While the `keymap` can be used to create a `SignerContainer`.
3939
//
4040
// The `SignerContainer` can sign for `PSBT`s.
41-
// a `bdk_wallet::Wallet` internally uses these to handle transaction signing.
42-
// But they can be used as independent tools also.
43-
let (wallet_desc, keymap) = desc.into_wallet_descriptor(&secp, Network::Testnet)?;
41+
// A `bdk_wallet::Wallet` internally uses these to handle transaction signing, but they can be
42+
// used as independent tools as well.
43+
let (wallet_desc, keymap) = desc.into_wallet_descriptor(&secp, NetworkKind::Test)?;
4444

4545
println!("Example Descriptor for policy analysis : {wallet_desc}");
4646

0 commit comments

Comments
 (0)