Skip to content

Commit 3d7bd2e

Browse files
committed
UtxoFilter has a Default implementation that applies no filtering
1 parent 9d4ebc5 commit 3d7bd2e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/psbt/params.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct PsbtParams {
3434
pub(crate) drain_wallet: bool,
3535
pub(crate) coin_selection: SelectionStrategy,
3636
pub(crate) canonical_params: CanonicalizationParams,
37-
pub(crate) utxo_filter: Option<UtxoFilter>,
37+
pub(crate) utxo_filter: UtxoFilter,
3838

3939
// PSBT
4040
pub(crate) version: Option<Version>,
@@ -57,7 +57,7 @@ impl Default for PsbtParams {
5757
drain_wallet: Default::default(),
5858
coin_selection: Default::default(),
5959
canonical_params: Default::default(),
60-
utxo_filter: None,
60+
utxo_filter: Default::default(),
6161
version: Default::default(),
6262
locktime: Default::default(),
6363
fallback_sequence: Default::default(),
@@ -173,7 +173,7 @@ impl PsbtParams {
173173
where
174174
F: Fn(&FullTxOut<ConfirmationBlockTime>) -> bool + Send + Sync + 'static,
175175
{
176-
self.utxo_filter = Some(UtxoFilter(Arc::new(exclude)));
176+
self.utxo_filter = UtxoFilter(Arc::new(exclude));
177177
self
178178
}
179179

@@ -229,6 +229,12 @@ pub(crate) struct UtxoFilter(
229229
pub Arc<dyn Fn(&FullTxOut<ConfirmationBlockTime>) -> bool + Send + Sync>,
230230
);
231231

232+
impl Default for UtxoFilter {
233+
fn default() -> Self {
234+
Self(Arc::new(|_| false))
235+
}
236+
}
237+
232238
impl fmt::Debug for UtxoFilter {
233239
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
234240
write!(f, "UtxoFilter")

src/wallet/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,10 +2895,7 @@ impl Wallet {
28952895
// Get input candidates
28962896
let mut may_spend: Vec<Input> = self
28972897
.filter_spendable(txouts.into_values(), &params, |txo| {
2898-
params
2899-
.utxo_filter
2900-
.as_ref()
2901-
.is_some_and(|filter| (filter.0)(txo))
2898+
(params.utxo_filter.0)(txo)
29022899
})
29032900
.flat_map(|txo| self.plan_input(&txo, &assets))
29042901
.collect();
@@ -3100,10 +3097,7 @@ impl Wallet {
31003097
// per replacement policy Rule 2.
31013098
to_replace.contains(&txo.outpoint.txid)
31023099
|| txo.chain_position.is_unconfirmed()
3103-
|| params
3104-
.utxo_filter
3105-
.as_ref()
3106-
.is_some_and(|filter| (filter.0)(txo))
3100+
|| (params.utxo_filter.0)(txo)
31073101
})
31083102
.flat_map(|txo| self.plan_input(&txo, &assets))
31093103
.collect();

0 commit comments

Comments
 (0)