diff --git a/src/single_random_draw.rs b/src/single_random_draw.rs index 465c796..8d8797d 100644 --- a/src/single_random_draw.rs +++ b/src/single_random_draw.rs @@ -23,19 +23,15 @@ fn get_effective_value( ) -> Result, 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 = 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