Skip to content

Commit bb46879

Browse files
committed
bitcoin: prevent division by 0 in high fee warning
1 parent 39343fd commit bb46879

File tree

1 file changed

+6
-2
lines changed
  • src/rust/bitbox02-rust/src/hww/api/bitcoin

1 file changed

+6
-2
lines changed

src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,15 @@ async fn _process(request: &pb::BtcSignInitRequest) -> Result<Response, Error> {
741741
let fee: u64 = total_out
742742
.checked_sub(outputs_sum_out)
743743
.ok_or(Error::InvalidInput)?;
744-
let fee_percentage: f64 = 100. * (fee as f64) / (outputs_sum_out as f64);
744+
let fee_percentage: Option<f64> = if outputs_sum_out == 0 {
745+
None
746+
} else {
747+
Some(100. * (fee as f64) / (outputs_sum_out as f64))
748+
};
745749
transaction::verify_total_fee(
746750
&format_amount(coin_params, format_unit, total_out)?,
747751
&format_amount(coin_params, format_unit, fee)?,
748-
Some(fee_percentage),
752+
fee_percentage,
749753
)
750754
.await?;
751755
status::status("Transaction\nconfirmed", true).await;

0 commit comments

Comments
 (0)