From 49cc78cba520d8b0bceb30f914a3f7de81a244f1 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Fri, 3 May 2024 20:51:46 +0200 Subject: [PATCH] Fix: make TaggedData data field optional (#1983) * Make TaggedDataPayload::data field optional * Tag also optional, still failing * Make TaggedDataPayload work * Uncomment, fix imports and lint * Raise error * Update date * reorder union * Remove unused import, update changelog, bump version * Update rustls --------- Co-authored-by: Alex Coats --- Cargo.lock | 6 +++--- bindings/python/CHANGELOG.md | 6 ++++++ bindings/python/Cargo.toml | 2 +- bindings/python/iota_sdk/types/block.py | 4 ++-- bindings/python/iota_sdk/types/payload.py | 4 ++-- bindings/python/setup.py | 2 +- bindings/python/tests/test_block.py | 8 ++++++++ 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1be293f4b..e73b3234d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1638,7 +1638,7 @@ dependencies = [ [[package]] name = "iota-sdk-python" -version = "1.1.3" +version = "1.1.4" dependencies = [ "futures", "iota-sdk-bindings-core", @@ -2688,9 +2688,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring", diff --git a/bindings/python/CHANGELOG.md b/bindings/python/CHANGELOG.md index a6711a1480..bf18fb07db 100644 --- a/bindings/python/CHANGELOG.md +++ b/bindings/python/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.1.4 - 2024-05-03 + +### Fixed + +- Made `TaggedDataPayload::{tag, data}` optional; + ## 1.1.3 - 2024-02-14 ### Added diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index b426e14fff..2fbcfc26b1 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iota-sdk-python" -version = "1.1.3" +version = "1.1.4" authors = ["IOTA Stiftung"] edition = "2021" description = "Python bindings for the IOTA SDK library" diff --git a/bindings/python/iota_sdk/types/block.py b/bindings/python/iota_sdk/types/block.py index 22ac15dadd..2878638a48 100644 --- a/bindings/python/iota_sdk/types/block.py +++ b/bindings/python/iota_sdk/types/block.py @@ -25,8 +25,8 @@ class Block: protocolVersion: int parents: List[HexStr] nonce: str - payload: Optional[Union[TaggedDataPayload, - TransactionPayload, MilestonePayload]] = None + payload: Optional[Union[TransactionPayload, + MilestonePayload, TaggedDataPayload]] = None @classmethod def from_dict(cls, block_dict: Dict) -> Block: diff --git a/bindings/python/iota_sdk/types/payload.py b/bindings/python/iota_sdk/types/payload.py index c479bf1844..4f1f0f5039 100644 --- a/bindings/python/iota_sdk/types/payload.py +++ b/bindings/python/iota_sdk/types/payload.py @@ -143,8 +143,8 @@ class TaggedDataPayload(Payload): tag: The tag part of the tagged data payload. data: The data part of the tagged data payload. """ - tag: HexStr - data: HexStr + tag: Optional[HexStr] = None + data: Optional[HexStr] = None type: int = field( default_factory=lambda: int( PayloadType.TaggedData), diff --git a/bindings/python/setup.py b/bindings/python/setup.py index d950a18e3f..1c97d88a48 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -22,7 +22,7 @@ def get_py_version_cfgs(): setup( name="iota_sdk", - version="1.1.3", + version="1.1.4", classifiers=[ "License :: SPDX-License-Identifier :: Apache-2.0", "Intended Audience :: Developers", diff --git a/bindings/python/tests/test_block.py b/bindings/python/tests/test_block.py index 4c76d98d49..142ea8a22f 100644 --- a/bindings/python/tests/test_block.py +++ b/bindings/python/tests/test_block.py @@ -44,3 +44,11 @@ def test_block(): assert block.as_dict() == block_dict assert isinstance(block.payload, Payload) assert block.payload.type == PayloadType.Milestone + + # with tx payload and tagged data payload where the data is optional + block_dict = {"protocolVersion": 2, "parents": ["0x0882f56f6aa18a473c1104aaa6df5260ccf0b4b7a013763c44f231ebdd23a3c7", "0x1b26789153a9f1d5e139498f18e4cb2b7e31b67f6ddbec1053f49ce5034cdac4", "0x25ac8b75c5b14f13875dafb4de92b5256dd9c7fd73576eacc99740bd90413f62", "0xd36066423f2b225c9b9566794ea2ed25331afee340ea045271a1dd1d28f87b92"], "payload": {"type": 6, "essence": {"type": 1, "networkId": "7784367046153662236", "inputs": [{"type": 0, "transactionId": "0x9649d1ce9177435ee8fd3234267d7f1c82a858d3d36994379c495be864fdb223", "transactionOutputIndex": 0}], "inputsCommitment": "0xbeb2d535e60610e4284dd8de2046b695ed820519b8d7bea1b4e87859e01a4613", "outputs": [{"type": 3, "amount": "1000000000", "unlockConditions": [ + {"type": 0, "address": {"type": 0, "pubKeyHash": "0x7258772f96283ebcc91997805a0b4acc98c83d3d0bb1bc919e31974bb6cea9a2"}}]}, {"type": 3, "amount": "288098760415811743", "unlockConditions": [{"type": 0, "address": {"type": 0, "pubKeyHash": "0x77c2f4cdd686cc9e7667ff66977fc9e7687866a3a97745917cf786ba13a4124c"}}]}], "payload": {"type": 5}}, "unlocks": [{"type": 0, "signature": {"type": 0, "publicKey": "0xbae586465c574fcc9339ee0baae32bbabede7fab87b94f150c6bd38afd76abbe", "signature": "0x1c208a3afe0a5cb1045c0a4d2a5ae003ea56c9bed06128c60bde7e07266314ecd8bbfba22ecbba04e4f2e436d50d699b402537aef65a586149e6ae4d8be1fe0a"}}]}, "nonce": "1673315"} + block = Block.from_dict(block_dict) + assert block.as_dict() == block_dict + assert isinstance(block.payload, Payload) + assert block.payload.type == PayloadType.Transaction