diff --git a/sdk/src/client/builder.rs b/sdk/src/client/builder.rs index 5089bdab6f..17198de47f 100644 --- a/sdk/src/client/builder.rs +++ b/sdk/src/client/builder.rs @@ -276,7 +276,7 @@ impl NetworkInfo { } pub fn with_tangle_time(mut self, tangle_time: u64) -> Self { - self.tangle_time = Some(tangle_time.into()); + self.tangle_time = Some(tangle_time); self } } diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 1962a482ce..06ed1b88ec 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -125,7 +125,7 @@ impl ClientInner { /// Returns the information of committee members at the given epoch index. If epoch index is not provided, the /// current committee members are returned. /// GET /api/core/v3/committee/?epochIndex - pub async fn get_committee(&self, epoch_index: impl Into>) -> Result { + pub async fn get_committee(&self, epoch_index: impl Into> + Send) -> Result { const PATH: &str = "api/core/v3/committee"; let epoch_index = epoch_index.into().map(|i| format!("epochIndex={i}")); diff --git a/sdk/src/types/block/address/ed25519.rs b/sdk/src/types/block/address/ed25519.rs index b8603d57f6..62a3146b1f 100644 --- a/sdk/src/types/block/address/ed25519.rs +++ b/sdk/src/types/block/address/ed25519.rs @@ -25,7 +25,6 @@ impl Ed25519Address { Self::from(address) } - #[allow(dead_code)] pub(crate) fn null() -> Self { Self::new([0; Self::LENGTH]) } diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index fe50ae8900..42333385ac 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -12,7 +12,7 @@ use super::{ }; use crate::types::{ block::{ - address::Address, + address::{Address, Ed25519Address}, output::{ feature::{verify_allowed_features, Feature, FeatureFlags, Features}, unlock_condition::{ @@ -64,6 +64,14 @@ impl BasicOutputBuilder { } } + /// Gets the current amount as a concrete value. + pub fn amount(&self) -> u64 { + match self.amount { + OutputBuilderAmount::Amount(amount) => amount, + OutputBuilderAmount::MinimumStorageDeposit(rent_structure) => self.rent_cost(rent_structure), + } + } + /// Sets the amount to the provided value. #[inline(always)] pub fn with_amount(mut self, amount: u64) -> Self { @@ -208,6 +216,13 @@ impl BasicOutputBuilder { }) } + pub fn min_storage_deposit_amount(&self, rent_structure: RentStructure, token_supply: u64) -> Result { + Ok(self + .clone() + .with_sufficient_storage_deposit(Ed25519Address::null(), rent_structure, token_supply)? + .amount()) + } + /// pub fn finish(self) -> Result { let amount = match self.amount { diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index a5e30df7dd..534f1db467 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -68,10 +68,7 @@ pub use self::{ unlock_condition::{UnlockCondition, UnlockConditions}, }; use super::{protocol::ProtocolParameters, slot::SlotIndex, BlockId}; -use crate::types::{ - block::{address::Address, semantic::ValidationContext, Error}, - ValidationParams, -}; +use crate::types::block::{address::Address, semantic::ValidationContext, Error}; /// The maximum number of outputs of a transaction. pub const OUTPUT_COUNT_MAX: u16 = 128; diff --git a/sdk/src/wallet/account/operations/output_claiming.rs b/sdk/src/wallet/account/operations/output_claiming.rs index 756139cd39..481ab62371 100644 --- a/sdk/src/wallet/account/operations/output_claiming.rs +++ b/sdk/src/wallet/account/operations/output_claiming.rs @@ -11,7 +11,7 @@ use crate::{ address::Address, output::{ unlock_condition::{AddressUnlockCondition, StorageDepositReturnUnlockCondition}, - BasicOutputBuilder, NativeTokens, NativeTokensBuilder, NftOutputBuilder, Output, OutputId, RentCost, + BasicOutputBuilder, NativeTokens, NativeTokensBuilder, NftOutputBuilder, Output, OutputId, }, }, wallet::account::{ @@ -294,15 +294,10 @@ where Some(new_native_tokens.clone().finish()?) }; - // 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() { - required_amount_for_nfts - } else { - required_amount_for_nfts - + BasicOutputBuilder::new_with_amount(Output::AMOUNT_MIN) - .with_native_tokens(option_native_token.into_iter().flatten()) - .rent_cost(rent_structure) - }; + // Get the required amount using a sufficient storage deposit + let mut required_amount = BasicOutputBuilder::new_with_amount(required_amount_for_nfts) + .with_native_tokens(option_native_token.into_iter().flatten()) + .min_storage_deposit_amount(rent_structure, token_supply)?; let mut additional_inputs = Vec::new(); if available_amount < required_amount { @@ -318,10 +313,9 @@ where }; // Recalculate every time, because new inputs can also add more native tokens, which would increase // the required storage deposit - required_amount = required_amount_for_nfts - + BasicOutputBuilder::new_with_amount(Output::AMOUNT_MIN) - .with_native_tokens(option_native_token.into_iter().flatten()) - .rent_cost(rent_structure); + required_amount = BasicOutputBuilder::new_with_amount(required_amount_for_nfts) + .with_native_tokens(option_native_token.into_iter().flatten()) + .min_storage_deposit_amount(rent_structure, token_supply)?; if available_amount < required_amount { if !additional_inputs_used.contains(&output_data.output_id) {