Skip to content

Commit 2e26aa5

Browse files
committed
fix: rm Drain::none method
We already have const `Drain::NONE` which should be used instead.
1 parent 8eb582b commit 2e26aa5

File tree

7 files changed

+12
-17
lines changed

7 files changed

+12
-17
lines changed

src/coin_selector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'a> CoinSelector<'a> {
391391

392392
/// Whether the constraints of `Target` have been met.
393393
pub fn is_target_met(&self, target: Target) -> bool {
394-
self.is_target_met_with_drain(target, Drain::none())
394+
self.is_target_met_with_drain(target, Drain::NONE)
395395
}
396396

397397
/// Select all unselected candidates
@@ -434,7 +434,7 @@ impl<'a> CoinSelector<'a> {
434434
}
435435

436436
/// Figures out whether the current selection should have a change output given the
437-
/// `change_policy`. If it shouldn't then it will return a [`Drain::none`]. The value of the
437+
/// `change_policy`. If it should not, then it will return [`Drain::NONE`]. The value of the
438438
/// `Drain` will be the same as [`drain_value`].
439439
///
440440
/// If [`is_target_met`] returns true for this selection then [`is_target_met_with_drain`] will
@@ -475,7 +475,7 @@ impl<'a> CoinSelector<'a> {
475475
pub fn select_until_target_met(&mut self, target: Target) -> Result<(), InsufficientFunds> {
476476
self.select_until(|cs| cs.is_target_met(target))
477477
.ok_or_else(|| InsufficientFunds {
478-
missing: self.excess(target, Drain::none()).unsigned_abs(),
478+
missing: self.excess(target, Drain::NONE).unsigned_abs(),
479479
})
480480
}
481481

src/drain.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ impl Drain {
8080
value: 0,
8181
};
8282

83-
/// A drian representing no drain at all.
84-
pub fn none() -> Self {
85-
Self::default()
86-
}
87-
8883
/// is the "none" drain
8984
pub fn is_none(&self) -> bool {
9085
self == &Drain::NONE

src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn change_lower_bound(cs: &CoinSelector, target: Target, change_policy: ChangePo
2828

2929
least_excess.drain(target, change_policy)
3030
} else {
31-
Drain::none()
31+
Drain::NONE
3232
}
3333
}
3434

src/metrics/lowest_fee.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl BnbMetric for LowestFee {
9898
self.long_term_feerate,
9999
self.target.outputs.n_outputs,
100100
);
101-
let cost_of_no_change = cs.excess(self.target, Drain::none());
101+
let cost_of_no_change = cs.excess(self.target, Drain::NONE);
102102

103103
let best_score_with_change =
104104
Ordf32(current_score.0 - cost_of_no_change as f32 + cost_of_adding_change);
@@ -131,7 +131,7 @@ impl BnbMetric for LowestFee {
131131
// scale = remaining_value_to_reach_feerate / effective_value_of_resized_input
132132
//
133133
// This should be intutive since we're finding out how to scale the input we're resizing to get the effective value we need.
134-
let rate_excess = cs.rate_excess(self.target, Drain::none()) as f32;
134+
let rate_excess = cs.rate_excess(self.target, Drain::NONE) as f32;
135135
let mut scale = Ordf32(0.0);
136136

137137
if rate_excess < 0.0 {
@@ -150,7 +150,7 @@ impl BnbMetric for LowestFee {
150150
// We can use the same approach for replacement we just have to use the
151151
// incremental_relay_feerate.
152152
if let Some(replace) = self.target.fee.replace {
153-
let replace_excess = cs.replacement_excess(self.target, Drain::none()) as f32;
153+
let replace_excess = cs.replacement_excess(self.target, Drain::NONE) as f32;
154154
if replace_excess < 0.0 {
155155
let remaining_value_to_reach_feerate = replace_excess.abs();
156156
let effective_value_of_resized_input =

tests/bnb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const EXCESS_RATIO: f32 = 1_000_000_f32;
3535

3636
impl BnbMetric for MinExcessThenWeight {
3737
fn score(&mut self, cs: &CoinSelector<'_>) -> Option<Ordf32> {
38-
let excess = cs.excess(self.target, Drain::none());
38+
let excess = cs.excess(self.target, Drain::NONE);
3939
if excess < 0 {
4040
None
4141
} else {
@@ -135,7 +135,7 @@ fn bnb_finds_solution_if_possible_in_n_iter() {
135135
.expect("found a solution");
136136

137137
assert_eq!(rounds, 193);
138-
let excess = sol.excess(target, Drain::none());
138+
let excess = sol.excess(target, Drain::NONE);
139139
assert_eq!(excess, 1);
140140
}
141141

tests/lowest_fee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn adding_another_input_to_remove_change() {
222222
let mut cs = cs.clone();
223223
cs.select(0);
224224
cs.select(2);
225-
cs.excess(target, Drain::none());
225+
cs.excess(target, Drain::NONE);
226226
assert!(cs.is_target_met(target));
227227
cs
228228
};
@@ -262,7 +262,7 @@ fn adding_another_input_to_remove_change() {
262262
let (score, _) = common::bnb_search(&mut cs, metric, 10).expect("finds solution");
263263
let best_solution_score = metric.score(&best_solution).expect("must be a solution");
264264

265-
assert_eq!(best_solution.drain(target, change_policy), Drain::none());
265+
assert_eq!(best_solution.drain(target, change_policy), Drain::NONE);
266266

267267
assert!(score <= best_solution_score);
268268
assert_eq!(cs.selected_indices(), best_solution.selected_indices());

tests/weight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn segwit_two_inputs_one_output() {
101101
);
102102
assert_eq!(
103103
(coin_selector
104-
.implied_feerate(target_ouputs, Drain::none())
104+
.implied_feerate(target_ouputs, Drain::NONE)
105105
.unwrap()
106106
.as_sat_vb()
107107
* 10.0)

0 commit comments

Comments
 (0)