Skip to content

Commit

Permalink
Merge branch '2.0' into bindings-cleanup-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Nov 3, 2023
2 parents 9d17189 + 912cf44 commit 5422865
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 242 deletions.
8 changes: 4 additions & 4 deletions bindings/core/src/method/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ pub enum SecretManagerMethod {
SignatureUnlock {
/// Transaction signing hash
transaction_signing_hash: String,
/// Chain to sign the hash with
/// Chain used to sign the hash
#[serde(with = "Bip44Def")]
chain: Bip44,
},
/// Signs a message with an Ed25519 private key.
SignEd25519 {
/// The message to sign, hex encoded String
message: String,
/// Chain to sign the message with
/// Chain used to sign the message
#[serde(with = "Bip44Def")]
chain: Bip44,
},
/// Signs a message with an Secp256k1Ecdsa private key.
SignSecp256k1Ecdsa {
/// The message to sign, hex encoded String
message: String,
/// Chain to sign the message with
/// Chain used to sign the message
#[serde(with = "Bip44Def")]
chain: Bip44,
},
Expand All @@ -66,7 +66,7 @@ pub enum SecretManagerMethod {
#[serde(rename_all = "camelCase")]
SignBlock {
unsigned_block: UnsignedBlockDto,
/// Chain to sign the essence hash with
/// Chain used to sign the block
#[serde(with = "Bip44Def")]
chain: Bip44,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
)


transaction = account.mint_nfts([params])
tx = account.mint_nfts([params])

# Wait for transaction to get included
block_id = account.reissue_transaction_until_included(
transaction.transaction_id)
tx.transaction_id)

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

essence = transaction.payload["essence"]
transaction = tx.payload.transaction

for outputIndex, output in enumerate(essence["outputs"]):
for outputIndex, output in enumerate(transaction.outputs):
# New minted NFT id is empty in the output
if output["type"] == 6 and output["nftId"] == '0x0000000000000000000000000000000000000000000000000000000000000000':
outputId = Utils.compute_output_id(
transaction.transaction_id, outputIndex)
tx.transaction_id, outputIndex)
nftId = Utils.compute_nft_id(outputId)
print(f'New minted NFT id: {nftId}')
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

# Signs prepared transaction offline.
signed_transaction_data = account.sign_transaction_essence(
signed_transaction_data = account.sign_transaction(
prepared_transaction_data)

print("Signed transaction.")
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 @@ -41,6 +41,7 @@
from .types.send_params import *
from .types.token_scheme import *
from .types.transaction import *
from .types.transaction_with_metadata import *
from .types.transaction_data import *
from .types.transaction_options import *
from .types.unlock import *
Expand Down
20 changes: 1 addition & 19 deletions bindings/python/iota_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@
from datetime import timedelta
from typing import Any, Dict, List, Optional, Union
import humps
from dacite import from_dict

from iota_sdk.external import create_client, call_client_method, listen_mqtt
from iota_sdk.client._node_core_api import NodeCoreAPI
from iota_sdk.client._node_indexer_api import NodeIndexerAPI
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.signed_block import UnsignedBlock
from iota_sdk.types.common import HexStr, Node
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, deserialize_output
from iota_sdk.types.payload import Payload, TransactionPayload
from iota_sdk.types.payload import Payload
from iota_sdk.types.token_scheme import SimpleTokenScheme
from iota_sdk.types.unlock_condition import UnlockCondition
from iota_sdk.types.transaction_data import PreparedTransactionData


class ClientError(Exception):
Expand Down Expand Up @@ -373,21 +370,6 @@ def unhealthy_nodes(self) -> List[Dict[str, Any]]:
"""
return self._call_method('unhealthyNodes')

def sign_transaction(
self,
secret_manager: Union[LedgerNanoSecretManager, MnemonicSecretManager, SeedSecretManager, StrongholdSecretManager],
prepared_transaction_data: PreparedTransactionData) -> TransactionPayload:
"""Sign a transaction.
Args:
secret_manager: One of the supported secret managers.
prepared_transaction_data: a prepared transaction to sign.
"""
return from_dict(TransactionPayload, self._call_method('signTransaction', {
'secretManager': secret_manager,
'preparedTransactionData': prepared_transaction_data
}))

def build_basic_block(
self,
issuer_id: HexStr,
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/iota_sdk/secret_manager/secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from iota_sdk.types.common import HexStr
from iota_sdk.types.signature import Ed25519Signature, Bip44
from iota_sdk.types.transaction_data import PreparedTransactionData
from iota_sdk.types.payload import TransactionPayload
from iota_sdk.types.payload import SignedTransactionPayload


class LedgerNanoSecretManager(dict):
Expand Down Expand Up @@ -268,13 +268,13 @@ def sign_secp256k1_ecdsa(self, message: HexStr, chain: Bip44):
})

def sign_transaction(
self, prepared_transaction_data: PreparedTransactionData) -> TransactionPayload:
self, prepared_transaction_data: PreparedTransactionData) -> SignedTransactionPayload:
"""Sign a transaction.
Args:
prepare_transaction_data: The prepared transaction data that needs to be signed.
"""
return from_dict(TransactionPayload, self._call_method('signTransaction', {
return from_dict(SignedTransactionPayload, self._call_method('signTransaction', {
'preparedTransactionData': prepared_transaction_data.to_dict()
}))

Expand Down
68 changes: 0 additions & 68 deletions bindings/python/iota_sdk/types/essence.py

This file was deleted.

22 changes: 11 additions & 11 deletions bindings/python/iota_sdk/types/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Dict, List, TypeAlias, Union
from dataclasses import dataclass, field
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.essence import TransactionEssence
from iota_sdk.types.transaction import Transaction
from iota_sdk.types.unlock import SignatureUnlock, ReferenceUnlock


Expand All @@ -15,11 +15,11 @@ class PayloadType(IntEnum):
Attributes:
TaggedData (0): A tagged data payload.
Transaction (1): A transaction payload.
SignedTransaction (1): A signed transaction payload.
CandidacyAnnouncement (2): A candidacy announcement payload.
"""
TaggedData = 0
Transaction = 1
SignedTransaction = 1
CandidacyAnnouncement = 2


Expand All @@ -42,18 +42,18 @@ class TaggedDataPayload:

@json
@dataclass
class TransactionPayload:
"""A transaction payload.
class SignedTransactionPayload:
"""A signed transaction payload.
Attributes:
essence: The transaction essence.
transaction: The transaction.
unlocks: The unlocks of the transaction.
"""
essence: TransactionEssence
transaction: Transaction
unlocks: List[Union[SignatureUnlock, ReferenceUnlock]]
type: int = field(
default_factory=lambda: int(
PayloadType.Transaction),
PayloadType.SignedTransaction),
init=False)


Expand All @@ -69,7 +69,7 @@ class CandidacyAnnouncementPayload:


Payload: TypeAlias = Union[TaggedDataPayload,
TransactionPayload, CandidacyAnnouncementPayload]
SignedTransactionPayload, CandidacyAnnouncementPayload]


def deserialize_payload(d: Dict[str, Any]) -> Payload:
Expand All @@ -82,8 +82,8 @@ def deserialize_payload(d: Dict[str, Any]) -> Payload:
payload_type = d['type']
if payload_type == PayloadType.TaggedData:
return TaggedDataPayload.from_dict(d)
if payload_type == PayloadType.Transaction:
return TransactionPayload.from_dict(d)
if payload_type == PayloadType.SignedTransaction:
return SignedTransactionPayload.from_dict(d)
if payload_type == PayloadType.CandidacyAnnouncement:
return CandidacyAnnouncementPayload.from_dict(d)
raise Exception(f'invalid payload type: {payload_type}')
Expand Down
72 changes: 35 additions & 37 deletions bindings/python/iota_sdk/types/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,49 @@
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
from dataclasses import dataclass
from typing import List, Optional
from enum import Enum
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.output_metadata import OutputWithMetadata
from iota_sdk.types.payload import TransactionPayload
from typing import TYPE_CHECKING, Optional, List

from dataclasses import dataclass, field

class InclusionState(str, Enum):
"""Inclusion state variants of a transaction.
from iota_sdk.types.common import HexStr, json, SlotIndex
from iota_sdk.types.mana import ManaAllotment
from iota_sdk.types.input import UtxoInput
from iota_sdk.types.context_input import ContextInput
from iota_sdk.types.output import Output

Attributes:
Pending: The transaction is pending.
Confirmed: The transaction is confirmed.
Conflicting: The transaction is conflicting.
UnknownPruned: The transaction is unknown or already pruned.
"""
Pending = 'pending'
Confirmed = 'confirmed'
Conflicting = 'conflicting'
UnknownPruned = 'unknownPruned'
# Required to prevent circular import
if TYPE_CHECKING:
from iota_sdk.types.payload import Payload


@json
@dataclass
class Transaction:
"""A transaction with some metadata.
"""A transaction consuming inputs, creating outputs and carrying an optional payload.
Attributes:
payload: The transaction payload.
inclusion_state: The inclusion state of the transaction.
timestamp: The timestamp of the transaction.
transaction_id: The ID of the corresponding transaction.
network_id: The ID of the network this transaction was issued in.
incoming: Indicates whether the transaction was created by the wallet or whether it was sent by someone else and is incoming.
inputs: The inputs of the transaction.
note: A note attached to the transaction.
block_id: The ID of the block that holds the transaction.
network_id: The unique value denoting whether the block was meant for mainnet, shimmer, testnet, or a private network.
It consists of the first 8 bytes of the BLAKE2b-256 hash of the network name.
creation_slot: The slot index in which the transaction was created.
context_inputs: The inputs that provide additional contextual information for the execution of a transaction.
inputs: The inputs to consume in order to fund the outputs of the Transaction Payload.
allotments: The allotments of Mana which which will be added upon commitment of the slot.
capabilities: The capability bitflags of the transaction.
outputs: The outputs that are created by the Transaction Payload
payload: An optional tagged data payload
"""
payload: TransactionPayload
inclusion_state: InclusionState
timestamp: int
transaction_id: HexStr
network_id: int
incoming: bool
inputs = List[OutputWithMetadata]
note: Optional[str] = None
block_id: Optional[HexStr] = None
network_id: str
creation_slot: SlotIndex
context_inputs: List[ContextInput]
inputs: List[UtxoInput]
allotments: List[ManaAllotment]
capabilities: HexStr = field(default='0x', init=False)
outputs: List[Output]
payload: Optional[Payload] = None

def with_capabilities(self, capabilities: bytes):
"""Sets the transaction capabilities from a byte array.
Attributes:
capabilities: The transaction capabilities bitflags.
"""
self.capabilities = '0x' + capabilities.hex()
Loading

0 comments on commit 5422865

Please sign in to comment.