Skip to content

Commit

Permalink
Add CoinsQueryError::[FUnexpectedInternalState error
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-ch committed Dec 12, 2024
1 parent 0175e41 commit 87245d4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/fuel-core/src/coins_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub enum CoinsQueryError {
IncorrectCoinKeyInIndex,
#[error("incorrect message key found in messages to spend index")]
IncorrectMessageKeyInIndex,
#[error("error while processing the query: {0}")]
UnexpectedInternalState(&'static str),
}

#[cfg(test)]
Expand Down Expand Up @@ -301,8 +303,14 @@ pub async fn select_coins_to_spend(
return Ok(vec![]);
}
let Some(last_selected_big_coin) = selected_big_coins.last() else {
// Should never happen.
return Ok(vec![]);
// Should never happen, because at this stage we know that:
// 1) selected_big_coins_total >= total
// 2) total > 0
// hence: selected_big_coins_total > 0
// therefore, at least one coin is selected - if not, it's a bug
return Err(CoinsQueryError::UnexpectedInternalState(
"at least one coin should be selected",
));
};

let selected_big_coins_len = selected_big_coins.len();
Expand Down

0 comments on commit 87245d4

Please sign in to comment.