Skip to content

Commit

Permalink
Python fix parse_bech32_address() (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M authored Sep 12, 2023
1 parent 3ece953 commit 1b05eb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions bindings/python/iota_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1b05eb3

Please sign in to comment.