Skip to content

Commit

Permalink
chore: return None early on empty utxo list
Browse files Browse the repository at this point in the history
  • Loading branch information
msgmaxim committed Oct 2, 2023
1 parent f38f44e commit 7a6fda7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions state-chain/pallets/cf-environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,22 +424,24 @@ impl<T: Config> Pallet<T> {
T::BitcoinFeeInfo::bitcoin_fee_info();
match utxo_selection_type {
UtxoSelectionType::SelectAllForRotation => {
let available_utxos = BitcoinAvailableUtxos::<T>::take();

let non_dust_utxos: Vec<_> = available_utxos
let spendable_utxos: Vec<_> = BitcoinAvailableUtxos::<T>::take()
.into_iter()
.filter(|utxo| utxo.amount > fee_per_input_utxo)
.collect();

let total_fee = non_dust_utxos.len() as u64 * fee_per_input_utxo +
if spendable_utxos.is_empty() {
return None
}

let total_fee = spendable_utxos.len() as u64 * fee_per_input_utxo +
fee_per_output_utxo + min_fee_required_per_tx;

non_dust_utxos
spendable_utxos
.iter()
.map(|utxo| utxo.amount)
.sum::<u64>()
.checked_sub(total_fee)
.map(|change_amount| (non_dust_utxos, change_amount))
.map(|change_amount| (spendable_utxos, change_amount))
},
UtxoSelectionType::Some { output_amount, number_of_outputs } =>
BitcoinAvailableUtxos::<T>::try_mutate(|available_utxos| {
Expand Down

0 comments on commit 7a6fda7

Please sign in to comment.