Skip to content

Commit

Permalink
Merge branch '2.0' into feat/btree-sets
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars authored Oct 3, 2023
2 parents bf618b6 + 9b39040 commit ce2087b
Show file tree
Hide file tree
Showing 30 changed files with 464 additions and 205 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/bindings-python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -105,11 +105,7 @@ jobs:
matrix:
os: [ubuntu-latest]
docker-container:
[
"python:3.9.12-slim-bullseye",
"python:3.10.10-slim-bullseye",
"python:3.11.1-slim-bullseye",
]
["python:3.10.10-slim-bullseye", "python:3.11.1-slim-bullseye"]

steps:
- name: Checkout
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/bindings-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
python-version: ["3.10"]

steps:
- name: Checkout the Source Code
Expand All @@ -67,7 +67,6 @@ jobs:
working-directory: bindings/python
run: tox -e format


test:
name: Linter & Tests
needs: lint
Expand All @@ -78,7 +77,7 @@ jobs:
matrix:
# os: [windows-latest, macos-latest, ubuntu-latest]
os: [windows-latest, ubuntu-latest]
python-version: ["3.9"]
python-version: ["3.10"]

steps:
- name: Checkout the Source Code
Expand Down Expand Up @@ -125,4 +124,4 @@ jobs:
# TODO temporarily disabled https://github.com/iotaledger/iota-sdk/issues/647
# - name: Run tests
# working-directory: bindings/python
# run: tox
# run: tox
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/block/core/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export class BasicBlock extends Block {
* The amount of mana the Account identified by IssuerID is at most
* willing to burn for this block.
*/
readonly burnedMana!: u64;
readonly maxBurnedMana!: u64;
}
6 changes: 4 additions & 2 deletions bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
Ed25519Signature,
HexEncodedString,
Block,
TransactionEssence,
TransactionPayload,
TransactionId,
TokenSchemeType,
Output,
RentStructure,
BlockWrapper,
ProtocolParameters,
} from '../../';
import { AccountId } from '../../block/id';
import { SlotCommitment } from '../../block/slot';
Expand Down Expand Up @@ -88,7 +89,8 @@ export interface __ParseBech32AddressMethod__ {
export interface __BlockIdMethod__ {
name: 'blockId';
data: {
block: Block;
block: BlockWrapper;
params: ProtocolParameters;
};
}

Expand Down
10 changes: 5 additions & 5 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { callUtilsMethod } from '../bindings';
import {
Address,
HexEncodedString,
Block,
Ed25519Signature,
TransactionEssence,
TransactionPayload,
Expand All @@ -15,6 +14,8 @@ import {
RentStructure,
OutputId,
u64,
BlockWrapper,
ProtocolParameters,
} from '../types';
import {
AccountId,
Expand Down Expand Up @@ -196,20 +197,19 @@ export class Utils {
* Compute the block ID (Blake2b256 hash of the block bytes) of a block.
*
* @param block A block.
* @param params The network protocol parameters.
* @returns The corresponding block ID.
*/
static blockId(block: Block): BlockId {
static blockId(block: BlockWrapper, params: ProtocolParameters): BlockId {
return callUtilsMethod({
name: 'blockId',
data: {
block,
params,
},
});
}

/**
/**
* Compute the transaction ID (Blake2b256 hash of the provided transaction payload) of a transaction payload.
*
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Python binding to the [iota-sdk library](/README.md).

## Requirements

- [Python 3.9+](https://www.python.org)
- [Python 3.10+](https://www.python.org)
- [pip ^21.x](https://pypi.org/project/pip)
- `Rust` and `Cargo` to compile the binding. Install
them [here](https://doc.rust-lang.org/cargo/getting-started/installation.html).
Expand Down
1 change: 1 addition & 0 deletions bindings/python/iota_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .types.output import *
from .types.output_data import *
from .types.output_id import *
from .types.output_metadata import *
from .types.output_params import *
from .types.payload import *
from .types.send_params import *
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/client/_high_level_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from abc import ABCMeta, abstractmethod
from iota_sdk.types.block import Block
from iota_sdk.types.common import CoinType, HexStr, json
from iota_sdk.types.output import OutputWithMetadata
from iota_sdk.types.output_metadata import OutputWithMetadata
from iota_sdk.types.output_id import OutputId


Expand Down
6 changes: 3 additions & 3 deletions bindings/python/iota_sdk/client/_node_core_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from typing import List, Union
from typing import List, Optional, Union
from abc import ABCMeta, abstractmethod
from dacite import from_dict

from iota_sdk.types.block import Block, BlockMetadata
from iota_sdk.types.common import HexStr
from iota_sdk.types.node_info import NodeInfo, NodeInfoWrapper
from iota_sdk.types.output import OutputWithMetadata, OutputMetadata
from iota_sdk.types.output_metadata import OutputWithMetadata, OutputMetadata
from iota_sdk.types.output_id import OutputId


Expand Down Expand Up @@ -149,7 +149,7 @@ def get_included_block_metadata(
}))

def call_plugin_route(self, base_plugin_path: str, method: str,
endpoint: str, query_params: [str] = None, request: str = None):
endpoint: str, query_params: Optional[List[str]] = None, request: Optional[str] = None):
"""Extension method which provides request methods for plugins.
Args:
Expand Down
10 changes: 5 additions & 5 deletions bindings/python/iota_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from iota_sdk.types.feature import Feature
from iota_sdk.types.native_token import NativeToken
from iota_sdk.types.network_info import NetworkInfo
from iota_sdk.types.output import AccountOutput, BasicOutput, FoundryOutput, NftOutput, output_from_dict
from iota_sdk.types.output import AccountOutput, BasicOutput, FoundryOutput, NftOutput, deserialize_output
from iota_sdk.types.payload import Payload, TransactionPayload
from iota_sdk.types.token_scheme import SimpleTokenScheme
from iota_sdk.types.unlock_condition import UnlockCondition
Expand Down Expand Up @@ -197,7 +197,7 @@ def build_account_output(self,
if mana:
mana = str(mana)

return output_from_dict(self._call_method('buildAccountOutput', {
return deserialize_output(self._call_method('buildAccountOutput', {
'accountId': account_id,
'unlockConditions': unlock_conditions,
'amount': amount,
Expand Down Expand Up @@ -245,7 +245,7 @@ def build_basic_output(self,
if mana:
mana = str(mana)

return output_from_dict(self._call_method('buildBasicOutput', {
return deserialize_output(self._call_method('buildBasicOutput', {
'unlockConditions': unlock_conditions,
'amount': amount,
'mana': mana,
Expand Down Expand Up @@ -292,7 +292,7 @@ def build_foundry_output(self,
if amount:
amount = str(amount)

return output_from_dict(self._call_method('buildFoundryOutput', {
return deserialize_output(self._call_method('buildFoundryOutput', {
'serialNumber': serial_number,
'tokenScheme': token_scheme.to_dict(),
'unlockConditions': unlock_conditions,
Expand Down Expand Up @@ -344,7 +344,7 @@ def build_nft_output(self,
if mana:
mana = str(mana)

return output_from_dict(self._call_method('buildNftOutput', {
return deserialize_output(self._call_method('buildNftOutput', {
'nftId': nft_id,
'unlockConditions': unlock_conditions,
'amount': amount,
Expand Down
48 changes: 32 additions & 16 deletions bindings/python/iota_sdk/types/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
# SPDX-License-Identifier: Apache-2.0

from enum import IntEnum

from dataclasses import dataclass, field


from typing import Any, Dict, List, TypeAlias, Union
from iota_sdk.types.common import HexStr, json


Expand Down Expand Up @@ -69,19 +67,6 @@ class NFTAddress(Address):
type: int = field(default_factory=lambda: int(AddressType.NFT), init=False)


@json
@dataclass
# pylint: disable=function-redefined
# TODO: Change name
class AccountAddress():
"""An Address of the Account.
"""
address: str
key_index: int
internal: bool
used: bool


@json
@dataclass
class AddressWithUnspentOutputs():
Expand All @@ -91,3 +76,34 @@ class AddressWithUnspentOutputs():
key_index: int
internal: bool
output_ids: bool


AddressUnion: TypeAlias = Union[Ed25519Address, AccountAddress, NFTAddress]


def deserialize_address(d: Dict[str, Any]) -> AddressUnion:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
address_type = d['type']
if address_type == AddressType.ED25519:
return Ed25519Address.from_dict(d)
if address_type == AddressType.ACCOUNT:
return AccountAddress.from_dict(d)
if address_type == AddressType.NFT:
return NFTAddress.from_dict(d)
raise Exception(f'invalid address type: {address_type}')


def deserialize_addresses(
dicts: List[Dict[str, Any]]) -> List[AddressUnion]:
"""
Takes a list of dictionaries as input and returns a list with specific instances of a classes based on the value of the 'type' key in the dictionary.
Arguments:
* `dicts`: A list of dictionaries that are expected to have a key called 'type' which specifies the type of the returned value.
"""
return list(map(deserialize_address, dicts))
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/types/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class Block:
strong_parents: Blocks that are strongly directly approved.
weak_parents: Blocks that are weakly directly approved.
shallow_like_parents: Blocks that are directly referenced to adjust opinion.
burned_mana: The amount of Mana the Account identified by the IssuerId is at most willing to burn for this block.
max_burned_mana: The amount of Mana the Account identified by the IssuerId is at most willing to burn for this block.
payload: The optional payload of this block.
"""

protocol_version: int
strong_parents: List[HexStr]
weak_parents: List[HexStr]
shallow_like_parents: List[HexStr]
burned_mana: str
max_burned_mana: str
payload: Optional[Union[TaggedDataPayload,
TransactionPayload]] = None

Expand Down
33 changes: 33 additions & 0 deletions bindings/python/iota_sdk/types/context_input.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 enum import IntEnum
from typing import Any, Dict, List, TypeAlias, Union
from iota_sdk.types.common import HexStr, json


Expand Down Expand Up @@ -70,3 +71,35 @@ class RewardContextInput(ContextInput):
default_factory=lambda: int(
ContextInputType.Reward),
init=False)


ContextInputUnion: TypeAlias = Union[CommitmentContextInput,
BlockIssuanceCreditContextInput, RewardContextInput]


def deserialize_context_input(d: Dict[str, Any]) -> ContextInputUnion:
"""
Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary.
Arguments:
* `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value.
"""
context_input_type = dict['type']
if context_input_type == ContextInputType.Commitment:
return CommitmentContextInput.from_dict(d)
if context_input_type == ContextInputType.BlockIssuanceCredit:
return BlockIssuanceCreditContextInput.from_dict(d)
if context_input_type == ContextInputType.Reward:
return RewardContextInput.from_dict(d)
raise Exception(f'invalid context input type: {context_input_type}')


def deserialize_context_inputs(
dicts: List[Dict[str, Any]]) -> List[ContextInputUnion]:
"""
Takes a list of dictionaries as input and returns a list with specific instances of a classes based on the value of the 'type' key in the dictionary.
Arguments:
* `dicts`: A list of dictionaries that are expected to have a key called 'type' which specifies the type of the returned value.
"""
return list(map(deserialize_context_input, dicts))
14 changes: 5 additions & 9 deletions bindings/python/iota_sdk/types/essence.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

from __future__ import annotations
from enum import IntEnum
from typing import TYPE_CHECKING, Optional, List, Union
from typing import TYPE_CHECKING, Optional, List

from dataclasses import dataclass, field

from iota_sdk.types.common import HexStr, json, SlotIndex
from iota_sdk.types.mana import ManaAllotment
# TODO: Add missing output types in #1174
# pylint: disable=no-name-in-module
from iota_sdk.types.output import BasicOutput, AccountOutput, FoundryOutput, NftOutput, DelegationOutput
from iota_sdk.types.input import UtxoInput
from iota_sdk.types.context_input import CommitmentContextInput, BlockIssuanceCreditContextInput, RewardContextInput
from iota_sdk.types.context_input import ContextInputUnion
from iota_sdk.types.output import OutputUnion

# Required to prevent circular import
if TYPE_CHECKING:
Expand Down Expand Up @@ -57,10 +55,8 @@ class RegularTransactionEssence(TransactionEssence):
creation_slot: SlotIndex
inputs: List[UtxoInput]
inputs_commitment: HexStr
outputs: List[Union[BasicOutput, AccountOutput,
FoundryOutput, NftOutput, DelegationOutput]]
context_inputs: Optional[List[Union[CommitmentContextInput,
BlockIssuanceCreditContextInput, RewardContextInput]]] = None
outputs: List[OutputUnion]
context_inputs: Optional[List[ContextInputUnion]] = None
allotments: Optional[List[ManaAllotment]] = None
payload: Optional[Payload] = None
type: int = field(
Expand Down
Loading

0 comments on commit ce2087b

Please sign in to comment.