From 8e08639997283c2874d2e76c4d2bc55a51de4ee7 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:40:27 +0200 Subject: [PATCH] Adjust claim_outputs() for very small inputs (#1388) * Adjust claim_outputs() to work even if an input has less amount than min storage deposit * Update changelog * Update sdk/CHANGELOG.md Co-authored-by: Thibault Martinez * CHANGELOG * Update sdk/CHANGELOG.md --------- Co-authored-by: Thibault Martinez Co-authored-by: Thibault Martinez --- sdk/CHANGELOG.md | 6 ++++++ .../wallet/account/operations/output_claiming.rs | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index cf5d01e97e..f3471ecfab 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.1.2 - 2023-MM-DD + +### Fixed + +- `Account::claim_outputs()` if an input has less amount than min storage deposit; + ## 1.1.1 - 2023-10-11 ### Added diff --git a/sdk/src/wallet/account/operations/output_claiming.rs b/sdk/src/wallet/account/operations/output_claiming.rs index 2333c754af..37ea891d15 100644 --- a/sdk/src/wallet/account/operations/output_claiming.rs +++ b/sdk/src/wallet/account/operations/output_claiming.rs @@ -242,6 +242,15 @@ where let mut available_amount = 0; let mut required_amount_for_nfts = 0; let mut new_native_tokens = NativeTokensBuilder::new(); + + // There can be outputs with less amount than min required storage deposit, so we have to check that we + // have enough amount to create a new basic output + let enough_amount_for_basic_output = possible_additional_inputs + .iter() + .map(|i| i.output.amount()) + .sum::() + >= MinimumStorageDepositBasicOutput::new(rent_structure, token_supply).finish()?; + // check native tokens for output_data in &outputs_to_claim { if let Some(native_tokens) = output_data.output.native_tokens() { @@ -266,7 +275,7 @@ where // build new output with same amount, nft_id, immutable/feature blocks and native tokens, just // updated address unlock conditions - let nft_output = if possible_additional_inputs.is_empty() { + let nft_output = if !enough_amount_for_basic_output { // Only update address and nft id if we have no additional inputs which can provide the storage // deposit for the remaining amount and possible NTs NftOutputBuilder::from(nft_output) @@ -296,7 +305,7 @@ where }; // Check if the new amount is enough for the storage deposit, otherwise increase it to this - let mut required_amount = if possible_additional_inputs.is_empty() { + let mut required_amount = if !enough_amount_for_basic_output { required_amount_for_nfts } else { required_amount_for_nfts