Skip to content

Commit

Permalink
Merge branch '2.0' into feat/dyn-secret-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars authored Sep 29, 2023
2 parents 00d80cc + 6ecd1cc commit 716dd4e
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 131 deletions.
2 changes: 2 additions & 0 deletions bindings/python/iota_sdk/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/iota_sdk/types/essence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions bindings/python/iota_sdk/types/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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),
Expand Down
22 changes: 8 additions & 14 deletions bindings/python/iota_sdk/types/node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,22 +22,18 @@ 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
relative_accepted_tangle_time: str
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
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/block/02_block_custom_parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn main() -> Result<()> {
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
Some(issuance.strong_parents),
Some(issuance.strong_parents()?),
None,
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn main() -> Result<()> {
.await?;

// Fetch a block ID from the node.
let block_id = client.get_issuance().await?.strong_parents[0];
let block_id = client.get_issuance().await?.strong_parents.into_iter().next().unwrap();

// Get the block.
let block = client.get_block(&block_id).await?;
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/node_api_core/06_get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn main() -> Result<()> {
block_id
} else {
// ... fetch one from the node.
client.get_issuance().await?.strong_parents[0]
client.get_issuance().await?.strong_parents.into_iter().next().unwrap()
};

// Get the block.
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/node_api_core/07_get_block_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn main() -> Result<()> {
block_id
} else {
// ... fetch one from the node.
client.get_issuance().await?.strong_parents[0]
client.get_issuance().await?.strong_parents.into_iter().next().unwrap()
};

// Get the block as raw bytes.
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/node_api_core/08_get_block_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn main() -> Result<()> {
block_id
} else {
// ... fetch one from the node.
client.get_issuance().await?.strong_parents[0]
client.get_issuance().await?.strong_parents.into_iter().next().unwrap()
};

// Send the request.
Expand Down
34 changes: 12 additions & 22 deletions sdk/src/client/api/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ pub mod transaction;
pub use self::transaction::verify_semantic;
use crate::{
client::{ClientInner, Result},
types::{
api::core::response::IssuanceBlockHeaderResponse,
block::{
core::{Block, BlockWrapper},
parent::StrongParents,
payload::Payload,
signature::Ed25519Signature,
IssuerId,
},
types::block::{
core::{basic, Block, BlockWrapper},
payload::Payload,
signature::Ed25519Signature,
IssuerId,
},
};

Expand All @@ -25,17 +21,11 @@ impl ClientInner {
issuer_id: IssuerId,
signature: Ed25519Signature,
issuing_time: Option<u64>,
strong_parents: Option<StrongParents>,
strong_parents: Option<basic::StrongParents>,
payload: Option<Payload>,
) -> Result<BlockWrapper> {
let IssuanceBlockHeaderResponse {
strong_parents: default_strong_parents,
weak_parents,
shallow_like_parents,
latest_finalized_slot,
commitment,
} = self.get_issuance().await?;
let strong_parents = strong_parents.unwrap_or(default_strong_parents);
let issuance = self.get_issuance().await?;
let strong_parents = strong_parents.unwrap_or(issuance.strong_parents()?);

let issuing_time = issuing_time.unwrap_or_else(|| {
#[cfg(feature = "std")]
Expand All @@ -56,13 +46,13 @@ impl ClientInner {
protocol_parameters.version(),
protocol_parameters.network_id(),
issuing_time,
commitment.id(),
latest_finalized_slot,
issuance.commitment.id(),
issuance.latest_finalized_slot,
issuer_id,
// TODO correct value for burned_mana
Block::build_basic(strong_parents, 0)
.with_weak_parents(weak_parents)
.with_shallow_like_parents(shallow_like_parents)
.with_weak_parents(issuance.weak_parents()?)
.with_shallow_like_parents(issuance.shallow_like_parents()?)
.with_payload(payload)
.finish_block()?,
signature,
Expand Down
33 changes: 28 additions & 5 deletions sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use alloc::{boxed::Box, collections::BTreeMap, string::String, vec::Vec};
use alloc::{
boxed::Box,
collections::{BTreeMap, BTreeSet},
string::String,
vec::Vec,
};

use serde::{Deserialize, Serialize};

use crate::{
types::block::{
core::Parents,
output::{dto::OutputDto, AccountId, OutputId, OutputMetadata, OutputWithMetadata},
parent::{ShallowLikeParents, StrongParents, WeakParents},
protocol::ProtocolParameters,
semantic::TransactionFailureReason,
slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex},
Expand Down Expand Up @@ -262,17 +267,35 @@ pub struct ValidatorResponse {
#[serde(rename_all = "camelCase")]
pub struct IssuanceBlockHeaderResponse {
/// Blocks that are strongly directly approved.
pub strong_parents: StrongParents,
pub strong_parents: BTreeSet<BlockId>,
/// Blocks that are weakly directly approved.
pub weak_parents: WeakParents,
pub weak_parents: BTreeSet<BlockId>,
/// Blocks that are directly referenced to adjust opinion.
pub shallow_like_parents: ShallowLikeParents,
pub shallow_like_parents: BTreeSet<BlockId>,
/// The slot index of the latest finalized slot.
pub latest_finalized_slot: SlotIndex,
/// The most recent slot commitment.
pub commitment: SlotCommitment,
}

impl IssuanceBlockHeaderResponse {
pub fn strong_parents<const MIN: u8, const MAX: u8>(
&self,
) -> Result<Parents<MIN, MAX>, crate::types::block::Error> {
Parents::from_set(self.strong_parents.clone())
}

pub fn weak_parents<const MIN: u8, const MAX: u8>(&self) -> Result<Parents<MIN, MAX>, crate::types::block::Error> {
Parents::from_set(self.weak_parents.clone())
}

pub fn shallow_like_parents<const MIN: u8, const MAX: u8>(
&self,
) -> Result<Parents<MIN, MAX>, crate::types::block::Error> {
Parents::from_set(self.shallow_like_parents.clone())
}
}

/// Response of GET /api/core/v3/accounts/{accountId}/congestion.
/// Provides the cost and readiness to issue estimates.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
Expand Down
12 changes: 8 additions & 4 deletions sdk/src/types/block/core/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ use packable::{
};

use crate::types::block::{
core::{verify_parents, Block},
parent::{ShallowLikeParents, StrongParents, WeakParents},
core::{parent::verify_parents_sets, Block, Parents},
payload::{OptionalPayload, Payload},
protocol::ProtocolParameters,
Error,
};

pub type StrongParents = Parents<1, 8>;
pub type WeakParents = Parents<0, 8>;
pub type ShallowLikeParents = Parents<0, 8>;

/// A builder for a [`BasicBlock`].
pub struct BasicBlockBuilder {
strong_parents: StrongParents,
Expand Down Expand Up @@ -75,7 +78,7 @@ impl BasicBlockBuilder {

/// Finishes the builder into a [`BasicBlock`].
pub fn finish(self) -> Result<BasicBlock, Error> {
verify_parents(&self.strong_parents, &self.weak_parents, &self.shallow_like_parents)?;
verify_parents_sets(&self.strong_parents, &self.weak_parents, &self.shallow_like_parents)?;

Ok(BasicBlock {
strong_parents: self.strong_parents,
Expand Down Expand Up @@ -164,7 +167,8 @@ impl Packable for BasicBlock {
let shallow_like_parents = ShallowLikeParents::unpack::<_, VERIFY>(unpacker, &())?;

if VERIFY {
verify_parents(&strong_parents, &weak_parents, &shallow_like_parents).map_err(UnpackError::Packable)?;
verify_parents_sets(&strong_parents, &weak_parents, &shallow_like_parents)
.map_err(UnpackError::Packable)?;
}

let payload = OptionalPayload::unpack::<_, VERIFY>(unpacker, visitor)?;
Expand Down
Loading

0 comments on commit 716dd4e

Please sign in to comment.