Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(types): vbyte -> storage score #1398

Closed
wants to merge 12 commits into from
5 changes: 3 additions & 2 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use iota_sdk::{
api::core::response::OutputWithMetadataResponse,
block::{
output::{
dto::OutputDto, AccountOutput, BasicOutput, FoundryOutput, NftOutput, Output, OutputBuilderAmount, Rent,
dto::OutputDto, AccountOutput, BasicOutput, FoundryOutput, NftOutput, Output, OutputBuilderAmount,
StorageScore,
},
payload::Payload,
BlockWrapper, BlockWrapperDto,
Expand Down Expand Up @@ -297,7 +298,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
let output = Output::try_from_dto_with_params(output, client.get_token_supply().await?)?;
let rent_structure = client.get_rent_structure().await?;

let minimum_storage_deposit = output.rent_cost(rent_structure);
let minimum_storage_deposit = output.storage_score(rent_structure);

Response::MinimumRequiredStorageDeposit(minimum_storage_deposit.to_string())
}
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iota_sdk::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
input::UtxoInput,
output::{AccountId, FoundryId, InputsCommitment, NftId, Output, OutputId, Rent, TokenId},
output::{AccountId, FoundryId, InputsCommitment, NftId, Output, OutputId, StorageScore, TokenId},
payload::{transaction::TransactionEssence, TransactionPayload},
BlockWrapper,
},
Expand Down Expand Up @@ -80,7 +80,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
}
UtilsMethod::ComputeStorageDeposit { output, rent } => {
let out = Output::try_from_dto(output)?;
Response::MinimumRequiredStorageDeposit(out.rent_cost(rent).to_string())
Response::MinimumRequiredStorageDeposit(out.storage_score(rent).to_string())
}
UtilsMethod::VerifyMnemonic { mnemonic } => {
let mnemonic = Mnemonic::from(mnemonic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
input::INPUT_COUNT_MAX,
output::{
unlock_condition::StorageDepositReturnUnlockCondition, AccountOutputBuilder, AccountTransition,
FoundryOutputBuilder, NftOutputBuilder, Output, OutputId, Rent,
FoundryOutputBuilder, NftOutputBuilder, Output, OutputId, StorageScore,
},
slot::SlotIndex,
},
Expand Down Expand Up @@ -240,7 +240,7 @@ impl InputSelection {
for output in outputs {
let diff = amount_selection.missing_amount();
let amount = output.amount();
let rent = output.rent_cost(self.protocol_parameters.rent_structure());
let rent = output.storage_score(self.protocol_parameters.rent_structure());

let new_amount = if amount >= diff + rent { amount - diff } else { rent };

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::types::{
verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions,
},
verify_output_amount_min, verify_output_amount_packable, verify_output_amount_supply, ChainId, NativeToken,
NativeTokens, Output, OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError,
StateTransitionVerifier,
NativeTokens, Output, OutputBuilderAmount, OutputId, RentStructure, StateTransitionError,
StateTransitionVerifier, StorageScore,
},
protocol::ProtocolParameters,
semantic::{TransactionFailureReason, ValidationContext},
Expand Down Expand Up @@ -319,7 +319,7 @@ impl AccountOutputBuilder {
output.amount = match self.amount {
OutputBuilderAmount::Amount(amount) => amount,
OutputBuilderAmount::MinimumStorageDeposit(rent_structure) => {
Output::Account(output.clone()).rent_cost(rent_structure)
Output::Account(output.clone()).storage_score(rent_structure)
}
};

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::types::{
verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions,
},
verify_output_amount_min, verify_output_amount_packable, verify_output_amount_supply, NativeToken,
NativeTokens, Output, OutputBuilderAmount, OutputId, Rent, RentStructure,
NativeTokens, Output, OutputBuilderAmount, OutputId, RentStructure, StorageScore,
},
protocol::ProtocolParameters,
semantic::{TransactionFailureReason, ValidationContext},
Expand Down Expand Up @@ -172,7 +172,7 @@ impl BasicOutputBuilder {
output.amount = match self.amount {
OutputBuilderAmount::Amount(amount) => amount,
OutputBuilderAmount::MinimumStorageDeposit(rent_structure) => {
Output::Basic(output.clone()).rent_cost(rent_structure)
Output::Basic(output.clone()).storage_score(rent_structure)
}
};

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::types::{
verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions,
},
verify_output_amount_min, verify_output_amount_packable, verify_output_amount_supply, Output,
OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier,
OutputBuilderAmount, OutputId, RentStructure, StateTransitionError, StateTransitionVerifier, StorageScore,
},
protocol::ProtocolParameters,
semantic::{TransactionFailureReason, ValidationContext},
Expand Down Expand Up @@ -195,7 +195,7 @@ impl DelegationOutputBuilder {
output.amount = match self.amount {
OutputBuilderAmount::Amount(amount) => amount,
OutputBuilderAmount::MinimumStorageDeposit(rent_structure) => {
Output::Delegation(output.clone()).rent_cost(rent_structure)
Output::Delegation(output.clone()).storage_score(rent_structure)
}
};

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::types::{
verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions,
},
verify_output_amount_min, verify_output_amount_packable, verify_output_amount_supply, ChainId, NativeToken,
NativeTokens, Output, OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError,
StateTransitionVerifier, TokenId, TokenScheme,
NativeTokens, Output, OutputBuilderAmount, OutputId, RentStructure, StateTransitionError,
StateTransitionVerifier, StorageScore, TokenId, TokenScheme,
},
protocol::ProtocolParameters,
semantic::{TransactionFailureReason, ValidationContext},
Expand Down Expand Up @@ -283,7 +283,7 @@ impl FoundryOutputBuilder {
output.amount = match self.amount {
OutputBuilderAmount::Amount(amount) => amount,
OutputBuilderAmount::MinimumStorageDeposit(rent_structure) => {
Output::Foundry(output.clone()).rent_cost(rent_structure)
Output::Foundry(output.clone()).storage_score(rent_structure)
}
};

Expand Down
8 changes: 4 additions & 4 deletions sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub use self::{
native_token::{NativeToken, NativeTokens, NativeTokensBuilder, TokenId},
nft::{NftId, NftOutput, NftOutputBuilder},
output_id::OutputId,
rent::{MinimumStorageDepositBasicOutput, Rent, RentStructure},
rent::{MinimumStorageDepositBasicOutput, RentStructure, StorageScore},
state_transition::{StateTransitionError, StateTransitionVerifier},
token_scheme::{SimpleTokenScheme, TokenScheme},
unlock_condition::{UnlockCondition, UnlockConditions},
Expand Down Expand Up @@ -384,7 +384,7 @@ impl Output {
/// If there is a [`StorageDepositReturnUnlockCondition`](unlock_condition::StorageDepositReturnUnlockCondition),
/// its amount is also checked.
pub fn verify_storage_deposit(&self, rent_structure: RentStructure, token_supply: u64) -> Result<(), Error> {
let required_output_amount = self.rent_cost(rent_structure);
let required_output_amount = self.storage_score(rent_structure);

if self.amount() < required_output_amount {
return Err(Error::InsufficientStorageDepositAmount {
Expand Down Expand Up @@ -468,9 +468,9 @@ impl Packable for Output {
}
}

impl Rent for Output {
impl StorageScore for Output {
fn weighted_bytes(&self, rent_structure: RentStructure) -> u64 {
self.packed_len() as u64 * rent_structure.byte_factor_data() as u64
self.packed_len() as u64 * rent_structure.storage_score_factor_data() as u64
}
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::types::{
verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions,
},
verify_output_amount_min, verify_output_amount_packable, verify_output_amount_supply, ChainId, NativeToken,
NativeTokens, Output, OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError,
StateTransitionVerifier,
NativeTokens, Output, OutputBuilderAmount, OutputId, RentStructure, StateTransitionError,
StateTransitionVerifier, StorageScore,
},
protocol::ProtocolParameters,
semantic::{TransactionFailureReason, ValidationContext},
Expand Down Expand Up @@ -244,7 +244,7 @@ impl NftOutputBuilder {
output.amount = match self.amount {
OutputBuilderAmount::Amount(amount) => amount,
OutputBuilderAmount::MinimumStorageDeposit(rent_structure) => {
Output::Nft(output.clone()).rent_cost(rent_structure)
Output::Nft(output.clone()).storage_score(rent_structure)
}
};

Expand Down
Loading
Loading