Skip to content

Commit e6e6266

Browse files
committed
feat!(examples,test): use NetworkKind
1 parent c6f24fe commit e6e6266

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

wallet/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);

wallet/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

wallet/tests/wallet.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use bitcoin::script::PushBytesBuf;
2727
use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
2828
use bitcoin::taproot::TapNodeHash;
2929
use bitcoin::{
30-
absolute, transaction, Address, Amount, BlockHash, FeeRate, Network, OutPoint, ScriptBuf,
31-
Sequence, Transaction, TxIn, TxOut, Txid, Weight,
30+
absolute, transaction, Address, Amount, BlockHash, FeeRate, Network, NetworkKind, OutPoint,
31+
ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid, Weight,
3232
};
3333
use bitcoin::{psbt, SignedAmount};
3434
use miniscript::{descriptor::KeyMap, Descriptor, DescriptorPublicKey};
@@ -69,7 +69,7 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
6969
let file_path = temp_dir.path().join(filename);
7070
let (external_desc, internal_desc) = get_test_tr_single_sig_xprv_and_change_desc();
7171

72-
// create new wallet
72+
// Create new wallet.
7373
let wallet_spk_index = {
7474
let mut db = create_db(&file_path)?;
7575
let mut wallet = Wallet::create(external_desc, internal_desc)
@@ -78,12 +78,12 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
7878
.create_wallet(&mut db)?;
7979
wallet.reveal_next_address(KeychainKind::External);
8080

81-
// persist new wallet changes
81+
// Persist new wallet changes.
8282
assert!(wallet.persist(&mut db)?, "must write");
8383
wallet.spk_index().clone()
8484
};
8585

86-
// recover wallet
86+
// Recover wallet.
8787
{
8888
let mut db = open_db(&file_path).context("failed to recover db")?;
8989
let wallet = Wallet::load()
@@ -106,12 +106,12 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
106106
assert_eq!(
107107
*wallet.public_descriptor(KeychainKind::External),
108108
external_desc
109-
.into_wallet_descriptor(&secp, wallet.network())
109+
.into_wallet_descriptor(&secp, NetworkKind::from(wallet.network()))
110110
.unwrap()
111111
.0
112112
);
113113
}
114-
// Test SPK cache
114+
// Test SPK cache.
115115
{
116116
let mut db = open_db(&file_path).context("failed to recover db")?;
117117
let mut wallet = Wallet::load()
@@ -149,7 +149,8 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
149149
assert_eq!(spk_cache.len(), 1);
150150
assert_eq!(spk_cache.keys().next(), Some(&25));
151151
}
152-
// SPK cache requires load params
152+
153+
// SPK cache requires load params.
153154
{
154155
let mut db = open_db(&file_path).context("failed to recover db")?;
155156
let mut wallet = Wallet::load()

0 commit comments

Comments
 (0)