Skip to content

Commit

Permalink
Remove SDRUC supply check
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 15, 2023
1 parent 010d70a commit 6884d91
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 180 deletions.
4 changes: 0 additions & 4 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down
16 changes: 2 additions & 14 deletions sdk/examples/client/output/build_basic_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! ```

use iota_sdk::{
client::{Client, Result},
client::Result,
types::block::{
address::Address,
output::{
Expand All @@ -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());
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions sdk/examples/how_tos/outputs/unlock_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Error> {
fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result<Self, Self::Error> {
let mut builder = AccountOutputBuilder::new_with_amount(dto.amount, dto.account_id)
.with_mana(dto.mana)
.with_foundry_counter(dto.foundry_counter)
Expand All @@ -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, &params)?);
builder = builder.add_unlock_condition(UnlockCondition::from(u));
}

builder.finish()
Expand All @@ -703,9 +703,7 @@ pub(crate) mod dto {
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
immutable_features: Option<Vec<Feature>>,
params: impl Into<ValidationParams<'a>> + Send,
) -> Result<Self, Error> {
let params = params.into();
let mut builder = match amount {
OutputBuilderAmount::Amount(amount) => AccountOutputBuilder::new_with_amount(amount, *account_id),
OutputBuilderAmount::MinimumAmount(params) => {
Expand All @@ -724,8 +722,8 @@ pub(crate) mod dto {

let unlock_conditions = unlock_conditions
.into_iter()
.map(|u| UnlockCondition::try_from_dto_with_params(u, &params))
.collect::<Result<Vec<UnlockCondition>, Error>>()?;
.map(UnlockCondition::from)
.collect::<Vec<UnlockCondition>>();
builder = builder.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions sdk/src/types/block/output/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Error> {
fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result<Self, Self::Error> {
let mut builder = AnchorOutputBuilder::new_with_amount(dto.amount, dto.anchor_id)
.with_mana(dto.mana)
.with_state_index(dto.state_index)
Expand All @@ -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, &params)?);
builder = builder.add_unlock_condition(UnlockCondition::from(u));
}

builder.finish()
Expand All @@ -787,9 +787,7 @@ pub(crate) mod dto {
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
immutable_features: Option<Vec<Feature>>,
params: impl Into<ValidationParams<'a>> + Send,
) -> Result<Self, Error> {
let params = params.into();
let mut builder = match amount {
OutputBuilderAmount::Amount(amount) => AnchorOutputBuilder::new_with_amount(amount, *anchor_id),
OutputBuilderAmount::MinimumAmount(params) => {
Expand All @@ -809,8 +807,8 @@ pub(crate) mod dto {

let unlock_conditions = unlock_conditions
.into_iter()
.map(|u| UnlockCondition::try_from_dto_with_params(u, &params))
.collect::<Result<Vec<UnlockCondition>, Error>>()?;
.map(UnlockCondition::from)
.collect::<Vec<UnlockCondition>>();
builder = builder.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
23 changes: 7 additions & 16 deletions sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ impl BasicOutputBuilder {
mut self,
return_address: impl Into<Address>,
params: StorageScoreParameters,
token_supply: u64,
) -> Result<Self, Error> {
Ok(match self.amount {
OutputBuilderAmount::Amount(amount) => {
Expand All @@ -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
Expand All @@ -192,8 +188,7 @@ impl BasicOutputBuilder {
.replace_unlock_condition(StorageDepositReturnUnlockCondition::new(
return_address,
sdruc_amount,
token_supply,
)?)
))
} else {
self
}
Expand Down Expand Up @@ -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<Self, Self::Error> {
fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result<Self, Self::Error> {
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, &params)?);
builder = builder.add_unlock_condition(UnlockCondition::from(u));
}

builder.finish()
Expand All @@ -489,9 +484,7 @@ pub(crate) mod dto {
native_tokens: Option<Vec<NativeToken>>,
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
params: impl Into<ValidationParams<'a>> + Send,
) -> Result<Self, Error> {
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),
Expand All @@ -504,8 +497,8 @@ pub(crate) mod dto {

let unlock_conditions = unlock_conditions
.into_iter()
.map(|u| UnlockCondition::try_from_dto_with_params(u, &params))
.collect::<Result<Vec<UnlockCondition>, Error>>()?;
.map(UnlockCondition::from)
.collect::<Vec<UnlockCondition>>();
builder = builder.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ pub(crate) mod dto {
output::{unlock_condition::dto::UnlockConditionDto, OutputBuilderAmount},
Error,
},
TryFromDto, ValidationParams,
TryFromDto,
},
utils::serde::string,
};
Expand Down Expand Up @@ -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<Self, Self::Error> {
let mut builder = DelegationOutputBuilder::new_with_amount(
dto.amount,
Expand All @@ -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, &params)?);
builder = builder.add_unlock_condition(UnlockCondition::from(u));
}

builder.finish()
Expand All @@ -510,9 +510,7 @@ pub(crate) mod dto {
start_epoch: impl Into<EpochIndex>,
end_epoch: impl Into<EpochIndex>,
unlock_conditions: Vec<UnlockConditionDto>,
params: impl Into<ValidationParams<'a>> + Send,
) -> Result<Self, Error> {
let params = params.into();
let mut builder = match amount {
OutputBuilderAmount::Amount(amount) => DelegationOutputBuilder::new_with_amount(
amount,
Expand All @@ -532,8 +530,8 @@ pub(crate) mod dto {

let unlock_conditions = unlock_conditions
.into_iter()
.map(|u| UnlockCondition::try_from_dto_with_params(u, &params))
.collect::<Result<Vec<UnlockCondition>, Error>>()?;
.map(UnlockCondition::from)
.collect::<Vec<UnlockCondition>>();
builder = builder.with_unlock_conditions(unlock_conditions);

builder.finish()
Expand Down
12 changes: 4 additions & 8 deletions sdk/src/types/block/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Error> {
fn try_from_dto_with_params_inner(dto: Self::Dto, _params: ValidationParams<'_>) -> Result<Self, Self::Error> {
let mut builder = FoundryOutputBuilder::new_with_amount(dto.amount, dto.serial_number, dto.token_scheme);

for t in dto.native_tokens {
Expand All @@ -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, &params)?);
builder = builder.add_unlock_condition(UnlockCondition::from(u));
}

builder.finish()
Expand All @@ -751,10 +751,7 @@ pub(crate) mod dto {
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
immutable_features: Option<Vec<Feature>>,
params: impl Into<ValidationParams<'a>> + Send,
) -> Result<Self, Error> {
let params = params.into();

let mut builder = match amount {
OutputBuilderAmount::Amount(amount) => {
FoundryOutputBuilder::new_with_amount(amount, serial_number, token_scheme)
Expand All @@ -770,8 +767,8 @@ pub(crate) mod dto {

let unlock_conditions = unlock_conditions
.into_iter()
.map(|u| UnlockCondition::try_from_dto_with_params(u, &params))
.collect::<Result<Vec<UnlockCondition>, Error>>()?;
.map(UnlockCondition::from)
.collect::<Vec<UnlockCondition>>();
builder = builder.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 6884d91

Please sign in to comment.