Skip to content

Commit

Permalink
Merge branch '2.0' of https://github.com/iotaledger/iota-sdk into 500…
Browse files Browse the repository at this point in the history
…-error-patch
  • Loading branch information
marc2332 committed Feb 8, 2024
2 parents a95aaf6 + 4724811 commit 3a69c47
Show file tree
Hide file tree
Showing 25 changed files with 156 additions and 85 deletions.
5 changes: 4 additions & 1 deletion bindings/python/iota_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .types.block.body.type import *
from .types.block.body.validation import *
from .types.block.metadata import *
from .types.block.id import *
from .types.block_builder_options import *
from .types.block_issuer_key import *
from .types.burn import *
Expand All @@ -43,10 +44,12 @@
from .types.output_params import *
from .types.payload import *
from .types.send_params import *
from .types.slot import *
from .types.token_scheme import *
from .types.transaction_with_metadata import *
from .types.transaction_data import *
from .types.transaction_id import *
from .types.transaction_options import *
from .types.transaction_with_metadata import *
from .types.unlock import *
from .types.unlock_condition import *
from .types.utxo_changes import *
Expand Down
5 changes: 3 additions & 2 deletions bindings/python/iota_sdk/client/_high_level_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from dataclasses import dataclass
from abc import ABCMeta, abstractmethod
from iota_sdk.types.block.block import Block
from iota_sdk.types.common import CoinType, HexStr, json
from iota_sdk.types.block.id import BlockId
from iota_sdk.types.common import CoinType, json
from iota_sdk.types.output_metadata import OutputWithMetadata
from iota_sdk.types.output_id import OutputId

Expand Down Expand Up @@ -111,7 +112,7 @@ def get_outputs_ignore_errors(
})
return [OutputWithMetadata.from_dict(o) for o in outputs]

def find_blocks(self, block_ids: List[HexStr]) -> List[Block]:
def find_blocks(self, block_ids: List[BlockId]) -> List[Block]:
"""Find all blocks by provided block IDs.
Args:
Expand Down
28 changes: 15 additions & 13 deletions bindings/python/iota_sdk/client/_node_core_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from dacite import from_dict

from iota_sdk.types.block.block import Block
from iota_sdk.types.block.id import BlockId
from iota_sdk.types.block.metadata import BlockMetadata, BlockWithMetadata
from iota_sdk.types.common import HexStr
from iota_sdk.types.node_info import NodeInfo, NodeInfoWrapper
from iota_sdk.types.output_metadata import OutputWithMetadata, OutputMetadata
from iota_sdk.types.output_id import OutputId
from iota_sdk.types.transaction_id import TransactionId


class NodeCoreAPI(metaclass=ABCMeta):
Expand Down Expand Up @@ -65,12 +67,12 @@ def get_info(self) -> NodeInfoWrapper:
"""
return from_dict(NodeInfoWrapper, self._call_method('getInfo'))

def get_tips(self) -> List[HexStr]:
def get_tips(self) -> List[BlockId]:
"""Request tips from the node.
"""
return self._call_method('getTips')

def post_block(self, block: Block) -> HexStr:
def post_block(self, block: Block) -> BlockId:
"""Post a block.
Args:
Expand All @@ -79,47 +81,47 @@ def post_block(self, block: Block) -> HexStr:
Returns:
The block id of the posted block.
"""
return self._call_method('postBlock', {
return BlockId(self._call_method('postBlock', {
'block': block
})
}))

def get_block(self, block_id: HexStr) -> Block:
def get_block(self, block_id: BlockId) -> Block:
"""Get the block corresponding to the given block id.
"""
return Block.from_dict(self._call_method('getBlock', {
'blockId': block_id
}))

def get_block_metadata(self, block_id: HexStr) -> BlockMetadata:
def get_block_metadata(self, block_id: BlockId) -> BlockMetadata:
"""Get the block metadata corresponding to the given block id.
"""
return BlockMetadata.from_dict(self._call_method('getBlockMetadata', {
'blockId': block_id
}))

def get_block_with_metadata(self, block_id: HexStr) -> BlockWithMetadata:
def get_block_with_metadata(self, block_id: BlockId) -> BlockWithMetadata:
"""Get a block with its metadata corresponding to the given block id.
"""
return BlockWithMetadata.from_dict(self._call_method('getBlockWithMetadata', {
'blockId': block_id
}))

def get_block_raw(self, block_id: HexStr) -> List[int]:
def get_block_raw(self, block_id: BlockId) -> List[int]:
"""Get the raw bytes of the block corresponding to the given block id.
"""
return self._call_method('getBlockRaw', {
'blockId': block_id
})

def post_block_raw(self, block_bytes: List[int]) -> HexStr:
def post_block_raw(self, block_bytes: List[int]) -> BlockId:
"""Post a block as raw bytes.
Returns:
The corresponding block id of the block.
"""
return self._call_method('postBlockRaw', {
return BlockId(self._call_method('postBlockRaw', {
'blockBytes': block_bytes
})
}))

def get_output(
self, output_id: Union[OutputId, HexStr]) -> OutputWithMetadata:
Expand Down Expand Up @@ -147,7 +149,7 @@ def get_output_metadata(
'outputId': output_id_str
}))

def get_included_block(self, transaction_id: HexStr) -> Block:
def get_included_block(self, transaction_id: TransactionId) -> Block:
"""Returns the included block of the given transaction.
Returns:
Expand All @@ -158,7 +160,7 @@ def get_included_block(self, transaction_id: HexStr) -> Block:
}))

def get_included_block_metadata(
self, transaction_id: HexStr) -> BlockMetadata:
self, transaction_id: TransactionId) -> BlockMetadata:
"""Returns the metadata of the included block of the given transaction.
Returns:
Expand Down
7 changes: 4 additions & 3 deletions bindings/python/iota_sdk/client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from abc import ABCMeta, abstractmethod

from iota_sdk.types.block.block import Block
from iota_sdk.types.block.id import BlockId
from iota_sdk.types.common import HexStr
from iota_sdk.types.output import Output

Expand Down Expand Up @@ -88,9 +89,9 @@ def request_funds_from_faucet(self, url: str, address: str) -> str:
}
)

def block_id(self, block: Block) -> HexStr:
def block_id(self, block: Block) -> BlockId:
""" Return a block ID (Blake2b256 hash of block bytes) from a block.
"""
return self._call_method('blockId', {
return BlockId(self._call_method('blockId', {
'block': block,
})
}))
3 changes: 2 additions & 1 deletion bindings/python/iota_sdk/types/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dataclasses_json import config
from iota_sdk.types.decayed_mana import DecayedMana
from iota_sdk.types.common import hex_str_decoder, HexStr, json
from iota_sdk.types.output_id import OutputId


@json
Expand Down Expand Up @@ -118,4 +119,4 @@ class Balance:
foundries: List[HexStr]
nfts: List[HexStr]
delegations: List[HexStr]
potentially_locked_outputs: dict[HexStr, bool]
potentially_locked_outputs: dict[OutputId, bool]
6 changes: 4 additions & 2 deletions bindings/python/iota_sdk/types/block/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
from iota_sdk.types.common import HexStr, json, SlotIndex
from iota_sdk.types.node_info import ProtocolParameters
from iota_sdk.types.signature import Signature
from iota_sdk.types.slot import SlotCommitmentId
from iota_sdk.types.block.body.basic import BasicBlockBody
from iota_sdk.types.block.body.validation import ValidationBlockBody
from iota_sdk.types.block.body.type import BlockBodyType
from iota_sdk.types.block.id import BlockId


@json
Expand All @@ -34,7 +36,7 @@ class BlockHeader:
issuing_time: int = field(metadata=config(
encoder=str
))
slot_commitment_id: HexStr
slot_commitment_id: SlotCommitmentId
latest_finalized_slot: SlotIndex
issuer_id: HexStr

Expand Down Expand Up @@ -85,7 +87,7 @@ class Block:
))
signature: Signature

def id(self, params: ProtocolParameters) -> HexStr:
def id(self, params: ProtocolParameters) -> BlockId:
"""Returns the block ID as a hexadecimal string.
"""
return Utils.block_id(self, params)
Expand Down
9 changes: 5 additions & 4 deletions bindings/python/iota_sdk/types/block/body/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from dataclasses import dataclass, field
from typing import List, Optional
from dataclasses_json import config
from iota_sdk.types.block.id import BlockId
from iota_sdk.types.block.body.type import BlockBodyType
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import json
from iota_sdk.types.payload import Payload, deserialize_payload


Expand All @@ -26,12 +27,12 @@ class BasicBlockBody:
type: int = field(
default_factory=lambda: int(BlockBodyType.Basic),
init=False)
strong_parents: List[HexStr]
strong_parents: List[BlockId]
max_burned_mana: int = field(metadata=config(
encoder=str
))
weak_parents: Optional[List[HexStr]] = None
shallow_like_parents: Optional[List[HexStr]] = None
weak_parents: Optional[List[BlockId]] = None
shallow_like_parents: Optional[List[BlockId]] = None
payload: Optional[Payload] = field(default=None, metadata=config(
decoder=deserialize_payload
))
7 changes: 4 additions & 3 deletions bindings/python/iota_sdk/types/block/body/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations
from dataclasses import dataclass, field
from typing import List, Optional
from iota_sdk.types.block.id import BlockId
from iota_sdk.types.block.body.type import BlockBodyType
from iota_sdk.types.common import HexStr, json

Expand All @@ -25,8 +26,8 @@ class ValidationBlockBody:
type: int = field(
default_factory=lambda: int(BlockBodyType.Validation),
init=False)
strong_parents: List[HexStr]
strong_parents: List[BlockId]
highest_supported_version: int
protocol_parameters_hash: HexStr
weak_parents: Optional[List[HexStr]] = None
shallow_like_parents: Optional[List[HexStr]] = None
weak_parents: Optional[List[BlockId]] = None
shallow_like_parents: Optional[List[BlockId]] = None
9 changes: 9 additions & 0 deletions bindings/python/iota_sdk/types/block/id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2024 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from iota_sdk.types.common import IdWithSlotIndex


class BlockId(IdWithSlotIndex):
"""Represents a block ID.
"""
5 changes: 3 additions & 2 deletions bindings/python/iota_sdk/types/block/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from enum import Enum, IntEnum
from dataclasses import dataclass
from typing import Optional
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import json
from iota_sdk.types.block.block import Block
from iota_sdk.types.block.id import BlockId


@json
Expand All @@ -21,7 +22,7 @@ class BlockMetadata:
block_failure_reason: The block failure reason.
transaction_failure_reason: The transaction failure reason.
"""
block_id: HexStr
block_id: BlockId
block_state: BlockState
transaction_state: Optional[TransactionState] = None
block_failure_reason: Optional[BlockFailureReason] = None
Expand Down
7 changes: 4 additions & 3 deletions bindings/python/iota_sdk/types/block_builder_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dataclasses_json import config
from iota_sdk.types.common import HexStr, AddressAndAmount, json
from iota_sdk.client._high_level_api import Range
from iota_sdk.types.block.id import BlockId
from iota_sdk.types.burn import Burn
from iota_sdk.types.output import Output
from iota_sdk.types.input import UtxoInput
Expand Down Expand Up @@ -34,7 +35,7 @@ class BlockBuilderOptions:
custom_remainder_address: Optional[str] = None
tag: Optional[HexStr] = None
data: Optional[HexStr] = None
strong_parents: Optional[List[HexStr]] = None
weak_parents: Optional[List[HexStr]] = None
shallow_like_parents: Optional[List[HexStr]] = None
strong_parents: Optional[List[BlockId]] = None
weak_parents: Optional[List[BlockId]] = None
shallow_like_parents: Optional[List[BlockId]] = None
burn: Optional[Burn] = None
15 changes: 15 additions & 0 deletions bindings/python/iota_sdk/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,18 @@ class AddressAndAmount():
encoder=str
))
address: str


class IdWithSlotIndex(str):
"""Represents an hex encoded ID that contains a slot index at the end.
Attributes:
id: The hex encoded ID with a slot index.
"""

def slot_index(self):
"""Returns the slot index of the ID.
"""
return int.from_bytes(
bytes.fromhex(self[-8:]), 'little')
3 changes: 2 additions & 1 deletion bindings/python/iota_sdk/types/context_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from enum import IntEnum
from typing import Any, Dict, List, TypeAlias, Union
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.slot import SlotCommitmentId


class ContextInputType(IntEnum):
Expand All @@ -29,7 +30,7 @@ class CommitmentContextInput:
default_factory=lambda: int(
ContextInputType.Commitment),
init=False)
commitment_id: HexStr
commitment_id: SlotCommitmentId


@json
Expand Down
5 changes: 3 additions & 2 deletions bindings/python/iota_sdk/types/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from enum import IntEnum
from typing import Dict, List, TypeAlias, Union, Any
from dataclasses import dataclass, field
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import json
from iota_sdk.types.transaction_id import TransactionId


class InputType(IntEnum):
Expand All @@ -31,7 +32,7 @@ class UtxoInput:
default_factory=lambda: int(
InputType.Utxo),
init=False)
transaction_id: HexStr
transaction_id: TransactionId
transaction_output_index: int


Expand Down
5 changes: 3 additions & 2 deletions bindings/python/iota_sdk/types/node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from dataclasses import dataclass, field
from typing import List, Optional
from dataclasses_json import config
from iota_sdk.types.common import EpochIndex, HexStr, json, SlotIndex
from iota_sdk.types.common import EpochIndex, json, SlotIndex
from iota_sdk.types.slot import SlotCommitmentId


@json
Expand Down Expand Up @@ -38,7 +39,7 @@ class NodeInfoStatus:
relative_confirmed_tangle_time: int = field(metadata=config(
encoder=str
))
latest_commitment_id: HexStr
latest_commitment_id: SlotCommitmentId
latest_finalized_slot: SlotIndex
latest_accepted_block_slot: SlotIndex
latest_confirmed_block_slot: SlotIndex
Expand Down
5 changes: 3 additions & 2 deletions bindings/python/iota_sdk/types/output_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from dataclasses import dataclass
from typing import Optional
from iota_sdk.types.address import Address
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import json
from iota_sdk.types.output import Output
from iota_sdk.types.output_id import OutputId
from iota_sdk.types.output_metadata import OutputMetadata
from iota_sdk.types.signature import Bip44

Expand All @@ -25,7 +26,7 @@ class OutputData():
remainder: Whether the output represents a remainder amount.
chain: A list of chain state indexes.
"""
output_id: HexStr
output_id: OutputId
metadata: OutputMetadata
output: Output
address: Address
Expand Down
Loading

0 comments on commit 3a69c47

Please sign in to comment.