-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More Python types and type hints (#712)
* More Python types and type hints * Review
- Loading branch information
Showing
17 changed files
with
183 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright 2023 IOTA Stiftung | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from typing import Any, Dict, Optional | ||
from iota_sdk.types.common import HexStr | ||
|
||
# TODO: https://github.com/iotaledger/iota-sdk/issues/129 | ||
# @dataclass | ||
# class Output(): | ||
# def __init__(self, type, sender=None, issuer=None, data=None, tag=None): | ||
# """Initialize an output | ||
|
||
# Parameters | ||
# ---------- | ||
# type : OutputType | ||
# The type of output | ||
# """ | ||
# self.type = type | ||
|
||
|
||
# @classmethod | ||
# def from_dict(cls, output_dict: Dict) -> Output: | ||
# obj = cls.__new__(cls) | ||
# super(Output, obj).__init__() | ||
# for k, v in output_dict.items(): | ||
# setattr(obj, k, v) | ||
# return obj | ||
|
||
@dataclass | ||
class OutputMetadata: | ||
"""Metadata about an output. | ||
""" | ||
|
||
blockId: HexStr | ||
transactionId: HexStr | ||
outputIndex: int | ||
isSpent: bool | ||
milestoneIndexBooked: int | ||
milestoneTimestampBooked: int | ||
ledgerIndex: int | ||
milestoneIndexSpent: Optional[int] = None | ||
milestoneTimestampSpent: Optional[int] = None | ||
transactionIdSpent: Optional[HexStr] = None | ||
|
||
@classmethod | ||
def from_dict(cls, dict: Dict) -> OutputMetadata: | ||
obj = cls.__new__(cls) | ||
super(OutputMetadata, obj).__init__() | ||
for k, v in dict.items(): | ||
setattr(obj, k, v) | ||
return obj | ||
|
||
|
||
@dataclass | ||
class OutputWithMetadata: | ||
"""An output with its metadata. | ||
""" | ||
|
||
metadata: OutputMetadata | ||
output: Any # TODO: Output https://github.com/iotaledger/iota-sdk/issues/129 | ||
|
||
@classmethod | ||
def from_dict(cls, dict: Dict) -> OutputWithMetadata: | ||
obj = cls.__new__(cls) | ||
super(OutputWithMetadata, obj).__init__() | ||
for k, v in dict.items(): | ||
setattr(obj, k, v) | ||
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2023 IOTA Stiftung | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from typing import Dict, List, Optional | ||
from iota_sdk.types.common import HexStr | ||
from iota_sdk.types.output import OutputWithMetadata | ||
from iota_sdk.types.payload import TransactionPayload | ||
from enum import Enum | ||
|
||
|
||
class InclusionState(str, Enum): | ||
Pending = 'pending' | ||
Confirmed = 'confirmed' | ||
Conflicting = 'conflicting' | ||
UnknownPruned = 'unknownPruned' | ||
|
||
|
||
@dataclass | ||
class Transaction: | ||
"""The transaction payload with metadata. | ||
""" | ||
|
||
payload: TransactionPayload | ||
inclusionState: InclusionState | ||
timestamp: int | ||
transactionId: HexStr | ||
networkId: int | ||
incoming: bool | ||
inputs = List[OutputWithMetadata] | ||
note: Optional[str] = None | ||
blockId: Optional[HexStr] = None | ||
|
||
@classmethod | ||
def from_dict(cls, dict: Dict) -> Transaction: | ||
obj = cls.__new__(cls) | ||
super(Transaction, obj).__init__() | ||
for k, v in dict.items(): | ||
setattr(obj, k, v) | ||
return obj |
Oops, something went wrong.