Skip to content

Commit efc5fc5

Browse files
committed
ci: fix clippy errors
1 parent 92cabb1 commit efc5fc5

File tree

3 files changed

+55
-32
lines changed

3 files changed

+55
-32
lines changed

src/commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub enum ClientType {
141141
#[cfg(feature = "esplora")]
142142
Esplora,
143143
#[cfg(feature = "rpc")]
144-
RPC,
144+
Rpc,
145145
}
146146

147147
/// Config options wallet operations can take.
@@ -162,7 +162,7 @@ pub struct WalletOpts {
162162
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
163163
#[arg(env = "CLIENT_TYPE", short = 'c', long, value_enum, required = true)]
164164
pub client_type: ClientType,
165-
#[cfg(any(feature = "sqlite",))]
165+
#[cfg(feature = "sqlite")]
166166
#[arg(env = "DATABASE_TYPE", short = 'd', long, value_enum, required = true)]
167167
pub database_type: DatabaseType,
168168
/// Sets the server url.

src/handlers.rs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ use bdk_wallet::bitcoin::bip32::{DerivationPath, KeySource};
2626
use bdk_wallet::bitcoin::consensus::encode::{serialize, serialize_hex};
2727
use bdk_wallet::bitcoin::script::PushBytesBuf;
2828
use bdk_wallet::bitcoin::Network;
29-
use bdk_wallet::bitcoin::{secp256k1::Secp256k1, Transaction, Txid};
29+
#[cfg(any(
30+
feature = "electrum",
31+
feature = "esplora",
32+
feature = "cbf",
33+
feature = "rpc"
34+
))]
35+
use bdk_wallet::bitcoin::Transaction;
36+
use bdk_wallet::bitcoin::{secp256k1::Secp256k1, Txid};
3037
use bdk_wallet::bitcoin::{Amount, FeeRate, Psbt, Sequence};
3138
use bdk_wallet::descriptor::Segwitv0;
3239
use bdk_wallet::keys::bip39::WordCount;
@@ -43,15 +50,35 @@ use bdk_wallet::keys::DescriptorKey::Secret;
4350
use bdk_wallet::keys::{DerivableKey, DescriptorKey, ExtendedKey, GeneratableKey, GeneratedKey};
4451
use bdk_wallet::miniscript::miniscript;
4552
use serde_json::json;
46-
use std::collections::{BTreeMap, HashSet};
53+
use std::collections::BTreeMap;
54+
#[cfg(any(
55+
feature = "electrum",
56+
feature = "esplora",
57+
feature = "cbf",
58+
feature = "rpc"
59+
))]
60+
use std::collections::HashSet;
4761
use std::convert::TryFrom;
62+
#[cfg(feature = "repl")]
4863
use std::io::Write;
4964
use std::str::FromStr;
5065

5166
#[cfg(feature = "electrum")]
5267
use crate::utils::BlockchainClient::Electrum;
5368
use bdk_wallet::bitcoin::base64::prelude::*;
69+
#[cfg(any(
70+
feature = "electrum",
71+
feature = "esplora",
72+
feature = "cbf",
73+
feature = "rpc"
74+
))]
5475
use bdk_wallet::bitcoin::consensus::Decodable;
76+
#[cfg(any(
77+
feature = "electrum",
78+
feature = "esplora",
79+
feature = "cbf",
80+
feature = "rpc"
81+
))]
5582
use bdk_wallet::bitcoin::hex::FromHex;
5683
#[cfg(feature = "esplora")]
5784
use {crate::utils::BlockchainClient::Esplora, bdk_esplora::EsploraAsyncExt};
@@ -385,7 +412,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
385412
hash: genesis_block.block_hash(),
386413
});
387414
let mut emitter =
388-
Emitter::new(&client, genesis_cp.clone(), genesis_cp.height());
415+
Emitter::new(&*client, genesis_cp.clone(), genesis_cp.height());
389416

390417
while let Some(block_event) = emitter.next_block()? {
391418
wallet.apply_block_connected_to(
@@ -433,7 +460,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
433460
#[cfg(feature = "rpc")]
434461
RpcClient { client } => {
435462
let wallet_cp = wallet.latest_checkpoint();
436-
let mut emitter = Emitter::new(&client, wallet_cp.clone(), wallet_cp.height());
463+
let mut emitter = Emitter::new(&*client, wallet_cp.clone(), wallet_cp.height());
437464

438465
while let Some(block_event) = emitter.next_block()? {
439466
wallet.apply_block_connected_to(
@@ -482,7 +509,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
482509
} => client
483510
.broadcast(&tx)
484511
.await
485-
.map(|()| tx.compute_txid().clone())
512+
.map(|()| tx.compute_txid())
486513
.map_err(|e| Error::Generic(e.to_string()))?,
487514
#[cfg(feature = "rpc")]
488515
RpcClient { client } => client
@@ -636,7 +663,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
636663
} => {
637664
let blockchain_client = new_blockchain_client(&wallet_opts)?;
638665
let network = cli_opts.network;
639-
#[cfg(any(feature = "sqlite"))]
666+
#[cfg(feature = "sqlite")]
640667
let result = {
641668
let home_dir = prepare_home_dir(cli_opts.datadir)?;
642669
let wallet_name = &wallet_opts.wallet;
@@ -674,7 +701,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
674701
subcommand: WalletSubCommand::OfflineWalletSubCommand(offline_subcommand),
675702
} => {
676703
let network = cli_opts.network;
677-
#[cfg(any(feature = "sqlite"))]
704+
#[cfg(feature = "sqlite")]
678705
let result = {
679706
let home_dir = prepare_home_dir(cli_opts.datadir)?;
680707
let wallet_name = &wallet_opts.wallet;
@@ -722,7 +749,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
722749
#[cfg(feature = "repl")]
723750
CliSubCommand::Repl { wallet_opts } => {
724751
let network = cli_opts.network;
725-
#[cfg(any(feature = "sqlite"))]
752+
#[cfg(feature = "sqlite")]
726753
let (mut wallet, mut persister) = {
727754
let wallet_name = &wallet_opts.wallet;
728755

@@ -753,7 +780,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
753780
}
754781

755782
let result = respond(network, &mut wallet, &wallet_opts, line).await;
756-
#[cfg(any(feature = "sqlite"))]
783+
#[cfg(feature = "sqlite")]
757784
wallet.persist(&mut persister)?;
758785

759786
match result {
@@ -798,7 +825,7 @@ async fn respond(
798825
ReplSubCommand::Wallet {
799826
subcommand: WalletSubCommand::OnlineWalletSubCommand(online_subcommand),
800827
} => {
801-
let blockchain = new_blockchain_client(&wallet_opts).map_err(|e| e.to_string())?;
828+
let blockchain = new_blockchain_client(wallet_opts).map_err(|e| e.to_string())?;
802829
let value = handle_online_wallet_subcommand(wallet, blockchain, online_subcommand)
803830
.await
804831
.map_err(|e| e.to_string())?;

src/utils.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::error::BDKCliError as Error;
1313
use std::str::FromStr;
1414

15-
#[cfg(any(feature = "sqlite"))]
15+
#[cfg(feature = "sqlite")]
1616
use std::path::{Path, PathBuf};
1717

1818
use crate::commands::WalletOpts;
@@ -21,15 +21,9 @@ use bdk_wallet::bitcoin::{Address, Network, OutPoint, ScriptBuf};
2121
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
2222
use crate::commands::ClientType;
2323

24-
#[cfg(any(feature = "sqlite",))]
25-
use bdk_wallet::{KeychainKind, PersistedWallet, WalletPersister};
26-
27-
#[cfg(feature = "electrum")]
28-
use bdk_electrum;
2924
use bdk_wallet::Wallet;
30-
31-
#[cfg(feature = "esplora")]
32-
use bdk_esplora;
25+
#[cfg(feature = "sqlite")]
26+
use bdk_wallet::{KeychainKind, PersistedWallet, WalletPersister};
3327

3428
/// Parse the recipient (Address,Amount) argument from cli input.
3529
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> {
7569
Ok(unchecked_address.assume_checked())
7670
}
7771

78-
#[cfg(any(feature = "sqlite",))]
72+
#[cfg(feature = "sqlite")]
7973
/// Prepare bdk-cli home directory
8074
///
8175
/// 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
10094
}
10195

10296
/// Prepare wallet database directory.
103-
#[cfg(any(feature = "sqlite"))]
97+
#[cfg(feature = "sqlite")]
10498
pub(crate) fn prepare_wallet_db_dir(
10599
wallet_name: &Option<String>,
106100
home_path: &Path,
@@ -126,17 +120,17 @@ pub(crate) fn prepare_wallet_db_dir(
126120
pub(crate) enum BlockchainClient {
127121
#[cfg(feature = "electrum")]
128122
Electrum {
129-
client: bdk_electrum::BdkElectrumClient<bdk_electrum::electrum_client::Client>,
123+
client: Box<bdk_electrum::BdkElectrumClient<bdk_electrum::electrum_client::Client>>,
130124
batch_size: usize,
131125
},
132126
#[cfg(feature = "esplora")]
133127
Esplora {
134-
client: bdk_esplora::esplora_client::AsyncClient,
128+
client: Box<bdk_esplora::esplora_client::AsyncClient>,
135129
parallel_requests: usize,
136130
},
137131
#[cfg(feature = "rpc")]
138132
RpcClient {
139-
client: bdk_bitcoind_rpc::bitcoincore_rpc::Client,
133+
client: Box<bdk_bitcoind_rpc::bitcoincore_rpc::Client>,
140134
},
141135
// TODO cbf
142136
}
@@ -154,23 +148,23 @@ pub(crate) fn new_blockchain_client(wallet_opts: &WalletOpts) -> Result<Blockcha
154148
#[cfg(feature = "electrum")]
155149
ClientType::Electrum => {
156150
let client = bdk_electrum::electrum_client::Client::new(url)
157-
.map(|client| bdk_electrum::BdkElectrumClient::new(client))?;
151+
.map(bdk_electrum::BdkElectrumClient::new)?;
158152
BlockchainClient::Electrum {
159-
client,
153+
client: Box::new(client),
160154
batch_size: wallet_opts.batch_size,
161155
}
162156
}
163157
#[cfg(feature = "esplora")]
164158
ClientType::Esplora => {
165159
let client = bdk_esplora::esplora_client::Builder::new(url).build_async()?;
166160
BlockchainClient::Esplora {
167-
client,
161+
client: Box::new(client),
168162
parallel_requests: wallet_opts.parallel_requests,
169163
}
170164
}
171165

172166
#[cfg(feature = "rpc")]
173-
ClientType::RPC => {
167+
ClientType::Rpc => {
174168
let auth = match &wallet_opts.cookie {
175169
Some(cookie) => bdk_bitcoind_rpc::bitcoincore_rpc::Auth::CookieFile(cookie.into()),
176170
None => bdk_bitcoind_rpc::bitcoincore_rpc::Auth::UserPass(
@@ -180,13 +174,15 @@ pub(crate) fn new_blockchain_client(wallet_opts: &WalletOpts) -> Result<Blockcha
180174
};
181175
let client = bdk_bitcoind_rpc::bitcoincore_rpc::Client::new(url, auth)
182176
.map_err(|e| Error::Generic(e.to_string()))?;
183-
BlockchainClient::RpcClient { client }
177+
BlockchainClient::RpcClient {
178+
client: Box::new(client),
179+
}
184180
}
185181
};
186182
Ok(client)
187183
}
188184

189-
#[cfg(any(feature = "sqlite",))]
185+
#[cfg(feature = "sqlite")]
190186
/// Create a new persisted wallet from given wallet configuration options.
191187
pub(crate) fn new_persisted_wallet<P: WalletPersister>(
192188
network: Network,

0 commit comments

Comments
 (0)