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

Python add NativeTokenFeature #1605

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 5
BlockIssuer = 5
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -110,16 +104,15 @@ class AccountOutput:
decoder=deserialize_unlock_conditions
))
features: Optional[List[Union[SenderFeature,
MetadataFeature]]] = field(default=None,
metadata=config(
decoder=deserialize_features
))
MetadataFeature, NativeTokenFeature]]] = field(default=None,
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
metadata=config(
decoder=deserialize_features
))
immutable_features: Optional[List[Union[IssuerFeature,
MetadataFeature]]] = field(default=None,
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 @@ -219,7 +207,6 @@ class FoundryOutput:
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
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/wallet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ 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]:
"""Returns the implicit accounts of the wallet.
"""
outputs = self._call_account_method(
'implicitAccounts'
)
)
return [from_dict(OutputData, o) for o in outputs]

def incoming_transactions(self) -> List[TransactionWithMetadata]:
Expand Down
Loading