Skip to content

Commit c6b9ed3

Browse files
committed
Merge #1186: Clean up clippy allows
1c15cb2 ref(example_cli): Add new struct Init (vmammal) 89a7ddc ref(esplora): `Box` a large `esplora_client::Error` (vmammal) 097d818 ref(wallet): `Wallet::preselect_utxos` now accepts a `&TxParams` (vmammal) f11d663 ref(psbt): refactor body of `get_utxo_for` to address `clippy::manual_map` (vmammal) 4679ca1 ref(example_cli): add typedefs to reduce type complexity (vmammal) 64a9019 refactor: remove old clippy allow attributes (vmammal) Pull request description: closes #1127 There are several instances in the code where we allow clippy lints that would otherwise be flagged during regular checks. It would be preferable to minimize the number of "clippy allow" attributes either by fixing the affected areas or setting a specific configuration in `clippy.toml`. In cases where we have to allow a particular lint, it should be documented why the lint doesn't apply. For context see #1127 (comment) as well as the commit message details. One area I'm unsure of is whether `Box`ing a large error in 4fc2216 is the right approach. Logically it makes sense to avoid allocating a needlessly heavy `Result`, but I haven't studied the implications or tradeoffs of such a change. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: evanlinjin: ACK 1c15cb2 Tree-SHA512: 5fa3796a33678651414e7aad7ef8309b4cbe2a9ab00dce094964b40784edb2f46a44067785d95ea26f4cd88d593420485be94c9b09ac589f632453fbd8c94d85
2 parents ba76247 + 1c15cb2 commit c6b9ed3

File tree

9 files changed

+121
-93
lines changed

9 files changed

+121
-93
lines changed

crates/bdk/src/psbt/mod.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,16 @@ pub trait PsbtUtils {
3535
}
3636

3737
impl PsbtUtils for Psbt {
38-
#[allow(clippy::all)] // We want to allow `manual_map` but it is too new.
3938
fn get_utxo_for(&self, input_index: usize) -> Option<TxOut> {
4039
let tx = &self.unsigned_tx;
40+
let input = self.inputs.get(input_index)?;
4141

42-
if input_index >= tx.input.len() {
43-
return None;
44-
}
45-
46-
if let Some(input) = self.inputs.get(input_index) {
47-
if let Some(wit_utxo) = &input.witness_utxo {
48-
Some(wit_utxo.clone())
49-
} else if let Some(in_tx) = &input.non_witness_utxo {
50-
Some(in_tx.output[tx.input[input_index].previous_output.vout as usize].clone())
51-
} else {
52-
None
53-
}
54-
} else {
55-
None
42+
match (&input.witness_utxo, &input.non_witness_utxo) {
43+
(Some(_), _) => input.witness_utxo.clone(),
44+
(_, Some(_)) => input.non_witness_utxo.as_ref().map(|in_tx| {
45+
in_tx.output[tx.input[input_index].previous_output.vout as usize].clone()
46+
}),
47+
_ => None,
5648
}
5749
}
5850

crates/bdk/src/wallet/mod.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! Wallet
1313
//!
1414
//! This module defines the [`Wallet`].
15-
use crate::collections::{BTreeMap, HashMap, HashSet};
15+
use crate::collections::{BTreeMap, HashMap};
1616
use alloc::{
1717
boxed::Box,
1818
string::{String, ToString},
@@ -1518,15 +1518,8 @@ impl<D> Wallet<D> {
15181518
return Err(CreateTxError::ChangePolicyDescriptor);
15191519
}
15201520

1521-
let (required_utxos, optional_utxos) = self.preselect_utxos(
1522-
params.change_policy,
1523-
&params.unspendable,
1524-
params.utxos.clone(),
1525-
params.drain_wallet,
1526-
params.manually_selected_only,
1527-
params.bumping_fee.is_some(), // we mandate confirmed transactions if we're bumping the fee
1528-
Some(current_height.to_consensus_u32()),
1529-
);
1521+
let (required_utxos, optional_utxos) =
1522+
self.preselect_utxos(&params, Some(current_height.to_consensus_u32()));
15301523

15311524
// get drain script
15321525
let drain_script = match params.drain_to {
@@ -2063,17 +2056,26 @@ impl<D> Wallet<D> {
20632056

20642057
/// Given the options returns the list of utxos that must be used to form the
20652058
/// transaction and any further that may be used if needed.
2066-
#[allow(clippy::too_many_arguments)]
20672059
fn preselect_utxos(
20682060
&self,
2069-
change_policy: tx_builder::ChangeSpendPolicy,
2070-
unspendable: &HashSet<OutPoint>,
2071-
manually_selected: Vec<WeightedUtxo>,
2072-
must_use_all_available: bool,
2073-
manual_only: bool,
2074-
must_only_use_confirmed_tx: bool,
2061+
params: &TxParams,
20752062
current_height: Option<u32>,
20762063
) -> (Vec<WeightedUtxo>, Vec<WeightedUtxo>) {
2064+
let TxParams {
2065+
change_policy,
2066+
unspendable,
2067+
utxos,
2068+
drain_wallet,
2069+
manually_selected_only,
2070+
bumping_fee,
2071+
..
2072+
} = params;
2073+
2074+
let manually_selected = utxos.clone();
2075+
// we mandate confirmed transactions if we're bumping the fee
2076+
let must_only_use_confirmed_tx = bumping_fee.is_some();
2077+
let must_use_all_available = *drain_wallet;
2078+
20772079
let chain_tip = self.chain.tip().block_id();
20782080
// must_spend <- manually selected utxos
20792081
// may_spend <- all other available utxos
@@ -2088,7 +2090,7 @@ impl<D> Wallet<D> {
20882090

20892091
// NOTE: we are intentionally ignoring `unspendable` here. i.e manual
20902092
// selection overrides unspendable.
2091-
if manual_only {
2093+
if *manually_selected_only {
20922094
return (must_spend, vec![]);
20932095
}
20942096

@@ -2290,9 +2292,6 @@ impl<D> Wallet<D> {
22902292
) -> Result<(), MiniscriptPsbtError> {
22912293
// We need to borrow `psbt` mutably within the loops, so we have to allocate a vec for all
22922294
// the input utxos and outputs
2293-
//
2294-
// Clippy complains that the collect is not required, but that's wrong
2295-
#[allow(clippy::needless_collect)]
22962295
let utxos = (0..psbt.inputs.len())
22972296
.filter_map(|i| psbt.get_utxo_for(i).map(|utxo| (true, i, utxo)))
22982297
.chain(

crates/bdk/src/wallet/signer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,6 @@ pub enum TapLeavesOptions {
820820
None,
821821
}
822822

823-
#[allow(clippy::derivable_impls)]
824823
impl Default for SignOptions {
825824
fn default() -> Self {
826825
SignOptions {

crates/esplora/src/async_ext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ use bdk_chain::{
66
local_chain::{self, CheckPoint},
77
BlockId, ConfirmationTimeHeightAnchor, TxGraph,
88
};
9-
use esplora_client::{Error, TxStatus};
9+
use esplora_client::TxStatus;
1010
use futures::{stream::FuturesOrdered, TryStreamExt};
1111

1212
use crate::anchor_from_status;
1313

14+
/// [`esplora_client::Error`]
15+
type Error = Box<esplora_client::Error>;
16+
1417
/// Trait to extend the functionality of [`esplora_client::AsyncClient`].
1518
///
1619
/// Refer to [crate-level documentation] for more.
@@ -35,7 +38,6 @@ pub trait EsploraAsyncExt {
3538
/// [`LocalChain`]: bdk_chain::local_chain::LocalChain
3639
/// [`LocalChain::tip`]: bdk_chain::local_chain::LocalChain::tip
3740
/// [`LocalChain::apply_update`]: bdk_chain::local_chain::LocalChain::apply_update
38-
#[allow(clippy::result_large_err)]
3941
async fn update_local_chain(
4042
&self,
4143
local_tip: CheckPoint,
@@ -50,7 +52,6 @@ pub trait EsploraAsyncExt {
5052
/// The full scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated
5153
/// transactions. `parallel_requests` specifies the max number of HTTP requests to make in
5254
/// parallel.
53-
#[allow(clippy::result_large_err)]
5455
async fn full_scan<K: Ord + Clone + Send>(
5556
&self,
5657
keychain_spks: BTreeMap<
@@ -73,7 +74,6 @@ pub trait EsploraAsyncExt {
7374
/// may include scripts that have been used, use [`full_scan`] with the keychain.
7475
///
7576
/// [`full_scan`]: EsploraAsyncExt::full_scan
76-
#[allow(clippy::result_large_err)]
7777
async fn sync(
7878
&self,
7979
misc_spks: impl IntoIterator<IntoIter = impl Iterator<Item = ScriptBuf> + Send> + Send,

crates/esplora/src/blocking_ext.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ use bdk_chain::{
77
local_chain::{self, CheckPoint},
88
BlockId, ConfirmationTimeHeightAnchor, TxGraph,
99
};
10-
use esplora_client::{Error, TxStatus};
10+
use esplora_client::TxStatus;
1111

1212
use crate::anchor_from_status;
1313

14+
/// [`esplora_client::Error`]
15+
type Error = Box<esplora_client::Error>;
16+
1417
/// Trait to extend the functionality of [`esplora_client::BlockingClient`].
1518
///
1619
/// Refer to [crate-level documentation] for more.
@@ -33,7 +36,6 @@ pub trait EsploraExt {
3336
/// [`LocalChain`]: bdk_chain::local_chain::LocalChain
3437
/// [`LocalChain::tip`]: bdk_chain::local_chain::LocalChain::tip
3538
/// [`LocalChain::apply_update`]: bdk_chain::local_chain::LocalChain::apply_update
36-
#[allow(clippy::result_large_err)]
3739
fn update_local_chain(
3840
&self,
3941
local_tip: CheckPoint,
@@ -48,7 +50,6 @@ pub trait EsploraExt {
4850
/// The full scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated
4951
/// transactions. `parallel_requests` specifies the max number of HTTP requests to make in
5052
/// parallel.
51-
#[allow(clippy::result_large_err)]
5253
fn full_scan<K: Ord + Clone>(
5354
&self,
5455
keychain_spks: BTreeMap<K, impl IntoIterator<Item = (u32, ScriptBuf)>>,
@@ -68,7 +69,6 @@ pub trait EsploraExt {
6869
/// may include scripts that have been used, use [`full_scan`] with the keychain.
6970
///
7071
/// [`full_scan`]: EsploraExt::full_scan
71-
#[allow(clippy::result_large_err)]
7272
fn sync(
7373
&self,
7474
misc_spks: impl IntoIterator<Item = ScriptBuf>,
@@ -247,7 +247,12 @@ impl EsploraExt for esplora_client::BlockingClient {
247247
.map(|txid| {
248248
std::thread::spawn({
249249
let client = self.clone();
250-
move || client.get_tx_status(&txid).map(|s| (txid, s))
250+
move || {
251+
client
252+
.get_tx_status(&txid)
253+
.map_err(Box::new)
254+
.map(|s| (txid, s))
255+
}
251256
})
252257
})
253258
.collect::<Vec<JoinHandle<Result<(Txid, TxStatus), Error>>>>();

example-crates/example_bitcoind_rpc_polling/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ enum RpcCommands {
110110

111111
fn main() -> anyhow::Result<()> {
112112
let start = Instant::now();
113-
114-
let (args, keymap, index, db, init_changeset) =
115-
example_cli::init::<RpcCommands, RpcArgs, ChangeSet>(DB_MAGIC, DB_PATH)?;
113+
let example_cli::Init {
114+
args,
115+
keymap,
116+
index,
117+
db,
118+
init_changeset,
119+
} = example_cli::init::<RpcCommands, RpcArgs, ChangeSet>(DB_MAGIC, DB_PATH)?;
116120
println!(
117121
"[{:>10}s] loaded initial changeset from db",
118122
start.elapsed().as_secs_f32()

0 commit comments

Comments
 (0)