Skip to content

Commit 252be3f

Browse files
committed
Add check for overflow when computing target
Return None during computation so that the result can be handled instead of panicking.
1 parent 49e96e9 commit 252be3f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/coin_grinder.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn select_coins<Utxo: WeightedUtxo>(
155155
let lookahead = build_lookahead(w_utxos.clone(), available_value);
156156
let min_tail_weight = build_min_tail_weight(w_utxos.clone());
157157

158-
let total_target = target + change_target;
158+
let total_target = target.checked_add(change_target)?;
159159

160160
if available_value < total_target {
161161
return None;
@@ -617,4 +617,17 @@ mod tests {
617617

618618
assert_coin_select_params(&params, 8, None);
619619
}
620+
621+
#[test]
622+
fn max_target_and_max_change_target() {
623+
let params = ParamsStr {
624+
target: "18446744073709551615 sats", //u64::MAX
625+
change_target: "18446744073709551615 sats", //u64::MAX
626+
max_weight: "100",
627+
fee_rate: "0",
628+
weighted_utxos: vec!["10 sats/8", "7 sats/4", "5 sats/4", "4 sats/8"],
629+
};
630+
631+
assert_coin_select_params(&params, 8, None);
632+
}
620633
}

0 commit comments

Comments
 (0)