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

Fix: make TaggedData data field optional #1983

Merged
merged 9 commits into from
May 3, 2024

Conversation

Thoralf-M
Copy link
Member

@Thoralf-M Thoralf-M commented Feb 12, 2024

Description of change

Without this change it fails to parse payloads where the data field is optional

dacite.exceptions.UnionMatchError: can not match type "dict" to any type of "payload" union: typing.Union[iota_sdk.types.payload.TaggedDataPayload, iota_sdk.types.payload.TransactionPayload, iota_sdk.types.payload.MilestonePayload, NoneType]

Type of change

  • Bug fix (a non-breaking change which fixes an issue)

How the change has been tested

from iota_sdk import Client, HexStr, Utils, OutputType

client = Client(nodes=['https://api.testnet.shimmer.network'])

transaction_id = HexStr(
    "0xe08103c471a1ccbd65b248a1bf0929b9b9c5e12bb219f3971aadf95b870a1ed4")
pub_key_hash = Utils.bech32_to_hex(
    "rms1qpe9sae0jc5ra0xfrxtcqkstftxf3jpa859mr0y3nccewjake656yu2k3pk")
amount = 1_000_000_000


block = client.get_included_block(transaction_id)


for output in block.payload.essence.outputs:
    if output.type == OutputType.Basic:
        if len(output.unlockConditions) == 1 and output.unlockConditions[0].type == 0:
            if output.unlockConditions[0].address.pubKeyHash == pub_key_hash and int(output.amount) == amount:
                print(f"{pub_key_hash} got {int(amount)}")

@Thoralf-M Thoralf-M marked this pull request as draft February 12, 2024 14:45
@Thoralf-M Thoralf-M changed the title Fix Block::from_dict() Fix: make TaggedData data field optional Feb 12, 2024
@Thoralf-M Thoralf-M marked this pull request as ready for review February 12, 2024 14:54
@Thoralf-M Thoralf-M marked this pull request as draft February 12, 2024 16:43
Copy link
Member

@thibault-martinez thibault-martinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflicts :trollface:

@Thoralf-M Thoralf-M marked this pull request as draft February 14, 2024 16:02
@Thoralf-M
Copy link
Member Author

Draft for now, maybe we can find a better way (without requiring the type in the TaggedDataPayload init)

@Thoralf-M Thoralf-M marked this pull request as ready for review May 3, 2024 15:44
@Thoralf-M Thoralf-M disabled auto-merge May 3, 2024 18:51
@Thoralf-M Thoralf-M merged commit 49cc78c into iotaledger:develop May 3, 2024
36 of 38 checks passed
@Thoralf-M Thoralf-M deleted the python-block-from-dict branch May 3, 2024 18:51
Thoralf-M added a commit that referenced this pull request May 7, 2024
* Fix nightly build (#1981)

* Fix TransactionOptions::as_dict() for remainder_value_strategy (#1993)

* Fix ClientOptions typing in wallet options (#1994)

* Bump version and set release date (#1996)

* Fix node.js readme example (#2220)

* Fix wasm compilation, bump wasm-bindgen (#2221)

* Fix wasm compilation, bump wasm-bindgen

* Update dependencies

* 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 <[email protected]>

* Update private tangle action

---------

Co-authored-by: Thibault Martinez <[email protected]>
Co-authored-by: Dr-Electron <[email protected]>
Co-authored-by: Alex Coats <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants