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

Rename python union types #1392

Merged
merged 7 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import ABCMeta, abstractmethod

from iota_sdk.types.common import HexStr
from iota_sdk.types.output import Output
from iota_sdk.types.output import BaseOutput


class ClientUtils(metaclass=ABCMeta):
Expand Down Expand Up @@ -49,7 +49,7 @@ def hex_public_key_to_bech32_address(
'bech32Hrp': bech32_hrp
})

def minimum_required_storage_deposit(self, output: Output) -> int:
def minimum_required_storage_deposit(self, output: BaseOutput) -> int:
"""Minimum required storage deposit.
"""
return int(self._call_method(
Expand Down
30 changes: 15 additions & 15 deletions bindings/python/iota_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from iota_sdk.secret_manager.secret_manager import LedgerNanoSecretManager, MnemonicSecretManager, StrongholdSecretManager, SeedSecretManager
from iota_sdk.types.block.wrapper import BlockWrapper
from iota_sdk.types.common import HexStr, Node
from iota_sdk.types.feature import Feature
from iota_sdk.types.feature import BaseFeature
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, TransactionPayload
from iota_sdk.types.payload import BasePayload, TransactionPayload
from iota_sdk.types.token_scheme import SimpleTokenScheme
from iota_sdk.types.unlock_condition import UnlockCondition
from iota_sdk.types.unlock_condition import BaseUnlockCondition
from iota_sdk.types.transaction_data import PreparedTransactionData


Expand Down Expand Up @@ -151,15 +151,15 @@ def get_handle(self):

def build_account_output(self,
account_id: HexStr,
unlock_conditions: List[UnlockCondition],
unlock_conditions: List[BaseUnlockCondition],
amount: Optional[int] = None,
mana: Optional[int] = None,
native_tokens: Optional[List[NativeToken]] = None,
state_index: Optional[int] = None,
state_metadata: Optional[str] = None,
foundry_counter: Optional[int] = None,
features: Optional[List[Feature]] = None,
immutable_features: Optional[List[Feature]] = None) -> AccountOutput:
features: Optional[List[BaseFeature]] = None,
immutable_features: Optional[List[BaseFeature]] = None) -> AccountOutput:
"""Build an AccountOutput.

Args:
Expand Down Expand Up @@ -211,11 +211,11 @@ def build_account_output(self,
}))

def build_basic_output(self,
unlock_conditions: List[UnlockCondition],
unlock_conditions: List[BaseUnlockCondition],
amount: Optional[int] = None,
mana: Optional[int] = None,
native_tokens: Optional[List[NativeToken]] = None,
features: Optional[List[Feature]] = None) -> BasicOutput:
features: Optional[List[BaseFeature]] = None) -> BasicOutput:
"""Build a BasicOutput.

Args:
Expand Down Expand Up @@ -256,11 +256,11 @@ def build_basic_output(self,
def build_foundry_output(self,
serial_number: int,
token_scheme: SimpleTokenScheme,
unlock_conditions: List[UnlockCondition],
unlock_conditions: List[BaseUnlockCondition],
amount: Optional[int] = None,
native_tokens: Optional[List[NativeToken]] = None,
features: Optional[List[Feature]] = None,
immutable_features: Optional[List[Feature]] = None) -> FoundryOutput:
features: Optional[List[BaseFeature]] = None,
immutable_features: Optional[List[BaseFeature]] = None) -> FoundryOutput:
"""Build a FoundryOutput.

Args:
Expand Down Expand Up @@ -304,12 +304,12 @@ def build_foundry_output(self,

def build_nft_output(self,
nft_id: HexStr,
unlock_conditions: List[UnlockCondition],
unlock_conditions: List[BaseUnlockCondition],
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:
features: Optional[List[BaseFeature]] = None,
immutable_features: Optional[List[BaseFeature]] = None) -> NftOutput:
"""Build an NftOutput.

Args:
Expand Down Expand Up @@ -395,7 +395,7 @@ def sign_transaction(
}))

def submit_payload(
self, payload: Payload) -> List[Union[HexStr, BlockWrapper]]:
self, payload: BasePayload) -> List[Union[HexStr, BlockWrapper]]:
"""Submit a payload in a block.

Args:
Expand Down
14 changes: 7 additions & 7 deletions bindings/python/iota_sdk/types/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class AddressType(IntEnum):

@json
@dataclass
class Address():
class BaseAddress():
"""Base class for addresses.
"""
type: int


@json
@dataclass
class Ed25519Address(Address):
class Ed25519Address(BaseAddress):
"""Represents an Ed25519 address.
Attributes:
pub_key_hash: The hex encoded Ed25519 public key hash.
Expand All @@ -44,7 +44,7 @@ class Ed25519Address(Address):

@json
@dataclass
class AccountAddress(Address):
class AccountAddress(BaseAddress):
"""Represents an Account address.
Attributes:
account_id: The hex encoded account id.
Expand All @@ -58,7 +58,7 @@ class AccountAddress(Address):

@json
@dataclass
class NFTAddress(Address):
class NFTAddress(BaseAddress):
"""Represents an NFT address.
Attributes:
nft_id: The hex encoded NFT id.
Expand All @@ -78,10 +78,10 @@ class AddressWithUnspentOutputs():
output_ids: bool


AddressUnion: TypeAlias = Union[Ed25519Address, AccountAddress, NFTAddress]
Address: TypeAlias = Union[Ed25519Address, AccountAddress, NFTAddress]


def deserialize_address(d: Dict[str, Any]) -> AddressUnion:
def deserialize_address(d: Dict[str, Any]) -> Address:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.

Expand All @@ -99,7 +99,7 @@ def deserialize_address(d: Dict[str, Any]) -> AddressUnion:


def deserialize_addresses(
dicts: List[Dict[str, Any]]) -> List[AddressUnion]:
dicts: List[Dict[str, Any]]) -> List[Address]:
"""
Takes a list of dictionaries as input and returns a list with specific instances of a classes based on the value of the 'type' key in the dictionary.

Expand Down
8 changes: 4 additions & 4 deletions bindings/python/iota_sdk/types/block/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from __future__ import annotations
from dataclasses import dataclass, field
from typing import List, Optional
from iota_sdk.types.block.block import Block, BlockType
from iota_sdk.types.block.block import BaseBlock, BlockType
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.payload import PayloadUnion
from iota_sdk.types.payload import Payload


@json
@dataclass
class BasicBlock(Block):
class BasicBlock(BaseBlock):
"""A `BasicBlock` is the most common type of block used to issue various kinds of payloads such as transactions
at the cost of burning Mana.

Expand All @@ -26,7 +26,7 @@ class BasicBlock(Block):
weak_parents: List[HexStr]
shallow_like_parents: List[HexStr]
max_burned_mana: str
payload: Optional[PayloadUnion] = None
payload: Optional[Payload] = None
type: int = field(
default_factory=lambda: BlockType.Basic,
init=False)
8 changes: 7 additions & 1 deletion bindings/python/iota_sdk/types/block/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from __future__ import annotations
from enum import IntEnum
from dataclasses import dataclass
from typing import TypeAlias, Union
from iota_sdk.types.common import json
from iota_sdk.types.block.basic import BasicBlock
from iota_sdk.types.block.validation import ValidationBlock


class BlockType(IntEnum):
Expand All @@ -20,7 +23,10 @@ class BlockType(IntEnum):

@json
@dataclass
class Block:
class BaseBlock:
"""Base class for blocks.
"""
type: int


Block: TypeAlias = Union[BasicBlock, ValidationBlock]
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/types/block/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from __future__ import annotations
from dataclasses import dataclass, field
from typing import List
from iota_sdk.types.block.block import Block, BlockType
from iota_sdk.types.block.block import BaseBlock, BlockType
from iota_sdk.types.common import HexStr, json


@json
@dataclass
class ValidationBlock(Block):
class ValidationBlock(BaseBlock):
"""A Validation Block is a special type of block used by validators to secure the network. It is recognized by the
Congestion Control of the IOTA 2.0 protocol and can be issued without burning Mana within the constraints of the
allowed validator throughput. It is allowed to reference more parent blocks than a normal Basic Block.
Expand Down
12 changes: 4 additions & 8 deletions bindings/python/iota_sdk/types/block/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

from __future__ import annotations
from dataclasses import dataclass
from typing import TypeAlias, Union
from iota_sdk.types.block.basic import BasicBlock
from iota_sdk.types.block.validation import ValidationBlock
from iota_sdk.types.common import HexStr, json, SlotIndex
from iota_sdk.types.node_info import ProtocolParameters
from iota_sdk.types.signature import SignatureUnion
from iota_sdk.types.signature import Signature
from iota_sdk.utils import Utils

BlockUnion: TypeAlias = Union[BasicBlock, ValidationBlock]
from iota_sdk.types.block.block import Block


@json
Expand All @@ -36,8 +32,8 @@ class BlockWrapper:
slot_commitment_id: HexStr
latest_finalized_slot: SlotIndex
issuer_id: HexStr
block: BlockUnion
signature: SignatureUnion
block: Block
signature: Signature

def id(self, params: ProtocolParameters) -> HexStr:
"""Returns the block ID as a hexadecimal string.
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/types/block_builder_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from iota_sdk.types.common import HexStr, AddressAndAmount, json
from iota_sdk.client._high_level_api import Range
from iota_sdk.types.burn import Burn
from iota_sdk.types.output import Output
from iota_sdk.types.output import BaseOutput
from iota_sdk.types.input import UtxoInput


Expand All @@ -25,7 +25,7 @@ class BlockBuilderOptions:
input_range: Optional[Range] = None
output: Optional[AddressAndAmount] = None
output_hex: Optional[List[Dict[str, Any]]] = None
outputs: Optional[List[Output]] = None
outputs: Optional[List[BaseOutput]] = None
custom_remainder_address: Optional[str] = None
tag: Optional[HexStr] = None
data: Optional[HexStr] = None
Expand Down
16 changes: 8 additions & 8 deletions bindings/python/iota_sdk/types/context_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class ContextInputType(IntEnum):

@json
@dataclass
class ContextInput():
class BaseContextInput():
"""Base class for context inputs.
"""
type: int


@json
@dataclass
class CommitmentContextInput(ContextInput):
class CommitmentContextInput(BaseContextInput):
"""A Commitment Context Input allows referencing a commitment to a certain slot.

Attributes:
Expand All @@ -42,7 +42,7 @@ class CommitmentContextInput(ContextInput):

@json
@dataclass
class BlockIssuanceCreditContextInput(ContextInput):
class BlockIssuanceCreditContextInput(BaseContextInput):
"""A Block Issuance Credit (BIC) Context Input provides the VM with context for the value of
the BIC vector of a specific slot.

Expand All @@ -59,7 +59,7 @@ class BlockIssuanceCreditContextInput(ContextInput):

@json
@dataclass
class RewardContextInput(ContextInput):
class RewardContextInput(BaseContextInput):
"""A Reward Context Input indicates which transaction Input is claiming Mana rewards.

Attributes:
Expand All @@ -73,11 +73,11 @@ class RewardContextInput(ContextInput):
init=False)


ContextInputUnion: TypeAlias = Union[CommitmentContextInput,
BlockIssuanceCreditContextInput, RewardContextInput]
ContextInput: TypeAlias = Union[CommitmentContextInput,
BlockIssuanceCreditContextInput, RewardContextInput]


def deserialize_context_input(d: Dict[str, Any]) -> ContextInputUnion:
def deserialize_context_input(d: Dict[str, Any]) -> ContextInput:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.

Expand All @@ -95,7 +95,7 @@ def deserialize_context_input(d: Dict[str, Any]) -> ContextInputUnion:


def deserialize_context_inputs(
dicts: List[Dict[str, Any]]) -> List[ContextInputUnion]:
dicts: List[Dict[str, Any]]) -> List[ContextInput]:
"""
Takes a list of dictionaries as input and returns a list with specific instances of a classes based on the value of the 'type' key in the dictionary.

Expand Down
12 changes: 6 additions & 6 deletions bindings/python/iota_sdk/types/essence.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from iota_sdk.types.common import HexStr, json, SlotIndex
from iota_sdk.types.mana import ManaAllotment
from iota_sdk.types.input import UtxoInput
from iota_sdk.types.context_input import ContextInputUnion
from iota_sdk.types.output import OutputUnion
from iota_sdk.types.context_input import ContextInput
from iota_sdk.types.output import Output

# Required to prevent circular import
if TYPE_CHECKING:
from iota_sdk.types.payload import Payload
from iota_sdk.types.payload import BasePayload


class EssenceType(IntEnum):
Expand Down Expand Up @@ -55,10 +55,10 @@ class RegularTransactionEssence(TransactionEssence):
creation_slot: SlotIndex
inputs: List[UtxoInput]
inputs_commitment: HexStr
outputs: List[OutputUnion]
context_inputs: Optional[List[ContextInputUnion]] = None
outputs: List[Output]
context_inputs: Optional[List[ContextInput]] = None
allotments: Optional[List[ManaAllotment]] = None
payload: Optional[Payload] = None
payload: Optional[BasePayload] = None
type: int = field(
default_factory=lambda: EssenceType.RegularTransactionEssence,
init=False)
Loading