Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Block Issuer Feature when Staking Feature is present requirement syntactic #2156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 41 additions & 44 deletions bindings/nodejs/lib/types/models/api/transaction-failure-reason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,47 @@ export enum TransactionFailureReason {
SenderFeatureNotUnlocked = 25,
IssuerFeatureNotUnlocked = 26,
StakingRewardInputMissing = 27,
StakingBlockIssuerFeatureMissing = 28,
StakingCommitmentInputMissing = 29,
StakingRewardClaimingInvalid = 30,
StakingFeatureRemovedBeforeUnbonding = 31,
StakingFeatureModifiedBeforeUnbonding = 32,
StakingStartEpochInvalid = 33,
StakingEndEpochTooEarly = 34,
BlockIssuerCommitmentInputMissing = 35,
BlockIssuanceCreditInputMissing = 36,
BlockIssuerNotExpired = 37,
BlockIssuerExpiryTooEarly = 38,
ManaMovedOffBlockIssuerAccount = 39,
AccountLocked = 40,
TimelockCommitmentInputMissing = 41,
TimelockNotExpired = 42,
ExpirationCommitmentInputMissing = 43,
ExpirationNotUnlockable = 44,
ReturnAmountNotFulFilled = 45,
NewChainOutputHasNonZeroedId = 46,
ChainOutputImmutableFeaturesChanged = 47,
ImplicitAccountDestructionDisallowed = 48,
MultipleImplicitAccountCreationAddresses = 49,
AccountInvalidFoundryCounter = 50,
AnchorInvalidStateTransition = 51,
AnchorInvalidGovernanceTransition = 52,
FoundryTransitionWithoutAccount = 53,
FoundrySerialInvalid = 54,
DelegationCommitmentInputMissing = 55,
DelegationRewardInputMissing = 56,
DelegationRewardsClaimingInvalid = 57,
DelegationOutputTransitionedTwice = 58,
DelegationModified = 59,
DelegationStartEpochInvalid = 60,
DelegationAmountMismatch = 61,
DelegationEndEpochNotZero = 62,
DelegationEndEpochInvalid = 63,
CapabilitiesNativeTokenBurningNotAllowed = 64,
CapabilitiesManaBurningNotAllowed = 65,
CapabilitiesAccountDestructionNotAllowed = 66,
CapabilitiesAnchorDestructionNotAllowed = 67,
CapabilitiesFoundryDestructionNotAllowed = 68,
CapabilitiesNftDestructionNotAllowed = 69,
StakingCommitmentInputMissing = 28,
StakingRewardClaimingInvalid = 29,
StakingFeatureRemovedBeforeUnbonding = 30,
StakingFeatureModifiedBeforeUnbonding = 31,
StakingStartEpochInvalid = 32,
StakingEndEpochTooEarly = 33,
BlockIssuerCommitmentInputMissing = 34,
BlockIssuanceCreditInputMissing = 35,
BlockIssuerNotExpired = 36,
BlockIssuerExpiryTooEarly = 37,
ManaMovedOffBlockIssuerAccount = 38,
AccountLocked = 39,
TimelockCommitmentInputMissing = 40,
TimelockNotExpired = 41,
ExpirationCommitmentInputMissing = 42,
ExpirationNotUnlockable = 43,
ReturnAmountNotFulFilled = 44,
NewChainOutputHasNonZeroedId = 45,
ChainOutputImmutableFeaturesChanged = 46,
ImplicitAccountDestructionDisallowed = 47,
MultipleImplicitAccountCreationAddresses = 48,
AccountInvalidFoundryCounter = 49,
AnchorInvalidStateTransition = 50,
AnchorInvalidGovernanceTransition = 51,
FoundryTransitionWithoutAccount = 52,
FoundrySerialInvalid = 53,
DelegationCommitmentInputMissing = 54,
DelegationRewardInputMissing = 55,
DelegationRewardsClaimingInvalid = 56,
DelegationOutputTransitionedTwice = 57,
DelegationModified = 58,
DelegationStartEpochInvalid = 59,
DelegationAmountMismatch = 60,
DelegationEndEpochNotZero = 61,
DelegationEndEpochInvalid = 62,
CapabilitiesNativeTokenBurningNotAllowed = 63,
CapabilitiesManaBurningNotAllowed = 64,
CapabilitiesAccountDestructionNotAllowed = 65,
CapabilitiesAnchorDestructionNotAllowed = 66,
CapabilitiesFoundryDestructionNotAllowed = 67,
CapabilitiesNftDestructionNotAllowed = 68,
SemanticValidationFailed = 255,
}

Expand Down Expand Up @@ -138,8 +137,6 @@ export const TRANSACTION_FAILURE_REASON_STRINGS: {
'Issuer feature is not unlocked.',
[TransactionFailureReason.StakingRewardInputMissing]:
'Staking feature removal or resetting requires a reward input.',
[TransactionFailureReason.StakingBlockIssuerFeatureMissing]:
'Block issuer feature missing for account with staking feature.',
[TransactionFailureReason.StakingCommitmentInputMissing]:
'Staking feature validation requires a commitment input.',
[TransactionFailureReason.StakingRewardClaimingInvalid]:
Expand Down
176 changes: 87 additions & 89 deletions bindings/python/iota_sdk/types/transaction_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,47 @@ class TransactionFailureReason(Enum):
SenderFeatureNotUnlocked = 25
IssuerFeatureNotUnlocked = 26
StakingRewardInputMissing = 27
StakingBlockIssuerFeatureMissing = 28
StakingCommitmentInputMissing = 29
StakingRewardClaimingInvalid = 30
StakingFeatureRemovedBeforeUnbonding = 31
StakingFeatureModifiedBeforeUnbonding = 32
StakingStartEpochInvalid = 33
StakingEndEpochTooEarly = 34
BlockIssuerCommitmentInputMissing = 35
BlockIssuanceCreditInputMissing = 36
BlockIssuerNotExpired = 37
BlockIssuerExpiryTooEarly = 38
ManaMovedOffBlockIssuerAccount = 39
AccountLocked = 40
TimelockCommitmentInputMissing = 41
TimelockNotExpired = 42
ExpirationCommitmentInputMissing = 43
ExpirationNotUnlockable = 44
ReturnAmountNotFulFilled = 45
NewChainOutputHasNonZeroedId = 46
ChainOutputImmutableFeaturesChanged = 47
ImplicitAccountDestructionDisallowed = 48
MultipleImplicitAccountCreationAddresses = 49
AccountInvalidFoundryCounter = 50
AnchorInvalidStateTransition = 51
AnchorInvalidGovernanceTransition = 52
FoundryTransitionWithoutAccount = 53
FoundrySerialInvalid = 54
DelegationCommitmentInputMissing = 55
DelegationRewardInputMissing = 56
DelegationRewardsClaimingInvalid = 57
DelegationOutputTransitionedTwice = 58
DelegationModified = 59
DelegationStartEpochInvalid = 60
DelegationAmountMismatch = 61
DelegationEndEpochNotZero = 62
DelegationEndEpochInvalid = 63
CapabilitiesNativeTokenBurningNotAllowed = 64
CapabilitiesManaBurningNotAllowed = 65
CapabilitiesAccountDestructionNotAllowed = 66
CapabilitiesAnchorDestructionNotAllowed = 67
CapabilitiesFoundryDestructionNotAllowed = 68
CapabilitiesNftDestructionNotAllowed = 69
StakingCommitmentInputMissing = 28
StakingRewardClaimingInvalid = 29
StakingFeatureRemovedBeforeUnbonding = 30
StakingFeatureModifiedBeforeUnbonding = 31
StakingStartEpochInvalid = 32
StakingEndEpochTooEarly = 33
BlockIssuerCommitmentInputMissing = 34
BlockIssuanceCreditInputMissing = 35
BlockIssuerNotExpired = 36
BlockIssuerExpiryTooEarly = 37
ManaMovedOffBlockIssuerAccount = 38
AccountLocked = 39
TimelockCommitmentInputMissing = 40
TimelockNotExpired = 41
ExpirationCommitmentInputMissing = 42
ExpirationNotUnlockable = 43
ReturnAmountNotFulFilled = 44
NewChainOutputHasNonZeroedId = 45
ChainOutputImmutableFeaturesChanged = 46
ImplicitAccountDestructionDisallowed = 47
MultipleImplicitAccountCreationAddresses = 48
AccountInvalidFoundryCounter = 49
AnchorInvalidStateTransition = 50
AnchorInvalidGovernanceTransition = 51
FoundryTransitionWithoutAccount = 52
FoundrySerialInvalid = 53
DelegationCommitmentInputMissing = 54
DelegationRewardInputMissing = 54
DelegationRewardsClaimingInvalid = 56
DelegationOutputTransitionedTwice = 57
DelegationModified = 58
DelegationStartEpochInvalid = 59
DelegationAmountMismatch = 60
DelegationEndEpochNotZero = 61
DelegationEndEpochInvalid = 62
CapabilitiesNativeTokenBurningNotAllowed = 63
CapabilitiesManaBurningNotAllowed = 64
CapabilitiesAccountDestructionNotAllowed = 65
CapabilitiesAnchorDestructionNotAllowed = 66
CapabilitiesFoundryDestructionNotAllowed = 67
CapabilitiesNftDestructionNotAllowed = 68
SemanticValidationFailed = 255

def __str__(self):
Expand All @@ -106,7 +105,7 @@ def __str__(self):
5: "Invalid unlock for chain address.",
6: "Invalid unlock for direct unlockable address.",
7: "Invalid unlock for multi address.",
8: "Commitment input required with reward or BIC input.",
8: "Commitment input references an invalid or non-existent commitment.",
9: "BIC input reference cannot be loaded.",
10: "Reward input does not reference a staking account or a delegation output.",
11: "Staking rewards could not be calculated due to storage issues or overflow.",
Expand All @@ -117,56 +116,55 @@ def __str__(self):
16: "Mana decay creation slot/epoch index exceeds target slot/epoch index.",
17: "Native token sums are unbalanced.",
18: "Simple token scheme minted/melted value decreased.",
19: "Simple token scheme minting invalid.",
20: "Simple token scheme melting invalid.",
21: "Simple token scheme maximum supply changed.",
22: "Simple token scheme genesis invalid.",
19: "Simple token scheme's minted tokens did not increase by the minted amount or melted tokens changed.",
20: "Simple token scheme's melted tokens did not increase by the melted amount or minted tokens changed.",
21: "Simple token scheme's maximum supply cannot change during transition.",
22: "Newly created simple token scheme's melted tokens are not zero or minted tokens do not equal native token amount in transaction.",
23: "Multi address length and multi unlock length do not match.",
24: "Multi address unlock threshold not reached.",
25: "Sender feature is not unlocked.",
26: "Issuer feature is not unlocked.",
27: "Staking feature removal or resetting requires a reward input.",
28: "Block issuer feature missing for account with staking feature.",
29: "Staking feature validation requires a commitment input.",
30: "Staking feature must be removed or reset in order to claim rewards.",
31: "Staking feature can only be removed after the unbonding period.",
32: "Staking start epoch, fixed cost and staked amount cannot be modified while bonded.",
33: "Staking start epoch must be the epoch of the transaction.",
34: "Staking end epoch must be set to the transaction epoch plus the unbonding period.",
35: "Commitment input missing for block issuer feature.",
36: "Block issuance credit input missing for account with block issuer feature.",
37: "Block issuer feature has not expired.",
38: "Block issuer feature expiry set too early.",
39: "Mana cannot be moved off block issuer accounts except with manalocks.",
40: "Account is locked due to negative block issuance credits.",
41: "Transaction's containing a timelock condition require a commitment input.",
42: "Timelock not expired.",
43: "Transaction's containing an expiration condition require a commitment input.",
44: "Expiration unlock condition cannot be unlocked.",
45: "Return amount not fulfilled.",
46: "New chain output has non-zeroed ID.",
47: "Immutable features in chain output modified during transition.",
48: "Cannot destroy implicit account; must be transitioned to account.",
49: "Multiple implicit account creation addresses on the input side.",
50: "Foundry counter in account decreased or did not increase by the number of new foundries.",
51: "Anchor has an invalid state transition.",
52: "Anchor has an invalid governance transition.",
53: "Foundry output transitioned without accompanying account on input or output side.",
54: "Foundry output serial number is invalid.",
55: "Delegation output validation requires a commitment input.",
56: "Delegation output cannot be destroyed without a reward input.",
57: "Invalid delegation mana rewards claiming.",
58: "Delegation output attempted to be transitioned twice.",
59: "Delegated amount, validator ID and start epoch cannot be modified.",
60: "Invalid start epoch.",
61: "Delegated amount does not match amount.",
62: "End epoch must be set to zero at output genesis.",
63: "Delegation end epoch does not match current epoch.",
64: "Native token burning is not allowed by the transaction capabilities.",
65: "Mana burning is not allowed by the transaction capabilities.",
66: "Account destruction is not allowed by the transaction capabilities.",
67: "Anchor destruction is not allowed by the transaction capabilities.",
68: "Foundry destruction is not allowed by the transaction capabilities.",
69: "NFT destruction is not allowed by the transaction capabilities.",
28: "Staking feature validation requires a commitment input.",
29: "Staking feature must be removed or reset in order to claim rewards.",
30: "Staking feature can only be removed after the unbonding period.",
31: "Staking start epoch, fixed cost and staked amount cannot be modified while bonded.",
32: "Staking start epoch must be the epoch of the transaction.",
33: "Staking end epoch must be set to the transaction epoch plus the unbonding period.",
34: "Commitment input missing for block issuer feature.",
35: "Block issuance credit input missing for account with block issuer feature.",
36: "Block issuer feature has not expired.",
37: "Block issuer feature expiry set too early.",
38: "Mana cannot be moved off block issuer accounts except with manalocks.",
39: "Account is locked due to negative block issuance credits.",
40: "Transaction's containing a timelock condition require a commitment input.",
41: "Timelock not expired.",
42: "Transaction's containing an expiration condition require a commitment input.",
43: "Expiration unlock condition cannot be unlocked.",
44: "Return amount not fulfilled.",
45: "New chain output has non-zeroed ID.",
46: "Immutable features in chain output modified during transition.",
47: "Cannot destroy implicit account; must be transitioned to account.",
48: "Multiple implicit account creation addresses on the input side.",
49: "Foundry counter in account decreased or did not increase by the number of new foundries.",
50: "Anchor has an invalid state transition.",
51: "Anchor has an invalid governance transition.",
52: "Foundry output transitioned without accompanying account on input or output side.",
53: "Foundry output serial number is invalid.",
54: "Delegation output validation requires a commitment input.",
55: "Delegation output cannot be destroyed without a reward input.",
56: "Invalid delegation mana rewards claiming.",
57: "Delegation output attempted to be transitioned twice.",
58: "Delegated amount, validator ID and start epoch cannot be modified.",
59: "Invalid start epoch.",
60: "Delegated amount does not match amount.",
61: "End epoch must be set to zero at output genesis.",
62: "Delegation end epoch does not match current epoch.",
63: "Native token burning is not allowed by the transaction capabilities.",
64: "Mana burning is not allowed by the transaction capabilities.",
65: "Account destruction is not allowed by the transaction capabilities.",
66: "Anchor destruction is not allowed by the transaction capabilities.",
67: "Foundry destruction is not allowed by the transaction capabilities.",
68: "NFT destruction is not allowed by the transaction capabilities.",
255: "Semantic validation failed.",
}[self.value]
11 changes: 7 additions & 4 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use packable::{
use crate::types::block::{
address::{AccountAddress, Address},
output::{
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
feature::{verify_allowed_features, Feature, FeatureError, FeatureFlags, Features},
unlock_condition::{
verify_allowed_unlock_conditions, verify_restricted_addresses, UnlockCondition, UnlockConditionFlags,
UnlockConditions,
Expand Down Expand Up @@ -259,7 +259,7 @@ impl AccountOutputBuilder {
OutputBuilderAmount::MinimumAmount(params) => output.minimum_amount(params),
};

verify_staked_amount(output.amount, &output.features)?;
verify_staking(output.amount, &output.features)?;

Ok(output)
}
Expand Down Expand Up @@ -511,7 +511,7 @@ impl Packable for AccountOutput {
verify_allowed_features(&features, Self::ALLOWED_FEATURES)
.map_err(UnpackError::Packable)
.coerce()?;
verify_staked_amount(amount, &features).map_err(UnpackError::Packable)?;
verify_staking(amount, &features).map_err(UnpackError::Packable)?;
}

let immutable_features = Features::unpack_inner(unpacker, visitor).coerce()?;
Expand Down Expand Up @@ -560,8 +560,11 @@ fn verify_unlock_conditions(unlock_conditions: &UnlockConditions, account_id: &A
)?)
}

fn verify_staked_amount(amount: u64, features: &Features) -> Result<(), OutputError> {
fn verify_staking(amount: u64, features: &Features) -> Result<(), OutputError> {
if let Some(staking) = features.staking() {
if features.block_issuer().is_none() {
return Err(FeatureError::StakingBlockIssuerMissing)?;
}
if amount < staking.staked_amount() {
return Err(OutputError::InvalidStakedAmount);
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/types/block/output/feature/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub enum FeatureError {
InvalidBlockIssuerKeyCount(<BlockIssuerKeyCount as TryFrom<usize>>::Error),
#[display(fmt = "block issuer keys are not unique and/or sorted")]
BlockIssuerKeysNotUniqueSorted,
#[display(fmt = "block issuer feature missing for account with staking feature")]
StakingBlockIssuerMissing,
#[from]
NativeToken(NativeTokenError),
#[from]
Expand Down
Loading
Loading