diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 3b63f2b81d..4958f697a4 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -46,11 +46,7 @@ impl From<&OutputId> for AccountId { impl AccountId { /// pub fn or_from_output_id(self, output_id: &OutputId) -> Self { - if self.is_null() { - Self::from(output_id) - } else { - self - } + if self.is_null() { Self::from(output_id) } else { self } } } diff --git a/sdk/src/wallet/account/operations/output_claiming.rs b/sdk/src/wallet/account/operations/output_claiming.rs index 58b5239130..3f16f91fd5 100644 --- a/sdk/src/wallet/account/operations/output_claiming.rs +++ b/sdk/src/wallet/account/operations/output_claiming.rs @@ -11,8 +11,8 @@ use crate::{ address::Address, output::{ unlock_condition::{AddressUnlockCondition, StorageDepositReturnUnlockCondition}, - BasicOutputBuilder, MinimumStorageDepositBasicOutput, NativeTokens, NativeTokensBuilder, NftOutputBuilder, - Output, OutputId, + BasicOutputBuilder, MinimumStorageDepositBasicOutput, NativeTokensBuilder, NftOutputBuilder, Output, + OutputId, }, slot::SlotIndex, }, @@ -249,13 +249,8 @@ where let mut new_native_tokens = NativeTokensBuilder::new(); // check native tokens for output_data in &outputs_to_claim { - if let Some(native_tokens) = output_data.output.native_tokens() { - // Skip output if the max native tokens count would be exceeded - if get_new_native_token_count(&new_native_tokens, native_tokens)? > NativeTokens::COUNT_MAX.into() { - log::debug!("[OUTPUT_CLAIMING] skipping output to not exceed the max native tokens count"); - continue; - } - new_native_tokens.add_native_tokens(native_tokens.clone())?; + if let Some(native_token) = output_data.output.native_token() { + new_native_tokens.add_native_token(native_token.clone())?; } if let Some(sdr) = sdr_not_expired(&output_data.output, slot_index) { // for own output subtract the return amount @@ -332,22 +327,13 @@ where // the required storage deposit required_amount = required_amount_for_nfts + MinimumStorageDepositBasicOutput::new(rent_structure, token_supply) - .with_native_tokens(option_native_token) + .with_native_token(option_native_token) .finish()?; if available_amount < required_amount { if !additional_inputs_used.contains(&output_data.output_id) { - if let Some(native_tokens) = output_data.output.native_tokens() { - // Skip input if the max native tokens count would be exceeded - if get_new_native_token_count(&new_native_tokens, native_tokens)? - > NativeTokens::COUNT_MAX.into() - { - log::debug!( - "[OUTPUT_CLAIMING] skipping input to not exceed the max native tokens count" - ); - continue; - } - new_native_tokens.add_native_tokens(native_tokens.clone())?; + if let Some(native_token) = output_data.output.native_token() { + new_native_tokens.add_native_token(native_token.clone())?; } available_amount += output_data.output.amount(); additional_inputs.push(output_data.output_id); @@ -430,15 +416,3 @@ pub(crate) fn sdr_not_expired(output: &Output, slot_index: SlotIndex) -> Option< }) }) } - -// Helper function to calculate the native token count without duplicates, when new native tokens are added -// Might be possible to refactor the sections where it's used to remove the clones -pub(crate) fn get_new_native_token_count( - native_tokens_builder: &NativeTokensBuilder, - native_tokens: &NativeTokens, -) -> crate::wallet::Result { - // Clone to get the new native token count without actually modifying it - let mut native_tokens_count = native_tokens_builder.clone(); - native_tokens_count.add_native_tokens(native_tokens.clone())?; - Ok(native_tokens_count.len()) -} diff --git a/sdk/src/wallet/account/operations/output_consolidation.rs b/sdk/src/wallet/account/operations/output_consolidation.rs index 8e838c219c..5edd68d2ee 100644 --- a/sdk/src/wallet/account/operations/output_consolidation.rs +++ b/sdk/src/wallet/account/operations/output_consolidation.rs @@ -10,9 +10,7 @@ use crate::{ types::block::{ address::Bech32Address, input::INPUT_COUNT_MAX, - output::{ - unlock_condition::AddressUnlockCondition, BasicOutputBuilder, NativeTokens, NativeTokensBuilder, Output, - }, + output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder, NativeTokensBuilder, Output}, slot::SlotIndex, }, }; @@ -31,7 +29,7 @@ use crate::wallet::account::constants::DEFAULT_LEDGER_OUTPUT_CONSOLIDATION_THRES use crate::wallet::{ account::{ constants::DEFAULT_OUTPUT_CONSOLIDATION_THRESHOLD, - operations::{helpers::time::can_output_be_unlocked_now, output_claiming::get_new_native_token_count}, + operations::helpers::time::can_output_be_unlocked_now, types::{OutputData, Transaction}, Account, AddressWithUnspentOutputs, TransactionOptions, }, @@ -241,13 +239,8 @@ where let mut total_native_tokens = NativeTokensBuilder::new(); for output_data in outputs_to_consolidate.iter().take(max_inputs.into()) { - if let Some(native_tokens) = output_data.output.native_tokens() { - // Skip output if the max native tokens count would be exceeded - if get_new_native_token_count(&total_native_tokens, native_tokens)? > NativeTokens::COUNT_MAX.into() { - log::debug!("[OUTPUT_CONSOLIDATION] skipping output to not exceed the max native tokens count"); - continue; - } - total_native_tokens.add_native_tokens(native_tokens.clone())?; + if let Some(native_token) = output_data.output.native_token() { + total_native_tokens.add_native_token(native_token.clone())?; }; total_amount += output_data.output.amount();