diff --git a/bindings/python/iota_sdk/types/common.py b/bindings/python/iota_sdk/types/common.py index ab2e1e766c..96a5fdcfd4 100644 --- a/bindings/python/iota_sdk/types/common.py +++ b/bindings/python/iota_sdk/types/common.py @@ -7,6 +7,8 @@ from dataclasses_json import DataClassJsonMixin, dataclass_json, LetterCase, Undefined HexStr = NewType("HexStr", str) +EpochIndex = NewType("EpochIndex", int) +SlotIndex = NewType("SlotIndex", int) def json(cls): diff --git a/bindings/python/iota_sdk/types/essence.py b/bindings/python/iota_sdk/types/essence.py index a7f3f3bfc4..530b45713f 100644 --- a/bindings/python/iota_sdk/types/essence.py +++ b/bindings/python/iota_sdk/types/essence.py @@ -7,7 +7,7 @@ from dataclasses import dataclass, field -from iota_sdk.types.common import HexStr, json +from iota_sdk.types.common import HexStr, json, SlotIndex from iota_sdk.types.mana import ManaAllotment # TODO: Add missing output types in #1174 # pylint: disable=no-name-in-module @@ -54,11 +54,11 @@ class RegularTransactionEssence(TransactionEssence): payload: An optional tagged data payload """ network_id: str - # TODO: Replace with a proper SlotIndex type - creation_slot: HexStr + creation_slot: SlotIndex inputs: List[UtxoInput] inputs_commitment: HexStr - outputs: List[Union[BasicOutput, AccountOutput, FoundryOutput, NftOutput, DelegationOutput]] + outputs: List[Union[BasicOutput, AccountOutput, + FoundryOutput, NftOutput, DelegationOutput]] context_inputs: Optional[List[Union[CommitmentContextInput, BlockIssuanceCreditContextInput, RewardContextInput]]] = None allotments: Optional[List[ManaAllotment]] = None diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index d9f8e6a3d6..4fc675e145 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -6,7 +6,7 @@ from dataclasses import dataclass, field from iota_sdk.types.address import Ed25519Address, AccountAddress, NFTAddress -from iota_sdk.types.common import HexStr, json +from iota_sdk.types.common import EpochIndex, HexStr, json, SlotIndex class FeatureType(IntEnum): @@ -97,8 +97,7 @@ class BlockIssuer(Feature): 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 + expiry_slot: SlotIndex # TODO Replace with a list of PublicKey types public_keys: List[HexStr] type: int = field( @@ -119,10 +118,8 @@ class StakingFeature(Feature): """ staked_amount: str fixed_cost: str - # TODO Replace with an EpochIndex type - start_epoch: HexStr - # TODO Replace with an EpochIndex type - end_epoch: HexStr + start_epoch: EpochIndex + end_epoch: EpochIndex type: int = field( default_factory=lambda: int( FeatureType.Staking), diff --git a/bindings/python/iota_sdk/types/node_info.py b/bindings/python/iota_sdk/types/node_info.py index 8ad83cc791..24f17afffa 100644 --- a/bindings/python/iota_sdk/types/node_info.py +++ b/bindings/python/iota_sdk/types/node_info.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass from typing import List, Optional -from iota_sdk.types.common import HexStr, json +from iota_sdk.types.common import EpochIndex, HexStr, json, SlotIndex @json @@ -22,7 +22,7 @@ class NodeInfoStatus: latest_finalized_slot: The index of the latest finalized slot. latest_accepted_block_slot: The slot index of the latest accepted block. latest_confirmed_block_slot: The slot index of the latest confirmed block. - pruning_epoch: The index of the slot before which the tangle history is pruned. + pruning_epoch: The index of the epoch before which the tangle history is pruned. """ is_healthy: bool accepted_tangle_time: str @@ -30,14 +30,10 @@ class NodeInfoStatus: confirmed_tangle_time: str relative_confirmed_tangle_time: str latest_commitment_id: HexStr - # TODO Replace with a proper SlotIndex type - latest_finalized_slot: str - # TODO Replace with a proper SlotIndex type - latest_accepted_block_slot: str - # TODO Replace with a proper SlotIndex type - latest_confirmed_block_slot: str - # TODO Replace with a proper SlotIndex type - pruning_epoch: str + latest_finalized_slot: SlotIndex + latest_accepted_block_slot: SlotIndex + latest_confirmed_block_slot: SlotIndex + pruning_epoch: EpochIndex @json @@ -217,11 +213,9 @@ class ProtocolParameters: staking_unbonding_period: str validation_blocks_per_slot: int punishment_epochs: str - staking_unbonding_period: str liveness_threshold: str min_committable_age: str max_committable_age: str - # TODO Replace with a proper SlotIndex type epoch_nearing_threshold: str congestion_control_parameters: CongestionControlParameters version_signaling: VersionSignaling @@ -236,7 +230,7 @@ class ProtocolParametersResponse: start_epoch: The start epoch of the set of protocol parameters. parameters: The protocol parameters. """ - start_epoch: str + start_epoch: EpochIndex parameters: ProtocolParameters @@ -255,9 +249,9 @@ class NodeInfoBaseToken: name: str ticker_symbol: str unit: str - subunit: Optional[str] = None decimals: int use_metric_prefix: bool + subunit: Optional[str] = None @json diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index 32d882a839..418e2afbbe 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -11,7 +11,7 @@ use packable::{prefix::StringPrefix, Packable, PackableExt}; use super::{ address::Hrp, mana::{ManaStructure, RewardsParameters}, - slot::{EpochIndex, SlotIndex}, + slot::SlotIndex, }; use crate::types::block::{helper::network_name_to_id, output::RentStructure, ConvertTo, Error, PROTOCOL_VERSION}; @@ -55,23 +55,28 @@ pub struct ProtocolParameters { #[getset(skip)] pub(crate) mana_structure: ManaStructure, /// The unbonding period in epochs before an account can stop staking. - pub(crate) staking_unbonding_period: EpochIndex, + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] + pub(crate) staking_unbonding_period: u64, /// The number of validation blocks that each validator should issue each slot. pub(crate) validation_blocks_per_slot: u16, /// The number of epochs worth of Mana that a node is punished with for each additional validation block it issues. #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] pub(crate) punishment_epochs: u64, - /// 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, + /// Liveness Threshold is used by tip-selection to determine if a block is eligible by evaluating issuingTimes and + /// commitments in its past-cone to Accepted Tangle Time and lastCommittedSlot respectively. + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] + pub(crate) liveness_threshold: u64, /// Minimum age relative to the accepted tangle time slot index that a slot can be committed. - pub(crate) min_committable_age: SlotIndex, + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] + pub(crate) min_committable_age: u64, /// Maximum age for a slot commitment to be included in a block relative to the slot index of the block issuing /// time. - pub(crate) max_committable_age: SlotIndex, - /// The slot index used by the epoch orchestrator to detect the slot that should trigger a new + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] + pub(crate) max_committable_age: u64, + /// Epoch Nearing Threshold is used by the epoch orchestrator to detect the slot that should trigger a new /// committee selection for the next and upcoming epoch. - pub(crate) epoch_nearing_threshold: SlotIndex, + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] + pub(crate) epoch_nearing_threshold: u64, /// Parameters used to calculate the Reference Mana Cost (RMC). pub(crate) congestion_control_parameters: CongestionControlParameters, /// Defines the parameters used to signal a protocol parameters upgrade. @@ -100,15 +105,15 @@ impl Default for ProtocolParameters { token_supply: 1_813_620_509_061_365, genesis_unix_timestamp: 1582328545, slot_duration_in_seconds: 10, - epoch_nearing_threshold: 20.into(), + epoch_nearing_threshold: 20, slots_per_epoch_exponent: Default::default(), mana_structure: Default::default(), - staking_unbonding_period: 10.into(), + staking_unbonding_period: 10, validation_blocks_per_slot: 10, punishment_epochs: 9, - liveness_threshold: 5.into(), - min_committable_age: 10.into(), - max_committable_age: 20.into(), + liveness_threshold: 5, + min_committable_age: 10, + max_committable_age: 20, congestion_control_parameters: Default::default(), version_signaling: Default::default(), rewards_parameters: Default::default(), @@ -127,7 +132,7 @@ impl ProtocolParameters { token_supply: u64, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8, - epoch_nearing_threshold: impl Into, + epoch_nearing_threshold: u64, ) -> Result { Ok(Self { version, @@ -137,7 +142,7 @@ impl ProtocolParameters { token_supply, genesis_unix_timestamp, slot_duration_in_seconds, - epoch_nearing_threshold: epoch_nearing_threshold.into(), + epoch_nearing_threshold, ..Default::default() }) }