From 5b5d199b5b18f41abac0aeeac9b0f40c83282ccc Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 16 Jan 2024 11:40:47 +0100 Subject: [PATCH] checked_sub --- .../api/block_builder/input_selection/remainder.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index efcfa38fed..cf59cb044b 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -18,6 +18,7 @@ use crate::{ unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, NativeTokensBuilder, NftOutputBuilder, Output, }, + Error as BlockError, }, }; @@ -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() {