Skip to content

Commit

Permalink
Update src/single_random_draw.rs
Browse files Browse the repository at this point in the history
Co-authored-by: Thibaut Le Guilly <[email protected]>

wip
  • Loading branch information
yancyribbens committed Aug 16, 2023
1 parent 66871e3 commit 2681d77
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/single_random_draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ fn get_effective_value(
) -> Result<Option<Amount>, Error> {
let satisfaction_weight = weighted_utxo.satisfaction_weight;

let checked_weight = satisfaction_weight.checked_add(TXIN_BASE_WEIGHT);
let weight = satisfaction_weight
.checked_add(TXIN_BASE_WEIGHT)
.ok_or_else(|| Error::AdditionOverflow(satisfaction_weight, TXIN_BASE_WEIGHT))?;

let weight = match checked_weight {
Some(w) => w,
None => return Err(Error::AdditionOverflow(satisfaction_weight, TXIN_BASE_WEIGHT)),
};
let input_fee = fee_rate
.checked_mul_by_weight(weight)
.ok_or_else(|| Error::MultiplicationOverflow(satisfaction_weight, fee_rate))?;

let input_fee: Option<Amount> = fee_rate.checked_mul_by_weight(weight);

match input_fee {
Some(f) => Ok(weighted_utxo.utxo.value.checked_sub(f)),
None => Err(Error::MultiplicationOverflow(satisfaction_weight, fee_rate)),
}
Ok(weighted_utxo.utxo.value.checked_sub(input_fee))
}

/// Randomly select coins for the given target by shuffling the UTXO pool and
Expand Down

0 comments on commit 2681d77

Please sign in to comment.