Skip to content

Commit

Permalink
Merge branch '2.0' into storage-score-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Nov 23, 2023
2 parents ed2764b + d4eb814 commit 8247027
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export interface ProtocolParameters {
/**
* The parameters used by signaling protocol parameters upgrade.
*/
versionSignaling: VersionSignalingParameters;
versionSignalingParameters: VersionSignalingParameters;
/**
* Rewards Parameters defines the parameters that are used to calculate Mana rewards.
*/
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/iota_sdk/types/node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class CongestionControlParameters:

@json
@dataclass
class VersionSignaling:
class VersionSignalingParameters:
"""Version Signaling defines the parameters used by signaling protocol parameters upgrade.
Attributes:
Expand Down Expand Up @@ -237,7 +237,7 @@ class ProtocolParameters:
max_committable_age: Max_committable_age is the maximum age for a slot commitment to be included in a block relative to the slot index of the block issuing time.
epoch_nearing_threshold: Determine the slot that should trigger a new committee selection for the next and upcoming epoch.
congestion_control_parameters: Congestion Control Parameters defines the parameters used to calculate the Reference Mana Cost (RMC).
version_signaling: The version signaling parameters.
version_signaling_parameters: The version signaling parameters.
rewards_parameters: Rewards Parameters defines the parameters that are used to calculate Mana rewards.
"""
type: int
Expand Down Expand Up @@ -271,7 +271,7 @@ class ProtocolParameters:
encoder=str
))
congestion_control_parameters: CongestionControlParameters
version_signaling: VersionSignaling
version_signaling_parameters: VersionSignalingParameters
rewards_parameters: RewardsParameters


Expand Down
6 changes: 4 additions & 2 deletions bindings/python/iota_sdk/types/payload.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.transaction import Transaction
from iota_sdk.types.unlock import SignatureUnlock, ReferenceUnlock
from iota_sdk.types.unlock import Unlock, deserialize_unlocks


class PayloadType(IntEnum):
Expand Down Expand Up @@ -50,7 +50,9 @@ class SignedTransactionPayload:
unlocks: The unlocks of the transaction.
"""
transaction: Transaction
unlocks: List[Union[SignatureUnlock, ReferenceUnlock]]
unlocks: List[Unlock] = field(metadata=config(
decoder=deserialize_unlocks
))
type: int = field(
default_factory=lambda: int(
PayloadType.SignedTransaction),
Expand Down
37 changes: 36 additions & 1 deletion bindings/python/iota_sdk/types/unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ class UnlockType(IntEnum):
Account (2): An unlock which must reference a previous unlock which unlocks the account that the input is locked to.
Anchor (3): An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to.
Nft (4): An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to.
Multi (5): Unlocks a MultiAddress with a list of other unlocks.
Empty (6): Used to maintain correct index relationship between addresses and signatures when unlocking a MultiUnlock where not all addresses are unlocked.
"""
Signature = 0
Reference = 1
Account = 2
Anchor = 3
Nft = 4
Multi = 5
Empty = 6


@json
Expand Down Expand Up @@ -84,11 +88,38 @@ class NftUnlock:
type: int = field(default_factory=lambda: int(UnlockType.Nft), init=False)


@json
@dataclass
class MultiUnlock:
"""Unlocks a MultiAddress with a list of other unlocks.
"""
unlocks: List[Unlock] = field(metadata=config(
decoder=deserialize_unlocks
))
type: int = field(
default_factory=lambda: int(
UnlockType.Multi),
init=False)


@json
@dataclass
class EmptyUnlock:
"""Used to maintain correct index relationship between addresses and signatures when unlocking a MultiUnlock where not all addresses are unlocked.
"""
type: int = field(
default_factory=lambda: int(
UnlockType.Empty),
init=False)


Unlock: TypeAlias = Union[SignatureUnlock,
ReferenceUnlock,
AccountUnlock,
AnchorUnlock,
NftUnlock]
NftUnlock,
MultiUnlock,
EmptyUnlock]


def deserialize_unlock(d: Dict[str, Any]) -> Unlock:
Expand All @@ -109,6 +140,10 @@ def deserialize_unlock(d: Dict[str, Any]) -> Unlock:
return AnchorUnlock.from_dict(d)
if unlock_type == UnlockType.Nft:
return NftUnlock.from_dict(d)
if unlock_type == UnlockType.Multi:
return MultiUnlock.from_dict(d)
if unlock_type == UnlockType.Empty:
return EmptyUnlock.from_dict(d)
raise Exception(f'invalid unlock type: {unlock_type}')


Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct ProtocolParameters {
/// 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.
pub(crate) version_signaling: VersionSignalingParameters,
pub(crate) version_signaling_parameters: VersionSignalingParameters,
/// Defines the parameters used for reward calculation.
pub(crate) rewards_parameters: RewardsParameters,
/// Defines the target size of the committee. If there's fewer candidates the actual committee size could be
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Default for ProtocolParameters {
min_committable_age: 10,
max_committable_age: 20,
congestion_control_parameters: Default::default(),
version_signaling: Default::default(),
version_signaling_parameters: Default::default(),
rewards_parameters: Default::default(),
target_committee_size: 32,
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/types/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
// "maxBufferSize":1000,
// "maxValidationBufferSize":100
// },
// "versionSignaling":{
// "versionSignalingParameters":{
// "windowSize":7,
// "windowTargetRatio":5,
// "activationOffset":7
Expand Down

0 comments on commit 8247027

Please sign in to comment.