diff --git a/bindings/python/iota_sdk/types/balance.py b/bindings/python/iota_sdk/types/balance.py index a6c25282c6..791dbb96c3 100644 --- a/bindings/python/iota_sdk/types/balance.py +++ b/bindings/python/iota_sdk/types/balance.py @@ -5,7 +5,7 @@ from typing import List, Optional from dataclasses import dataclass, field from dataclasses_json import config -from iota_sdk.types.common import HexStr, json +from iota_sdk.types.common import hex_str_decoder, HexStr, json @json @@ -64,11 +64,11 @@ class NativeTokensBalance: token_id: HexStr total: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) available: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) metadata: Optional[HexStr] diff --git a/bindings/python/iota_sdk/types/common.py b/bindings/python/iota_sdk/types/common.py index 261f62e3f2..3cd9ee4218 100644 --- a/bindings/python/iota_sdk/types/common.py +++ b/bindings/python/iota_sdk/types/common.py @@ -112,6 +112,11 @@ def opt_int_encoder(value): return None +def hex_str_decoder(value: str) -> int: + """Parses a given string as a hexadecimal integer.""" + return int(value, 16) + + @json @dataclass class AddressAndAmount(): diff --git a/bindings/python/iota_sdk/types/native_token.py b/bindings/python/iota_sdk/types/native_token.py index 7b70d63a4e..c382c31070 100644 --- a/bindings/python/iota_sdk/types/native_token.py +++ b/bindings/python/iota_sdk/types/native_token.py @@ -4,7 +4,7 @@ from dataclasses import dataclass, field from dataclasses_json import config -from iota_sdk.types.common import HexStr, json +from iota_sdk.types.common import hex_str_decoder, HexStr, json @json @@ -19,5 +19,5 @@ class NativeToken(): id: HexStr amount: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) diff --git a/bindings/python/iota_sdk/types/send_params.py b/bindings/python/iota_sdk/types/send_params.py index a9dcf7a133..cd3e404472 100644 --- a/bindings/python/iota_sdk/types/send_params.py +++ b/bindings/python/iota_sdk/types/send_params.py @@ -5,7 +5,7 @@ from dataclasses import dataclass, field from typing import Optional, List from dataclasses_json import config -from iota_sdk.types.common import HexStr, json +from iota_sdk.types.common import hex_str_decoder, HexStr, json from iota_sdk.types.native_token import NativeToken @@ -73,11 +73,11 @@ class CreateNativeTokenParams(): """ circulating_supply: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) maximum_supply: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) foundry_metadata: Optional[str] = None account_id: Optional[str] = None diff --git a/bindings/python/iota_sdk/types/token_scheme.py b/bindings/python/iota_sdk/types/token_scheme.py index ef7a7bb59d..3a60e9282d 100644 --- a/bindings/python/iota_sdk/types/token_scheme.py +++ b/bindings/python/iota_sdk/types/token_scheme.py @@ -4,7 +4,7 @@ from typing import TypeAlias from dataclasses import dataclass, field from dataclasses_json import config -from iota_sdk.types.common import json +from iota_sdk.types.common import hex_str_decoder, json @json @@ -20,15 +20,15 @@ class SimpleTokenScheme: """ minted_tokens: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) melted_tokens: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) maximum_supply: int = field(metadata=config( encoder=hex, - decoder=lambda v: int(v, 16) + decoder=hex_str_decoder, )) type: int = field(default=0, init=False)