diff --git a/bindings/python/examples/client/05_get_address_balance.py b/bindings/python/examples/client/05_get_address_balance.py index be1745f320..d849fd69ea 100644 --- a/bindings/python/examples/client/05_get_address_balance.py +++ b/bindings/python/examples/client/05_get_address_balance.py @@ -2,7 +2,7 @@ from dotenv import load_dotenv -from iota_sdk import Client, NodeIndexerAPI +from iota_sdk import Client, NodeIndexerAPI, FeatureType load_dotenv() @@ -35,8 +35,10 @@ for output_with_metadata in outputs: output = output_with_metadata.output total_amount += output.amount - if output.native_tokens: - native_tokens.append(output.native_tokens) + native_token = [feature for feature in output.features if feature.type + == FeatureType.NativeToken] + if native_token: + native_tokens.append(native_token) print( f'Outputs controlled by {ADDRESS} have {total_amount} glow and native tokens: {native_tokens}') diff --git a/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py b/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py index 129a53de1e..6bf89a6d0c 100644 --- a/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py +++ b/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py @@ -2,7 +2,7 @@ from dotenv import load_dotenv -from iota_sdk import ConsolidationParams, Utils, Wallet +from iota_sdk import ConsolidationParams, Utils, Wallet, FeatureType # In this example we will consolidate basic outputs from an account with only an AddressUnlockCondition by sending # them to the same address again. @@ -38,7 +38,8 @@ '- address: {}\n- amount: {}\n- native tokens: {}'.format( Utils.hex_to_bech32(output_data.address.pub_key_hash, 'rms'), output_data.output.amount, - output_data.output.native_tokens + [feature for feature in output_data.output.features if feature.type + == FeatureType.NativeToken] ) ) @@ -71,6 +72,7 @@ '- address: {}\n- amount: {}\n- native tokens: {}'.format( Utils.hex_to_bech32(output_data.address.pub_key_hash, 'rms'), output_data.output.amount, - output_data.output.native_tokens + [feature for feature in output_data.output.features if feature.type + == FeatureType.NativeToken] ) ) diff --git a/bindings/python/iota_sdk/client/client.py b/bindings/python/iota_sdk/client/client.py index fbcd621509..06e38a42cc 100644 --- a/bindings/python/iota_sdk/client/client.py +++ b/bindings/python/iota_sdk/client/client.py @@ -14,7 +14,6 @@ from iota_sdk.types.block.signed_block import UnsignedBlock from iota_sdk.types.common import HexStr, Node from iota_sdk.types.feature import Feature -from iota_sdk.types.native_token import NativeToken from iota_sdk.types.network_info import NetworkInfo from iota_sdk.types.output import AccountOutput, BasicOutput, FoundryOutput, NftOutput, deserialize_output from iota_sdk.types.payload import Payload @@ -151,7 +150,6 @@ def build_account_output(self, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, mana: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, foundry_counter: Optional[int] = None, features: Optional[List[Feature]] = None, immutable_features: Optional[List[Feature]] = None) -> AccountOutput: @@ -162,7 +160,6 @@ def build_account_output(self, unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. mana: Amount of stored Mana held by this output. - native_tokens: Native tokens added to the new output. foundry_counter: A counter that denotes the number of foundries created by this account output. features: A list of features. immutable_features: A list of immutable features. @@ -174,10 +171,6 @@ def build_account_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.to_dict() - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] if immutable_features: @@ -195,7 +188,6 @@ def build_account_output(self, 'unlockConditions': unlock_conditions, 'amount': amount, 'mana': mana, - 'nativeTokens': native_tokens, 'foundryCounter': foundry_counter, 'features': features, 'immutableFeatures': immutable_features @@ -205,7 +197,6 @@ def build_basic_output(self, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, mana: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, features: Optional[List[Feature]] = None) -> BasicOutput: """Build a BasicOutput. @@ -213,7 +204,6 @@ def build_basic_output(self, unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. mana: Amount of stored Mana held by this output. - native_tokens: Native tokens added to the new output. features: Features that add utility to the output but do not impose unlocking conditions. Returns: @@ -223,10 +213,6 @@ def build_basic_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.to_dict() - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] @@ -240,7 +226,6 @@ def build_basic_output(self, 'unlockConditions': unlock_conditions, 'amount': amount, 'mana': mana, - 'nativeTokens': native_tokens, 'features': features, })) @@ -249,7 +234,6 @@ def build_foundry_output(self, token_scheme: SimpleTokenScheme, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, features: Optional[List[Feature]] = None, immutable_features: Optional[List[Feature]] = None) -> FoundryOutput: """Build a FoundryOutput. @@ -259,7 +243,6 @@ def build_foundry_output(self, token_scheme: Defines the supply control scheme of the tokens controlled by the foundry. Currently only a simple scheme is supported. unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. - native_tokens: Native tokens added to the new output. features: Features that add utility to the output but do not impose unlocking conditions. immutable_features: Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. @@ -270,10 +253,6 @@ def build_foundry_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.__dict__ - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] if immutable_features: @@ -288,7 +267,6 @@ def build_foundry_output(self, 'tokenScheme': token_scheme.to_dict(), 'unlockConditions': unlock_conditions, 'amount': amount, - 'nativeTokens': native_tokens, 'features': features, 'immutableFeatures': immutable_features })) @@ -298,7 +276,6 @@ def build_nft_output(self, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, mana: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, features: Optional[List[Feature]] = None, immutable_features: Optional[List[Feature]] = None) -> NftOutput: """Build an NftOutput. @@ -308,7 +285,6 @@ def build_nft_output(self, unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. mana: Amount of stored Mana held by this output. - native_tokens: Native tokens added to the new output. features: Features that add utility to the output but do not impose unlocking conditions. immutable_features: Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. @@ -319,10 +295,6 @@ def build_nft_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.__dict__ - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] if immutable_features: @@ -340,7 +312,6 @@ def build_nft_output(self, 'unlockConditions': unlock_conditions, 'amount': amount, 'mana': mana, - 'nativeTokens': native_tokens, 'features': features, 'immutableFeatures': immutable_features })) diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index 7b392f2ca1..cb4064f4ac 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -7,7 +7,7 @@ from dataclasses_json import config from iota_sdk.types.address import Address, deserialize_address from iota_sdk.types.block_issuer_key import BlockIssuerKey -from iota_sdk.types.common import EpochIndex, HexStr, json, SlotIndex +from iota_sdk.types.common import EpochIndex, HexStr, hex_str_decoder, json, SlotIndex class FeatureType(IntEnum): @@ -18,15 +18,17 @@ class FeatureType(IntEnum): Issuer (1): The issuer feature. Metadata (2): The metadata feature. Tag (3): The tag feature. - BlockIssuer (4): The block issuer feature. - Staking (5): The staking feature. + NativeToken (4): The native token feature. + BlockIssuer (5): The block issuer feature. + Staking (6): The staking feature. """ Sender = 0 Issuer = 1 Metadata = 2 Tag = 3 - BlockIssuer = 4 - Staking = 5 + NativeToken = 4 + BlockIssuer = 5 + Staking = 6 @json @@ -88,6 +90,22 @@ class TagFeature: type: int = field(default_factory=lambda: int(FeatureType.Tag), init=False) +@json +@dataclass +class NativeTokenFeature: + """Contains a native token. + id: The unique identifier of the native token. + amount: The amount of native tokens. + """ + id: HexStr + amount: int = field(metadata=config( + encoder=hex, + decoder=hex_str_decoder, + )) + type: int = field(default_factory=lambda: int( + FeatureType.NativeToken), init=False) + + @json @dataclass class BlockIssuerFeature: @@ -129,7 +147,7 @@ class StakingFeature: Feature: TypeAlias = Union[SenderFeature, IssuerFeature, - MetadataFeature, TagFeature, BlockIssuerFeature, StakingFeature] + MetadataFeature, TagFeature, NativeTokenFeature, BlockIssuerFeature, StakingFeature] def deserialize_feature(d: Dict[str, Any]) -> Feature: @@ -148,6 +166,8 @@ def deserialize_feature(d: Dict[str, Any]) -> Feature: return MetadataFeature.from_dict(d) if feature_type == FeatureType.Tag: return TagFeature.from_dict(d) + if feature_type == FeatureType.NativeToken: + return NativeTokenFeature.from_dict(d) if feature_type == FeatureType.BlockIssuer: return BlockIssuerFeature.from_dict(d) if feature_type == FeatureType.Staking: diff --git a/bindings/python/iota_sdk/types/output.py b/bindings/python/iota_sdk/types/output.py index 92769c780a..345bd73fab 100644 --- a/bindings/python/iota_sdk/types/output.py +++ b/bindings/python/iota_sdk/types/output.py @@ -7,8 +7,7 @@ from dataclasses import dataclass, field from dataclasses_json import config from iota_sdk.types.common import HexStr, json, EpochIndex -from iota_sdk.types.feature import deserialize_features, SenderFeature, IssuerFeature, MetadataFeature, TagFeature -from iota_sdk.types.native_token import NativeToken +from iota_sdk.types.feature import deserialize_features, SenderFeature, IssuerFeature, MetadataFeature, TagFeature, NativeTokenFeature from iota_sdk.types.token_scheme import SimpleTokenScheme from iota_sdk.types.unlock_condition import deserialize_unlock_conditions, AddressUnlockCondition, StateControllerAddressUnlockCondition, GovernorAddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition, ExpirationUnlockCondition, ImmutableAccountAddressUnlockCondition @@ -46,8 +45,6 @@ class BasicOutput: The conditions to unlock the output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. type : The type of output. """ @@ -62,11 +59,10 @@ class BasicOutput: decoder=deserialize_unlock_conditions )) features: Optional[List[Union[SenderFeature, - MetadataFeature, TagFeature]]] = field(default=None, - metadata=config( - decoder=deserialize_features - )) - native_tokens: Optional[List[NativeToken]] = None + MetadataFeature, TagFeature, NativeTokenFeature]]] = field(default=None, + metadata=config( + decoder=deserialize_features + )) type: int = field( default_factory=lambda: int( OutputType.Basic), @@ -90,8 +86,6 @@ class AccountOutput: A counter that denotes the number of foundries created by this account output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. immutable_features : Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. type : @@ -119,7 +113,6 @@ class AccountOutput: metadata=config( decoder=deserialize_features )) - native_tokens: Optional[List[NativeToken]] = None type: int = field( default_factory=lambda: int( OutputType.Account), @@ -147,8 +140,6 @@ class AnchorOutput: Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. state_metadata : Metadata that can only be changed by the state controller. - native_tokens : - Native tokens added to the new output. type : The type of output. """ @@ -176,7 +167,6 @@ class AnchorOutput: decoder=deserialize_features )) state_metadata: Optional[HexStr] = None - native_tokens: Optional[List[NativeToken]] = None type: int = field( default_factory=lambda: int( OutputType.Anchor), @@ -194,8 +184,6 @@ class FoundryOutput: The conditions to unlock the output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. immutable_features : Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. serial_number : @@ -211,15 +199,14 @@ class FoundryOutput: serial_number: int token_scheme: SimpleTokenScheme unlock_conditions: List[ImmutableAccountAddressUnlockCondition] - features: Optional[List[MetadataFeature]] = field(default=None, - metadata=config( - decoder=deserialize_features - )) + features: Optional[List[Union[MetadataFeature, NativeTokenFeature]]] = field(default=None, + metadata=config( + decoder=deserialize_features + )) immutable_features: Optional[List[MetadataFeature]] = field(default=None, metadata=config( decoder=deserialize_features )) - native_tokens: Optional[List[NativeToken]] = None type: int = field( default_factory=lambda: int( OutputType.Foundry), @@ -241,8 +228,6 @@ class NftOutput: The NFT ID if it's an NFT output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. immutable_features : Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. type : @@ -270,7 +255,6 @@ class NftOutput: metadata=config( decoder=deserialize_features )) - native_tokens: Optional[List[NativeToken]] = None type: int = field(default_factory=lambda: int(OutputType.Nft), init=False) diff --git a/bindings/python/iota_sdk/wallet/account.py b/bindings/python/iota_sdk/wallet/account.py index 7219e560e9..1d0a463097 100644 --- a/bindings/python/iota_sdk/wallet/account.py +++ b/bindings/python/iota_sdk/wallet/account.py @@ -283,7 +283,7 @@ def accounts(self) -> List[OutputData]: """ outputs = self._call_account_method( 'accounts' - ) + ) return [from_dict(OutputData, o) for o in outputs] def implicit_accounts(self) -> List[OutputData]: @@ -291,7 +291,7 @@ def implicit_accounts(self) -> List[OutputData]: """ outputs = self._call_account_method( 'implicitAccounts' - ) + ) return [from_dict(OutputData, o) for o in outputs] def incoming_transactions(self) -> List[TransactionWithMetadata]: diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 62dfbaec12..f534b2e41b 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -19,9 +19,9 @@ use iota_sdk::{ }, payload::signed_transaction::TransactionId, slot::SlotIndex, - ConvertTo, }, }, + utils::ConvertTo, wallet::{ types::{OutputData, TransactionWithMetadata}, ConsolidationParams, CreateNativeTokenParams, MintNftParams, OutputsToClaim, SendNativeTokensParams, diff --git a/sdk/src/client/api/address.rs b/sdk/src/client/api/address.rs index 173de7289f..6d5501d4d7 100644 --- a/sdk/src/client/api/address.rs +++ b/sdk/src/client/api/address.rs @@ -12,10 +12,8 @@ use crate::{ secret::{GenerateAddressOptions, SecretManage, SecretManager}, Client, Result, }, - types::block::{ - address::{Address, Bech32Address, Hrp, ToBech32Ext}, - ConvertTo, - }, + types::block::address::{Address, Bech32Address, Hrp, ToBech32Ext}, + utils::ConvertTo, }; #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/sdk/src/client/node_api/participation.rs b/sdk/src/client/node_api/participation.rs index 68c721fa2f..5f9dddc4a4 100644 --- a/sdk/src/client/node_api/participation.rs +++ b/sdk/src/client/node_api/participation.rs @@ -15,8 +15,9 @@ use crate::{ ParticipationEventType, }, }, - block::{address::Bech32Address, output::OutputId, ConvertTo}, + block::{address::Bech32Address, output::OutputId}, }, + utils::ConvertTo, }; impl ClientInner { diff --git a/sdk/src/client/utils.rs b/sdk/src/client/utils.rs index da07957425..ba2f0056aa 100644 --- a/sdk/src/client/utils.rs +++ b/sdk/src/client/utils.rs @@ -21,8 +21,9 @@ use crate::{ address::{Address, Bech32Address, Ed25519Address, Hrp, ToBech32Ext}, output::{AccountId, NftId}, payload::TaggedDataPayload, - BlockId, ConvertTo, SignedBlock, + BlockId, SignedBlock, }, + utils::ConvertTo, }; /// Transforms bech32 to hex diff --git a/sdk/src/types/block/address/bech32.rs b/sdk/src/types/block/address/bech32.rs index cbc8d26d5b..36cbe7bbea 100644 --- a/sdk/src/types/block/address/bech32.rs +++ b/sdk/src/types/block/address/bech32.rs @@ -16,9 +16,12 @@ use packable::{ Packable, PackableExt, }; -use crate::types::block::{ - address::{Address, MultiAddress}, - ConvertTo, Error, +use crate::{ + types::block::{ + address::{Address, MultiAddress}, + Error, + }, + utils::ConvertTo, }; #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deref, Display)] diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 4857bf4093..4a8021ad8e 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -26,12 +26,15 @@ pub use self::{ nft::NftAddress, restricted::{AddressCapabilities, AddressCapabilityFlag, RestrictedAddress}, }; -use crate::types::block::{ - output::Output, - semantic::{SemanticValidationContext, TransactionFailureReason}, - signature::Signature, - unlock::Unlock, - ConvertTo, Error, +use crate::{ + types::block::{ + output::Output, + semantic::{SemanticValidationContext, TransactionFailureReason}, + signature::Signature, + unlock::Unlock, + Error, + }, + utils::ConvertTo, }; /// A generic address supporting different address kinds. diff --git a/sdk/src/types/block/macro.rs b/sdk/src/types/block/macro.rs index d4783a93cd..b7a5b6695a 100644 --- a/sdk/src/types/block/macro.rs +++ b/sdk/src/types/block/macro.rs @@ -75,13 +75,13 @@ macro_rules! impl_id { } } - impl $crate::types::block::ConvertTo<$hash_name> for &alloc::string::String { + impl $crate::utils::ConvertTo<$hash_name> for &alloc::string::String { fn convert(self) -> Result<$hash_name, $crate::types::block::Error> { self.try_into() } } - impl $crate::types::block::ConvertTo<$hash_name> for &str { + impl $crate::utils::ConvertTo<$hash_name> for &str { fn convert(self) -> Result<$hash_name, $crate::types::block::Error> { self.try_into() } @@ -205,13 +205,13 @@ macro_rules! impl_id { } } - impl $crate::types::block::ConvertTo<$id_name> for &alloc::string::String { + impl $crate::utils::ConvertTo<$id_name> for &alloc::string::String { fn convert(self) -> Result<$id_name, $crate::types::block::Error> { self.try_into() } } - impl $crate::types::block::ConvertTo<$id_name> for &str { + impl $crate::utils::ConvertTo<$id_name> for &str { fn convert(self) -> Result<$id_name, $crate::types::block::Error> { self.try_into() } diff --git a/sdk/src/types/block/mod.rs b/sdk/src/types/block/mod.rs index d010281bab..df210e8224 100644 --- a/sdk/src/types/block/mod.rs +++ b/sdk/src/types/block/mod.rs @@ -4,7 +4,6 @@ //! Core data types for blocks in the tangle. mod block_id; -mod convert; mod error; mod issuer_id; mod r#macro; @@ -46,7 +45,6 @@ pub use self::core::dto::{BlockDto, SignedBlockDto, UnsignedBlockDto}; pub(crate) use self::r#macro::*; pub use self::{ block_id::{BlockHash, BlockId}, - convert::ConvertTo, core::{Block, SignedBlock, UnsignedBlock}, error::Error, issuer_id::IssuerId, diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 3dee4b05f3..e389d899c8 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -1,7 +1,7 @@ // Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use alloc::{collections::BTreeSet, vec::Vec}; +use alloc::collections::BTreeSet; use hashbrown::HashMap; use packable::{ @@ -11,24 +11,19 @@ use packable::{ Packable, }; -use crate::types::{ - block::{ - address::{AccountAddress, Address}, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, - }, - payload::signed_transaction::TransactionCapabilityFlag, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{AccountAddress, Address}, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + payload::signed_transaction::TransactionCapabilityFlag, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -623,13 +618,15 @@ fn verify_unlock_conditions(unlock_conditions: &UnlockConditions, account_id: &A #[cfg(feature = "serde")] pub(crate) mod dto { + use alloc::vec::Vec; + use serde::{Deserialize, Serialize}; use super::*; use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index 8dccff6276..e6d5c03e8d 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -13,24 +13,19 @@ use packable::{ Packable, }; -use crate::types::{ - block::{ - address::{Address, AnchorAddress}, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, - }, - payload::signed_transaction::TransactionCapabilityFlag, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{Address, AnchorAddress}, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + payload::signed_transaction::TransactionCapabilityFlag, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -711,7 +706,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::{prefix_hex_bytes, string}, }; diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index dd11477dee..0eb2281963 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -5,23 +5,18 @@ use alloc::collections::BTreeSet; use packable::Packable; -use crate::types::{ - block::{ - address::Address, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, - }, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::Address, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, }, - ValidationParams, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; /// Builder for a [`BasicOutput`]. @@ -361,7 +356,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index 0097d54dc4..1562a35169 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -5,24 +5,19 @@ use alloc::collections::BTreeSet; use packable::Packable; -use crate::types::{ - block::{ - address::{AccountAddress, Address}, - output::{ - chain_id::ChainId, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, Output, OutputBuilderAmount, OutputId, Rent, - RentStructure, StateTransitionError, StateTransitionVerifier, - }, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - slot::EpochIndex, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{AccountAddress, Address}, + output::{ + chain_id::ChainId, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, Output, OutputBuilderAmount, OutputId, Rent, + RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + slot::EpochIndex, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -442,7 +437,7 @@ pub(crate) mod dto { output::{unlock_condition::dto::UnlockConditionDto, OutputBuilderAmount}, Error, }, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index f979bc1a5d..f918872ca5 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -12,26 +12,21 @@ use packable::{ }; use primitive_types::U256; -use crate::types::{ - block::{ - address::{AccountAddress, Address}, - output::{ - account::AccountId, - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, TokenId, - TokenScheme, - }, - payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag}, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{AccountAddress, Address}, + output::{ + account::AccountId, + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, TokenId, + TokenScheme, }, - ValidationParams, + payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag}, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -679,7 +674,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 28c32ff138..599d451d07 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -10,24 +10,19 @@ use packable::{ Packable, }; -use crate::types::{ - block::{ - address::{Address, NftAddress}, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, - }, - payload::signed_transaction::TransactionCapabilityFlag, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{Address, NftAddress}, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + payload::signed_transaction::TransactionCapabilityFlag, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -541,7 +536,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index 25556c4fd2..30ecf8e94f 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -13,7 +13,10 @@ use super::{ mana::{ManaParameters, RewardsParameters}, slot::{EpochIndex, SlotIndex}, }; -use crate::types::block::{helper::network_name_to_id, output::RentStructure, ConvertTo, Error, PROTOCOL_VERSION}; +use crate::{ + types::block::{helper::network_name_to_id, output::RentStructure, Error, PROTOCOL_VERSION}, + utils::ConvertTo, +}; /// Defines the parameters of the protocol at a particular version. #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Packable, Getters, CopyGetters)] diff --git a/sdk/src/types/block/unlock/account.rs b/sdk/src/types/block/unlock/account.rs index 25ade32fcd..f8f7872ac3 100644 --- a/sdk/src/types/block/unlock/account.rs +++ b/sdk/src/types/block/unlock/account.rs @@ -36,6 +36,7 @@ impl AccountUnlock { } } +#[cfg(feature = "serde")] mod dto { use serde::{Deserialize, Serialize}; diff --git a/sdk/src/types/block/unlock/anchor.rs b/sdk/src/types/block/unlock/anchor.rs index cc9f6d9e64..aad3c49b78 100644 --- a/sdk/src/types/block/unlock/anchor.rs +++ b/sdk/src/types/block/unlock/anchor.rs @@ -36,6 +36,7 @@ impl AnchorUnlock { } } +#[cfg(feature = "serde")] mod dto { use serde::{Deserialize, Serialize}; diff --git a/sdk/src/types/block/unlock/empty.rs b/sdk/src/types/block/unlock/empty.rs index a4b89ff15a..2449e7668f 100644 --- a/sdk/src/types/block/unlock/empty.rs +++ b/sdk/src/types/block/unlock/empty.rs @@ -11,6 +11,7 @@ impl EmptyUnlock { pub const KIND: u8 = 6; } +#[cfg(feature = "serde")] mod dto { use serde::{Deserialize, Serialize}; diff --git a/sdk/src/types/block/unlock/multi.rs b/sdk/src/types/block/unlock/multi.rs index 024a9d8c88..99a2f2f0fd 100644 --- a/sdk/src/types/block/unlock/multi.rs +++ b/sdk/src/types/block/unlock/multi.rs @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use alloc::{boxed::Box, vec::Vec}; +use alloc::boxed::Box; use derive_more::Deref; use packable::{prefix::BoxedSlicePrefix, Packable}; @@ -46,7 +46,10 @@ fn verify_unlocks(unlocks: &[Unlock], _visitor: &()) -> Resu } } +#[cfg(feature = "serde")] mod dto { + use alloc::vec::Vec; + use serde::{Deserialize, Serialize}; use super::*; diff --git a/sdk/src/types/block/convert.rs b/sdk/src/utils/convert.rs similarity index 100% rename from sdk/src/types/block/convert.rs rename to sdk/src/utils/convert.rs diff --git a/sdk/src/utils/mod.rs b/sdk/src/utils/mod.rs index 9671dfe13d..1341ced35a 100644 --- a/sdk/src/utils/mod.rs +++ b/sdk/src/utils/mod.rs @@ -1,6 +1,10 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +mod convert; + pub mod merkle_hasher; #[cfg(feature = "serde")] pub mod serde; + +pub use convert::ConvertTo; diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs index 76246b9b14..779227f649 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs @@ -13,9 +13,9 @@ use crate::{ block::{ address::{AccountAddress, Bech32Address, ToBech32Ext}, output::{Output, OutputId}, - ConvertTo, }, }, + utils::ConvertTo, wallet::{operations::syncing::SyncOptions, task, Wallet}, }; diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs index d709c49a22..4374d0c859 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs @@ -3,7 +3,8 @@ use crate::{ client::{node_api::indexer::query_parameters::BasicOutputQueryParameters, secret::SecretManage}, - types::block::{address::Bech32Address, output::OutputId, ConvertTo}, + types::block::{address::Bech32Address, output::OutputId}, + utils::ConvertTo, wallet::Wallet, }; diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs index b445d4dfd1..5430bcb009 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs @@ -3,7 +3,8 @@ use crate::{ client::{node_api::indexer::query_parameters::NftOutputQueryParameters, secret::SecretManage}, - types::block::{address::Bech32Address, output::OutputId, ConvertTo}, + types::block::{address::Bech32Address, output::OutputId}, + utils::ConvertTo, wallet::Wallet, }; diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs index c9c4400023..b5eb4a945e 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs @@ -13,8 +13,8 @@ use crate::{ unlock_condition::AddressUnlockCondition, NftId, NftOutputBuilder, }, - ConvertTo, }, + utils::ConvertTo, wallet::{ operations::transaction::{TransactionOptions, TransactionWithMetadata}, Wallet, diff --git a/sdk/src/wallet/operations/transaction/high_level/send.rs b/sdk/src/wallet/operations/transaction/high_level/send.rs index 235572f0e7..dadc527e4b 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send.rs @@ -15,9 +15,8 @@ use crate::{ BasicOutputBuilder, MinimumStorageDepositBasicOutput, }, slot::SlotIndex, - ConvertTo, }, - utils::serde::string, + utils::{serde::string, ConvertTo}, wallet::{ constants::DEFAULT_EXPIRATION_SLOTS, operations::transaction::{TransactionOptions, TransactionWithMetadata}, 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 bf02fd7797..3f77ad9e19 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 @@ -16,8 +16,8 @@ use crate::{ BasicOutputBuilder, MinimumStorageDepositBasicOutput, NativeToken, NativeTokens, TokenId, }, slot::SlotIndex, - ConvertTo, }, + utils::ConvertTo, wallet::{ constants::DEFAULT_EXPIRATION_SLOTS, operations::transaction::{TransactionOptions, TransactionWithMetadata}, diff --git a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs index 1eb3dc31f6..33212d22a5 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs @@ -9,8 +9,8 @@ use crate::{ types::block::{ address::Bech32Address, output::{unlock_condition::AddressUnlockCondition, NftId, NftOutputBuilder, Output}, - ConvertTo, }, + utils::ConvertTo, wallet::{ operations::transaction::{TransactionOptions, TransactionWithMetadata}, Wallet, diff --git a/sdk/src/wallet/types/address.rs b/sdk/src/wallet/types/address.rs index a1539ad157..2eced539d4 100644 --- a/sdk/src/wallet/types/address.rs +++ b/sdk/src/wallet/types/address.rs @@ -6,9 +6,12 @@ use std::hash::Hash; use getset::{Getters, Setters}; use serde::{Deserialize, Serialize}; -use crate::types::{ - self, - block::{address::Bech32Address, output::OutputId, ConvertTo}, +use crate::{ + types::{ + self, + block::{address::Bech32Address, output::OutputId}, + }, + utils::ConvertTo, }; /// A BIP44 address.