]> Untitled Git - bdk-cli/commitdiff
ci: fix clippy errors
authorSteve Myers <steve@notmandatory.org>
Wed, 12 Mar 2025 17:10:21 +0000 (12:10 -0500)
committerSteve Myers <steve@notmandatory.org>
Wed, 12 Mar 2025 17:18:55 +0000 (12:18 -0500)
src/commands.rs
src/handlers.rs
src/utils.rs

index 20468708eacff404c27ffffea7ab603a04df0c67..8b05fe186914d621f70935263d3379a0ace61682 100644 (file)
@@ -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.
index 13c3fe16a508c6b45d5a23575b9a915f3ba526dc..1025024392b0250781c68a7a0112a96c23c2dc85 100644 (file)
@@ -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<String, Error> {
         } => {
             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<String, Error> {
             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<String, Error> {
         #[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<String, Error> {
                 }
 
                 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())?;
index 91ccec6a86a10a7fd59a05e2d2148754fa89ffa7..b293f8b386a6603db4608782ed08c919e67bc080 100644 (file)
@@ -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<Address, Error> {
     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<PathBuf>) -> Result<PathBuf, Er
 }
 
 /// Prepare wallet database directory.
-#[cfg(any(feature = "sqlite"))]
+#[cfg(feature = "sqlite")]
 pub(crate) fn prepare_wallet_db_dir(
     wallet_name: &Option<String>,
     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<bdk_electrum::electrum_client::Client>,
+        client: Box<bdk_electrum::BdkElectrumClient<bdk_electrum::electrum_client::Client>>,
         batch_size: usize,
     },
     #[cfg(feature = "esplora")]
     Esplora {
-        client: bdk_esplora::esplora_client::AsyncClient,
+        client: Box<bdk_esplora::esplora_client::AsyncClient>,
         parallel_requests: usize,
     },
     #[cfg(feature = "rpc")]
     RpcClient {
-        client: bdk_bitcoind_rpc::bitcoincore_rpc::Client,
+        client: Box<bdk_bitcoind_rpc::bitcoincore_rpc::Client>,
     },
     // TODO cbf
 }
@@ -154,9 +148,9 @@ pub(crate) fn new_blockchain_client(wallet_opts: &WalletOpts) -> Result<Blockcha
         #[cfg(feature = "electrum")]
         ClientType::Electrum => {
             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<Blockcha
         ClientType::Esplora => {
             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<Blockcha
             };
             let client = bdk_bitcoind_rpc::bitcoincore_rpc::Client::new(url, auth)
                 .map_err(|e| Error::Generic(e.to_string()))?;
-            BlockchainClient::RpcClient { client }
+            BlockchainClient::RpcClient {
+                client: Box::new(client),
+            }
         }
     };
     Ok(client)
 }
 
-#[cfg(any(feature = "sqlite",))]
+#[cfg(feature = "sqlite")]
 /// Create a new persisted wallet from given wallet configuration options.
 pub(crate) fn new_persisted_wallet<P: WalletPersister>(
     network: Network,