Skip to content

Commit a04fa29

Browse files
committed
feat!(examples,test): use NetworkKind
1 parent 17530f8 commit a04fa29

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
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 <[email protected]>
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

tests/persisted_wallet.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use bitcoin::constants::ChainHash;
1616
use bitcoin::hashes::Hash;
1717
use bitcoin::key::Secp256k1;
1818
use bitcoin::{
19-
absolute, secp256k1, transaction, Amount, BlockHash, Network, ScriptBuf, Transaction, TxOut,
19+
absolute, secp256k1, transaction, Amount, BlockHash, Network, NetworkKind, ScriptBuf,
20+
Transaction, TxOut,
2021
};
2122
use miniscript::{Descriptor, DescriptorPublicKey};
2223

@@ -42,10 +43,10 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
4243
let secp = secp256k1::Secp256k1::new();
4344
let (external, internal) = get_test_tr_single_sig_xprv_and_change_desc();
4445
let (external_desc, _) = external
45-
.into_wallet_descriptor(&secp, Network::Testnet)
46+
.into_wallet_descriptor(&secp, NetworkKind::Test)
4647
.unwrap();
4748
let (internal_desc, _) = internal
48-
.into_wallet_descriptor(&secp, Network::Testnet)
49+
.into_wallet_descriptor(&secp, NetworkKind::Test)
4950
.unwrap();
5051
let external_did = external_desc.descriptor_id();
5152
let internal_did = internal_desc.descriptor_id();
@@ -144,7 +145,7 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
144145
assert_eq!(
145146
*wallet.public_descriptor(KeychainKind::External),
146147
external_desc
147-
.into_wallet_descriptor(&secp, wallet.network())
148+
.into_wallet_descriptor(&secp, wallet.network().into())
148149
.unwrap()
149150
.0
150151
);

0 commit comments

Comments
 (0)