From 6884d912b7444453f889ae7614c1ba6c22aa7702 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 15 Nov 2023 10:12:35 +0100 Subject: [PATCH] Remove SDRUC supply check --- bindings/core/src/method_handler/client.rs | 4 -- .../client/output/build_basic_output.rs | 16 +---- .../how_tos/outputs/unlock_conditions.rs | 7 +- sdk/src/types/block/output/account.rs | 12 ++-- sdk/src/types/block/output/anchor.rs | 12 ++-- sdk/src/types/block/output/basic.rs | 23 ++----- sdk/src/types/block/output/delegation.rs | 12 ++-- sdk/src/types/block/output/foundry.rs | 12 ++-- sdk/src/types/block/output/mod.rs | 22 +++--- sdk/src/types/block/output/nft.rs | 23 ++----- .../block/output/unlock_condition/mod.rs | 21 ++---- .../storage_deposit_return.rs | 69 +++++-------------- .../operations/transaction/high_level/send.rs | 3 +- .../high_level/send_native_tokens.rs | 3 +- .../operations/transaction/prepare_output.rs | 10 +-- sdk/tests/client/mod.rs | 7 +- 16 files changed, 76 insertions(+), 180 deletions(-) diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index e1be21057c..a5982664fe 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -79,7 +79,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM unlock_conditions, features, immutable_features, - client.get_token_supply().await?, )?); Response::Output(OutputDto::from(&output)) @@ -101,7 +100,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM native_tokens, unlock_conditions, features, - client.get_token_supply().await?, )?); Response::Output(OutputDto::from(&output)) @@ -127,7 +125,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM unlock_conditions, features, immutable_features, - client.get_token_supply().await?, )?); Response::Output(OutputDto::from(&output)) @@ -153,7 +150,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM unlock_conditions, features, immutable_features, - client.get_token_supply().await?, )?); Response::Output(OutputDto::from(&output)) diff --git a/sdk/examples/client/output/build_basic_output.rs b/sdk/examples/client/output/build_basic_output.rs index 5f92114e56..c7ef6391ac 100644 --- a/sdk/examples/client/output/build_basic_output.rs +++ b/sdk/examples/client/output/build_basic_output.rs @@ -9,7 +9,7 @@ //! ``` use iota_sdk::{ - client::{Client, Result}, + client::Result, types::block::{ address::Address, output::{ @@ -30,14 +30,6 @@ async fn main() -> Result<()> { // This example uses secrets in environment variables for simplicity which should not be done in production. dotenvy::dotenv().ok(); - // Create a node client. - let client = Client::builder() - .with_node(&std::env::var("NODE_URL").unwrap())? - .finish() - .await?; - - let token_supply = client.get_token_supply().await?; - let address = std::env::args() .nth(1) .unwrap_or("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string()); @@ -57,11 +49,7 @@ async fn main() -> Result<()> { // with storage deposit return basic_output_builder .clone() - .add_unlock_condition(StorageDepositReturnUnlockCondition::new( - address.clone(), - 1_000_000, - token_supply, - )?) + .add_unlock_condition(StorageDepositReturnUnlockCondition::new(address.clone(), 1_000_000)) .finish_output()?, // with expiration basic_output_builder diff --git a/sdk/examples/how_tos/outputs/unlock_conditions.rs b/sdk/examples/how_tos/outputs/unlock_conditions.rs index e926e9fde8..94cb8ce779 100644 --- a/sdk/examples/how_tos/outputs/unlock_conditions.rs +++ b/sdk/examples/how_tos/outputs/unlock_conditions.rs @@ -33,7 +33,6 @@ async fn main() -> Result<()> { // Create a client instance. let client = Client::builder().with_node(&node_url)?.finish().await?; - let token_supply = client.get_token_supply().await?; let storage_score_params = client.get_storage_score_parameters().await?; let address = Address::try_from_bech32("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy")?; @@ -51,11 +50,7 @@ async fn main() -> Result<()> { // with storage deposit return unlock condition basic_output_builder .clone() - .add_unlock_condition(StorageDepositReturnUnlockCondition::new( - address.clone(), - 1000000, - token_supply, - )?) + .add_unlock_condition(StorageDepositReturnUnlockCondition::new(address.clone(), 1000000)) .finish_output()?, // with timeout unlock condition basic_output_builder diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index ddb2ec9501..aa8630581c 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -676,7 +676,7 @@ pub(crate) mod dto { type Dto = AccountOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result { let mut builder = AccountOutputBuilder::new_with_amount(dto.amount, dto.account_id) .with_mana(dto.mana) .with_foundry_counter(dto.foundry_counter) @@ -685,7 +685,7 @@ pub(crate) mod dto { .with_immutable_features(dto.immutable_features); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::from(u)); } builder.finish() @@ -703,9 +703,7 @@ pub(crate) mod dto { unlock_conditions: Vec, features: Option>, immutable_features: Option>, - params: impl Into> + Send, ) -> Result { - let params = params.into(); let mut builder = match amount { OutputBuilderAmount::Amount(amount) => AccountOutputBuilder::new_with_amount(amount, *account_id), OutputBuilderAmount::MinimumAmount(params) => { @@ -724,8 +722,8 @@ pub(crate) mod dto { let unlock_conditions = unlock_conditions .into_iter() - .map(|u| UnlockCondition::try_from_dto_with_params(u, ¶ms)) - .collect::, Error>>()?; + .map(UnlockCondition::from) + .collect::>(); builder = builder.with_unlock_conditions(unlock_conditions); if let Some(features) = features { @@ -780,7 +778,6 @@ mod tests { output.unlock_conditions().iter().map(Into::into).collect(), Some(output.features().to_vec()), Some(output.immutable_features().to_vec()), - &protocol_parameters, ) .unwrap(); assert_eq!(output, output_split); @@ -799,7 +796,6 @@ mod tests { builder.unlock_conditions.iter().map(Into::into).collect(), Some(builder.features.iter().cloned().collect()), Some(builder.immutable_features.iter().cloned().collect()), - &protocol_parameters, ) .unwrap(); assert_eq!(builder.finish().unwrap(), output_split); diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index 60ae4bada5..cac739c1d8 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -758,7 +758,7 @@ pub(crate) mod dto { type Dto = AnchorOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result { let mut builder = AnchorOutputBuilder::new_with_amount(dto.amount, dto.anchor_id) .with_mana(dto.mana) .with_state_index(dto.state_index) @@ -768,7 +768,7 @@ pub(crate) mod dto { .with_state_metadata(dto.state_metadata); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::from(u)); } builder.finish() @@ -787,9 +787,7 @@ pub(crate) mod dto { unlock_conditions: Vec, features: Option>, immutable_features: Option>, - params: impl Into> + Send, ) -> Result { - let params = params.into(); let mut builder = match amount { OutputBuilderAmount::Amount(amount) => AnchorOutputBuilder::new_with_amount(amount, *anchor_id), OutputBuilderAmount::MinimumAmount(params) => { @@ -809,8 +807,8 @@ pub(crate) mod dto { let unlock_conditions = unlock_conditions .into_iter() - .map(|u| UnlockCondition::try_from_dto_with_params(u, ¶ms)) - .collect::, Error>>()?; + .map(UnlockCondition::from) + .collect::>(); builder = builder.with_unlock_conditions(unlock_conditions); if let Some(features) = features { @@ -865,7 +863,6 @@ mod tests { output.unlock_conditions().iter().map(Into::into).collect(), Some(output.features().to_vec()), Some(output.immutable_features().to_vec()), - &protocol_parameters, ) .unwrap(); assert_eq!(output, output_split); @@ -885,7 +882,6 @@ mod tests { builder.unlock_conditions.iter().map(Into::into).collect(), Some(builder.features.iter().cloned().collect()), Some(builder.immutable_features.iter().cloned().collect()), - &protocol_parameters, ) .unwrap(); assert_eq!(builder.finish().unwrap(), output_split); diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index 4407b942d7..23872aa848 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -156,7 +156,6 @@ impl BasicOutputBuilder { mut self, return_address: impl Into
, params: StorageScoreParameters, - token_supply: u64, ) -> Result { Ok(match self.amount { OutputBuilderAmount::Amount(amount) => { @@ -171,11 +170,8 @@ impl BasicOutputBuilder { .finish()? .amount(); // Add a temporary storage deposit unlock condition so the new storage requirement can be calculated - self = self.add_unlock_condition(StorageDepositReturnUnlockCondition::new( - return_address.clone(), - 1, - token_supply, - )?); + self = + self.add_unlock_condition(StorageDepositReturnUnlockCondition::new(return_address.clone(), 1)); // Get the min amount of the output with the added storage deposit return unlock condition let min_amount_with_sdruc = self.clone().finish()?.minimum_amount(params); // If the return storage cost and amount are less than the required min @@ -192,8 +188,7 @@ impl BasicOutputBuilder { .replace_unlock_condition(StorageDepositReturnUnlockCondition::new( return_address, sdruc_amount, - token_supply, - )?) + )) } else { self } @@ -468,14 +463,14 @@ pub(crate) mod dto { type Dto = BasicOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result { let mut builder = BasicOutputBuilder::new_with_amount(dto.amount) .with_native_tokens(dto.native_tokens) .with_mana(dto.mana) .with_features(dto.features); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::from(u)); } builder.finish() @@ -489,9 +484,7 @@ pub(crate) mod dto { native_tokens: Option>, unlock_conditions: Vec, features: Option>, - params: impl Into> + Send, ) -> Result { - let params = params.into(); let mut builder = match amount { OutputBuilderAmount::Amount(amount) => BasicOutputBuilder::new_with_amount(amount), OutputBuilderAmount::MinimumAmount(params) => BasicOutputBuilder::new_with_minimum_amount(params), @@ -504,8 +497,8 @@ pub(crate) mod dto { let unlock_conditions = unlock_conditions .into_iter() - .map(|u| UnlockCondition::try_from_dto_with_params(u, ¶ms)) - .collect::, Error>>()?; + .map(UnlockCondition::from) + .collect::>(); builder = builder.with_unlock_conditions(unlock_conditions); if let Some(features) = features { @@ -552,7 +545,6 @@ mod tests { Some(output.native_tokens().to_vec()), output.unlock_conditions().iter().map(Into::into).collect(), Some(output.features().to_vec()), - protocol_parameters.token_supply(), ) .unwrap(); assert_eq!(output, output_split); @@ -567,7 +559,6 @@ mod tests { Some(builder.native_tokens.iter().copied().collect()), builder.unlock_conditions.iter().map(Into::into).collect(), Some(builder.features.iter().cloned().collect()), - protocol_parameters.token_supply(), ) .unwrap(); assert_eq!(builder.finish().unwrap(), output_split); diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index b4683aa063..cb512d2b06 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -439,7 +439,7 @@ pub(crate) mod dto { output::{unlock_condition::dto::UnlockConditionDto, OutputBuilderAmount}, Error, }, - TryFromDto, ValidationParams, + TryFromDto, }, utils::serde::string, }; @@ -481,7 +481,7 @@ pub(crate) mod dto { fn try_from_dto_with_params_inner( dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + _params: crate::types::ValidationParams<'_>, ) -> Result { let mut builder = DelegationOutputBuilder::new_with_amount( dto.amount, @@ -493,7 +493,7 @@ pub(crate) mod dto { .with_end_epoch(dto.end_epoch); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::from(u)); } builder.finish() @@ -510,9 +510,7 @@ pub(crate) mod dto { start_epoch: impl Into, end_epoch: impl Into, unlock_conditions: Vec, - params: impl Into> + Send, ) -> Result { - let params = params.into(); let mut builder = match amount { OutputBuilderAmount::Amount(amount) => DelegationOutputBuilder::new_with_amount( amount, @@ -532,8 +530,8 @@ pub(crate) mod dto { let unlock_conditions = unlock_conditions .into_iter() - .map(|u| UnlockCondition::try_from_dto_with_params(u, ¶ms)) - .collect::, Error>>()?; + .map(UnlockCondition::from) + .collect::>(); builder = builder.with_unlock_conditions(unlock_conditions); builder.finish() diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index cc4f9b59d9..b69eb9d480 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -718,7 +718,7 @@ pub(crate) mod dto { type Dto = FoundryOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result { let mut builder = FoundryOutputBuilder::new_with_amount(dto.amount, dto.serial_number, dto.token_scheme); for t in dto.native_tokens { @@ -734,7 +734,7 @@ pub(crate) mod dto { } for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::from(u)); } builder.finish() @@ -751,10 +751,7 @@ pub(crate) mod dto { unlock_conditions: Vec, features: Option>, immutable_features: Option>, - params: impl Into> + Send, ) -> Result { - let params = params.into(); - let mut builder = match amount { OutputBuilderAmount::Amount(amount) => { FoundryOutputBuilder::new_with_amount(amount, serial_number, token_scheme) @@ -770,8 +767,8 @@ pub(crate) mod dto { let unlock_conditions = unlock_conditions .into_iter() - .map(|u| UnlockCondition::try_from_dto_with_params(u, ¶ms)) - .collect::, Error>>()?; + .map(UnlockCondition::from) + .collect::>(); builder = builder.with_unlock_conditions(unlock_conditions); if let Some(features) = features { @@ -831,7 +828,6 @@ mod tests { builder.unlock_conditions.iter().map(Into::into).collect(), Some(builder.features.iter().cloned().collect()), Some(builder.immutable_features.iter().cloned().collect()), - protocol_parameters.clone(), ) .unwrap(); assert_eq!(builder.finish().unwrap(), output_split); diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 53095f9ee5..e948c51a8b 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -448,17 +448,17 @@ impl StorageScore for Output { impl MinimumOutputAmount for Output {} -pub(crate) fn verify_output_amount_supply(amount: u64, token_supply: u64) -> Result<(), Error> { - if amount > token_supply { - Err(Error::InvalidOutputAmount(amount)) - } else { - Ok(()) - } -} - -pub(crate) fn verify_output_amount(amount: u64, token_supply: u64) -> Result<(), Error> { - verify_output_amount_supply(amount, token_supply) -} +// pub(crate) fn verify_output_amount_supply(amount: u64, token_supply: u64) -> Result<(), Error> { +// if amount > token_supply { +// Err(Error::InvalidOutputAmount(amount)) +// } else { +// Ok(()) +// } +// } + +// pub(crate) fn verify_output_amount(amount: u64, token_supply: u64) -> Result<(), Error> { +// verify_output_amount_supply(amount, token_supply) +// } /// A trait that is shared by all output types, which is used to calculate the minimum amount the output /// must contain to satisfy its storage cost. diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 11b758d456..4b1b3fe19c 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -225,7 +225,6 @@ impl NftOutputBuilder { mut self, return_address: impl Into
, params: StorageScoreParameters, - token_supply: u64, ) -> Result { Ok(match self.amount { OutputBuilderAmount::Amount(amount) => { @@ -240,11 +239,8 @@ impl NftOutputBuilder { .finish()? .amount(); // Add a temporary storage deposit unlock condition so the new storage requirement can be calculated - self = self.add_unlock_condition(StorageDepositReturnUnlockCondition::new( - return_address.clone(), - 1, - token_supply, - )?); + self = + self.add_unlock_condition(StorageDepositReturnUnlockCondition::new(return_address.clone(), 1)); // Get the min amount of the output with the added storage deposit return unlock condition let min_amount_with_sdruc = self.clone().finish()?.minimum_amount(params); // If the return storage cost and amount are less than the required min @@ -261,8 +257,7 @@ impl NftOutputBuilder { .replace_unlock_condition(StorageDepositReturnUnlockCondition::new( return_address, sdruc_amount, - token_supply, - )?) + )) } else { self } @@ -642,7 +637,7 @@ pub(crate) mod dto { type Dto = NftOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result { let mut builder = NftOutputBuilder::new_with_amount(dto.amount, dto.nft_id) .with_mana(dto.mana) .with_native_tokens(dto.native_tokens) @@ -650,7 +645,7 @@ pub(crate) mod dto { .with_immutable_features(dto.immutable_features); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::from(u)); } builder.finish() @@ -667,9 +662,7 @@ pub(crate) mod dto { unlock_conditions: Vec, features: Option>, immutable_features: Option>, - params: impl Into> + Send, ) -> Result { - let params = params.into(); let mut builder = match amount { OutputBuilderAmount::Amount(amount) => NftOutputBuilder::new_with_amount(amount, *nft_id), OutputBuilderAmount::MinimumAmount(params) => { @@ -684,8 +677,8 @@ pub(crate) mod dto { let unlock_conditions = unlock_conditions .into_iter() - .map(|u| UnlockCondition::try_from_dto_with_params(u, ¶ms)) - .collect::, Error>>()?; + .map(UnlockCondition::from) + .collect::>(); builder = builder.with_unlock_conditions(unlock_conditions); if let Some(features) = features { @@ -740,7 +733,6 @@ mod tests { output.unlock_conditions().iter().map(Into::into).collect(), Some(output.features().to_vec()), Some(output.immutable_features().to_vec()), - &protocol_parameters, ) .unwrap(); assert_eq!(output, output_split); @@ -754,7 +746,6 @@ mod tests { builder.unlock_conditions.iter().map(Into::into).collect(), Some(builder.features.iter().cloned().collect()), Some(builder.immutable_features.iter().cloned().collect()), - &protocol_parameters, ) .unwrap(); assert_eq!(builder.finish().unwrap(), output_split); diff --git a/sdk/src/types/block/output/unlock_condition/mod.rs b/sdk/src/types/block/output/unlock_condition/mod.rs index 6a6c9688f2..6c5d9becfc 100644 --- a/sdk/src/types/block/output/unlock_condition/mod.rs +++ b/sdk/src/types/block/output/unlock_condition/mod.rs @@ -436,9 +436,7 @@ mod test { pub mod dto { use serde::{Deserialize, Serialize}; - pub use self::storage_deposit_return::dto::StorageDepositReturnUnlockConditionDto; use super::*; - use crate::types::{block::Error, TryFromDto, ValidationParams}; #[derive(Clone, Debug, Eq, PartialEq, From, Serialize, Deserialize)] #[serde(untagged)] @@ -446,7 +444,7 @@ pub mod dto { /// An address unlock condition. Address(AddressUnlockCondition), /// A storage deposit return unlock condition. - StorageDepositReturn(StorageDepositReturnUnlockConditionDto), + StorageDepositReturn(StorageDepositReturnUnlockCondition), /// A timelock unlock condition. Timelock(TimelockUnlockCondition), /// An expiration unlock condition. @@ -463,7 +461,7 @@ pub mod dto { fn from(value: &UnlockCondition) -> Self { match value { UnlockCondition::Address(v) => Self::Address(v.clone()), - UnlockCondition::StorageDepositReturn(v) => Self::StorageDepositReturn(v.into()), + UnlockCondition::StorageDepositReturn(v) => Self::StorageDepositReturn(v.clone()), UnlockCondition::Timelock(v) => Self::Timelock(*v), UnlockCondition::Expiration(v) => Self::Expiration(v.clone()), UnlockCondition::StateControllerAddress(v) => Self::StateControllerAddress(v.clone()), @@ -473,22 +471,17 @@ pub mod dto { } } - impl TryFromDto for UnlockCondition { - type Dto = UnlockConditionDto; - type Error = Error; - - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { - Ok(match dto { + impl From for UnlockCondition { + fn from(dto: UnlockConditionDto) -> Self { + match dto { UnlockConditionDto::Address(v) => Self::Address(v), - UnlockConditionDto::StorageDepositReturn(v) => Self::StorageDepositReturn( - StorageDepositReturnUnlockCondition::try_from_dto_with_params_inner(v, params)?, - ), + UnlockConditionDto::StorageDepositReturn(v) => Self::StorageDepositReturn(v), UnlockConditionDto::Timelock(v) => Self::Timelock(v), UnlockConditionDto::Expiration(v) => Self::Expiration(v), UnlockConditionDto::StateControllerAddress(v) => Self::StateControllerAddress(v), UnlockConditionDto::GovernorAddress(v) => Self::GovernorAddress(v), UnlockConditionDto::ImmutableAccountAddress(v) => Self::ImmutableAccountAddress(v), - }) + } } } diff --git a/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs b/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs index fb937a0e05..6824e728ec 100644 --- a/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs +++ b/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs @@ -3,12 +3,8 @@ use crate::types::block::{ address::Address, - output::{ - storage_score::{StorageScore, StorageScoreParameters}, - verify_output_amount, - }, + output::storage_score::{StorageScore, StorageScoreParameters}, protocol::ProtocolParameters, - Error, }; /// Defines the amount of IOTAs used as storage deposit that have to be returned to the return [`Address`]. @@ -18,7 +14,6 @@ pub struct StorageDepositReturnUnlockCondition { // The [`Address`] to return the amount to. return_address: Address, // Amount of IOTA coins the consuming transaction should deposit to `return_address`. - #[packable(verify_with = verify_amount_packable)] amount: u64, } @@ -29,13 +24,11 @@ impl StorageDepositReturnUnlockCondition { /// Creates a new [`StorageDepositReturnUnlockCondition`]. #[inline(always)] - pub fn new(return_address: impl Into
, amount: u64, token_supply: u64) -> Result { - verify_amount::(amount, token_supply)?; - - Ok(Self { + pub fn new(return_address: impl Into
, amount: u64) -> Self { + Self { return_address: return_address.into(), amount, - }) + } } /// Returns the return address. @@ -57,32 +50,14 @@ impl StorageScore for StorageDepositReturnUnlockCondition { } } -fn verify_amount(amount: u64, token_supply: u64) -> Result<(), Error> { - if VERIFY { - verify_output_amount(amount, token_supply).map_err(|_| Error::InvalidStorageDepositAmount(amount))?; - } - - Ok(()) -} - -fn verify_amount_packable( - amount: &u64, - protocol_parameters: &ProtocolParameters, -) -> Result<(), Error> { - verify_amount::(*amount, protocol_parameters.token_supply()) -} - #[cfg(feature = "serde")] -pub(crate) mod dto { +mod dto { use alloc::format; use serde::{Deserialize, Serialize}; use super::*; - use crate::{ - types::{block::Error, TryFromDto, ValidationParams}, - utils::serde::string, - }; + use crate::utils::serde::string; #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -119,28 +94,18 @@ pub(crate) mod dto { } } - impl TryFromDto for StorageDepositReturnUnlockCondition { - type Dto = StorageDepositReturnUnlockConditionDto; - type Error = Error; - - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { - Ok(if let Some(token_supply) = params.token_supply() { - Self::new(dto.return_address, dto.amount, token_supply)? - } else { - Self { - return_address: dto.return_address, - amount: dto.amount, - } - }) + impl From for StorageDepositReturnUnlockCondition { + fn from(dto: StorageDepositReturnUnlockConditionDto) -> Self { + Self { + return_address: dto.return_address, + amount: dto.amount, + } } } - impl Serialize for StorageDepositReturnUnlockCondition { - fn serialize(&self, s: S) -> Result - where - S: serde::Serializer, - { - StorageDepositReturnUnlockConditionDto::from(self).serialize(s) - } - } + crate::impl_serde_typed_dto!( + StorageDepositReturnUnlockCondition, + StorageDepositReturnUnlockConditionDto, + "storage deposit return unlock condition" + ); } diff --git a/sdk/src/wallet/operations/transaction/high_level/send.rs b/sdk/src/wallet/operations/transaction/high_level/send.rs index 6c43bcd0e7..accd247f79 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send.rs @@ -137,7 +137,6 @@ where log::debug!("[TRANSACTION] prepare_send"); let options = options.into(); let storage_score_params = self.client().get_storage_score_parameters().await?; - let token_supply = self.client().get_token_supply().await?; let wallet_address = self.address().await; @@ -186,7 +185,7 @@ where return_address.clone(), expiration_slot_index, )?) - .with_sufficient_storage_deposit(return_address, storage_score_params, token_supply)? + .with_sufficient_storage_deposit(return_address, storage_score_params)? .finish_output()?; if !options.as_ref().map(|o| o.allow_micro_amount).unwrap_or_default() { diff --git a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs index 67fac19420..a3dbc318b4 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs @@ -128,7 +128,6 @@ where { log::debug!("[TRANSACTION] prepare_send_native_tokens"); let storage_score_params = self.client().get_storage_score_parameters().await?; - let token_supply = self.client().get_token_supply().await?; let wallet_address = self.address().await; let default_return_address = wallet_address.to_bech32(self.client().get_bech32_hrp().await?); @@ -179,7 +178,7 @@ where return_address.clone(), expiration_slot_index, )?) - .with_sufficient_storage_deposit(return_address, storage_score_params, token_supply)? + .with_sufficient_storage_deposit(return_address, storage_score_params)? .finish_output()?, ) } diff --git a/sdk/src/wallet/operations/transaction/prepare_output.rs b/sdk/src/wallet/operations/transaction/prepare_output.rs index ae9e822e7d..afc93d3c2f 100644 --- a/sdk/src/wallet/operations/transaction/prepare_output.rs +++ b/sdk/src/wallet/operations/transaction/prepare_output.rs @@ -45,7 +45,6 @@ where ) -> crate::wallet::Result { log::debug!("[OUTPUT] prepare_output {params:?}"); let transaction_options = transaction_options.into(); - let token_supply = self.client().get_token_supply().await?; self.client().bech32_hrp_matches(params.recipient_address.hrp()).await?; @@ -141,8 +140,7 @@ where remainder_address.clone(), // Return minimum amount min_amount_basic_output, - token_supply, - )?); + )); // Update output amount, so recipient still gets the provided amount let new_amount = params.amount + min_amount_basic_output; @@ -163,8 +161,7 @@ where remainder_address.clone(), // Return minimum amount min_amount_basic_output + additional_required_amount, - token_supply, - )?); + )); } else { // new_amount is enough second_output_builder = second_output_builder.with_amount(new_amount); @@ -219,8 +216,7 @@ where remainder_address, // Return minimum amount new_sdr_amount, - token_supply, - )?); + )); } } else { // Would leave dust behind, so return what's required for a remainder diff --git a/sdk/tests/client/mod.rs b/sdk/tests/client/mod.rs index 4d8db30740..d01b8a394c 100644 --- a/sdk/tests/client/mod.rs +++ b/sdk/tests/client/mod.rs @@ -39,7 +39,6 @@ use iota_sdk::{ }, }; -const TOKEN_SUPPLY: u64 = 1_813_620_509_061_365; const ACCOUNT_ID_0: &str = "0x0000000000000000000000000000000000000000000000000000000000000000"; const ACCOUNT_ID_1: &str = "0x1111111111111111111111111111111111111111111111111111111111111111"; const ACCOUNT_ID_2: &str = "0x2222222222222222222222222222222222222222222222222222222222222222"; @@ -119,8 +118,7 @@ fn build_basic_output( } if let Some((address, amount)) = sdruc { - builder = builder - .add_unlock_condition(StorageDepositReturnUnlockCondition::new(address, amount, TOKEN_SUPPLY).unwrap()); + builder = builder.add_unlock_condition(StorageDepositReturnUnlockCondition::new(address, amount)); } if let Some(timelock) = timelock { @@ -165,8 +163,7 @@ fn build_nft_output( } if let Some((address, amount)) = sdruc { - builder = builder - .add_unlock_condition(StorageDepositReturnUnlockCondition::new(address, amount, TOKEN_SUPPLY).unwrap()); + builder = builder.add_unlock_condition(StorageDepositReturnUnlockCondition::new(address, amount)); } if let Some((address, timestamp)) = expiration {