Skip to content

Commit

Permalink
Merge branch '2.0' into python/parents-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Sep 11, 2023
2 parents 887088e + 7d98236 commit 567ec09
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 13 deletions.
1 change: 1 addition & 0 deletions bindings/python/iota_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .types.burn import *
from .types.client_options import *
from .types.common import *
from .types.context_input import *
from .types.event import *
from .types.feature import *
from .types.filter_options import *
Expand Down
1 change: 1 addition & 0 deletions bindings/python/iota_sdk/client/_high_level_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import List, Optional
from dataclasses import dataclass
from iota_sdk.types.block import Block
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.output import OutputWithMetadata
from iota_sdk.types.output_id import OutputId
Expand Down
34 changes: 34 additions & 0 deletions bindings/python/iota_sdk/types/context_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

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


class ContextInputType(IntEnum):
"""Context input types.
"""
BlockIssuanceCredit = 1


@json
@dataclass
class ContextInput():
"""Base class for context inputs.
"""
type: int


@json
@dataclass
class BlockIssuanceCreditContextInput(ContextInput):
"""A Block Issuance Credit (BIC) Context Input provides the VM with context for the value of
the BIC vector of a specific slot.
"""
account_id: HexStr
type: int = field(
default_factory=lambda: int(
ContextInputType.BlockIssuanceCredit),
init=False)
53 changes: 49 additions & 4 deletions bindings/python/iota_sdk/types/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from enum import IntEnum

from dataclasses import dataclass, field
from typing import List

from iota_sdk.types.address import Ed25519Address, AccountAddress, NFTAddress
from iota_sdk.types.common import HexStr, json
Expand All @@ -17,11 +18,15 @@ class FeatureType(IntEnum):
Issuer (1): The issuer feature.
Metadata (2): The metadata feature.
Tag (3): The tag feature.
BlockIssuer (4): The block issuer feature.
Staking (5): The staking feature.
"""
Sender = 0
Issuer = 1
Metadata = 2
Tag = 3
BlockIssuer = 4
Staking = 5


@json
Expand All @@ -35,7 +40,7 @@ class Feature():
@json
@dataclass
class SenderFeature(Feature):
"""Sender feature.
"""Identifies the validated sender of an output.
Attributes:
address: A given sender address.
"""
Expand All @@ -49,7 +54,7 @@ class SenderFeature(Feature):
@json
@dataclass
class IssuerFeature(Feature):
"""Issuer feature.
"""Identifies the validated issuer of the UTXO state machine.
Attributes:
address: A given issuer address.
"""
Expand All @@ -63,7 +68,7 @@ class IssuerFeature(Feature):
@json
@dataclass
class MetadataFeature(Feature):
"""Metadata feature.
"""Defines metadata, arbitrary binary data, that will be stored in the output.
Attributes:
data: Some hex encoded metadata.
"""
Expand All @@ -77,9 +82,49 @@ class MetadataFeature(Feature):
@json
@dataclass
class TagFeature(Feature):
"""Tag feature.
"""Makes it possible to tag outputs with an index, so they can be retrieved through an indexer API.
Attributes:
tag: A hex encoded tag used to index the output.
"""
tag: HexStr
type: int = field(default_factory=lambda: int(FeatureType.Tag), init=False)


@json
@dataclass
class BlockIssuer(Feature):
"""Contains the public keys to verify block signatures and allows for unbonding the issuer deposit.
Attributes:
expiry_slot: The slot index at which the Block Issuer Feature expires and can be removed.
public_keys: The Block Issuer Keys.
"""
# TODO Replace with a proper SlotIndex type
expiry_slot: str
# TODO Replace with a list of PublicKey types
public_keys: List[HexStr]
type: int = field(
default_factory=lambda: int(
FeatureType.BlockIssuer),
init=False)


@json
@dataclass
class StakingFeature(Feature):
"""Stakes IOTA coins to become eligible for committee selection, validate the network and receive Mana rewards.
Attributes:
staked_amount: The amount of IOTA coins that are locked and staked in the containing account.
fixed_cost: The fixed cost of the validator, which it receives as part of its Mana rewards.
start_epoch: The epoch index in which the staking started.
end_epoch: The epoch index in which the staking ends.
"""
staked_amount: str
fixed_cost: str
# TODO Replace with an EpochIndex type
start_epoch: HexStr
# TODO Replace with an EpochIndex type
end_epoch: HexStr
type: int = field(
default_factory=lambda: int(
FeatureType.Staking),
init=False)
17 changes: 10 additions & 7 deletions sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ pub struct ValidatorsResponse {
page_size: u32,
/// The cursor that needs to be provided as cursor query parameter to request the next page. If empty, this was the
/// last page.
cursor: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
cursor: Option<String>,
}

/// Response of GET /api/core/v3/rewards/{outputId}.
Expand Down Expand Up @@ -335,14 +336,16 @@ pub enum TransactionState {
pub enum BlockFailureReason {
/// The block is too old to issue.
TooOldToIssue = 1,
/// The block's parents are too old.
ParentsTooOld = 2,
/// The block failed at the booker.
FailedAtBooker = 3,
/// One of the block's parents is too old.
ParentTooOld = 2,
/// One of the block's parents does not exist.
ParentDoesNotExist = 3,
/// One of the block's parents is invalid.
ParentInvalid = 4,
/// The block is dropped due to congestion.
DroppedDueToCongestion = 4,
DroppedDueToCongestion = 5,
/// The block is invalid.
Invalid = 5,
Invalid = 6,
}

/// Response of GET /api/core/v3/blocks/{blockId}/metadata.
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/types/block/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct ProtocolParameters {
pub(crate) mana_structure: ManaStructure,
/// The unbonding period in epochs before an account can stop staking.
pub(crate) staking_unbonding_period: EpochIndex,
/// The number of validation blocks that each validator should issue each slot.
pub(crate) validation_blocks_per_slot: u16,
/// The slot index used by tip-selection to determine if a block is eligible by evaluating issuing times
/// and commitments in its past-cone against accepted tangle time and last committed slot respectively.
pub(crate) liveness_threshold: SlotIndex,
Expand Down Expand Up @@ -93,6 +95,7 @@ impl Default for ProtocolParameters {
slots_per_epoch_exponent: Default::default(),
mana_structure: Default::default(),
staking_unbonding_period: 10.into(),
validation_blocks_per_slot: 10,
liveness_threshold: 5.into(),
min_committable_age: 10.into(),
max_committable_age: 20.into(),
Expand Down
4 changes: 2 additions & 2 deletions sdk/tests/types/block_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ fn compute() {
// TODO: Independently verify this value
assert_eq!(
block_id.to_string(),
"0x5e3d8befccbd36860a589cf9427efa108bcc781f630ebfdf6f57cef7eed8b5bb0b00000000000000"
"0x7ac622307277e700e4161d805d22dfb03f89904657a6353f985bd6e78ed267550b00000000000000"
);
assert_eq!(
block_id.hash().to_string(),
"0x5e3d8befccbd36860a589cf9427efa108bcc781f630ebfdf6f57cef7eed8b5bb"
"0x7ac622307277e700e4161d805d22dfb03f89904657a6353f985bd6e78ed26755"
);
assert_eq!(block_id.slot_index(), slot_index);
}

0 comments on commit 567ec09

Please sign in to comment.