From b9ebed90ca775e2a69772e7e80ae33950c723f93 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 11 Dec 2023 18:18:59 +0100 Subject: [PATCH 1/8] rename block body types --- bindings/python/examples/client/08_data_block.py | 4 ++-- .../examples/client/submit_and_read_block.py | 4 ++-- bindings/python/iota_sdk/types/block/basic.py | 8 ++++---- bindings/python/iota_sdk/types/block/block.py | 6 +++--- .../python/iota_sdk/types/block/signed_block.py | 12 ++++++------ bindings/python/iota_sdk/types/block/validation.py | 8 ++++---- bindings/python/iota_sdk/utils.py | 6 +++--- bindings/python/tests/test_block.py | 14 +++++++------- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bindings/python/examples/client/08_data_block.py b/bindings/python/examples/client/08_data_block.py index 900313a537..b19a696315 100644 --- a/bindings/python/examples/client/08_data_block.py +++ b/bindings/python/examples/client/08_data_block.py @@ -3,7 +3,7 @@ import os from dataclasses import asdict from dotenv import load_dotenv -from iota_sdk import BasicBlock, Bip44, CoinType, Client, utf8_to_hex, hex_to_utf8, TaggedDataPayload, MnemonicSecretManager, SecretManager +from iota_sdk import BasicBlockBody, Bip44, CoinType, Client, utf8_to_hex, hex_to_utf8, TaggedDataPayload, MnemonicSecretManager, SecretManager load_dotenv() @@ -34,7 +34,7 @@ block = client.get_block(block_id).block -if isinstance(block, BasicBlock): +if isinstance(block, BasicBlockBody): print(f'Block data: {json.dumps(asdict(block), indent=4)}') payload = block.payload diff --git a/bindings/python/examples/client/submit_and_read_block.py b/bindings/python/examples/client/submit_and_read_block.py index 00002ff09b..6eb5a71351 100644 --- a/bindings/python/examples/client/submit_and_read_block.py +++ b/bindings/python/examples/client/submit_and_read_block.py @@ -11,7 +11,7 @@ # Make sure you have first installed it with `pip install iota_sdk` import os from dotenv import load_dotenv -from iota_sdk import BasicBlock, Bip44, Client, CoinType, hex_to_utf8, utf8_to_hex, TaggedDataPayload, MnemonicSecretManager, SecretManager +from iota_sdk import BasicBlockBody, Bip44, Client, CoinType, hex_to_utf8, utf8_to_hex, TaggedDataPayload, MnemonicSecretManager, SecretManager load_dotenv() @@ -92,7 +92,7 @@ # Get the whole block block = client.get_block(block_id).block -if isinstance(block, BasicBlock): +if isinstance(block, BasicBlockBody): payload_out = block.payload tag_hex_out = block.payload.tag message_hex_out = block.payload.data diff --git a/bindings/python/iota_sdk/types/block/basic.py b/bindings/python/iota_sdk/types/block/basic.py index 6300ad5399..87dd1e2cfb 100644 --- a/bindings/python/iota_sdk/types/block/basic.py +++ b/bindings/python/iota_sdk/types/block/basic.py @@ -5,15 +5,15 @@ from dataclasses import dataclass, field from typing import List, Optional from dataclasses_json import config -from iota_sdk.types.block.block import BlockType +from iota_sdk.types.block.block import BlockBodyType from iota_sdk.types.common import HexStr, json from iota_sdk.types.payload import Payload @json @dataclass -class BasicBlock: - """A `BasicBlock` is the most common type of block used to issue various kinds of payloads such as transactions +class BasicBlockBody: + """A `BasicBlockBody` is the most common type of block body used to issue various kinds of payloads such as transactions at the cost of burning Mana. Attributes: @@ -31,5 +31,5 @@ class BasicBlock: shallow_like_parents: Optional[List[HexStr]] = None payload: Optional[Payload] = None type: int = field( - default_factory=lambda: int(BlockType.Basic), + default_factory=lambda: int(BlockBodyType.Basic), init=False) diff --git a/bindings/python/iota_sdk/types/block/block.py b/bindings/python/iota_sdk/types/block/block.py index 9fc0d54747..eedace6c97 100644 --- a/bindings/python/iota_sdk/types/block/block.py +++ b/bindings/python/iota_sdk/types/block/block.py @@ -5,12 +5,12 @@ from enum import IntEnum -class BlockType(IntEnum): +class BlockBodyType(IntEnum): """Block types. Attributes: - Basic (0): A Basic Block. - Validation (1): A Validation Block. + Basic (0): A Basic Block Body. + Validation (1): A Validation Block Body. """ Basic = 0 Validation = 1 diff --git a/bindings/python/iota_sdk/types/block/signed_block.py b/bindings/python/iota_sdk/types/block/signed_block.py index 46439c6a77..3ad3297b32 100644 --- a/bindings/python/iota_sdk/types/block/signed_block.py +++ b/bindings/python/iota_sdk/types/block/signed_block.py @@ -9,8 +9,8 @@ from iota_sdk.types.common import HexStr, json, SlotIndex from iota_sdk.types.node_info import ProtocolParameters from iota_sdk.types.signature import Signature -from iota_sdk.types.block.basic import BasicBlock -from iota_sdk.types.block.validation import ValidationBlock +from iota_sdk.types.block.basic import BasicBlockBody +from iota_sdk.types.block.validation import ValidationBlockBody @json @@ -26,7 +26,7 @@ class SignedBlock: slot_commitment_id: The identifier of the slot to which this block commits. latest_finalized_slot: The slot index of the latest finalized slot. issuer_id: The identifier of the account that issued this block. - block: Holds either a `BasicBlock` or a `ValidationBlock`. + body: Holds either a `BasicBlockBody` or a `ValidationBlockBody`. signature: The Block signature. """ protocol_version: int @@ -39,7 +39,7 @@ class SignedBlock: slot_commitment_id: HexStr latest_finalized_slot: SlotIndex issuer_id: HexStr - block: Block + body: BlockBody signature: Signature def id(self, params: ProtocolParameters) -> HexStr: @@ -73,7 +73,7 @@ class UnsignedBlock: slot_commitment_id: HexStr latest_finalized_slot: SlotIndex issuer_id: HexStr - block: Block + body: BlockBody -Block: TypeAlias = Union[BasicBlock, ValidationBlock] +BlockBody: TypeAlias = Union[BasicBlockBody, ValidationBlockBody] diff --git a/bindings/python/iota_sdk/types/block/validation.py b/bindings/python/iota_sdk/types/block/validation.py index 3cee5b0cde..75249c24cb 100644 --- a/bindings/python/iota_sdk/types/block/validation.py +++ b/bindings/python/iota_sdk/types/block/validation.py @@ -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 BlockType +from iota_sdk.types.block.block import BlockBodyType from iota_sdk.types.common import HexStr, json @json @dataclass -class ValidationBlock: - """A Validation Block is a special type of block used by validators to secure the network. It is recognized by the +class ValidationBlockBody: + """A Validation Block Body is a special type of block body 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. @@ -28,5 +28,5 @@ class ValidationBlock: weak_parents: Optional[List[HexStr]] = None shallow_like_parents: Optional[List[HexStr]] = None type: int = field( - default_factory=lambda: int(BlockType.Validation), + default_factory=lambda: int(BlockBodyType.Validation), init=False) diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index f029feb703..46c110abfc 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -3,7 +3,7 @@ from __future__ import annotations from json import dumps, loads -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING, List, Optional from iota_sdk.types.signature import Ed25519Signature from iota_sdk.types.address import Address, deserialize_address @@ -11,7 +11,7 @@ from iota_sdk.types.transaction import Transaction from iota_sdk.types.node_info import ProtocolParameters from iota_sdk.types.output_id import OutputId -from iota_sdk.types.output import Output +from iota_sdk.types.unlock import Unlock from iota_sdk.external import call_utils_method from iota_sdk.types.payload import SignedTransactionPayload from iota_sdk.types.transaction_data import InputSigningData @@ -218,7 +218,7 @@ def verify_secp256k1_ecdsa_signature( @staticmethod def verify_transaction_semantic( - inputs: transaction: Transaction, inputs: List[InputSigningData], unlocks: Optional[List[Unlock]] = None) -> str: + transaction: Transaction, inputs: List[InputSigningData], unlocks: Optional[List[Unlock]] = None) -> str: """Verifies the semantic of a transaction. """ return _call_method('verifyTransactionSemantic', { diff --git a/bindings/python/tests/test_block.py b/bindings/python/tests/test_block.py index 8a76a91b87..43938117a2 100644 --- a/bindings/python/tests/test_block.py +++ b/bindings/python/tests/test_block.py @@ -3,7 +3,7 @@ from typing import get_args import pytest -from iota_sdk import BasicBlock, BlockType, SignedBlock, Payload, PayloadType +from iota_sdk import BasicBlockBody, BlockBodyType, SignedBlock, Payload, PayloadType def test_basic_block_with_tagged_data_payload(): @@ -19,7 +19,7 @@ def test_basic_block_with_tagged_data_payload(): "type": 0, "tag": "0x484f524e4554205370616d6d6572", "data": "0x57652061726520616c6c206d616465206f662073746172647573742e0a436f756e743a20353436333730330a54696d657374616d703a20323032332d30372d31395430373a32323a32385a0a54697073656c656374696f6e3a20343732c2b573"}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.TaggedData @@ -65,8 +65,8 @@ def test_signed_block_with_tagged_data_payload(): } signed_block = SignedBlock.from_dict(block_dict) assert signed_block.to_dict() == block_dict - assert isinstance(signed_block.block, BasicBlock) - assert signed_block.block.type == BlockType.Basic + assert isinstance(signed_block.block, BasicBlockBody) + assert signed_block.block.type == BlockBodyType.Basic assert isinstance(signed_block.block.payload, get_args(Payload)) assert signed_block.block.payload.type == PayloadType.TaggedData # TODO: determine the actual hash of the block @@ -104,7 +104,7 @@ def test_basic_block_with_tx_payload(): "signature": {"type": 0, "publicKey": "0xa7af600976f440ec97d7bddbf17eacf0bfbf710e8cfb4ae3eae475d4ae8e1b16", "signature": "0x6bbe2eed95300a3d707af1bb17e04f83087fe31261256020fd00c24a54543c084079bed29c6d1479ee5acfd1e2fa32316e88c4c1577b4fbea3fe247f71114500"}}]}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.SignedTransaction @@ -245,7 +245,7 @@ def test_basic_block_with_tx_payload_all_output_types(): "type": 1, "reference": 0}, { "type": 2, "reference": 1}, { "type": 1, "reference": 0}]}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.SignedTransaction @@ -291,7 +291,7 @@ def test_basic_block_with_tx_payload_with_tagged_data_payload(): "signature": "0x30cb012af3402be1b4b2ed18e2aba86839da06ba38ff3277c481e17c003f0199ba26f5613199e0d24035628bb2b69a6ea2a7682e41c30244996baf3a2adc1c00"}}, {"type": 1, "reference": 0}]}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.SignedTransaction From 42a378a64a7d658fd5867435043ef0408c1f0c52 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 11 Dec 2023 18:24:50 +0100 Subject: [PATCH 2/8] rename block type --- bindings/python/iota_sdk/client/_high_level_api.py | 6 +++--- bindings/python/iota_sdk/client/_node_core_api.py | 12 ++++++------ .../python/iota_sdk/secret_manager/secret_manager.py | 6 +++--- bindings/python/iota_sdk/types/block/metadata.py | 4 ++-- bindings/python/iota_sdk/types/block/signed_block.py | 4 ++-- bindings/python/iota_sdk/utils.py | 4 ++-- bindings/python/tests/test_block.py | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/bindings/python/iota_sdk/client/_high_level_api.py b/bindings/python/iota_sdk/client/_high_level_api.py index 080a1e3041..bf337e630d 100644 --- a/bindings/python/iota_sdk/client/_high_level_api.py +++ b/bindings/python/iota_sdk/client/_high_level_api.py @@ -4,7 +4,7 @@ from typing import List, Optional from dataclasses import dataclass from abc import ABCMeta, abstractmethod -from iota_sdk.types.block.signed_block import SignedBlock +from iota_sdk.types.block.signed_block import Block from iota_sdk.types.common import CoinType, HexStr, json from iota_sdk.types.output_metadata import OutputWithMetadata from iota_sdk.types.output_id import OutputId @@ -111,7 +111,7 @@ def get_outputs_ignore_errors( }) return [OutputWithMetadata.from_dict(o) for o in outputs] - def find_blocks(self, block_ids: List[HexStr]) -> List[SignedBlock]: + def find_blocks(self, block_ids: List[HexStr]) -> List[Block]: """Find all blocks by provided block IDs. Args: @@ -123,7 +123,7 @@ def find_blocks(self, block_ids: List[HexStr]) -> List[SignedBlock]: blocks = self._call_method('findBlocks', { 'blockIds': block_ids }) - return [SignedBlock.from_dict(block) for block in blocks] + return [Block.from_dict(block) for block in blocks] def find_inputs(self, addresses: List[str], amount: int): """Function to find inputs from addresses for a provided amount(useful for offline signing). diff --git a/bindings/python/iota_sdk/client/_node_core_api.py b/bindings/python/iota_sdk/client/_node_core_api.py index b48a59798f..91ae8d8960 100644 --- a/bindings/python/iota_sdk/client/_node_core_api.py +++ b/bindings/python/iota_sdk/client/_node_core_api.py @@ -5,7 +5,7 @@ from abc import ABCMeta, abstractmethod from dacite import from_dict -from iota_sdk.types.block.signed_block import SignedBlock +from iota_sdk.types.block.signed_block import Block from iota_sdk.types.block.metadata import BlockMetadata, BlockWithMetadata from iota_sdk.types.common import HexStr from iota_sdk.types.node_info import NodeInfo, NodeInfoWrapper @@ -75,7 +75,7 @@ def get_tips(self) -> List[HexStr]: """ return self._call_method('getTips') - def post_block(self, block: SignedBlock) -> HexStr: + def post_block(self, block: Block) -> HexStr: """Post a block. Args: @@ -88,10 +88,10 @@ def post_block(self, block: SignedBlock) -> HexStr: 'block': block.__dict__ }) - def get_block(self, block_id: HexStr) -> SignedBlock: + def get_block(self, block_id: HexStr) -> Block: """Get the block corresponding to the given block id. """ - return SignedBlock.from_dict(self._call_method('getBlock', { + return Block.from_dict(self._call_method('getBlock', { 'blockId': block_id })) @@ -152,13 +152,13 @@ def get_output_metadata( 'outputId': output_id_str })) - def get_included_block(self, transaction_id: HexStr) -> SignedBlock: + def get_included_block(self, transaction_id: HexStr) -> Block: """Returns the included block of the given transaction. Returns: The included block. """ - return SignedBlock.from_dict(self._call_method('getIncludedBlock', { + return Block.from_dict(self._call_method('getIncludedBlock', { 'transactionId': transaction_id })) diff --git a/bindings/python/iota_sdk/secret_manager/secret_manager.py b/bindings/python/iota_sdk/secret_manager/secret_manager.py index 4c3e669c96..780c725fed 100644 --- a/bindings/python/iota_sdk/secret_manager/secret_manager.py +++ b/bindings/python/iota_sdk/secret_manager/secret_manager.py @@ -7,7 +7,7 @@ import humps from iota_sdk.external import create_secret_manager, call_secret_manager_method -from iota_sdk.types.block.signed_block import SignedBlock, UnsignedBlock +from iota_sdk.types.block.signed_block import Block, UnsignedBlock from iota_sdk.types.common import HexStr from iota_sdk.types.signature import Ed25519Signature, Bip44 from iota_sdk.types.transaction_data import PreparedTransactionData @@ -280,14 +280,14 @@ def sign_transaction( })) def sign_block( - self, unsigned_block: UnsignedBlock, chain: Bip44) -> SignedBlock: + self, unsigned_block: UnsignedBlock, chain: Bip44) -> Block: """Sign a block. Args: unsigned_block: The unsigned block data. chain: The Bip44 chain to use. """ - return from_dict(SignedBlock, self._call_method('signBlock', { + return from_dict(Block, self._call_method('signBlock', { 'unsignedBlock': unsigned_block.to_dict(), 'chain': chain.to_dict() })) diff --git a/bindings/python/iota_sdk/types/block/metadata.py b/bindings/python/iota_sdk/types/block/metadata.py index ae313ecd73..adcb0b1913 100644 --- a/bindings/python/iota_sdk/types/block/metadata.py +++ b/bindings/python/iota_sdk/types/block/metadata.py @@ -7,7 +7,7 @@ from typing import Optional from iota_sdk.types.common import HexStr, json # TODO rename change to Block -from iota_sdk.types.block.signed_block import SignedBlock +from iota_sdk.types.block.signed_block import Block @json @@ -196,5 +196,5 @@ class BlockWithMetadata: block: The block. metadata: The block metadata. """ - block: SignedBlock + block: Block metadata: BlockMetadata diff --git a/bindings/python/iota_sdk/types/block/signed_block.py b/bindings/python/iota_sdk/types/block/signed_block.py index 3ad3297b32..bccdef0d92 100644 --- a/bindings/python/iota_sdk/types/block/signed_block.py +++ b/bindings/python/iota_sdk/types/block/signed_block.py @@ -15,8 +15,8 @@ @json @dataclass -class SignedBlock: - """A signed block type that can hold either a `BasicBlock` or a `ValidationBlock`. +class Block: + """A signed block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`. Shared data is stored alongside such a block in the header fields. Attributes: diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index 46c110abfc..9f121ec87b 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -18,7 +18,7 @@ # Required to prevent circular import if TYPE_CHECKING: - from iota_sdk.types.block.signed_block import SignedBlock + from iota_sdk.types.block.signed_block import Block # pylint: disable=too-many-public-methods @@ -163,7 +163,7 @@ def compute_token_id(account_id: HexStr, serial_number: int, }) @staticmethod - def block_id(block: SignedBlock, params: ProtocolParameters) -> HexStr: + def block_id(block: Block, params: ProtocolParameters) -> HexStr: """ Return a block ID (Blake2b256 hash of block bytes) from a block. """ return _call_method('blockId', { diff --git a/bindings/python/tests/test_block.py b/bindings/python/tests/test_block.py index 43938117a2..a09003d471 100644 --- a/bindings/python/tests/test_block.py +++ b/bindings/python/tests/test_block.py @@ -3,7 +3,7 @@ from typing import get_args import pytest -from iota_sdk import BasicBlockBody, BlockBodyType, SignedBlock, Payload, PayloadType +from iota_sdk import BasicBlockBody, BlockBodyType, Block, Payload, PayloadType def test_basic_block_with_tagged_data_payload(): @@ -63,7 +63,7 @@ def test_signed_block_with_tagged_data_payload(): "signature": "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" } } - signed_block = SignedBlock.from_dict(block_dict) + signed_block = Block.from_dict(block_dict) assert signed_block.to_dict() == block_dict assert isinstance(signed_block.block, BasicBlockBody) assert signed_block.block.type == BlockBodyType.Basic From 5745b8c5bc6bb46e540343c2e3503a88485b13a7 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 11 Dec 2023 18:46:53 +0100 Subject: [PATCH 3/8] re-org files --- .../python/examples/client/06_simple_block.py | 4 +- bindings/python/iota_sdk/__init__.py | 6 +- .../python/iota_sdk/client/_high_level_api.py | 2 +- .../python/iota_sdk/client/_node_core_api.py | 2 +- bindings/python/iota_sdk/client/_utils.py | 2 +- bindings/python/iota_sdk/client/client.py | 2 +- .../iota_sdk/secret_manager/secret_manager.py | 2 +- bindings/python/iota_sdk/types/block/block.py | 77 ++++++++++++++++-- .../iota_sdk/types/block/{ => body}/basic.py | 4 +- .../python/iota_sdk/types/block/body/kind.py | 16 ++++ .../types/block/{ => body}/validation.py | 2 +- .../python/iota_sdk/types/block/metadata.py | 2 +- .../iota_sdk/types/block/signed_block.py | 79 ------------------- .../python/iota_sdk/types/output_params.py | 2 +- bindings/python/iota_sdk/types/send_params.py | 2 +- 15 files changed, 102 insertions(+), 102 deletions(-) rename bindings/python/iota_sdk/types/block/{ => body}/basic.py (90%) create mode 100644 bindings/python/iota_sdk/types/block/body/kind.py rename bindings/python/iota_sdk/types/block/{ => body}/validation.py (96%) delete mode 100644 bindings/python/iota_sdk/types/block/signed_block.py diff --git a/bindings/python/examples/client/06_simple_block.py b/bindings/python/examples/client/06_simple_block.py index 734444a108..967913787c 100644 --- a/bindings/python/examples/client/06_simple_block.py +++ b/bindings/python/examples/client/06_simple_block.py @@ -26,7 +26,7 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data")))[0] -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) print(f'Empty block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') diff --git a/bindings/python/iota_sdk/__init__.py b/bindings/python/iota_sdk/__init__.py index a08515c175..94fef21188 100644 --- a/bindings/python/iota_sdk/__init__.py +++ b/bindings/python/iota_sdk/__init__.py @@ -12,11 +12,11 @@ from .prefix_hex import * from .types.address import * from .types.balance import * -from .types.block.basic import * from .types.block.block import * +from .types.block.body.basic import * +from .types.block.body.kind import * +from .types.block.body.validation import * from .types.block.metadata import * -from .types.block.signed_block import * -from .types.block.validation import * from .types.block_builder_options import * from .types.block_issuer_key import * from .types.burn import * diff --git a/bindings/python/iota_sdk/client/_high_level_api.py b/bindings/python/iota_sdk/client/_high_level_api.py index bf337e630d..928d165804 100644 --- a/bindings/python/iota_sdk/client/_high_level_api.py +++ b/bindings/python/iota_sdk/client/_high_level_api.py @@ -4,7 +4,7 @@ from typing import List, Optional from dataclasses import dataclass from abc import ABCMeta, abstractmethod -from iota_sdk.types.block.signed_block import Block +from iota_sdk.types.block.block import Block from iota_sdk.types.common import CoinType, HexStr, json from iota_sdk.types.output_metadata import OutputWithMetadata from iota_sdk.types.output_id import OutputId diff --git a/bindings/python/iota_sdk/client/_node_core_api.py b/bindings/python/iota_sdk/client/_node_core_api.py index 91ae8d8960..23ed49bec5 100644 --- a/bindings/python/iota_sdk/client/_node_core_api.py +++ b/bindings/python/iota_sdk/client/_node_core_api.py @@ -5,7 +5,7 @@ from abc import ABCMeta, abstractmethod from dacite import from_dict -from iota_sdk.types.block.signed_block import Block +from iota_sdk.types.block.block import Block from iota_sdk.types.block.metadata import BlockMetadata, BlockWithMetadata from iota_sdk.types.common import HexStr from iota_sdk.types.node_info import NodeInfo, NodeInfoWrapper diff --git a/bindings/python/iota_sdk/client/_utils.py b/bindings/python/iota_sdk/client/_utils.py index a1b0859062..3855d4d8a3 100644 --- a/bindings/python/iota_sdk/client/_utils.py +++ b/bindings/python/iota_sdk/client/_utils.py @@ -34,7 +34,7 @@ def _call_method(self, name, data=None): """ # pylint: disable=redefined-builtin - def hex_to_bech32(self, hex: HexStr, bech32_hrp: str) -> str: + def hex_to_bech32(self, hex_str: HexStr, bech32_hrp: str) -> str: """Transforms a hex encoded address to a bech32 encoded address. """ return self._call_method('hexToBech32', { diff --git a/bindings/python/iota_sdk/client/client.py b/bindings/python/iota_sdk/client/client.py index 06e38a42cc..97f44c3ec8 100644 --- a/bindings/python/iota_sdk/client/client.py +++ b/bindings/python/iota_sdk/client/client.py @@ -11,7 +11,7 @@ from iota_sdk.client._node_indexer_api import NodeIndexerAPI from iota_sdk.client._high_level_api import HighLevelAPI from iota_sdk.client._utils import ClientUtils -from iota_sdk.types.block.signed_block import UnsignedBlock +from iota_sdk.types.block.block import UnsignedBlock from iota_sdk.types.common import HexStr, Node from iota_sdk.types.feature import Feature from iota_sdk.types.network_info import NetworkInfo diff --git a/bindings/python/iota_sdk/secret_manager/secret_manager.py b/bindings/python/iota_sdk/secret_manager/secret_manager.py index 780c725fed..01fd5aad7c 100644 --- a/bindings/python/iota_sdk/secret_manager/secret_manager.py +++ b/bindings/python/iota_sdk/secret_manager/secret_manager.py @@ -7,7 +7,7 @@ import humps from iota_sdk.external import create_secret_manager, call_secret_manager_method -from iota_sdk.types.block.signed_block import Block, UnsignedBlock +from iota_sdk.types.block.block import Block, UnsignedBlock from iota_sdk.types.common import HexStr from iota_sdk.types.signature import Ed25519Signature, Bip44 from iota_sdk.types.transaction_data import PreparedTransactionData diff --git a/bindings/python/iota_sdk/types/block/block.py b/bindings/python/iota_sdk/types/block/block.py index eedace6c97..e1f7abe4f7 100644 --- a/bindings/python/iota_sdk/types/block/block.py +++ b/bindings/python/iota_sdk/types/block/block.py @@ -2,15 +2,78 @@ # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations -from enum import IntEnum +from dataclasses import dataclass, field +from typing import TypeAlias, Union +from dataclasses_json import config +from iota_sdk.utils import Utils +from iota_sdk.types.common import HexStr, json, SlotIndex +from iota_sdk.types.node_info import ProtocolParameters +from iota_sdk.types.signature import Signature +from iota_sdk.types.block.body.basic import BasicBlockBody +from iota_sdk.types.block.body.validation import ValidationBlockBody -class BlockBodyType(IntEnum): - """Block types. +@json +@dataclass +class Block: + """A signed block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`. + Shared data is stored alongside such a block in the header fields. Attributes: - Basic (0): A Basic Block Body. - Validation (1): A Validation Block Body. + protocol_version: Protocol version of the network to which this block belongs. + network_id: The identifier of the network to which this block belongs. + issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. + slot_commitment_id: The identifier of the slot to which this block commits. + latest_finalized_slot: The slot index of the latest finalized slot. + issuer_id: The identifier of the account that issued this block. + body: Holds either a `BasicBlockBody` or a `ValidationBlockBody`. + signature: The Block signature. """ - Basic = 0 - Validation = 1 + protocol_version: int + network_id: int = field(metadata=config( + encoder=str + )) + issuing_time: int = field(metadata=config( + encoder=str + )) + slot_commitment_id: HexStr + latest_finalized_slot: SlotIndex + issuer_id: HexStr + body: BlockBody + signature: Signature + + def id(self, params: ProtocolParameters) -> HexStr: + """Returns the block ID as a hexadecimal string. + """ + return Utils.block_id(self, params) + + +@json +@dataclass +class UnsignedBlock: + """An unsigned block type that can hold either a `BasicBlock` or a `ValidationBlock`. + Shared data is stored alongside such a block in the header fields. + + Attributes: + protocol_version: Protocol version of the network to which this block belongs. + network_id: The identifier of the network to which this block belongs. + issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. + slot_commitment_id: The identifier of the slot to which this block commits. + latest_finalized_slot: The slot index of the latest finalized slot. + issuer_id: The identifier of the account that issued this block. + block: Holds either a `BasicBlock` or a `ValidationBlock`. + """ + protocol_version: int + network_id: int = field(metadata=config( + encoder=str + )) + issuing_time: int = field(metadata=config( + encoder=str + )) + slot_commitment_id: HexStr + latest_finalized_slot: SlotIndex + issuer_id: HexStr + body: BlockBody + + +BlockBody: TypeAlias = Union[BasicBlockBody, ValidationBlockBody] diff --git a/bindings/python/iota_sdk/types/block/basic.py b/bindings/python/iota_sdk/types/block/body/basic.py similarity index 90% rename from bindings/python/iota_sdk/types/block/basic.py rename to bindings/python/iota_sdk/types/block/body/basic.py index 87dd1e2cfb..dcea4da319 100644 --- a/bindings/python/iota_sdk/types/block/basic.py +++ b/bindings/python/iota_sdk/types/block/body/basic.py @@ -5,7 +5,7 @@ from dataclasses import dataclass, field from typing import List, Optional from dataclasses_json import config -from iota_sdk.types.block.block import BlockBodyType +from iota_sdk.types.block.body.kind import BlockBodyType from iota_sdk.types.common import HexStr, json from iota_sdk.types.payload import Payload @@ -13,7 +13,7 @@ @json @dataclass class BasicBlockBody: - """A `BasicBlockBody` is the most common type of block body used to issue various kinds of payloads such as transactions + """A Basic Block Body is the most common type of block body used to issue various kinds of payloads such as transactions at the cost of burning Mana. Attributes: diff --git a/bindings/python/iota_sdk/types/block/body/kind.py b/bindings/python/iota_sdk/types/block/body/kind.py new file mode 100644 index 0000000000..fcd8b3d1d4 --- /dev/null +++ b/bindings/python/iota_sdk/types/block/body/kind.py @@ -0,0 +1,16 @@ +# Copyright 2023 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations +from enum import IntEnum + + +class BlockBodyType(IntEnum): + """Block Body types. + + Attributes: + Basic (0): A Basic Block Body. + Validation (1): A Validation Block Body. + """ + Basic = 0 + Validation = 1 diff --git a/bindings/python/iota_sdk/types/block/validation.py b/bindings/python/iota_sdk/types/block/body/validation.py similarity index 96% rename from bindings/python/iota_sdk/types/block/validation.py rename to bindings/python/iota_sdk/types/block/body/validation.py index 75249c24cb..752e7349c8 100644 --- a/bindings/python/iota_sdk/types/block/validation.py +++ b/bindings/python/iota_sdk/types/block/body/validation.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass, field from typing import List, Optional -from iota_sdk.types.block.block import BlockBodyType +from iota_sdk.types.block.body.kind import BlockBodyType from iota_sdk.types.common import HexStr, json diff --git a/bindings/python/iota_sdk/types/block/metadata.py b/bindings/python/iota_sdk/types/block/metadata.py index adcb0b1913..d1f7a67cf3 100644 --- a/bindings/python/iota_sdk/types/block/metadata.py +++ b/bindings/python/iota_sdk/types/block/metadata.py @@ -7,7 +7,7 @@ from typing import Optional from iota_sdk.types.common import HexStr, json # TODO rename change to Block -from iota_sdk.types.block.signed_block import Block +from iota_sdk.types.block.block import Block @json diff --git a/bindings/python/iota_sdk/types/block/signed_block.py b/bindings/python/iota_sdk/types/block/signed_block.py deleted file mode 100644 index bccdef0d92..0000000000 --- a/bindings/python/iota_sdk/types/block/signed_block.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright 2023 IOTA Stiftung -# SPDX-License-Identifier: Apache-2.0 - -from __future__ import annotations -from dataclasses import dataclass, field -from typing import TypeAlias, Union -from dataclasses_json import config -from iota_sdk.utils import Utils -from iota_sdk.types.common import HexStr, json, SlotIndex -from iota_sdk.types.node_info import ProtocolParameters -from iota_sdk.types.signature import Signature -from iota_sdk.types.block.basic import BasicBlockBody -from iota_sdk.types.block.validation import ValidationBlockBody - - -@json -@dataclass -class Block: - """A signed block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`. - Shared data is stored alongside such a block in the header fields. - - Attributes: - protocol_version: Protocol version of the network to which this block belongs. - network_id: The identifier of the network to which this block belongs. - issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. - slot_commitment_id: The identifier of the slot to which this block commits. - latest_finalized_slot: The slot index of the latest finalized slot. - issuer_id: The identifier of the account that issued this block. - body: Holds either a `BasicBlockBody` or a `ValidationBlockBody`. - signature: The Block signature. - """ - protocol_version: int - network_id: int = field(metadata=config( - encoder=str - )) - issuing_time: int = field(metadata=config( - encoder=str - )) - slot_commitment_id: HexStr - latest_finalized_slot: SlotIndex - issuer_id: HexStr - body: BlockBody - signature: Signature - - def id(self, params: ProtocolParameters) -> HexStr: - """Returns the block ID as a hexadecimal string. - """ - return Utils.block_id(self, params) - - -@json -@dataclass -class UnsignedBlock: - """An unsigned block type that can hold either a `BasicBlock` or a `ValidationBlock`. - Shared data is stored alongside such a block in the header fields. - - Attributes: - protocol_version: Protocol version of the network to which this block belongs. - network_id: The identifier of the network to which this block belongs. - issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. - slot_commitment_id: The identifier of the slot to which this block commits. - latest_finalized_slot: The slot index of the latest finalized slot. - issuer_id: The identifier of the account that issued this block. - block: Holds either a `BasicBlock` or a `ValidationBlock`. - """ - protocol_version: int - network_id: int = field(metadata=config( - encoder=str - )) - issuing_time: int = field(metadata=config( - encoder=str - )) - slot_commitment_id: HexStr - latest_finalized_slot: SlotIndex - issuer_id: HexStr - body: BlockBody - - -BlockBody: TypeAlias = Union[BasicBlockBody, ValidationBlockBody] diff --git a/bindings/python/iota_sdk/types/output_params.py b/bindings/python/iota_sdk/types/output_params.py index b5b896b61b..6133a2e704 100644 --- a/bindings/python/iota_sdk/types/output_params.py +++ b/bindings/python/iota_sdk/types/output_params.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass, field from enum import Enum -from typing import List, Optional +from typing import Optional from dataclasses_json import config from iota_sdk.types.common import HexStr, json, opt_int_encoder from iota_sdk.types.native_token import NativeToken diff --git a/bindings/python/iota_sdk/types/send_params.py b/bindings/python/iota_sdk/types/send_params.py index 6bcccd9c2e..4807147df8 100644 --- a/bindings/python/iota_sdk/types/send_params.py +++ b/bindings/python/iota_sdk/types/send_params.py @@ -3,7 +3,7 @@ from __future__ import annotations from dataclasses import dataclass, field -from typing import Optional, List +from typing import Optional from dataclasses_json import config from iota_sdk.types.common import hex_str_decoder, HexStr, json from iota_sdk.types.native_token import NativeToken From 8a45b7f7102d12487f9d36abceb2aec026352a48 Mon Sep 17 00:00:00 2001 From: /alex/ Date: Mon, 11 Dec 2023 20:40:24 +0100 Subject: [PATCH 4/8] good catch Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> --- bindings/python/iota_sdk/types/block/block.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/iota_sdk/types/block/block.py b/bindings/python/iota_sdk/types/block/block.py index e1f7abe4f7..61c94bebf2 100644 --- a/bindings/python/iota_sdk/types/block/block.py +++ b/bindings/python/iota_sdk/types/block/block.py @@ -16,7 +16,7 @@ @json @dataclass class Block: - """A signed block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`. + """A block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`. Shared data is stored alongside such a block in the header fields. Attributes: From 74876491818ff76f7525dd5150722cbfbb72cfc5 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 12 Dec 2023 12:11:15 +0100 Subject: [PATCH 5/8] some more missed --- bindings/python/examples/client/08_data_block.py | 4 ++-- bindings/python/examples/client/post_raw_block.py | 4 ++-- .../examples/client/submit_and_read_block.py | 6 +++--- bindings/python/iota_sdk/types/block/metadata.py | 1 - bindings/python/iota_sdk/utils.py | 2 +- bindings/python/tests/test_block.py | 14 +++++++------- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/bindings/python/examples/client/08_data_block.py b/bindings/python/examples/client/08_data_block.py index b19a696315..89cdd4bd34 100644 --- a/bindings/python/examples/client/08_data_block.py +++ b/bindings/python/examples/client/08_data_block.py @@ -27,8 +27,8 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data")))[0] -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) print(f'Data block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') diff --git a/bindings/python/examples/client/post_raw_block.py b/bindings/python/examples/client/post_raw_block.py index ea60a51839..8f01ca0a88 100644 --- a/bindings/python/examples/client/post_raw_block.py +++ b/bindings/python/examples/client/post_raw_block.py @@ -24,8 +24,8 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data")))[0] -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) blockBytes = client.get_block_raw(block_id) # Post raw block diff --git a/bindings/python/examples/client/submit_and_read_block.py b/bindings/python/examples/client/submit_and_read_block.py index 6eb5a71351..2c3d444207 100644 --- a/bindings/python/examples/client/submit_and_read_block.py +++ b/bindings/python/examples/client/submit_and_read_block.py @@ -70,14 +70,14 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data"))) -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) print('\nThe block ID for your submitted block is:') print(f' {block_id}') print('\nMetadata for your submitted block is:') -print(f' {signed_block}') +print(f' {block}') ######################################################## # Step 3: Use the block ID to read the payload back diff --git a/bindings/python/iota_sdk/types/block/metadata.py b/bindings/python/iota_sdk/types/block/metadata.py index d1f7a67cf3..19a45386e2 100644 --- a/bindings/python/iota_sdk/types/block/metadata.py +++ b/bindings/python/iota_sdk/types/block/metadata.py @@ -6,7 +6,6 @@ from dataclasses import dataclass from typing import Optional from iota_sdk.types.common import HexStr, json -# TODO rename change to Block from iota_sdk.types.block.block import Block diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index 9f121ec87b..17fdfc9395 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -18,7 +18,7 @@ # Required to prevent circular import if TYPE_CHECKING: - from iota_sdk.types.block.signed_block import Block + from iota_sdk.types.block.block import Block # pylint: disable=too-many-public-methods diff --git a/bindings/python/tests/test_block.py b/bindings/python/tests/test_block.py index a09003d471..4a26b54d55 100644 --- a/bindings/python/tests/test_block.py +++ b/bindings/python/tests/test_block.py @@ -63,14 +63,14 @@ def test_signed_block_with_tagged_data_payload(): "signature": "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" } } - signed_block = Block.from_dict(block_dict) - assert signed_block.to_dict() == block_dict - assert isinstance(signed_block.block, BasicBlockBody) - assert signed_block.block.type == BlockBodyType.Basic - assert isinstance(signed_block.block.payload, get_args(Payload)) - assert signed_block.block.payload.type == PayloadType.TaggedData + block = Block.from_dict(block_dict) + assert block.to_dict() == block_dict + assert isinstance(block.body, BasicBlockBody) + assert block.body.type == BlockBodyType.Basic + assert isinstance(block.body.payload, get_args(Payload)) + assert block.body.payload.type == PayloadType.TaggedData # TODO: determine the actual hash of the block - # assert signed_block.id() == "0x7ce5ad074d4162e57f83cfa01cd2303ef5356567027ce0bcee0c9f57bc11656e" + # assert block.id() == "0x7ce5ad074d4162e57f83cfa01cd2303ef5356567027ce0bcee0c9f57bc11656e" @pytest.mark.skip(reason="https://github.com/iotaledger/iota-sdk/issues/1387") From f1d3853c7f1310435c00a0f064f359bcd0e3b819 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 12 Dec 2023 12:15:26 +0100 Subject: [PATCH 6/8] file rename --- bindings/python/iota_sdk/types/block/body/{kind.py => type.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bindings/python/iota_sdk/types/block/body/{kind.py => type.py} (100%) diff --git a/bindings/python/iota_sdk/types/block/body/kind.py b/bindings/python/iota_sdk/types/block/body/type.py similarity index 100% rename from bindings/python/iota_sdk/types/block/body/kind.py rename to bindings/python/iota_sdk/types/block/body/type.py From 1ac100d338785db1d0c3d70dce6f8af943785734 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 12 Dec 2023 12:18:19 +0100 Subject: [PATCH 7/8] fix imports --- bindings/python/iota_sdk/__init__.py | 2 +- bindings/python/iota_sdk/types/block/body/basic.py | 2 +- bindings/python/iota_sdk/types/block/body/validation.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/python/iota_sdk/__init__.py b/bindings/python/iota_sdk/__init__.py index 94fef21188..2d8174022b 100644 --- a/bindings/python/iota_sdk/__init__.py +++ b/bindings/python/iota_sdk/__init__.py @@ -14,7 +14,7 @@ from .types.balance import * from .types.block.block import * from .types.block.body.basic import * -from .types.block.body.kind import * +from .types.block.body.type import * from .types.block.body.validation import * from .types.block.metadata import * from .types.block_builder_options import * diff --git a/bindings/python/iota_sdk/types/block/body/basic.py b/bindings/python/iota_sdk/types/block/body/basic.py index dcea4da319..52a1110189 100644 --- a/bindings/python/iota_sdk/types/block/body/basic.py +++ b/bindings/python/iota_sdk/types/block/body/basic.py @@ -5,7 +5,7 @@ from dataclasses import dataclass, field from typing import List, Optional from dataclasses_json import config -from iota_sdk.types.block.body.kind import BlockBodyType +from iota_sdk.types.block.body.type import BlockBodyType from iota_sdk.types.common import HexStr, json from iota_sdk.types.payload import Payload diff --git a/bindings/python/iota_sdk/types/block/body/validation.py b/bindings/python/iota_sdk/types/block/body/validation.py index 752e7349c8..b963fcdeb4 100644 --- a/bindings/python/iota_sdk/types/block/body/validation.py +++ b/bindings/python/iota_sdk/types/block/body/validation.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass, field from typing import List, Optional -from iota_sdk.types.block.body.kind import BlockBodyType +from iota_sdk.types.block.body.type import BlockBodyType from iota_sdk.types.common import HexStr, json From 95653f78b4f3c1a191f2311e8b893deeb099ecea Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 12 Dec 2023 12:21:54 +0100 Subject: [PATCH 8/8] Nit --- bindings/python/tests/test_block.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/tests/test_block.py b/bindings/python/tests/test_block.py index 4a26b54d55..b1d10b0af8 100644 --- a/bindings/python/tests/test_block.py +++ b/bindings/python/tests/test_block.py @@ -30,7 +30,7 @@ def test_basic_block_with_tagged_data_payload(): assert block_to_dict == block_dict -def test_signed_block_with_tagged_data_payload(): +def test_block_with_tagged_data_payload(): block_dict = { "protocolVersion": 3, "networkId": "10549460113735494767",