Skip to main content

dpp/errors/consensus/
codes.rs

1use crate::consensus::signature::SignatureError;
2use crate::consensus::state::data_trigger::DataTriggerError;
3use crate::data_contract::errors::DataContractError;
4
5use crate::errors::consensus::{
6    basic::BasicError, fee::fee_error::FeeError, state::state_error::StateError, ConsensusError,
7};
8
9pub trait ErrorWithCode {
10    /// Returns the error code
11    fn code(&self) -> u32;
12}
13
14impl ErrorWithCode for ConsensusError {
15    fn code(&self) -> u32 {
16        match self {
17            Self::BasicError(e) => e.code(),
18            Self::SignatureError(e) => e.code(),
19            Self::StateError(e) => e.code(),
20            Self::FeeError(e) => e.code(),
21
22            #[cfg(test)]
23            ConsensusError::TestConsensusError(_) => 1000,
24            ConsensusError::DefaultError => 1, // this should never happen
25        }
26    }
27}
28impl ErrorWithCode for BasicError {
29    fn code(&self) -> u32 {
30        match self {
31            // Versioning Errors: 10000-10099
32            Self::UnsupportedVersionError(_) => 10000,
33            Self::ProtocolVersionParsingError { .. } => 10001,
34            Self::SerializedObjectParsingError { .. } => 10002,
35            Self::UnsupportedProtocolVersionError(_) => 10003,
36            Self::IncompatibleProtocolVersionError(_) => 10004,
37            Self::VersionError(_) => 10005,
38            Self::UnsupportedFeatureError(_) => 10006,
39
40            // Structure Errors: 10100-10199
41            Self::JsonSchemaCompilationError(..) => 10100,
42            Self::JsonSchemaError(_) => 10101,
43            Self::InvalidIdentifierError { .. } => 10102,
44            Self::ValueError(_) => 10103,
45
46            // DataContract Errors: 10200-10349
47            Self::DataContractMaxDepthExceedError { .. } => 10200,
48            Self::DuplicateIndexError { .. } => 10201,
49            Self::IncompatibleRe2PatternError { .. } => 10202,
50            Self::InvalidCompoundIndexError { .. } => 10203,
51            Self::InvalidDataContractIdError { .. } => 10204,
52            Self::InvalidIndexedPropertyConstraintError { .. } => 10205,
53            Self::InvalidIndexPropertyTypeError { .. } => 10206,
54            Self::InvalidJsonSchemaRefError { .. } => 10207,
55            Self::SystemPropertyIndexAlreadyPresentError { .. } => 10208,
56            Self::UndefinedIndexPropertyError { .. } => 10209,
57            Self::UniqueIndicesLimitReachedError { .. } => 10210,
58            Self::DuplicateIndexNameError { .. } => 10211,
59            Self::InvalidDataContractVersionError { .. } => 10212,
60            Self::IncompatibleDataContractSchemaError { .. } => 10213,
61            Self::ContractError(DataContractError::DocumentTypesAreMissingError { .. }) => 10214,
62            Self::DataContractImmutablePropertiesUpdateError { .. } => 10215,
63            Self::DataContractUniqueIndicesChangedError { .. } => 10216,
64            Self::DataContractInvalidIndexDefinitionUpdateError { .. } => 10217,
65            Self::DataContractHaveNewUniqueIndexError { .. } => 10218,
66            Self::InvalidDocumentTypeRequiredSecurityLevelError { .. } => 10219,
67            Self::UnknownSecurityLevelError { .. } => 10220,
68            Self::UnknownStorageKeyRequirementsError { .. } => 10221,
69            Self::ContractError(DataContractError::DecodingContractError { .. }) => 10222,
70            Self::ContractError(DataContractError::DecodingDocumentError { .. }) => 10223,
71            Self::ContractError(DataContractError::InvalidDocumentTypeError { .. }) => 10224,
72            Self::ContractError(DataContractError::MissingRequiredKey(_)) => 10225,
73            Self::ContractError(DataContractError::FieldRequirementUnmet(_)) => 10226,
74            Self::ContractError(DataContractError::KeyWrongType(_)) => 10227,
75            Self::ContractError(DataContractError::ValueWrongType(_)) => 10228,
76            Self::ContractError(DataContractError::ValueDecodingError(_)) => 10229,
77            Self::ContractError(DataContractError::EncodingDataStructureNotSupported(_)) => 10230,
78            Self::ContractError(DataContractError::InvalidContractStructure(_)) => 10231,
79            Self::ContractError(DataContractError::DocumentTypeNotFound(_)) => 10232,
80            Self::ContractError(DataContractError::DocumentTypeFieldNotFound(_)) => 10233,
81            Self::ContractError(DataContractError::ReferenceDefinitionNotFound(_)) => 10234,
82            Self::ContractError(DataContractError::DocumentOwnerIdMissing(_)) => 10235,
83            Self::ContractError(DataContractError::DocumentIdMissing(_)) => 10236,
84            Self::ContractError(DataContractError::Unsupported(_)) => 10237,
85            Self::ContractError(DataContractError::CorruptedSerialization(_)) => 10238,
86            Self::ContractError(DataContractError::JsonSchema(_)) => 10239,
87            Self::ContractError(DataContractError::InvalidURI(_)) => 10240,
88            Self::ContractError(DataContractError::KeyWrongBounds(_)) => 10241,
89            Self::ContractError(DataContractError::KeyValueMustExist(_)) => 10242,
90            Self::UnknownTransferableTypeError { .. } => 10243,
91            Self::UnknownTradeModeError { .. } => 10244,
92            Self::UnknownDocumentCreationRestrictionModeError { .. } => 10245,
93            Self::IncompatibleDocumentTypeSchemaError { .. } => 10246,
94            Self::ContractError(DataContractError::RegexError(_)) => 10247,
95            Self::ContestedUniqueIndexOnMutableDocumentTypeError(_) => 10248,
96            Self::ContestedUniqueIndexWithUniqueIndexError(_) => 10249,
97            Self::DataContractTokenConfigurationUpdateError { .. } => 10250,
98            Self::InvalidTokenBaseSupplyError(_) => 10251,
99            Self::NonContiguousContractGroupPositionsError(_) => 10252,
100            Self::NonContiguousContractTokenPositionsError(_) => 10253,
101            Self::InvalidTokenDistributionFunctionDivideByZeroError(_) => 10254,
102            Self::InvalidTokenDistributionFunctionInvalidParameterError(_) => 10255,
103            Self::InvalidTokenDistributionFunctionInvalidParameterTupleError(_) => 10256,
104            Self::InvalidTokenDistributionFunctionIncoherenceError(_) => 10257,
105            Self::MissingDefaultLocalizationError(_) => 10258,
106            Self::UnknownGasFeesPaidByError(_) => 10259,
107            Self::UnknownDocumentActionTokenEffectError(_) => 10260,
108            Self::TokenPaymentByBurningOnlyAllowedOnInternalTokenError(_) => 10261,
109            Self::TooManyKeywordsError(_) => 10262,
110            Self::DuplicateKeywordsError(_) => 10263,
111            Self::InvalidDescriptionLengthError(_) => 10264,
112            Self::NewTokensDestinationIdentityOptionRequiredError(_) => 10265,
113            Self::InvalidTokenNameCharacterError(_) => 10266,
114            Self::InvalidTokenNameLengthError(_) => 10267,
115            Self::InvalidTokenLanguageCodeError(_) => 10268,
116            Self::InvalidKeywordCharacterError(_) => 10269,
117            Self::InvalidKeywordLengthError(_) => 10270,
118            Self::DecimalsOverLimitError(_) => 10271,
119            Self::InvalidTokenDistributionBlockIntervalTooShortError(_) => 10272,
120            Self::InvalidTokenDistributionTimeIntervalTooShortError(_) => 10273,
121            Self::InvalidTokenDistributionTimeIntervalNotMinuteAlignedError(_) => 10274,
122            Self::RedundantDocumentPaidForByTokenWithContractId(_) => 10275,
123            Self::DataContractInvalidRequiredFieldsUpdateError { .. } => 10276,
124            Self::PreProgrammedDistributionAmountOverLimitError(_) => 10277,
125            Self::TokenShieldedPoolIncompatibleRulesError(_) => 10278,
126
127            // Group Errors: 10350-10399
128            Self::GroupPositionDoesNotExistError(_) => 10350,
129            Self::GroupActionNotAllowedOnTransitionError(_) => 10351,
130            Self::GroupTotalPowerLessThanRequiredError(_) => 10352,
131            Self::GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError(_) => 10353,
132            Self::GroupExceedsMaxMembersError(_) => 10354,
133            Self::GroupMemberHasPowerOfZeroError(_) => 10355,
134            Self::GroupMemberHasPowerOverLimitError(_) => 10356,
135            Self::MainGroupIsNotDefinedError(_) => 10357,
136            Self::GroupRequiredPowerIsInvalidError(_) => 10358,
137            Self::GroupHasTooFewMembersError(_) => 10359,
138
139            // Contract groups
140            Self::ContractGroupMembershipsOverLimitError(_) => 10360,
141            Self::DuplicateContractGroupMembershipError(_) => 10361,
142            Self::RedundantContractGroupMembershipError(_) => 10362,
143            Self::ContractGroupMemberNotInContractError(_) => 10363,
144            Self::InvalidContractGroupAdminsError(_) => 10364,
145            // 10365 is unassigned: the registrant-not-owner rule became inexpressible when the
146            // owner left the wire, before protocol version 14 shipped.
147            Self::InvalidContractGroupNameLengthError(_) => 10366,
148            Self::InvalidContractGroupDescriptionLengthError(_) => 10367,
149
150            // Document Errors: 10400-10449
151            Self::DataContractNotPresentError { .. } => 10400,
152            Self::DuplicateDocumentTransitionsWithIdsError { .. } => 10401,
153            Self::DuplicateDocumentTransitionsWithIndicesError { .. } => 10402,
154            Self::InconsistentCompoundIndexDataError { .. } => 10403,
155            Self::InvalidDocumentTransitionActionError { .. } => 10404,
156            Self::InvalidDocumentTransitionIdError { .. } => 10405,
157            Self::InvalidDocumentTypeError { .. } => 10406,
158            Self::MissingDataContractIdBasicError { .. } => 10407,
159            Self::MissingDocumentTransitionActionError { .. } => 10408,
160            Self::MissingDocumentTransitionTypeError { .. } => 10409,
161            Self::MissingDocumentTypeError { .. } => 10410,
162            Self::MissingPositionsInDocumentTypePropertiesError { .. } => 10411,
163            Self::MaxDocumentsTransitionsExceededError { .. } => 10412,
164            Self::DocumentTransitionsAreAbsentError { .. } => 10413,
165            Self::NonceOutOfBoundsError(_) => 10414,
166            Self::InvalidDocumentTypeNameError(_) => 10415,
167            Self::DocumentCreationNotAllowedError(_) => 10416,
168            Self::DocumentFieldMaxSizeExceededError(_) => 10417,
169            Self::ContestedDocumentsTemporarilyNotAllowedError(_) => 10418,
170            Self::DocumentPropertyNotDistinctError(_) => 10419,
171            Self::InvalidEncryptedPropertyShapeError(_) => 10420,
172            Self::DocumentPropertyMaxBytesExceededError(_) => 10421,
173            Self::DocumentPropertyConstraintViolatedError(_) => 10422,
174            Self::DocumentReferencePreimageInvalidError(_) => 10423,
175            Self::DocumentPropertyNotGeneratedError(_) => 10424,
176
177            // Token Errors: 10450-10499
178            Self::InvalidTokenIdError(_) => 10450,
179            Self::InvalidTokenPositionError(_) => 10451,
180            Self::InvalidActionIdError(_) => 10452,
181            Self::ContractHasNoTokensError(_) => 10453,
182            Self::DestinationIdentityForTokenMintingNotSetError(_) => 10454,
183            Self::ChoosingTokenMintRecipientNotAllowedError(_) => 10455,
184            Self::TokenTransferToOurselfError(_) => 10456,
185            Self::InvalidTokenConfigUpdateNoChangeError(_) => 10457,
186            Self::InvalidTokenAmountError(_) => 10458,
187            Self::InvalidTokenNoteTooBigError(_) => 10459,
188            Self::TokenNoteOnlyAllowedWhenProposerError(_) => 10460,
189            Self::TokenPricingScheduleEmptyError(_) => 10461,
190
191            // Identity Errors: 10500-10599
192            Self::DuplicatedIdentityPublicKeyBasicError(_) => 10500,
193            Self::DuplicatedIdentityPublicKeyIdBasicError(_) => 10501,
194            Self::IdentityAssetLockProofLockedTransactionMismatchError(_) => 10502,
195            Self::IdentityAssetLockTransactionIsNotFoundError(_) => 10503,
196            Self::IdentityAssetLockTransactionOutPointAlreadyConsumedError(_) => 10504,
197            Self::IdentityAssetLockTransactionOutputNotFoundError(_) => 10505,
198            Self::InvalidAssetLockProofCoreChainHeightError(_) => 10506,
199            Self::InvalidAssetLockProofTransactionHeightError(_) => 10507,
200            Self::InvalidAssetLockTransactionOutputReturnSizeError(_) => 10508,
201            Self::InvalidIdentityAssetLockTransactionError(_) => 10509,
202            Self::InvalidIdentityAssetLockTransactionOutputError(_) => 10510,
203            Self::InvalidIdentityPublicKeyDataError(_) => 10511,
204            Self::InvalidInstantAssetLockProofError(_) => 10512,
205            Self::InvalidInstantAssetLockProofSignatureError(_) => 10513,
206            Self::InvalidIdentityAssetLockProofChainLockValidationError(_) => 10514,
207            Self::DataContractBoundsNotPresentError(_) => 10515,
208            Self::DisablingKeyIdAlsoBeingAddedInSameTransitionError(_) => 10516,
209            Self::MissingMasterPublicKeyError(_) => 10517,
210            Self::TooManyMasterPublicKeyError(_) => 10518,
211            Self::InvalidIdentityPublicKeySecurityLevelError(_) => 10519,
212            Self::InvalidIdentityKeySignatureError { .. } => 10520,
213            Self::InvalidCreditWithdrawalTransitionOutputScriptError(_) => 10521,
214            Self::InvalidCreditWithdrawalTransitionCoreFeeError(_) => 10522,
215            Self::NotImplementedCreditWithdrawalTransitionPoolingError(_) => 10523,
216            Self::InvalidIdentityCreditTransferAmountError(_) => 10524,
217            Self::InvalidIdentityCreditWithdrawalTransitionAmountError(_) => 10525,
218            Self::InvalidIdentityUpdateTransitionEmptyError(_) => 10526,
219            Self::InvalidIdentityUpdateTransitionDisableKeysError(_) => 10527,
220            Self::IdentityCreditTransferToSelfError(_) => 10528,
221            Self::MasterPublicKeyUpdateError(_) => 10529,
222            Self::IdentityAssetLockTransactionOutPointNotEnoughBalanceError(_) => 10530,
223            Self::IdentityAssetLockStateTransitionReplayError(_) => 10531,
224            Self::WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError(_) => 10532,
225            Self::InvalidKeyPurposeForContractBoundsError(_) => 10533,
226            Self::IdentityAssetLockTransactionTooManyInputsError(_) => 10534,
227            Self::ContractGroupBoundKeyNotAllowedInShieldedIdentityCreationError(_) => 10535,
228            Self::IdentityPublicKeyLimitsNotAllowedError(_) => 10536,
229            Self::InvalidIdentityPublicKeyBudgetError(_) => 10537,
230            Self::IdentityPublicKeyLimitsNotAllowedInShieldedIdentityCreationError(_) => 10538,
231            Self::IdentityKeyLimitsUpdateEmptyError(_) => 10539,
232
233            // State Transition Errors: 10600-10699
234            Self::InvalidStateTransitionTypeError { .. } => 10600,
235            Self::MissingStateTransitionTypeError { .. } => 10601,
236            Self::StateTransitionMaxSizeExceededError { .. } => 10602,
237            Self::StateTransitionNotActiveError(_) => 10603,
238
239            // General Errors 10700-10799
240            Self::OverflowError(_) => 10700,
241
242            // Address Errors: 10800-10899
243            Self::TransitionOverMaxInputsError(_) => 10800,
244            Self::TransitionOverMaxOutputsError(_) => 10801,
245            Self::InputWitnessCountMismatchError(_) => 10802,
246            Self::TransitionNoInputsError(_) => 10803,
247            Self::TransitionNoOutputsError(_) => 10804,
248            Self::FeeStrategyEmptyError(_) => 10805,
249            Self::FeeStrategyDuplicateError(_) => 10806,
250            Self::FeeStrategyIndexOutOfBoundsError(_) => 10807,
251            Self::FeeStrategyTooManyStepsError(_) => 10808,
252            Self::InputBelowMinimumError(_) => 10809,
253            Self::OutputBelowMinimumError(_) => 10810,
254            Self::InputOutputBalanceMismatchError(_) => 10811,
255            Self::OutputsNotGreaterThanInputsError(_) => 10812,
256            Self::WithdrawalBalanceMismatchError(_) => 10813,
257            Self::InsufficientFundingAmountError(_) => 10814,
258            Self::InputsNotLessThanOutputsError(_) => 10815,
259            Self::OutputAddressAlsoInputError(_) => 10816,
260            Self::InvalidRemainderOutputCountError(_) => 10817,
261            Self::WithdrawalBelowMinAmountError(_) => 10818,
262            // Shielded transition errors (10819-10827)
263            Self::ShieldedNoActionsError(_) => 10819,
264            Self::ShieldedEmptyProofError(_) => 10820,
265            Self::ShieldedZeroAnchorError(_) => 10821,
266            Self::ShieldedInvalidValueBalanceError(_) => 10822,
267            Self::ShieldedEncryptedNoteSizeMismatchError(_) => 10823,
268            Self::ShieldedTooManyActionsError(_) => 10825,
269            Self::ShieldedImplicitFeeCapExceededError(_) => 10826,
270            Self::ShieldedInvalidDenominationError(_) => 10827,
271            Self::InvalidTokenDistributionEpochIntervalTooShortError(_) => 10828,
272            Self::InvalidTokenOncePerIdentityDistributionAmountError(_) => 10829,
273
274            // Contract Moderation Errors: 10900-10949
275            Self::InvalidContractModerationConfigError(_) => 10900,
276            Self::ContractModerationSelfTargetError(_) => 10901,
277            Self::DocumentActionFeesWithoutModerationError(_) => 10902,
278            Self::ContractModerationReasonTooLongError(_) => 10903,
279            Self::InvalidContractModerationReasonDocumentsError(_) => 10904,
280            Self::InvalidContractModerationDocumentFieldsError(_) => 10905,
281
282            // Moderation Team Errors: 11000-11099
283            Self::ModerationCharterMalformedFieldError(_) => 11000,
284            Self::ModerationCharterRewardSplitNotOneHundredError(_) => 11001,
285        }
286    }
287}
288
289impl ErrorWithCode for SignatureError {
290    fn code(&self) -> u32 {
291        match self {
292            Self::IdentityNotFoundError { .. } => 20000,
293            Self::InvalidIdentityPublicKeyTypeError { .. } => 20001,
294            Self::InvalidStateTransitionSignatureError { .. } => 20002,
295            Self::MissingPublicKeyError { .. } => 20003,
296            Self::InvalidSignaturePublicKeySecurityLevelError { .. } => 20004,
297            Self::WrongPublicKeyPurposeError { .. } => 20005,
298            Self::PublicKeyIsDisabledError { .. } => 20006,
299            Self::PublicKeySecurityLevelNotMetError { .. } => 20007,
300            Self::SignatureShouldNotBePresentError(_) => 20008,
301            Self::BasicECDSAError(_) => 20009,
302            Self::BasicBLSError(_) => 20010,
303            Self::InvalidSignaturePublicKeyPurposeError(_) => 20011,
304            Self::UncompressedPublicKeyNotAllowedError(_) => 20012,
305            Self::ContractBoundedKeyOutOfBoundsError(_) => 20014,
306            Self::ContractBoundedKeyNonBatchError(_) => 20013,
307            Self::PublicKeyBudgetExhaustedError(_) => 20015,
308            Self::PublicKeyExpiredError(_) => 20016,
309            Self::PublicKeyWithLimitsCannotUpdateKeyLimitsError(_) => 20017,
310        }
311    }
312}
313
314impl ErrorWithCode for FeeError {
315    fn code(&self) -> u32 {
316        match self {
317            Self::BalanceIsNotEnoughError { .. } => 30000,
318        }
319    }
320}
321
322impl ErrorWithCode for StateError {
323    fn code(&self) -> u32 {
324        match self {
325            // Data contract Errors: 40000-40099
326            Self::DataContractAlreadyPresentError { .. } => 40000,
327            Self::DataContractIsReadonlyError { .. } => 40001,
328            Self::DataContractConfigUpdateError { .. } => 40002,
329            Self::DataContractUpdatePermissionError(_) => 40003,
330            Self::DataContractUpdateActionNotAllowedError(_) => 40004,
331            Self::PreProgrammedDistributionTimestampInPastError(_) => 40005,
332            Self::IdentityInTokenConfigurationNotFoundError(_) => 40006,
333            Self::IdentityMemberOfGroupNotFoundError(_) => 40007,
334            Self::DataContractNotFoundError(_) => 40008,
335            Self::InvalidTokenPositionStateError(_) => 40009,
336
337            // Document Errors: 40100-40199
338            Self::DocumentAlreadyPresentError { .. } => 40100,
339            Self::DocumentNotFoundError { .. } => 40101,
340            Self::DocumentOwnerIdMismatchError { .. } => 40102,
341            Self::DocumentTimestampsMismatchError { .. } => 40103,
342            Self::DocumentTimestampWindowViolationError { .. } => 40104,
343            Self::DuplicateUniqueIndexError { .. } => 40105,
344            Self::InvalidDocumentRevisionError { .. } => 40106,
345            Self::DocumentTimestampsAreEqualError(_) => 40107,
346            Self::DocumentNotForSaleError(_) => 40108,
347            Self::DocumentIncorrectPurchasePriceError(_) => 40109,
348            Self::DocumentContestCurrentlyLockedError(_) => 40110,
349            Self::DocumentContestNotJoinableError(_) => 40111,
350            Self::DocumentContestIdentityAlreadyContestantError(_) => 40112,
351            Self::DocumentContestDocumentWithSameIdAlreadyPresentError(_) => 40113,
352            Self::DocumentContestNotPaidForError(_) => 40114,
353            Self::RequiredTokenPaymentInfoNotSetError(_) => 40115,
354            Self::IdentityHasNotAgreedToPayRequiredTokenAmountError(_) => 40116,
355            Self::IdentityTryingToPayWithWrongTokenError(_) => 40117,
356            Self::DocumentContestIndexMismatchError(_) => 40118,
357            Self::DocumentContestNotRequiredError(_) => 40119,
358            Self::ReferencedEntityNotFoundError(_) => 40120,
359            Self::ReferencedDocumentTypeNotFoundError(_) => 40121,
360            Self::ReferencedDocumentTypeDeletableError(_) => 40122,
361            Self::ReferencedIdentityKeyNotFoundError(_) => 40123,
362            Self::ReferencedIdentityKeyDisabledError(_) => 40124,
363            Self::ReferencedKeyIdPropertyInvalidError(_) => 40125,
364            Self::ReferencedDocumentPropertyAgreementInvalidError(_) => 40126,
365            Self::ReferencedDocumentPropertyMismatchError(_) => 40127,
366            Self::DocumentImmutablePropertyChangedError(_) => 40128,
367            Self::GasFeesPaidByNotAllowedError(_) => 40129,
368            Self::InconsistentGasFeesPaidByInBatchError(_) => 40130,
369            Self::ReferencedDocumentTypeNotDeletableError(_) => 40131,
370            Self::DocumentActionFeeAgreementNotSetError(_) => 40132,
371            Self::DocumentActionFeeAgreementMismatchError(_) => 40133,
372            Self::DocumentActionFeeMultiplierNotToleratedError(_) => 40134,
373            Self::ReferencedContractRequirementNotMetError(_) => 40135,
374            Self::ReferencedIdentityKeyRequirementNotMetError(_) => 40136,
375            Self::ReferencedDocumentLookupInvalidError(_) => 40137,
376            Self::ReferencedDocumentListInvalidError(_) => 40138,
377            Self::DocumentActionFeeModeratorsShareMismatchError(_) => 40139,
378            Self::DocumentExpiredError(_) => 40140,
379            Self::DocumentContestMaximumContendersReachedError(_) => 40141,
380            Self::ReferencedDocumentRequirementNotMetError(_) => 40142,
381            Self::ReferencedDocumentTypeNotModeratedError(_) => 40143,
382            Self::ReferencedDocumentTypeModeratedError(_) => 40144,
383            Self::ReferencedDocumentRemovedError(_) => 40145,
384            Self::ReferencedDocumentTypeIndexOnlyError(_) => 40146,
385            Self::DocumentDeleteConstraintViolatedError(_) => 40147,
386
387            // Identity Errors: 40200-40299
388            Self::IdentityAlreadyExistsError(_) => 40200,
389            Self::IdentityPublicKeyIsReadOnlyError { .. } => 40201,
390            Self::InvalidIdentityPublicKeyIdError { .. } => 40202,
391            Self::InvalidIdentityRevisionError { .. } => 40203,
392            Self::InvalidIdentityNonceError(_) => 40204,
393            Self::MaxIdentityPublicKeyLimitReachedError { .. } => 40205,
394            Self::DuplicatedIdentityPublicKeyStateError { .. } => 40206,
395            Self::DuplicatedIdentityPublicKeyIdStateError { .. } => 40207,
396            Self::IdentityPublicKeyIsDisabledError { .. } => 40208,
397            Self::MissingIdentityPublicKeyIdsError { .. } => 40209,
398            Self::IdentityInsufficientBalanceError(_) => 40210,
399            Self::IdentityPublicKeyAlreadyExistsForUniqueContractBoundsError(_) => 40211,
400            Self::DocumentTypeUpdateError(_) => 40212,
401            Self::MissingTransferKeyError(_) => 40214,
402            Self::NoTransferKeyForCoreWithdrawalAvailableError(_) => 40215,
403            Self::RecipientIdentityDoesNotExistError(_) => 40216,
404            Self::IdentityToFreezeDoesNotExistError(_) => 40217,
405            Self::IdentityPublicKeyBudgetExceededError(_) => 40218,
406            Self::IdentityPublicKeyAlreadyExpiredError(_) => 40219,
407            Self::IdentityPublicKeyLimitNotSetError(_) => 40220,
408            Self::IdentityPublicKeyLimitNotRaisedError(_) => 40221,
409            Self::GasSponsorInsufficientBalanceError(_) => 40222,
410
411            // Voting Errors: 40300-40399
412            Self::MasternodeNotFoundError(_) => 40300,
413            Self::VotePollNotFoundError(_) => 40301,
414            Self::VotePollNotAvailableForVotingError(_) => 40302,
415            Self::MasternodeVotedTooManyTimesError(_) => 40303,
416            Self::MasternodeVoteAlreadyPresentError(_) => 40304,
417            Self::MasternodeIncorrectVotingAddressError(_) => 40305,
418            Self::MasternodeIncorrectVoterIdentityIdError(_) => 40306,
419            Self::VoteChoiceNotAllowedForVotePollError(_) => 40307,
420
421            // Prefunded specialized balances Errors: 40400-40499
422            Self::PrefundedSpecializedBalanceInsufficientError(_) => 40400,
423            Self::PrefundedSpecializedBalanceNotFoundError(_) => 40401,
424
425            // Data trigger errors: 40500-40699
426            Self::DataTriggerError(ref e) => e.code(),
427
428            // Address errors
429            Self::AddressDoesNotExistError(_) => 40600,
430            Self::AddressNotEnoughFundsError(_) => 40601,
431            Self::AddressesNotEnoughFundsError(_) => 40602,
432            Self::AddressInvalidNonceError(_) => 40603,
433
434            // Token errors: 40700-40799
435            Self::IdentityDoesNotHaveEnoughTokenBalanceError(_) => 40700,
436            Self::UnauthorizedTokenActionError(_) => 40701,
437            Self::IdentityTokenAccountFrozenError(_) => 40702,
438            Self::IdentityTokenAccountNotFrozenError(_) => 40703,
439            Self::TokenSettingMaxSupplyToLessThanCurrentSupplyError(_) => 40704,
440            Self::TokenMintPastMaxSupplyError(_) => 40705,
441            Self::NewTokensDestinationIdentityDoesNotExistError(_) => 40706,
442            Self::NewAuthorizedActionTakerIdentityDoesNotExistError(_) => 40707,
443            Self::NewAuthorizedActionTakerGroupDoesNotExistError(_) => 40708,
444            Self::NewAuthorizedActionTakerMainGroupNotSetError(_) => 40709,
445            Self::InvalidGroupPositionError(_) => 40710,
446            Self::TokenIsPausedError(_) => 40711,
447            Self::IdentityTokenAccountAlreadyFrozenError(_) => 40712,
448            Self::TokenAlreadyPausedError(_) => 40713,
449            Self::TokenNotPausedError(_) => 40714,
450            Self::InvalidTokenClaimPropertyMismatch(_) => 40715,
451            Self::InvalidTokenClaimNoCurrentRewards(_) => 40716,
452            Self::InvalidTokenClaimWrongClaimant(_) => 40717,
453            Self::TokenTransferRecipientIdentityNotExistError(_) => 40718,
454            Self::TokenDirectPurchaseUserPriceTooLow(_) => 40719,
455            Self::TokenAmountUnderMinimumSaleAmount(_) => 40720,
456            Self::TokenNotForDirectSale(_) => 40721,
457            Self::TokenOncePerIdentityDistributionAlreadyClaimedError(_) => 40722,
458            Self::TokenShieldedPoolNotEnabledError(_) => 40723,
459            Self::TokenShieldedPaymentAmountMismatchError(_) => 40724,
460            Self::TokenShieldedPaymentNotRequiredError(_) => 40725,
461
462            // Group errors: 40800-40899
463            Self::IdentityNotMemberOfGroupError(_) => 40800,
464            Self::GroupActionDoesNotExistError(_) => 40801,
465            Self::GroupActionAlreadyCompletedError(_) => 40802,
466            Self::GroupActionAlreadySignedByIdentityError(_) => 40803,
467            Self::ModificationOfGroupActionMainParametersNotPermittedError(_) => 40804,
468
469            // Shielded errors: 40900-40999
470            Self::InvalidAnchorError(_) => 40900,
471            Self::NullifierAlreadySpentError(_) => 40901,
472            Self::InvalidShieldedProofError(_) => 40902,
473            Self::InsufficientPoolNotesError(_) => 40903,
474            Self::InsufficientShieldedFeeError(_) => 40904,
475
476            // Contract group errors: 41000-41099
477            Self::ContractGroupAlreadyExistsError(_) => 41000,
478            Self::ContractGroupNotFoundError(_) => 41001,
479            Self::IdentityNotContractGroupOwnerOrAdminError(_) => 41002,
480            Self::ContractGroupAdminNotFoundError(_) => 41003,
481
482            // Contract moderation errors: 41100-41199
483            Self::ContractModerationNotEnabledError(_) => 41100,
484            Self::IdentityNotContractModeratorError(_) => 41101,
485            Self::ContractModerationTargetNotAllowedError(_) => 41102,
486            Self::ContractUserAlreadyBannedError(_) => 41103,
487            Self::ContractUserNotBannedError(_) => 41104,
488            Self::ContractUserNotSuspendedError(_) => 41105,
489            Self::ContractSuspensionNotInFutureError(_) => 41106,
490            Self::ContractUserBannedError(_) => 41107,
491            Self::ContractUserSuspendedError(_) => 41108,
492            Self::ContractModerationTargetNotFoundError(_) => 41109,
493            Self::ContractModeratorIdentityNotFoundError(_) => 41110,
494            Self::ContractFeesAlreadyClaimedThisEpochError(_) => 41111,
495            Self::ContractFeesNothingToClaimError(_) => 41112,
496            Self::ContractFeeClaimNotAllowedError(_) => 41113,
497            Self::ContractModerationCounterpartyBarredError(_) => 41114,
498            Self::DocumentTypeNotDeletableByModeratorsError(_) => 41115,
499            Self::DocumentModerationWindowElapsedError(_) => 41116,
500            Self::ContractUserNotWarnedError(_) => 41117,
501            Self::ContractUserWarningLimitReachedError(_) => 41118,
502            Self::ContractDocumentRemovalNotFoundError(_) => 41119,
503            Self::DocumentRestoreWindowElapsedError(_) => 41120,
504            Self::DocumentRestoreHashMismatchError(_) => 41121,
505            Self::ContractDocumentAlreadyRestoredError(_) => 41122,
506            Self::DocumentFieldNotChangeableByModeratorsError(_) => 41123,
507            Self::DocumentModeratorFieldNotWritableError(_) => 41124,
508
509            // Contract moderation team errors: 41200-41299
510            Self::ContractModeratedDocumentTypeNotYetUsableError(_) => 41200,
511            Self::ContractModerationAbilityNotGrantedError(_) => 41201,
512            Self::ModerationCharterAddedModeratorLimitReachedError(_) => 41202,
513            Self::ModerationReasonNotListedError(_) => 41203,
514            Self::DocumentTypeNotDeletableOnceSettledError(_) => 41204,
515            Self::ContractModerationTeamNotSeatedError(_) => 41205,
516            Self::DocumentNotSettledError(_) => 41206,
517            Self::ContractTeamActionDoesNotExistError(_) => 41207,
518            Self::ContractTeamActionAlreadySignedError(_) => 41208,
519            Self::SettledDeletionNotRestorableError(_) => 41209,
520            Self::ContractTeamActionAlreadyCompletedError(_) => 41210,
521            Self::ContractTeamActionDocumentChangedError(_) => 41211,
522            Self::ContractTeamMemberAddedAfterDocumentError(_) => 41212,
523        }
524    }
525}
526
527impl ErrorWithCode for DataTriggerError {
528    fn code(&self) -> u32 {
529        match self {
530            Self::DataTriggerConditionError { .. } => 40500,
531            Self::DataTriggerExecutionError { .. } => 40501,
532            Self::DataTriggerInvalidResultError { .. } => 40502,
533        }
534    }
535}