Skip to content

Commit

Permalink
Remove verify_output_amount_packable
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 15, 2023
1 parent 1474064 commit 14819c6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 37 deletions.
7 changes: 2 additions & 5 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use crate::types::block::{
output::{
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions},
verify_output_amount_packable, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output,
OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore,
StorageScoreParameters,
ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId,
StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters,
},
payload::signed_transaction::TransactionCapabilityFlag,
protocol::ProtocolParameters,
Expand Down Expand Up @@ -555,8 +554,6 @@ impl Packable for AccountOutput {
) -> Result<Self, UnpackError<Self::UnpackError, U::Error>> {
let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

verify_output_amount_packable::<VERIFY>(&amount, visitor).map_err(UnpackError::Packable)?;

let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?;
Expand Down
7 changes: 2 additions & 5 deletions sdk/src/types/block/output/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use crate::types::block::{
output::{
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions},
verify_output_amount_packable, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output,
OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore,
StorageScoreParameters,
ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId,
StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters,
},
payload::signed_transaction::TransactionCapabilityFlag,
protocol::ProtocolParameters,
Expand Down Expand Up @@ -622,8 +621,6 @@ impl Packable for AnchorOutput {
) -> Result<Self, UnpackError<Self::UnpackError, U::Error>> {
let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

verify_output_amount_packable::<VERIFY>(&amount, visitor).map_err(UnpackError::Packable)?;

let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?;
Expand Down
7 changes: 3 additions & 4 deletions sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::types::block::{
verify_allowed_unlock_conditions, AddressUnlockCondition, StorageDepositReturnUnlockCondition,
UnlockCondition, UnlockConditionFlags, UnlockConditions,
},
verify_output_amount_packable, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount,
OutputId, StorageScore, StorageScoreParameters,
MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId, StorageScore,
StorageScoreParameters,
},
protocol::ProtocolParameters,
semantic::{SemanticValidationContext, TransactionFailureReason},
Expand Down Expand Up @@ -252,7 +252,6 @@ impl From<&BasicOutput> for BasicOutputBuilder {
#[packable(unpack_visitor = ProtocolParameters)]
pub struct BasicOutput {
/// Amount of IOTA coins to deposit with this output.
#[packable(verify_with = verify_output_amount_packable)]
amount: u64,
/// Amount of stored Mana held by this output.
mana: u64,
Expand All @@ -261,8 +260,8 @@ pub struct BasicOutput {
/// Define how the output can be unlocked in a transaction.
#[packable(verify_with = verify_unlock_conditions_packable)]
unlock_conditions: UnlockConditions,
#[packable(verify_with = verify_features_packable)]
/// Features of the output.
#[packable(verify_with = verify_features_packable)]
features: Features,
}

Expand Down
5 changes: 2 additions & 3 deletions sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::types::block::{
output::{
chain_id::ChainId,
unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions},
verify_output_amount_packable, MinimumOutputAmount, Output, OutputBuilderAmount, OutputId,
StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters,
MinimumOutputAmount, Output, OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier,
StorageScore, StorageScoreParameters,
},
protocol::ProtocolParameters,
semantic::{SemanticValidationContext, TransactionFailureReason},
Expand Down Expand Up @@ -217,7 +217,6 @@ impl From<&DelegationOutput> for DelegationOutputBuilder {
#[packable(unpack_visitor = ProtocolParameters)]
pub struct DelegationOutput {
/// Amount of IOTA coins to deposit with this output.
#[packable(verify_with = verify_output_amount_packable)]
amount: u64,
/// Amount of delegated IOTA coins.
delegated_amount: u64,
Expand Down
7 changes: 2 additions & 5 deletions sdk/src/types/block/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use crate::types::block::{
account::AccountId,
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions},
verify_output_amount_packable, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output,
OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore,
StorageScoreParameters, TokenId, TokenScheme,
ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId,
StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters, TokenId, TokenScheme,
},
payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag},
protocol::ProtocolParameters,
Expand Down Expand Up @@ -624,8 +623,6 @@ impl Packable for FoundryOutput {
) -> Result<Self, UnpackError<Self::UnpackError, U::Error>> {
let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

verify_output_amount_packable::<VERIFY>(&amount, visitor).map_err(UnpackError::Packable)?;

let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?;
let serial_number = u32::unpack::<_, VERIFY>(unpacker, &()).coerce()?;
let token_scheme = TokenScheme::unpack::<_, VERIFY>(unpacker, &())?;
Expand Down
10 changes: 0 additions & 10 deletions sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,6 @@ pub(crate) fn verify_output_amount(amount: u64, token_supply: u64) -> Result<(),
verify_output_amount_supply(amount, token_supply)
}

pub(crate) fn verify_output_amount_packable<const VERIFY: bool>(
amount: &u64,
protocol_parameters: &ProtocolParameters,
) -> Result<(), Error> {
if VERIFY {
verify_output_amount(*amount, protocol_parameters.token_supply())?;
}
Ok(())
}

/// 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.
pub trait MinimumOutputAmount: StorageScore {
Expand Down
7 changes: 2 additions & 5 deletions sdk/src/types/block/output/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use crate::types::block::{
verify_allowed_unlock_conditions, AddressUnlockCondition, StorageDepositReturnUnlockCondition,
UnlockCondition, UnlockConditionFlags, UnlockConditions,
},
verify_output_amount_packable, BasicOutputBuilder, ChainId, MinimumOutputAmount, NativeToken, NativeTokens,
Output, OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore,
StorageScoreParameters,
BasicOutputBuilder, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount,
OutputId, StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters,
},
payload::signed_transaction::TransactionCapabilityFlag,
protocol::ProtocolParameters,
Expand Down Expand Up @@ -541,8 +540,6 @@ impl Packable for NftOutput {
) -> Result<Self, UnpackError<Self::UnpackError, U::Error>> {
let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

verify_output_amount_packable::<VERIFY>(&amount, visitor).map_err(UnpackError::Packable)?;

let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?;
Expand Down

0 comments on commit 14819c6

Please sign in to comment.