From 1b05eb3ff6f566d1148a8295e95a75831d6454cf Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Tue, 12 Sep 2023 15:17:35 +0200 Subject: [PATCH] Python fix parse_bech32_address() (#1210) --- bindings/python/CHANGELOG.md | 4 ++++ bindings/python/iota_sdk/utils.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bindings/python/CHANGELOG.md b/bindings/python/CHANGELOG.md index 2f3c0ac01d..6c0a924cba 100644 --- a/bindings/python/CHANGELOG.md +++ b/bindings/python/CHANGELOG.md @@ -25,6 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `ClientOptions::maxParallelApiRequests`; +### Fixed + +- `Utils::parse_bech32_address()`; + ## 1.0.1 - 2023-08-23 ### Fixed diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index f540286144..aea2c52464 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -4,7 +4,7 @@ from __future__ import annotations from iota_sdk import call_utils_method from iota_sdk.types.signature import Ed25519Signature -from iota_sdk.types.address import Address +from iota_sdk.types.address import Address, AddressType, Ed25519Address, AliasAddress, NFTAddress from iota_sdk.types.common import HexStr from iota_sdk.types.output_id import OutputId from iota_sdk.types.output import Output @@ -69,9 +69,18 @@ def hex_public_key_to_bech32_address(hex: HexStr, bech32_hrp: str) -> str: def parse_bech32_address(address: str) -> Address: """Parse a string into a valid address. """ - return from_dict(Address, _call_method('parseBech32Address', { + response = _call_method('parseBech32Address', { 'address': address - })) + }) + + address_type = AddressType(response['type']) + + if address_type == AddressType.ED25519: + return from_dict(Ed25519Address, response) + if address_type == AddressType.ALIAS: + return from_dict(AliasAddress, response) + if address_type == AddressType.NFT: + return from_dict(NFTAddress, response) @staticmethod def is_address_valid(address: str) -> bool: