Skip to content

Commit

Permalink
checked_sub
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jan 16, 2024
1 parent 3e28db3 commit 5b5d199
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sdk/src/client/api/block_builder/input_selection/remainder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, NativeTokensBuilder,
NftOutputBuilder, Output,
},
Error as BlockError,
},
};

Expand Down Expand Up @@ -140,8 +141,12 @@ impl InputSelection {
return Ok((None, storage_deposit_returns));
}

let amount_diff = input_amount - output_amount;
let mana_diff = input_mana - output_mana;
let amount_diff = input_amount
.checked_sub(output_amount)
.ok_or(BlockError::ConsumedAmountOverflow)?;
let mana_diff = input_mana
.checked_sub(output_mana)
.ok_or(BlockError::ConsumedManaOverflow)?;

// If there is only a mana remainder, try to fit it in an automatically transitioned output.
if input_amount == output_amount && input_mana != output_mana && native_tokens_diff.is_none() {
Expand Down

0 comments on commit 5b5d199

Please sign in to comment.