Skip to content

Commit

Permalink
Python: update API routes (iotaledger#1856)
Browse files Browse the repository at this point in the history
* update core api routes

* Python: update core api types

* Python: update core api types (part 2)

* address docs related todos

* fix optionals, add issuance test

* adjustments

* docs

* align sdk

* align renames

* simplify

* add GetOutputRaw method

* update python binding

* remove todo

* from_dict

* revert

* revert nits

* revert more

* revert sdk changes

* revert sdk changes 2

* revert sdk changes 3

* add todos to bindings core

* update python binding

* add todos to sdk

* rename

* reorder fields

Co-authored-by: Thoralf-M <[email protected]>

* fix merge

* fix tests

* hexstr

Co-authored-by: Thoralf-M <[email protected]>

* remove 'test_issuance.py'

* node info + routes suffixes

* issuance suffixes

* committee, validator, validators response suffixes

* remaining suffixes

* nits

* even more nits that aren't worth their own PR

* responses.py module

* fix whooopsie

* parents

Co-authored-by: Thoralf-M <[email protected]>

* review

* good catches

* how?

---------

Co-authored-by: Thoralf-M <[email protected]>
Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2024
1 parent 0e1dc3e commit 7fb722c
Show file tree
Hide file tree
Showing 34 changed files with 1,095 additions and 379 deletions.
6 changes: 6 additions & 0 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,18 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.get_utxo_changes_full_by_slot_commitment_id(&commitment_id)
.await?,
),
// TODO: this should be renamed to `GetCommitmentBySlot`
// https://github.com/iotaledger/iota-sdk/issues/1921
ClientMethod::GetCommitmentByIndex { slot } => {
Response::SlotCommitment(client.get_slot_commitment_by_slot(slot).await?)
}
// TODO: this should be renamed to `GetUtxoChangesBySlot`
// https://github.com/iotaledger/iota-sdk/issues/1921
ClientMethod::GetUtxoChangesByIndex { slot } => {
Response::UtxoChanges(client.get_utxo_changes_by_slot(slot).await?)
}
// TODO: this should be renamed to `GetUtxoChangesFullBySlot`
// https://github.com/iotaledger/iota-sdk/issues/1921
ClientMethod::GetUtxoChangesFullByIndex { slot } => {
Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(slot).await?)
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/client/07_get_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
client = Client(nodes=[node_url])

# Fetch a block ID from the node
block_ids = client.get_tips()
block_ids = client.get_issuance().strong_parents
print(f'Block id: {block_ids[0]}')

# Get the metadata for the block
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/client/get_raw_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
client = Client(nodes=[node_url])

# Fetch a block ID from the node
block_id = client.get_tips()[0]
block_id = client.get_issuance().strong_parents[0]
print(f'Block id: {block_id}')

# Get block raw
Expand Down
6 changes: 4 additions & 2 deletions bindings/python/iota_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .common import custom_encoder
from .client.client import Client, NodeIndexerAPI
from .client.common import ClientError
from .client.responses import *
from .client._high_level_api import GenerateAddressesOptions, GenerateAddressOptions
from .utils import Utils
from .wallet.wallet import Wallet, WalletOptions
Expand All @@ -30,16 +31,17 @@
from .types.decayed_mana import *
from .types.event import *
from .types.feature import *
from .types.input import *
from .types.irc_27 import *
from .types.irc_30 import *
from .types.filter_options import *
from .types.input import *
from .types.native_token import *
from .types.network_info import *
from .types.node_info import *
from .types.output import *
from .types.output_data import *
from .types.output_id import *
from .types.output_id_proof import *
from .types.output_metadata import *
from .types.output_params import *
from .types.payload import *
Expand All @@ -48,9 +50,9 @@
from .types.token_scheme import *
from .types.transaction_data import *
from .types.transaction_id import *
from .types.transaction_metadata 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 *
from .types.consolidation_params import *
11 changes: 8 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,11 +4,12 @@
from typing import List, Optional
from dataclasses import dataclass
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 CoinType, json
from iota_sdk.types.output_metadata import OutputWithMetadata
from iota_sdk.types.output_id import OutputId
from iota_sdk.types.output_metadata import OutputWithMetadata


@json
Expand All @@ -26,7 +27,7 @@ class Range:

@json
@dataclass
class GenerateAddressOptions():
class GenerateAddressOptions:
"""Options for generating an address.
Attributes:
Expand All @@ -39,7 +40,7 @@ class GenerateAddressOptions():

@json
@dataclass
class GenerateAddressesOptions():
class GenerateAddressesOptions:
"""Options for generating addresses.
Attributes:
Expand Down Expand Up @@ -81,6 +82,8 @@ def _call_method(self, name, data=None):
no payload.
"""

# TODO: this should return `List[OutputResponse]`, not `List[OutputWithMetadata]`
# https://github.com/iotaledger/iota-sdk/issues/1921
def get_outputs(
self, output_ids: List[OutputId]) -> List[OutputWithMetadata]:
"""Fetch OutputWithMetadata from provided OutputIds (requests are sent in parallel).
Expand All @@ -96,6 +99,8 @@ def get_outputs(
})
return [OutputWithMetadata.from_dict(o) for o in outputs]

# TODO: this should return `List[OutputResponse]`, not `List[OutputWithMetadata]`
# https://github.com/iotaledger/iota-sdk/issues/1921
def get_outputs_ignore_errors(
self, output_ids: List[OutputId]) -> List[OutputWithMetadata]:
"""Try to get OutputWithMetadata from provided OutputIds.
Expand Down
Loading

0 comments on commit 7fb722c

Please sign in to comment.