diff --git a/bindings/python/iota_sdk/__init__.py b/bindings/python/iota_sdk/__init__.py index d59e9e0a47..2c6aaf12de 100644 --- a/bindings/python/iota_sdk/__init__.py +++ b/bindings/python/iota_sdk/__init__.py @@ -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 * diff --git a/bindings/python/iota_sdk/client/_high_level_api.py b/bindings/python/iota_sdk/client/_high_level_api.py index 77f16c4a0b..931cbb5cfb 100644 --- a/bindings/python/iota_sdk/client/_high_level_api.py +++ b/bindings/python/iota_sdk/client/_high_level_api.py @@ -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 diff --git a/bindings/python/iota_sdk/types/context_input.py b/bindings/python/iota_sdk/types/context_input.py new file mode 100644 index 0000000000..ac7b57efea --- /dev/null +++ b/bindings/python/iota_sdk/types/context_input.py @@ -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) diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index 52be6bbe97..842c012837 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -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 @@ -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 @@ -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. """ @@ -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. """ @@ -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. """ @@ -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) diff --git a/sdk/src/types/api/core/response.rs b/sdk/src/types/api/core/response.rs index f9a9904888..43ef4ea3b3 100644 --- a/sdk/src/types/api/core/response.rs +++ b/sdk/src/types/api/core/response.rs @@ -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, } /// Response of GET /api/core/v3/rewards/{outputId}. @@ -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. diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index fa16ad6fe7..7c1a5cbfc3 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -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, @@ -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(), diff --git a/sdk/tests/types/block_id.rs b/sdk/tests/types/block_id.rs index 5a380bba05..c4e9ef024a 100644 --- a/sdk/tests/types/block_id.rs +++ b/sdk/tests/types/block_id.rs @@ -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); }