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

Use ints for U256 values in Python #1552

Merged
merged 8 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bindings/python/iota_sdk/types/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ class NativeTokensBalance:
metadata: Some metadata of the native token.
"""
token_id: HexStr
total: HexStr
available: HexStr
total: int = field(metadata=config(
encoder=hex,
decoder=lambda v: int(v, 0)
))
available: int = field(metadata=config(
encoder=hex,
decoder=lambda v: int(v, 0)
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
))
metadata: Optional[HexStr]


Expand Down
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/block/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ class BasicBlock:
))
payload: Optional[Payload] = None
type: int = field(
default_factory=lambda: BlockType.Basic,
default_factory=lambda: int(BlockType.Basic),
init=False)
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/block/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ class ValidationBlock:
highest_supported_version: int
protocol_parameters_hash: HexStr
type: int = field(
default_factory=lambda: BlockType.Validation,
default_factory=lambda: int(BlockType.Validation),
init=False)
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/essence.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RegularTransactionEssence:
capabilities: HexStr = field(default='0x', init=False)
payload: Optional[Payload] = None
type: int = field(
default_factory=lambda: EssenceType.RegularTransactionEssence,
default_factory=lambda: int(EssenceType.RegularTransactionEssence),
init=False)

def with_capabilities(self, capabilities: bytes):
Expand Down
8 changes: 6 additions & 2 deletions bindings/python/iota_sdk/types/native_token.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from dataclasses import dataclass
from dataclasses import dataclass, field
from dataclasses_json import config

from iota_sdk.types.common import HexStr, json

Expand All @@ -16,4 +17,7 @@ class NativeToken():
amount: The amount of native tokens.
"""
id: HexStr
amount: HexStr
amount: int = field(metadata=config(
encoder=hex,
decoder=lambda v: int(v, 0)
))
6 changes: 4 additions & 2 deletions bindings/python/iota_sdk/types/send_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ class CreateNativeTokenParams():
account_id: The ID of the corresponding account.
"""
circulating_supply: int = field(metadata=config(
encoder=str
encoder=hex,
decoder=lambda v: int(v, 0)
))
maximum_supply: int = field(metadata=config(
encoder=str
encoder=hex,
decoder=lambda v: int(v, 0)
))
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
foundry_metadata: Optional[str] = None
account_id: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Ed25519Signature:
"""
public_key: HexStr
signature: HexStr
type: int = field(default_factory=lambda: 0, init=False)
type: int = field(default=0, init=False)


Signature: TypeAlias = Ed25519Signature
Expand Down
20 changes: 15 additions & 5 deletions bindings/python/iota_sdk/types/token_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# SPDX-License-Identifier: Apache-2.0

from dataclasses import dataclass, field
from dataclasses_json import config
from typing import TypeAlias
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import json


@json
Expand All @@ -17,10 +18,19 @@ class SimpleTokenScheme:
maximum_supply: The maximum supply of the token.
type: The type code of the token scheme.
"""
minted_tokens: HexStr
melted_tokens: HexStr
maximum_supply: HexStr
type: int = field(default_factory=lambda: 0, init=False)
minted_tokens: int = field(metadata=config(
encoder=hex,
decoder=lambda v: int(v, 0)
))
melted_tokens: int = field(metadata=config(
encoder=hex,
decoder=lambda v: int(v, 0)
))
maximum_supply: int = field(metadata=config(
encoder=hex,
decoder=lambda v: int(v, 0)
))
type: int = field(default=0, init=False)


TokenScheme: TypeAlias = SimpleTokenScheme
12 changes: 2 additions & 10 deletions bindings/python/iota_sdk/types/unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ class UnlockType(IntEnum):

@json
@dataclass
class Unlock:
"""Unlock type.
"""
type: int


@json
@dataclass
class SignatureUnlock(Unlock):
class SignatureUnlock:
"""An unlock holding a signature unlocking one or more inputs.
"""
signature: Ed25519Signature
Expand All @@ -49,7 +41,7 @@ class SignatureUnlock(Unlock):

@json
@dataclass
class ReferenceUnlock(Unlock):
class ReferenceUnlock:
"""An unlock which must reference a previous unlock which unlocks also the input at the same index as this Reference Unlock.
"""
reference: int
Expand Down