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 4, 2023
2 parents ce2087b + 9e8ef00 commit 416bf62
Show file tree
Hide file tree
Showing 26 changed files with 500 additions and 328 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/bindings-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ jobs:
working-directory: bindings/python
run: tox -e lint-examples

# TODO temporarily disabled https://github.com/iotaledger/iota-sdk/issues/647
# - name: Run tests
# working-directory: bindings/python
# run: tox
- name: Run tests
working-directory: bindings/python
run: tox
4 changes: 0 additions & 4 deletions bindings/nodejs/lib/types/models/info/node-info-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ export interface CongestionControlParameters {
* The rate at which the scheduler runs in workscore units per second.
*/
schedulerRate: number;
/**
* The minimum amount of Mana that an account must have to have a block scheduled.
*/
minMana: u64;
/**
* The maximum size of the buffer.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
print(f'Block metadata: {json.dumps(asdict(metadata), indent=4)}')

# Request the block by its id
block = client.get_block_data(block_ids[0])
block = client.get_block(block_ids[0])
print(f'Block: {json.dumps(asdict(block), indent=4)}')
22 changes: 13 additions & 9 deletions bindings/python/examples/client/08_data_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from dataclasses import asdict
from dotenv import load_dotenv
from iota_sdk import Client, utf8_to_hex, hex_to_utf8, TaggedDataPayload
from iota_sdk import BasicBlock, Client, utf8_to_hex, hex_to_utf8, TaggedDataPayload

load_dotenv()

Expand All @@ -13,17 +13,21 @@
client = Client(nodes=[node_url])

# Create and post a block with a tagged data payload
block = client.submit_payload(
block_id = client.submit_payload(
TaggedDataPayload(
utf8_to_hex("tag"),
utf8_to_hex("data")))
utf8_to_hex("data")))[0]

print(f'Data block sent: {os.environ["EXPLORER_URL"]}/block/{block[0]}')
print(f'Data block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}')

block = client.get_block_data(block[0])
print(f'Block data: {json.dumps(asdict(block), indent=4)}')
block = client.get_block(block_id).block

payload = block.payload
if isinstance(block, BasicBlock):
print(f'Block data: {json.dumps(asdict(block), indent=4)}')

if payload and 'data' in payload and payload['data']:
print(f'Decoded data: { hex_to_utf8(payload["data"]) }')
payload = block.payload

if payload and 'data' in payload and payload['data']:
print(f'Decoded data: { hex_to_utf8(payload["data"]) }')
else:
raise ValueError("block must be an instance of BasicBlock")
23 changes: 13 additions & 10 deletions bindings/python/examples/client/submit_and_read_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Make sure you have first installed it with `pip install iota_sdk`
import os
from dotenv import load_dotenv
from iota_sdk import Client, hex_to_utf8, utf8_to_hex, TaggedDataPayload
from iota_sdk import BasicBlock, Client, hex_to_utf8, utf8_to_hex, TaggedDataPayload

load_dotenv()

Expand Down Expand Up @@ -82,15 +82,18 @@
metadata = client.get_block_metadata(block_id)

# Get the whole block
block = client.get_block_data(block_id)
payload_out = block.payload
tag_hex_out = block.payload.tag
message_hex_out = block.payload.data

# Unpackage the payload (from hex to text)
message_out = hex_to_utf8(message_hex_out)
print('\nYour message, read from the Shimmer network:')
print(f' {message_out}')
block = client.get_block(block_id).block
if isinstance(block, BasicBlock):
payload_out = block.payload
tag_hex_out = block.payload.tag
message_hex_out = block.payload.data

# Unpackage the payload (from hex to text)
message_out = hex_to_utf8(message_hex_out)
print('\nYour message, read from the Shimmer network:')
print(f' {message_out}')
else:
raise ValueError("block must be an instance of BasicBlock")

# Or see the message online, with the testnet explorer.
print(
Expand Down
6 changes: 5 additions & 1 deletion bindings/python/iota_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from .prefix_hex import *
from .types.address import *
from .types.balance import *
from .types.block import *
from .types.block.basic import *
from .types.block.block import *
from .types.block.metadata import *
from .types.block.wrapper import *
from .types.block.validation import *
from .types.block_builder_options import *
from .types.burn import *
from .types.client_options import *
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/iota_sdk/client/_high_level_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Optional
from dataclasses import dataclass
from abc import ABCMeta, abstractmethod
from iota_sdk.types.block import Block
from iota_sdk.types.block.wrapper import BlockWrapper
from iota_sdk.types.common import CoinType, HexStr, json
from iota_sdk.types.output_metadata import OutputWithMetadata
from iota_sdk.types.output_id import OutputId
Expand Down Expand Up @@ -94,7 +94,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[HexStr]) -> List[BlockWrapper]:
"""Find all blocks by provided block IDs.
Args:
Expand All @@ -106,7 +106,7 @@ def find_blocks(self, block_ids: List[HexStr]) -> List[Block]:
blocks = self._call_method('findBlocks', {
'blockIds': block_ids
})
return [Block.from_dict(block) for block in blocks]
return [BlockWrapper.from_dict(block) for block in blocks]

def find_inputs(self, addresses: List[str], amount: int):
"""Function to find inputs from addresses for a provided amount(useful for offline signing).
Expand Down
13 changes: 7 additions & 6 deletions bindings/python/iota_sdk/client/_node_core_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from abc import ABCMeta, abstractmethod
from dacite import from_dict

from iota_sdk.types.block import Block, BlockMetadata
from iota_sdk.types.block.wrapper import BlockWrapper
from iota_sdk.types.block.metadata import BlockMetadata
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
Expand Down Expand Up @@ -57,7 +58,7 @@ def get_tips(self) -> List[HexStr]:
"""
return self._call_method('getTips')

def post_block(self, block: Block) -> HexStr:
def post_block(self, block: BlockWrapper) -> HexStr:
"""Post a block.
Args:
Expand All @@ -70,10 +71,10 @@ def post_block(self, block: Block) -> HexStr:
'block': block.__dict__
})

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

Expand Down Expand Up @@ -127,13 +128,13 @@ def get_output_metadata(
'outputId': output_id_str
}))

def get_included_block(self, transaction_id: HexStr) -> Block:
def get_included_block(self, transaction_id: HexStr) -> BlockWrapper:
"""Returns the included block of the given transaction.
Returns:
The included block.
"""
return Block.from_dict(self._call_method('getIncludedBlock', {
return BlockWrapper.from_dict(self._call_method('getIncludedBlock', {
'transactionId': transaction_id
}))

Expand Down
7 changes: 4 additions & 3 deletions bindings/python/iota_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from iota_sdk.client._high_level_api import HighLevelAPI
from iota_sdk.client._utils import ClientUtils
from iota_sdk.secret_manager.secret_manager import LedgerNanoSecretManager, MnemonicSecretManager, StrongholdSecretManager, SeedSecretManager
from iota_sdk.types.block import Block
from iota_sdk.types.block.wrapper import BlockWrapper
from iota_sdk.types.common import HexStr, Node
from iota_sdk.types.feature import Feature
from iota_sdk.types.native_token import NativeToken
Expand Down Expand Up @@ -394,7 +394,8 @@ def sign_transaction(
'preparedTransactionData': prepared_transaction_data
}))

def submit_payload(self, payload: Payload) -> List[Union[HexStr, Block]]:
def submit_payload(
self, payload: Payload) -> List[Union[HexStr, BlockWrapper]]:
"""Submit a payload in a block.
Args:
Expand All @@ -406,7 +407,7 @@ def submit_payload(self, payload: Payload) -> List[Union[HexStr, Block]]:
result = self._call_method('postBlockPayload', {
'payload': payload.to_dict()
})
result[1] = Block.from_dict(result[1])
result[1] = BlockWrapper.from_dict(result[1])
return result

def listen_mqtt(self, topics: List[str], handler):
Expand Down
32 changes: 32 additions & 0 deletions bindings/python/iota_sdk/types/block/basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
from dataclasses import dataclass, field
from typing import List, Optional
from iota_sdk.types.block.block import Block, BlockType
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.payload import PayloadUnion


@json
@dataclass
class BasicBlock(Block):
"""A `BasicBlock` is the most common type of block used to issue various kinds of payloads such as transactions
at the cost of burning Mana.
Attributes:
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.
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.
"""
strong_parents: List[HexStr]
weak_parents: List[HexStr]
shallow_like_parents: List[HexStr]
max_burned_mana: str
payload: Optional[PayloadUnion] = None
type: int = field(
default_factory=lambda: BlockType.Basic,
init=False)
26 changes: 26 additions & 0 deletions bindings/python/iota_sdk/types/block/block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
from enum import IntEnum
from dataclasses import dataclass
from iota_sdk.types.common import json


class BlockType(IntEnum):
"""Block types.
Attributes:
Basic (0): A Basic Block.
Validation (1): A Validation Block.
"""
Basic = 0
Validation = 1


@json
@dataclass
class Block:
"""Base class for blocks.
"""
type: int
Loading

0 comments on commit 416bf62

Please sign in to comment.