|
| 1 | +use sp_runtime::transaction_validity::{InvalidTransaction, TransactionValidityError}; |
| 2 | + |
| 3 | +#[derive(Debug, PartialEq)] |
| 4 | +pub enum CustomTransactionError { |
| 5 | + ColdkeyInSwapSchedule, |
| 6 | + StakeAmountTooLow, |
| 7 | + BalanceTooLow, |
| 8 | + SubnetNotExists, |
| 9 | + HotkeyAccountDoesntExist, |
| 10 | + NotEnoughStakeToWithdraw, |
| 11 | + RateLimitExceeded, |
| 12 | + InsufficientLiquidity, |
| 13 | + SlippageTooHigh, |
| 14 | + TransferDisallowed, |
| 15 | + HotKeyNotRegisteredInNetwork, |
| 16 | + InvalidIpAddress, |
| 17 | + ServingRateLimitExceeded, |
| 18 | + InvalidPort, |
| 19 | + BadRequest, |
| 20 | + ZeroMaxAmount, |
| 21 | + InvalidRevealRound, |
| 22 | + CommitNotFound, |
| 23 | + CommitBlockNotInRevealRange, |
| 24 | + InputLengthsUnequal, |
| 25 | + UidNotFound, |
| 26 | + EvmKeyAssociateRateLimitExceeded, |
| 27 | + ColdkeySwapDisputed, |
| 28 | + InvalidRealAccount, |
| 29 | + FailedShieldedTxParsing, |
| 30 | + InvalidShieldedTxPubKeyHash, |
| 31 | +} |
| 32 | + |
| 33 | +impl From<CustomTransactionError> for u8 { |
| 34 | + fn from(variant: CustomTransactionError) -> u8 { |
| 35 | + match variant { |
| 36 | + CustomTransactionError::ColdkeyInSwapSchedule => 0, |
| 37 | + CustomTransactionError::StakeAmountTooLow => 1, |
| 38 | + CustomTransactionError::BalanceTooLow => 2, |
| 39 | + CustomTransactionError::SubnetNotExists => 3, |
| 40 | + CustomTransactionError::HotkeyAccountDoesntExist => 4, |
| 41 | + CustomTransactionError::NotEnoughStakeToWithdraw => 5, |
| 42 | + CustomTransactionError::RateLimitExceeded => 6, |
| 43 | + CustomTransactionError::InsufficientLiquidity => 7, |
| 44 | + CustomTransactionError::SlippageTooHigh => 8, |
| 45 | + CustomTransactionError::TransferDisallowed => 9, |
| 46 | + CustomTransactionError::HotKeyNotRegisteredInNetwork => 10, |
| 47 | + CustomTransactionError::InvalidIpAddress => 11, |
| 48 | + CustomTransactionError::ServingRateLimitExceeded => 12, |
| 49 | + CustomTransactionError::InvalidPort => 13, |
| 50 | + CustomTransactionError::BadRequest => 255, |
| 51 | + CustomTransactionError::ZeroMaxAmount => 14, |
| 52 | + CustomTransactionError::InvalidRevealRound => 15, |
| 53 | + CustomTransactionError::CommitNotFound => 16, |
| 54 | + CustomTransactionError::CommitBlockNotInRevealRange => 17, |
| 55 | + CustomTransactionError::InputLengthsUnequal => 18, |
| 56 | + CustomTransactionError::UidNotFound => 19, |
| 57 | + CustomTransactionError::EvmKeyAssociateRateLimitExceeded => 20, |
| 58 | + CustomTransactionError::ColdkeySwapDisputed => 21, |
| 59 | + CustomTransactionError::InvalidRealAccount => 22, |
| 60 | + CustomTransactionError::FailedShieldedTxParsing => 23, |
| 61 | + CustomTransactionError::InvalidShieldedTxPubKeyHash => 24, |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +impl From<CustomTransactionError> for TransactionValidityError { |
| 67 | + fn from(variant: CustomTransactionError) -> Self { |
| 68 | + TransactionValidityError::Invalid(InvalidTransaction::Custom(variant.into())) |
| 69 | + } |
| 70 | +} |
0 commit comments