Skip to content

Commit

Permalink
Merge branch '2.0' into relax-implicit-account-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Nov 13, 2023
2 parents 00b889d + 1ff3657 commit c0e093d
Show file tree
Hide file tree
Showing 35 changed files with 185 additions and 213 deletions.
8 changes: 5 additions & 3 deletions bindings/python/examples/client/05_get_address_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dotenv import load_dotenv

from iota_sdk import Client, NodeIndexerAPI
from iota_sdk import Client, NodeIndexerAPI, FeatureType

load_dotenv()

Expand Down Expand Up @@ -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}')
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
)
)

Expand Down Expand Up @@ -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]
)
)
29 changes: 0 additions & 29 deletions bindings/python/iota_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -205,15 +197,13 @@ 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.
Args:
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:
Expand All @@ -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]

Expand All @@ -240,7 +226,6 @@ def build_basic_output(self,
'unlockConditions': unlock_conditions,
'amount': amount,
'mana': mana,
'nativeTokens': native_tokens,
'features': features,
}))

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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
}))
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -340,7 +312,6 @@ def build_nft_output(self,
'unlockConditions': unlock_conditions,
'amount': amount,
'mana': mana,
'nativeTokens': native_tokens,
'features': features,
'immutableFeatures': immutable_features
}))
Expand Down
32 changes: 26 additions & 6 deletions bindings/python/iota_sdk/types/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
34 changes: 9 additions & 25 deletions bindings/python/iota_sdk/types/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
"""
Expand All @@ -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),
Expand All @@ -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 :
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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),
Expand All @@ -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 :
Expand All @@ -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),
Expand All @@ -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 :
Expand Down Expand Up @@ -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)


Expand Down
Loading

0 comments on commit c0e093d

Please sign in to comment.