Skip to content

Commit 08425f4

Browse files
committed
refactor: use getter methods
1 parent a83e5f7 commit 08425f4

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/branch_and_bound.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ pub fn branch_and_bound<'a, T: IntoIterator<Item = &'a WeightedUtxo> + std::mark
171171
let mut weighted_utxos: Vec<_> = weighted_utxos.into_iter().collect();
172172

173173
// descending sort by effective_value, ascending sort by waste.
174-
weighted_utxos
175-
.sort_by(|a, b| b.effective_value().cmp(&a.effective_value()).then(a.waste.cmp(&b.waste)));
174+
weighted_utxos.sort_by(|a, b| {
175+
b.effective_value().cmp(&a.effective_value()).then(a.waste().cmp(&b.waste()))
176+
});
176177

177178
if available_value < target {
178179
return Err(InsufficentFunds);
@@ -247,13 +248,13 @@ pub fn branch_and_bound<'a, T: IntoIterator<Item = &'a WeightedUtxo> + std::mark
247248
break;
248249
}
249250

250-
let eff_value = weighted_utxos[index].effective_value;
251+
let eff_value = weighted_utxos[index].effective_value_raw();
251252
available_value += eff_value;
252253
}
253254

254255
assert_eq!(index, *index_selection.last().unwrap());
255-
let eff_value = weighted_utxos[index].effective_value;
256-
let utxo_waste = weighted_utxos[index].waste;
256+
let eff_value = weighted_utxos[index].effective_value_raw();
257+
let utxo_waste = weighted_utxos[index].waste_raw();
257258
let utxo_weight = weighted_utxos[index].weight();
258259
current_waste = current_waste.checked_sub(utxo_waste).ok_or(Overflow(Subtraction))?;
259260
value = value.checked_sub(eff_value).ok_or(Overflow(Addition))?;
@@ -262,9 +263,9 @@ pub fn branch_and_bound<'a, T: IntoIterator<Item = &'a WeightedUtxo> + std::mark
262263
}
263264
// * Add next node to the inclusion branch.
264265
else {
265-
let eff_value = weighted_utxos[index].effective_value;
266+
let eff_value = weighted_utxos[index].effective_value_raw();
266267
let utxo_weight = weighted_utxos[index].weight();
267-
let utxo_waste = weighted_utxos[index].waste;
268+
let utxo_waste = weighted_utxos[index].waste_raw();
268269

269270
// unchecked sub is used her for performance.
270271
// The bounds for available_value are at most the sum of utxos
@@ -277,7 +278,7 @@ pub fn branch_and_bound<'a, T: IntoIterator<Item = &'a WeightedUtxo> + std::mark
277278
// Check if the previous UTXO was included.
278279
|| index - 1 == *index_selection.last().unwrap()
279280
// Check if the previous UTXO has the same value has the previous one.
280-
|| weighted_utxos[index].effective_value != weighted_utxos[index - 1].effective_value
281+
|| weighted_utxos[index].effective_value_raw() != weighted_utxos[index - 1].effective_value_raw()
281282
{
282283
index_selection.push(index);
283284
current_waste = current_waste.checked_add(utxo_waste).ok_or(Overflow(Addition))?;

src/coin_grinder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ mod tests {
672672
let w = u.int_in_range::<u64>(1..=Weight::MAX.to_wu()).unwrap();
673673
let wu = Weight::from_wu(w);
674674
WeightedUtxo::new(
675-
utxo.value,
675+
utxo.value(),
676676
wu,
677677
exclusion_set.fee_rate,
678678
exclusion_set.long_term_fee_rate,
@@ -685,14 +685,14 @@ mod tests {
685685
.iter()
686686
.map(|utxo| {
687687
WeightedUtxo::new(
688-
utxo.value,
688+
utxo.value(),
689689
Weight::ZERO,
690690
inclusion_set.fee_rate,
691691
inclusion_set.long_term_fee_rate,
692692
)
693693
.unwrap()
694694
})
695-
.filter(|utxo| utxo.value == Amount::ZERO)
695+
.filter(|utxo| utxo.value() == Amount::ZERO)
696696
.collect();
697697

698698
if let Some(target) = weightless_pool.iter().map(|utxo| utxo.value()).checked_sum() {

0 commit comments

Comments
 (0)