From: Steve Myers Date: Wed, 12 Mar 2025 17:10:21 +0000 (-0500) Subject: ci: fix clippy errors X-Git-Tag: v1.0.0~7^2~5 X-Git-Url: http://internal-gitweb-vhost/trait.impl/bdk_wallet/keys/trait.IntoDescriptorKey.js?a=commitdiff_plain;h=efc5fc5a15650e804215a516cdf9e624d19bb5c3;p=bdk-cli ci: fix clippy errors --- diff --git a/src/commands.rs b/src/commands.rs index 2046870..8b05fe1 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -141,7 +141,7 @@ pub enum ClientType { #[cfg(feature = "esplora")] Esplora, #[cfg(feature = "rpc")] - RPC, + Rpc, } /// Config options wallet operations can take. @@ -162,7 +162,7 @@ pub struct WalletOpts { #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] #[arg(env = "CLIENT_TYPE", short = 'c', long, value_enum, required = true)] pub client_type: ClientType, - #[cfg(any(feature = "sqlite",))] + #[cfg(feature = "sqlite")] #[arg(env = "DATABASE_TYPE", short = 'd', long, value_enum, required = true)] pub database_type: DatabaseType, /// Sets the server url. diff --git a/src/handlers.rs b/src/handlers.rs index 13c3fe1..1025024 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -26,7 +26,14 @@ use bdk_wallet::bitcoin::bip32::{DerivationPath, KeySource}; use bdk_wallet::bitcoin::consensus::encode::{serialize, serialize_hex}; use bdk_wallet::bitcoin::script::PushBytesBuf; use bdk_wallet::bitcoin::Network; -use bdk_wallet::bitcoin::{secp256k1::Secp256k1, Transaction, Txid}; +#[cfg(any( + feature = "electrum", + feature = "esplora", + feature = "cbf", + feature = "rpc" +))] +use bdk_wallet::bitcoin::Transaction; +use bdk_wallet::bitcoin::{secp256k1::Secp256k1, Txid}; use bdk_wallet::bitcoin::{Amount, FeeRate, Psbt, Sequence}; use bdk_wallet::descriptor::Segwitv0; use bdk_wallet::keys::bip39::WordCount; @@ -43,15 +50,35 @@ use bdk_wallet::keys::DescriptorKey::Secret; use bdk_wallet::keys::{DerivableKey, DescriptorKey, ExtendedKey, GeneratableKey, GeneratedKey}; use bdk_wallet::miniscript::miniscript; use serde_json::json; -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; +#[cfg(any( + feature = "electrum", + feature = "esplora", + feature = "cbf", + feature = "rpc" +))] +use std::collections::HashSet; use std::convert::TryFrom; +#[cfg(feature = "repl")] use std::io::Write; use std::str::FromStr; #[cfg(feature = "electrum")] use crate::utils::BlockchainClient::Electrum; use bdk_wallet::bitcoin::base64::prelude::*; +#[cfg(any( + feature = "electrum", + feature = "esplora", + feature = "cbf", + feature = "rpc" +))] use bdk_wallet::bitcoin::consensus::Decodable; +#[cfg(any( + feature = "electrum", + feature = "esplora", + feature = "cbf", + feature = "rpc" +))] use bdk_wallet::bitcoin::hex::FromHex; #[cfg(feature = "esplora")] use {crate::utils::BlockchainClient::Esplora, bdk_esplora::EsploraAsyncExt}; @@ -385,7 +412,7 @@ pub(crate) async fn handle_online_wallet_subcommand( hash: genesis_block.block_hash(), }); let mut emitter = - Emitter::new(&client, genesis_cp.clone(), genesis_cp.height()); + Emitter::new(&*client, genesis_cp.clone(), genesis_cp.height()); while let Some(block_event) = emitter.next_block()? { wallet.apply_block_connected_to( @@ -433,7 +460,7 @@ pub(crate) async fn handle_online_wallet_subcommand( #[cfg(feature = "rpc")] RpcClient { client } => { let wallet_cp = wallet.latest_checkpoint(); - let mut emitter = Emitter::new(&client, wallet_cp.clone(), wallet_cp.height()); + let mut emitter = Emitter::new(&*client, wallet_cp.clone(), wallet_cp.height()); while let Some(block_event) = emitter.next_block()? { wallet.apply_block_connected_to( @@ -482,7 +509,7 @@ pub(crate) async fn handle_online_wallet_subcommand( } => client .broadcast(&tx) .await - .map(|()| tx.compute_txid().clone()) + .map(|()| tx.compute_txid()) .map_err(|e| Error::Generic(e.to_string()))?, #[cfg(feature = "rpc")] RpcClient { client } => client @@ -636,7 +663,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { } => { let blockchain_client = new_blockchain_client(&wallet_opts)?; let network = cli_opts.network; - #[cfg(any(feature = "sqlite"))] + #[cfg(feature = "sqlite")] let result = { let home_dir = prepare_home_dir(cli_opts.datadir)?; let wallet_name = &wallet_opts.wallet; @@ -674,7 +701,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { subcommand: WalletSubCommand::OfflineWalletSubCommand(offline_subcommand), } => { let network = cli_opts.network; - #[cfg(any(feature = "sqlite"))] + #[cfg(feature = "sqlite")] let result = { let home_dir = prepare_home_dir(cli_opts.datadir)?; let wallet_name = &wallet_opts.wallet; @@ -722,7 +749,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { #[cfg(feature = "repl")] CliSubCommand::Repl { wallet_opts } => { let network = cli_opts.network; - #[cfg(any(feature = "sqlite"))] + #[cfg(feature = "sqlite")] let (mut wallet, mut persister) = { let wallet_name = &wallet_opts.wallet; @@ -753,7 +780,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { } let result = respond(network, &mut wallet, &wallet_opts, line).await; - #[cfg(any(feature = "sqlite"))] + #[cfg(feature = "sqlite")] wallet.persist(&mut persister)?; match result { @@ -798,7 +825,7 @@ async fn respond( ReplSubCommand::Wallet { subcommand: WalletSubCommand::OnlineWalletSubCommand(online_subcommand), } => { - let blockchain = new_blockchain_client(&wallet_opts).map_err(|e| e.to_string())?; + let blockchain = new_blockchain_client(wallet_opts).map_err(|e| e.to_string())?; let value = handle_online_wallet_subcommand(wallet, blockchain, online_subcommand) .await .map_err(|e| e.to_string())?; diff --git a/src/utils.rs b/src/utils.rs index 91ccec6..b293f8b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,7 +12,7 @@ use crate::error::BDKCliError as Error; use std::str::FromStr; -#[cfg(any(feature = "sqlite"))] +#[cfg(feature = "sqlite")] use std::path::{Path, PathBuf}; use crate::commands::WalletOpts; @@ -21,15 +21,9 @@ use bdk_wallet::bitcoin::{Address, Network, OutPoint, ScriptBuf}; #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] use crate::commands::ClientType; -#[cfg(any(feature = "sqlite",))] -use bdk_wallet::{KeychainKind, PersistedWallet, WalletPersister}; - -#[cfg(feature = "electrum")] -use bdk_electrum; use bdk_wallet::Wallet; - -#[cfg(feature = "esplora")] -use bdk_esplora; +#[cfg(feature = "sqlite")] +use bdk_wallet::{KeychainKind, PersistedWallet, WalletPersister}; /// Parse the recipient (Address,Amount) argument from cli input. pub(crate) fn parse_recipient(s: &str) -> Result<(ScriptBuf, u64), String> { @@ -75,7 +69,7 @@ pub(crate) fn parse_address(address_str: &str) -> Result { Ok(unchecked_address.assume_checked()) } -#[cfg(any(feature = "sqlite",))] +#[cfg(feature = "sqlite")] /// Prepare bdk-cli home directory /// /// This function is called to check if [`crate::CliOpts`] datadir is set. @@ -100,7 +94,7 @@ pub(crate) fn prepare_home_dir(home_path: Option) -> Result, home_path: &Path, @@ -126,17 +120,17 @@ pub(crate) fn prepare_wallet_db_dir( pub(crate) enum BlockchainClient { #[cfg(feature = "electrum")] Electrum { - client: bdk_electrum::BdkElectrumClient, + client: Box>, batch_size: usize, }, #[cfg(feature = "esplora")] Esplora { - client: bdk_esplora::esplora_client::AsyncClient, + client: Box, parallel_requests: usize, }, #[cfg(feature = "rpc")] RpcClient { - client: bdk_bitcoind_rpc::bitcoincore_rpc::Client, + client: Box, }, // TODO cbf } @@ -154,9 +148,9 @@ pub(crate) fn new_blockchain_client(wallet_opts: &WalletOpts) -> Result { let client = bdk_electrum::electrum_client::Client::new(url) - .map(|client| bdk_electrum::BdkElectrumClient::new(client))?; + .map(bdk_electrum::BdkElectrumClient::new)?; BlockchainClient::Electrum { - client, + client: Box::new(client), batch_size: wallet_opts.batch_size, } } @@ -164,13 +158,13 @@ pub(crate) fn new_blockchain_client(wallet_opts: &WalletOpts) -> Result { let client = bdk_esplora::esplora_client::Builder::new(url).build_async()?; BlockchainClient::Esplora { - client, + client: Box::new(client), parallel_requests: wallet_opts.parallel_requests, } } #[cfg(feature = "rpc")] - ClientType::RPC => { + ClientType::Rpc => { let auth = match &wallet_opts.cookie { Some(cookie) => bdk_bitcoind_rpc::bitcoincore_rpc::Auth::CookieFile(cookie.into()), None => bdk_bitcoind_rpc::bitcoincore_rpc::Auth::UserPass( @@ -180,13 +174,15 @@ pub(crate) fn new_blockchain_client(wallet_opts: &WalletOpts) -> Result( network: Network,