Skip to content

Commit

Permalink
Check if max_weight is exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Jan 8, 2025
1 parent b2a29f8 commit 779ecf9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/coin_grinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn select_coins<Utxo: WeightedUtxo>(
weighted_utxos: &[Utxo],
) -> Option<std::vec::IntoIter<&Utxo>> {
let mut w_utxos = calc_effective_values::<Utxo>(weighted_utxos, fee_rate);

let available_value = w_utxos.clone().into_iter().map(|(ev, _)| ev).checked_sum()?;

// descending sort by effective_value using weight as tie breaker.
Expand Down Expand Up @@ -382,4 +383,23 @@ mod tests {

assert_coin_select_params(&params, None);
}

#[test]
fn max_weight_exceeded () {
let mut wu = Vec::new();
for i in 0..10 {
wu.push("1 BTC/272");
wu.push("2 BTC/272");
}

let params = ParamsStr {
target: "29.5 BTC",
change_target: "1000000 sats",
max_weight: "3000",
fee_rate: "5",
weighted_utxos: wu
};

assert_coin_select_params(&params, None);
}
}

0 comments on commit 779ecf9

Please sign in to comment.