From 0b9d5346c863b0ff3545a92e210327a1398624dd Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Wed, 20 Sep 2023 23:07:51 +0200 Subject: [PATCH] feat/Python: Regular tx fields (#1201) * transaction essence updated * readme update * union and comment order * format * Update bindings/python/iota_sdk/types/essence.py Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> --------- Co-authored-by: Thibault Martinez Co-authored-by: Thibault Martinez Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> --- bindings/python/README.md | 2 +- bindings/python/iota_sdk/types/essence.py | 57 +++++++++++++++++++ bindings/python/iota_sdk/types/payload.py | 18 ------ .../python/iota_sdk/types/transaction_data.py | 3 +- 4 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 bindings/python/iota_sdk/types/essence.py diff --git a/bindings/python/README.md b/bindings/python/README.md index a0ecdb5bdd..190ebaa0a6 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -82,7 +82,7 @@ python3 example/[example file] - Where `[example file]` is the file name from the example folder. For example: ```bash -python3 examples/client/00_get_info.py +python3 examples/how_tos/client/get_info.py ``` ## API Reference diff --git a/bindings/python/iota_sdk/types/essence.py b/bindings/python/iota_sdk/types/essence.py new file mode 100644 index 0000000000..7185423d23 --- /dev/null +++ b/bindings/python/iota_sdk/types/essence.py @@ -0,0 +1,57 @@ +# Copyright 2023 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations +from enum import IntEnum +from typing import Optional, List, Union + +from dataclasses import dataclass, field + +from iota_sdk.types.common import HexStr, json +from iota_sdk.types.output import BasicOutput, AccountOutput, FoundryOutput, NftOutput +from iota_sdk.types.input import UtxoInput +from iota_sdk.types.payload import TaggedDataPayload +from iota_sdk.types.unlock import SignatureUnlock, ReferenceUnlock + + +class EssenceType(IntEnum): + """Block payload types. + + Attributes: + RegularTransactionEssence (2): A Regular Transaction Essence. + """ + RegularTransactionEssence = 5 + + +@json +@dataclass +class TransactionEssence: + type: int + + +@json +@dataclass +class RegularTransactionEssence(TransactionEssence): + """Describes the essence data making up a transaction by defining its inputs, outputs, and an optional payload. + + Attributes: + network_id: The unique value denoting whether the block was meant for mainnet, shimmer, testnet, or a private network. + It consists of the first 8 bytes of the BLAKE2b-256 hash of the network name. + creation_slot: The slot index in which the transaction was created. + context_inputs: The inputs that provide additional contextual information for the execution of a transaction. + inputs: The inputs to consume in order to fund the outputs of the Transaction Payload. + inputs_commitment: BLAKE2b-256 hash serving as a commitment to the serialized outputs referenced by Inputs. + outputs: The outputs that are created by the Transaction Payload + allotments: The allotments of Mana which which will be added upon commitment of the slot. + payload: An optional tagged data payload + """ + network_id: str + # TODO: Replace with a proper SlotIndex type + creation_slot: HexStr + context_inputs: Optional[List[Union[CommitmentInput, BlockIssuanceCreditInput, RewardInput]]] = None + inputs: List[UtxoInput] + inputs_commitment: HexStr + outputs: List[Union[BasicOutput, AccountOutput, FoundryOutput, NftOutput, DelegationOutput]] + allotments: Optional[List[Allotment]] = None + payload: Optional[TaggedDataPayload] = None + type: int = field(default_factory=lambda: EssenceType.RegularTransactionEssence, init=False) diff --git a/bindings/python/iota_sdk/types/payload.py b/bindings/python/iota_sdk/types/payload.py index e49c900d33..9acab31e9c 100644 --- a/bindings/python/iota_sdk/types/payload.py +++ b/bindings/python/iota_sdk/types/payload.py @@ -25,24 +25,6 @@ class PayloadType(IntEnum): Transaction = 6 -@json -@dataclass -class TransactionEssence: - type: int - - -@json -@dataclass -class RegularTransactionEssence(TransactionEssence): - network_id: str - inputs_commitment: HexStr - inputs: List[UtxoInput] - outputs: List[Union[AccountOutput, FoundryOutput, NftOutput, BasicOutput]] - allotments: List[ManaAllotment] - payload: Optional[TaggedDataPayload] = None - type: int = field(default_factory=lambda: 1, init=False) - - @json @dataclass class Payload(): diff --git a/bindings/python/iota_sdk/types/transaction_data.py b/bindings/python/iota_sdk/types/transaction_data.py index 3c35022d5a..ae071d5011 100644 --- a/bindings/python/iota_sdk/types/transaction_data.py +++ b/bindings/python/iota_sdk/types/transaction_data.py @@ -6,7 +6,8 @@ from typing import Optional, List, Union from iota_sdk.types.address import Ed25519Address, AccountAddress, NFTAddress from iota_sdk.types.output import BasicOutput, AccountOutput, FoundryOutput, NftOutput, OutputMetadata -from iota_sdk.types.payload import RegularTransactionEssence, TransactionPayload +from iota_sdk.types.essence import RegularTransactionEssence +from iota_sdk.types.payload import TransactionPayload from iota_sdk.types.signature import Bip44 from iota_sdk.types.common import json