From 18e9e0a645384eddc3f66519cd0d5e0ff6eb3933 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sat, 11 Nov 2023 13:02:02 -0600 Subject: [PATCH] chore: remove bdk dependency on log and dev dependency on env_logger --- crates/bdk/Cargo.toml | 2 -- crates/bdk/examples/compiler.rs | 15 ++++----------- crates/bdk/examples/policy.rs | 10 ++-------- crates/bdk/src/descriptor/mod.rs | 5 ----- crates/bdk/src/descriptor/policy.rs | 3 --- crates/bdk/src/lib.rs | 1 - crates/bdk/src/wallet/coin_selection.rs | 13 ------------- crates/bdk/src/wallet/mod.rs | 18 +----------------- 8 files changed, 7 insertions(+), 60 deletions(-) diff --git a/crates/bdk/Cargo.toml b/crates/bdk/Cargo.toml index 354a7d1e0b..b4953c3ab6 100644 --- a/crates/bdk/Cargo.toml +++ b/crates/bdk/Cargo.toml @@ -13,7 +13,6 @@ edition = "2021" rust-version = "1.57" [dependencies] -log = "0.4" rand = "^0.8" miniscript = { version = "10.0.0", features = ["serde"], default-features = false } bitcoin = { version = "0.30.0", features = ["serde", "base64", "rand-std"], default-features = false } @@ -45,7 +44,6 @@ dev-getrandom-wasm = ["getrandom/js"] [dev-dependencies] lazy_static = "1.4" -env_logger = "0.7" assert_matches = "1.5.0" [package.metadata.docs.rs] diff --git a/crates/bdk/examples/compiler.rs b/crates/bdk/examples/compiler.rs index f8918895ce..e22ccadc76 100644 --- a/crates/bdk/examples/compiler.rs +++ b/crates/bdk/examples/compiler.rs @@ -11,15 +11,12 @@ extern crate bdk; extern crate bitcoin; -extern crate log; extern crate miniscript; extern crate serde_json; use std::error::Error; use std::str::FromStr; -use log::info; - use bitcoin::Network; use miniscript::policy::Concrete; use miniscript::Descriptor; @@ -36,13 +33,9 @@ use bdk::{KeychainKind, Wallet}; /// This example demonstrates the interaction between a bdk wallet and miniscript policy. fn main() -> Result<(), Box> { - env_logger::init_from_env( - env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), - ); - // We start with a generic miniscript policy string let policy_str = "or(10@thresh(4,pk(029ffbe722b147f3035c87cb1c60b9a5947dd49c774cc31e94773478711a929ac0),pk(025f05815e3a1a8a83bfbb03ce016c9a2ee31066b98f567f6227df1d76ec4bd143),pk(025625f41e4a065efc06d5019cbbd56fe8c07595af1231e7cbc03fafb87ebb71ec),pk(02a27c8b850a00f67da3499b60562673dcf5fdfb82b7e17652a7ac54416812aefd),pk(03e618ec5f384d6e19ca9ebdb8e2119e5bef978285076828ce054e55c4daf473e2)),1@and(older(4209713),thresh(2,pk(03deae92101c790b12653231439f27b8897264125ecb2f46f48278603102573165),pk(033841045a531e1adf9910a6ec279589a90b3b8a904ee64ffd692bd08a8996c1aa),pk(02aebf2d10b040eb936a6f02f44ee82f8b34f5c1ccb20ff3949c2b28206b7c1068))))"; - info!("Compiling policy: \n{}", policy_str); + println!("Compiling policy: \n{}", policy_str); // Parse the string as a [`Concrete`] type miniscript policy. let policy = Concrete::::from_str(policy_str)?; @@ -51,12 +44,12 @@ fn main() -> Result<(), Box> { // `policy.compile()` returns the resulting miniscript from the policy. let descriptor = Descriptor::new_wsh(policy.compile()?)?; - info!("Compiled into following Descriptor: \n{}", descriptor); + println!("Compiled into following Descriptor: \n{}", descriptor); // Create a new wallet from this descriptor let mut wallet = Wallet::new_no_persist(&format!("{}", descriptor), None, Network::Regtest)?; - info!( + println!( "First derived address from the descriptor: \n{}", wallet.get_address(New) ); @@ -64,7 +57,7 @@ fn main() -> Result<(), Box> { // BDK also has it's own `Policy` structure to represent the spending condition in a more // human readable json format. let spending_policy = wallet.policies(KeychainKind::External)?; - info!( + println!( "The BDK spending policy: \n{}", serde_json::to_string_pretty(&spending_policy)? ); diff --git a/crates/bdk/examples/policy.rs b/crates/bdk/examples/policy.rs index 64e17825b7..0f31cccdee 100644 --- a/crates/bdk/examples/policy.rs +++ b/crates/bdk/examples/policy.rs @@ -10,8 +10,6 @@ // licenses. extern crate bdk; -extern crate env_logger; -extern crate log; use std::error::Error; use bdk::bitcoin::Network; @@ -29,10 +27,6 @@ use bdk::wallet::signer::SignersContainer; /// one of the Extend Private key. fn main() -> Result<(), Box> { - env_logger::init_from_env( - env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), - ); - let secp = bitcoin::secp256k1::Secp256k1::new(); // The descriptor used in the example @@ -48,7 +42,7 @@ fn main() -> Result<(), Box> { // But they can be used as independent tools also. let (wallet_desc, keymap) = desc.into_wallet_descriptor(&secp, Network::Testnet)?; - log::info!("Example Descriptor for policy analysis : {}", wallet_desc); + println!("Example Descriptor for policy analysis : {}", wallet_desc); // Create the signer with the keymap and descriptor. let signers_container = SignersContainer::build(keymap, &wallet_desc, &secp); @@ -60,7 +54,7 @@ fn main() -> Result<(), Box> { .extract_policy(&signers_container, BuildSatisfaction::None, &secp)? .expect("We expect a policy"); - log::info!("Derived Policy for the descriptor {:#?}", policy); + println!("Derived Policy for the descriptor {:#?}", policy); Ok(()) } diff --git a/crates/bdk/src/descriptor/mod.rs b/crates/bdk/src/descriptor/mod.rs index d5c3415f7b..153ade2543 100644 --- a/crates/bdk/src/descriptor/mod.rs +++ b/crates/bdk/src/descriptor/mod.rs @@ -488,11 +488,6 @@ impl DescriptorMeta for ExtendedDescriptor { ) { Some(derive_path) } else { - log::debug!( - "Key `{}` derived with {} yields an unexpected key", - root_fingerprint, - derive_path - ); None } }); diff --git a/crates/bdk/src/descriptor/policy.rs b/crates/bdk/src/descriptor/policy.rs index 14b2459ebe..9385f60fbf 100644 --- a/crates/bdk/src/descriptor/policy.rs +++ b/crates/bdk/src/descriptor/policy.rs @@ -57,9 +57,6 @@ use miniscript::{ Descriptor, Miniscript, Satisfier, ScriptContext, SigType, Terminal, ToPublicKey, }; -#[allow(unused_imports)] -use log::{debug, error, info, trace}; - use crate::descriptor::ExtractPolicy; use crate::keys::ExtScriptContext; use crate::wallet::signer::{SignerId, SignersContainer}; diff --git a/crates/bdk/src/lib.rs b/crates/bdk/src/lib.rs index 012a868a61..2e850dde20 100644 --- a/crates/bdk/src/lib.rs +++ b/crates/bdk/src/lib.rs @@ -19,7 +19,6 @@ pub extern crate alloc; pub extern crate bitcoin; #[cfg(feature = "hardware-signer")] pub extern crate hwi; -extern crate log; pub extern crate miniscript; extern crate serde; extern crate serde_json; diff --git a/crates/bdk/src/wallet/coin_selection.rs b/crates/bdk/src/wallet/coin_selection.rs index c3e84af2ba..417688be4c 100644 --- a/crates/bdk/src/wallet/coin_selection.rs +++ b/crates/bdk/src/wallet/coin_selection.rs @@ -213,12 +213,6 @@ impl CoinSelectionAlgorithm for LargestFirstCoinSelection { target_amount: u64, drain_script: &Script, ) -> Result { - log::debug!( - "target_amount = `{}`, fee_rate = `{:?}`", - target_amount, - fee_rate - ); - // We put the "required UTXOs" first and make sure the optional UTXOs are sorted, // initially smallest to largest, before being reversed with `.rev()`. let utxos = { @@ -311,13 +305,6 @@ fn select_sorted_utxos( (TXIN_BASE_WEIGHT + weighted_utxo.satisfaction_weight) as u64, )); **selected_amount += weighted_utxo.utxo.txout().value; - - log::debug!( - "Selected {}, updated fee_amount = `{}`", - weighted_utxo.utxo.outpoint(), - fee_amount - ); - Some(weighted_utxo.utxo) } else { None diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index 659da90a26..30c3144d1b 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -41,8 +41,6 @@ use core::ops::Deref; use miniscript::psbt::{PsbtExt, PsbtInputExt, PsbtInputSatisfier}; use bdk_chain::tx_graph::CalculateFeeError; -#[allow(unused_imports)] -use log::{debug, error, info, trace}; pub mod coin_selection; pub mod export; @@ -919,7 +917,6 @@ impl Wallet { let requirements = external_requirements.merge(&internal_requirements.unwrap_or_default())?; - debug!("Policy requirements: {:?}", requirements); let version = match params.version { Some(tx_builder::Version(0)) => { @@ -1508,11 +1505,6 @@ impl Wallet { .assume_height .or(self.chain.tip().map(|b| b.height())); - debug!( - "Input #{} - {}, using `confirmation_height` = {:?}, `current_height` = {:?}", - n, input.previous_output, confirmation_height, current_height - ); - // - Try to derive the descriptor by looking at the txout. If it's in our database, we // know exactly which `keychain` to use, and which derivation index it is // - If that fails, try to derive it by looking at the psbt input: the complete logic @@ -1555,10 +1547,7 @@ impl Wallet { psbt_input.partial_sigs.clear(); } } - Err(e) => { - debug!("satisfy error {:?} for input {}", e, n); - finished = false - } + Err(_) => finished = false, } } None => finished = false, @@ -1884,11 +1873,6 @@ impl Wallet { if let Some(&(keychain, child)) = self.indexed_graph.index.index_of_spk(&out.script_pubkey) { - debug!( - "Found descriptor for input #{} {:?}/{}", - index, keychain, child - ); - let desc = self.get_descriptor_for_keychain(keychain); let desc = desc .at_derivation_index(child)