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

Add block failure reason strings #1859

Merged
merged 8 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 30 additions & 2 deletions bindings/nodejs/lib/types/models/block-failure-reason.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 IOTA Stiftung
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

/**
Expand All @@ -19,7 +19,7 @@ export enum BlockFailureReason {
VersionInvalid = 6,
/** The mana cost could not be calculated. */
ManaCostCalculationFailed = 7,
// The block's issuer account burned insufficient Mana for a block.
/** The block's issuer account burned insufficient Mana for a block. */
BurnedInsufficientMana = 8,
/** The account is invalid. */
AccountInvalid = 9,
Expand All @@ -32,3 +32,31 @@ export enum BlockFailureReason {
/** The block is invalid. */
Invalid = 255,
}

/**
* Transaction failure reason strings.
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
*/
export const BLOCK_FAILURE_REASON_STRINGS: {
[key in BlockFailureReason]: string;
} = {
[BlockFailureReason.TooOldToIssue]: 'The block is too old to issue.',
[BlockFailureReason.ParentTooOld]: "One of the block's parents is too old.",
[BlockFailureReason.ParentDoesNotExist]:
"One of the block's parents does not exist.",
[BlockFailureReason.ParentInvalid]:
"One of the block's parents is invalid.",
[BlockFailureReason.IssuerAccountNotFound]:
"The block's issuer account could not be found.",
[BlockFailureReason.VersionInvalid]:
"The block's protocol version is invalid.",
[BlockFailureReason.ManaCostCalculationFailed]:
'The mana cost could not be calculated.',
[BlockFailureReason.BurnedInsufficientMana]:
"The block's issuer account burned insufficient Mana for a block.",
[BlockFailureReason.AccountInvalid]: 'The account is invalid.',
[BlockFailureReason.SignatureInvalid]: "The block's signature is invalid.",
[BlockFailureReason.DroppedDueToCongestion]:
'The block is dropped due to congestion.',
[BlockFailureReason.PayloadInvalid]: 'The block payload is invalid.',
[BlockFailureReason.Invalid]: 'The block is invalid.',
};
148 changes: 74 additions & 74 deletions bindings/nodejs/lib/types/models/transaction-failure-reason.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 IOTA Stiftung
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

/**
Expand All @@ -8,139 +8,139 @@ export enum TransactionFailureReason {
/**
* The referenced UTXO was already spent.
*/
inputUTXOAlreadySpent = 1,
InputUTXOAlreadySpent = 1,

/**
* The transaction is conflicting with another transaction.
* Conflicting specifically means a double spend situation that both transactions pass all validation rules,
* eventually losing one(s) should have this reason.
*/
conflictingWithAnotherTx = 2,
ConflictingWithAnotherTx = 2,

/**
* The referenced UTXO is invalid.
* The referenced UTXO is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidReferencedUtxo = 3,
InvalidReferencedUtxo = 3,

/**
* The transaction is invalid.
* The transaction is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidTransaction = 4,
InvalidTransaction = 4,

/**
* The sum of the inputs and output base token amount does not match.
*/
sumInputsOutputsAmountMismatch = 5,
SumInputsOutputsAmountMismatch = 5,

/**
* The unlock block signature is invalid.
* The unlock block signature is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidUnlockBlockSignature = 6,
InvalidUnlockBlockSignature = 6,

/**
* The configured timelock is not yet expired.
*/
timelockNotExpired = 7,
TimelockNotExpired = 7,

/**
* The given native tokens are invalid.
* The given native tokens are Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidNativeTokens = 8,
InvalidNativeTokens = 8,

/**
* The return amount in a transaction is not fulfilled by the output side.
*/
storageDepositReturnUnfulfilled = 9,
StorageDepositReturnUnfulfilled = 9,

/**
* An input unlock was invalid.
* An input unlock was Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidInputUnlock = 10,
InvalidInputUnlock = 10,

/**
* The output contains a Sender with an ident (address) which is not unlocked.
*/
senderNotUnlocked = 11,
SenderNotUnlocked = 11,

/**
* The chain state transition is invalid.
* The chain state transition is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidChainStateTransition = 12,
InvalidChainStateTransition = 12,

/**
* The referenced input is created after transaction issuing time.
*/
invalidTransactionIssuingTime = 13,
InvalidTransactionIssuingTime = 13,

/**
* The mana amount is invalid.
* The mana amount is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidManaAmount = 14,
InvalidManaAmount = 14,

/**
* The Block Issuance Credits amount is invalid.
* The Block Issuance Credits amount is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidBlockIssuanceCreditsAmount = 15,
InvalidBlockIssuanceCreditsAmount = 15,

/**
* Reward Context Input is invalid.
* Reward Context Input is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidRewardContextInput = 16,
InvalidRewardContextInput = 16,

/**
* Commitment Context Input is invalid.
* Commitment Context Input is Invalid.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
*/
invalidCommitmentContextInput = 17,
InvalidCommitmentContextInput = 17,

/**
* Staking Feature is not provided in account output when claiming rewards.
*/
missingStakingFeature = 18,
MissingStakingFeature = 18,

/**
* Failed to claim staking reward.
*/
failedToClaimStakingReward = 19,
FailedToClaimStakingReward = 19,

/**
* Failed to claim delegation reward.
*/
failedToClaimDelegationReward = 20,
FailedToClaimDelegationReward = 20,

/**
* Burning of native tokens is not allowed in the transaction capabilities.
*/
transactionCapabilityNativeTokenBurningNotAllowed = 21,
TransactionCapabilityNativeTokenBurningNotAllowed = 21,

/**
* Burning of mana is not allowed in the transaction capabilities.
*/
transactionCapabilityManaBurningNotAllowed = 22,
TransactionCapabilityManaBurningNotAllowed = 22,

/**
* Destruction of accounts is not allowed in the transaction capabilities.
*/
transactionCapabilityAccountDestructionNotAllowed = 23,
TransactionCapabilityAccountDestructionNotAllowed = 23,

/**
* Destruction of anchors is not allowed in the transaction capabilities.
*/
transactionCapabilityAnchorDestructionNotAllowed = 24,
TransactionCapabilityAnchorDestructionNotAllowed = 24,

/**
* Destruction of foundries is not allowed in the transaction capabilities.
*/
transactionCapabilityFoundryDestructionNotAllowed = 25,
TransactionCapabilityFoundryDestructionNotAllowed = 25,

/**
* Destruction of nfts is not allowed in the transaction capabilities.
*/
transactionCapabilityNftDestructionNotAllowed = 26,
TransactionCapabilityNftDestructionNotAllowed = 26,

/**
* The semantic validation failed for a reason not covered by the previous variants.
*/
semanticValidationFailed = 255,
SemanticValidationFailed = 255,
}

/**
Expand All @@ -149,57 +149,57 @@ export enum TransactionFailureReason {
export const TRANSACTION_FAILURE_REASON_STRINGS: {
[key in TransactionFailureReason]: string;
} = {
[TransactionFailureReason.inputUTXOAlreadySpent]:
[TransactionFailureReason.InputUTXOAlreadySpent]:
'The referenced UTXO was already spent.',
[TransactionFailureReason.conflictingWithAnotherTx]:
[TransactionFailureReason.ConflictingWithAnotherTx]:
'The transaction is conflicting with another transaction. Conflicting specifically means a double spend situation that both transactions pass all validation rules, eventually losing one(s) should have this reason.',
[TransactionFailureReason.invalidReferencedUtxo]:
'The referenced UTXO is invalid.',
[TransactionFailureReason.invalidTransaction]:
'The transaction is invalid.',
[TransactionFailureReason.sumInputsOutputsAmountMismatch]:
[TransactionFailureReason.InvalidReferencedUtxo]:
'The referenced UTXO is Invalid.',
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
[TransactionFailureReason.InvalidTransaction]:
'The transaction is Invalid.',
[TransactionFailureReason.SumInputsOutputsAmountMismatch]:
'The sum of the inputs and output base token amount does not match.',
[TransactionFailureReason.invalidUnlockBlockSignature]:
'The unlock block signature is invalid.',
[TransactionFailureReason.timelockNotExpired]:
[TransactionFailureReason.InvalidUnlockBlockSignature]:
'The unlock block signature is Invalid.',
[TransactionFailureReason.TimelockNotExpired]:
'The configured timelock is not yet expired.',
[TransactionFailureReason.invalidNativeTokens]:
'The given native tokens are invalid.',
[TransactionFailureReason.storageDepositReturnUnfulfilled]:
[TransactionFailureReason.InvalidNativeTokens]:
'The given native tokens are Invalid.',
[TransactionFailureReason.StorageDepositReturnUnfulfilled]:
'The return amount in a transaction is not fulfilled by the output side.',
[TransactionFailureReason.invalidInputUnlock]:
'An input unlock was invalid.',
[TransactionFailureReason.senderNotUnlocked]:
[TransactionFailureReason.InvalidInputUnlock]:
'An input unlock was Invalid.',
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
[TransactionFailureReason.SenderNotUnlocked]:
'The output contains a Sender with an ident (address) which is not unlocked.',
[TransactionFailureReason.invalidChainStateTransition]:
'The chain state transition is invalid.',
[TransactionFailureReason.invalidTransactionIssuingTime]:
[TransactionFailureReason.InvalidChainStateTransition]:
'The chain state transition is Invalid.',
[TransactionFailureReason.InvalidTransactionIssuingTime]:
'The referenced input is created after transaction issuing time.',
[TransactionFailureReason.invalidManaAmount]: 'The mana amount is invalid.',
[TransactionFailureReason.invalidBlockIssuanceCreditsAmount]:
'The Block Issuance Credits amount is invalid.',
[TransactionFailureReason.invalidRewardContextInput]:
'Reward Context Input is invalid.',
[TransactionFailureReason.invalidCommitmentContextInput]:
'Commitment Context Input is invalid.',
[TransactionFailureReason.missingStakingFeature]:
[TransactionFailureReason.InvalidManaAmount]: 'The mana amount is Invalid.',
[TransactionFailureReason.InvalidBlockIssuanceCreditsAmount]:
'The Block Issuance Credits amount is Invalid.',
[TransactionFailureReason.InvalidRewardContextInput]:
'Reward Context Input is Invalid.',
[TransactionFailureReason.InvalidCommitmentContextInput]:
'Commitment Context Input is Invalid.',
[TransactionFailureReason.MissingStakingFeature]:
'Staking Feature is not provided in account output when claiming rewards.',
[TransactionFailureReason.failedToClaimStakingReward]:
[TransactionFailureReason.FailedToClaimStakingReward]:
'Failed to claim staking reward.',
[TransactionFailureReason.failedToClaimDelegationReward]:
[TransactionFailureReason.FailedToClaimDelegationReward]:
'Failed to claim delegation reward.',
[TransactionFailureReason.transactionCapabilityNativeTokenBurningNotAllowed]:
[TransactionFailureReason.TransactionCapabilityNativeTokenBurningNotAllowed]:
'Burning of native tokens is not allowed in the transaction capabilities.',
[TransactionFailureReason.transactionCapabilityManaBurningNotAllowed]:
[TransactionFailureReason.TransactionCapabilityManaBurningNotAllowed]:
'Burning of mana is not allowed in the transaction capabilities.',
[TransactionFailureReason.transactionCapabilityAccountDestructionNotAllowed]:
[TransactionFailureReason.TransactionCapabilityAccountDestructionNotAllowed]:
'Destruction of accounts is not allowed in the transaction capabilities.',
[TransactionFailureReason.transactionCapabilityAnchorDestructionNotAllowed]:
[TransactionFailureReason.TransactionCapabilityAnchorDestructionNotAllowed]:
'Destruction of anchors is not allowed in the transaction capabilities.',
[TransactionFailureReason.transactionCapabilityFoundryDestructionNotAllowed]:
[TransactionFailureReason.TransactionCapabilityFoundryDestructionNotAllowed]:
'Destruction of foundries is not allowed in the transaction capabilities.',
[TransactionFailureReason.transactionCapabilityNftDestructionNotAllowed]:
[TransactionFailureReason.TransactionCapabilityNftDestructionNotAllowed]:
'Destruction of nfts is not allowed in the transaction capabilities.',
[TransactionFailureReason.semanticValidationFailed]:
[TransactionFailureReason.SemanticValidationFailed]:
'The semantic validation failed for a reason not covered by the previous variants.',
};
17 changes: 17 additions & 0 deletions bindings/python/iota_sdk/types/block/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ class BlockFailureReason(IntEnum):
PayloadInvalid = 12
Invalid = 255

def __str__(self):
return {
1: "The block is too old to issue.",
2: "One of the block's parents is too old.",
3: "One of the block's parents does not exist.",
4: "One of the block's parents is invalid.",
5: "The block's issuer account could not be found.",
6: "The block's protocol version is invalid.",
7: "The mana cost could not be calculated.",
8: "The block's issuer account burned insufficient Mana for a block.",
9: "The account is invalid.",
10: "The block's signature is invalid.",
11: "The block is dropped due to congestion.",
12: "The block payload is invalid.",
255: "The block is invalid."
}[self.value]


class TransactionFailureReason(Enum):
"""Represents the possible reasons for a conflicting transaction.
Expand Down
24 changes: 23 additions & 1 deletion sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 IOTA Stiftung
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use alloc::{
Expand Down Expand Up @@ -402,6 +402,28 @@ pub enum BlockFailureReason {
Invalid = 255,
}

impl core::fmt::Display for BlockFailureReason {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::TooOldToIssue => write!(f, "The block is too old to issue."),
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
Self::ParentTooOld => write!(f, "One of the block's parents is too old."),
Self::ParentDoesNotExist => write!(f, "One of the block's parents does not exist."),
Self::ParentInvalid => write!(f, "One of the block's parents is invalid."),
Self::IssuerAccountNotFound => write!(f, "The block's issuer account could not be found."),
Self::VersionInvalid => write!(f, "The block's protocol version is invalid."),
Self::ManaCostCalculationFailed => write!(f, "The mana cost could not be calculated."),
Self::BurnedInsufficientMana => {
write!(f, "The block's issuer account burned insufficient Mana for a block.")
}
Self::AccountInvalid => write!(f, "The account is invalid."),
Self::SignatureInvalid => write!(f, "The block's signature is invalid."),
Self::DroppedDueToCongestion => write!(f, "The block is dropped due to congestion."),
Self::PayloadInvalid => write!(f, "The block payload is invalid."),
Self::Invalid => write!(f, "The block is invalid."),
}
}
}

// Response of a GET transaction metadata REST API call.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down