Skip to content

feat!: use NetworkKind #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions wallet/examples/mnemonic_to_descriptors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
// Copyright (c) 2020-2025 Bitcoin Dev Kit Developers
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
Expand All @@ -9,7 +9,7 @@
use anyhow::anyhow;
use bdk_wallet::bitcoin::bip32::DerivationPath;
use bdk_wallet::bitcoin::secp256k1::Secp256k1;
use bdk_wallet::bitcoin::Network;
use bdk_wallet::bitcoin::NetworkKind;
use bdk_wallet::descriptor;
use bdk_wallet::descriptor::IntoWalletDescriptor;
use bdk_wallet::keys::bip39::{Language, Mnemonic, WordCount};
Expand All @@ -18,32 +18,32 @@ use bdk_wallet::miniscript::Tap;
use std::str::FromStr;

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

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

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

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

// generate external and internal descriptor from mnemonic
// Generate external and internal descriptors from the mnemonic phrase.
let (external_descriptor, ext_keymap) =
descriptor!(tr((mnemonic_with_passphrase.clone(), external_path)))?
.into_wallet_descriptor(&secp, Network::Testnet)?;
.into_wallet_descriptor(&secp, NetworkKind::Test)?;
let (internal_descriptor, int_keymap) =
descriptor!(tr((mnemonic_with_passphrase, internal_path)))?
.into_wallet_descriptor(&secp, Network::Testnet)?;
.into_wallet_descriptor(&secp, NetworkKind::Test)?;

println!("tpub external descriptor: {}", external_descriptor);
println!("tpub internal descriptor: {}", internal_descriptor);
Expand Down
14 changes: 7 additions & 7 deletions wallet/examples/policy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Bitcoin Dev Kit
// Written in 2020 by Alekos Filini <alekos.filini@gmail.com>
//
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
// Copyright (c) 2020-2025 Bitcoin Dev Kit Developers
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
Expand All @@ -10,11 +10,12 @@
// licenses.

extern crate bdk_wallet;

use std::error::Error;

use bdk_wallet::bitcoin::Network;
use bdk_wallet::descriptor::{policy::BuildSatisfaction, ExtractPolicy, IntoWalletDescriptor};
use bdk_wallet::signer::SignersContainer;
use bitcoin::NetworkKind;

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

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

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

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

Expand Down
Loading
Loading