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 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, }
26 }
27}
28impl ErrorWithCode for BasicError {
29 fn code(&self) -> u32 {
30 match self {
31 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 Self::JsonSchemaCompilationError(..) => 10100,
42 Self::JsonSchemaError(_) => 10101,
43 Self::InvalidIdentifierError { .. } => 10102,
44 Self::ValueError(_) => 10103,
45
46 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
124 Self::GroupPositionDoesNotExistError(_) => 10350,
126 Self::GroupActionNotAllowedOnTransitionError(_) => 10351,
127 Self::GroupTotalPowerLessThanRequiredError(_) => 10352,
128 Self::GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError(_) => 10353,
129 Self::GroupExceedsMaxMembersError(_) => 10354,
130 Self::GroupMemberHasPowerOfZeroError(_) => 10355,
131 Self::GroupMemberHasPowerOverLimitError(_) => 10356,
132 Self::MainGroupIsNotDefinedError(_) => 10357,
133 Self::GroupRequiredPowerIsInvalidError(_) => 10358,
134 Self::GroupHasTooFewMembersError(_) => 10359,
135
136 Self::DataContractNotPresentError { .. } => 10400,
138 Self::DuplicateDocumentTransitionsWithIdsError { .. } => 10401,
139 Self::DuplicateDocumentTransitionsWithIndicesError { .. } => 10402,
140 Self::InconsistentCompoundIndexDataError { .. } => 10403,
141 Self::InvalidDocumentTransitionActionError { .. } => 10404,
142 Self::InvalidDocumentTransitionIdError { .. } => 10405,
143 Self::InvalidDocumentTypeError { .. } => 10406,
144 Self::MissingDataContractIdBasicError { .. } => 10407,
145 Self::MissingDocumentTransitionActionError { .. } => 10408,
146 Self::MissingDocumentTransitionTypeError { .. } => 10409,
147 Self::MissingDocumentTypeError { .. } => 10410,
148 Self::MissingPositionsInDocumentTypePropertiesError { .. } => 10411,
149 Self::MaxDocumentsTransitionsExceededError { .. } => 10412,
150 Self::DocumentTransitionsAreAbsentError { .. } => 10413,
151 Self::NonceOutOfBoundsError(_) => 10414,
152 Self::InvalidDocumentTypeNameError(_) => 10415,
153 Self::DocumentCreationNotAllowedError(_) => 10416,
154 Self::DocumentFieldMaxSizeExceededError(_) => 10417,
155 Self::ContestedDocumentsTemporarilyNotAllowedError(_) => 10418,
156
157 Self::InvalidTokenIdError(_) => 10450,
159 Self::InvalidTokenPositionError(_) => 10451,
160 Self::InvalidActionIdError(_) => 10452,
161 Self::ContractHasNoTokensError(_) => 10453,
162 Self::DestinationIdentityForTokenMintingNotSetError(_) => 10454,
163 Self::ChoosingTokenMintRecipientNotAllowedError(_) => 10455,
164 Self::TokenTransferToOurselfError(_) => 10456,
165 Self::InvalidTokenConfigUpdateNoChangeError(_) => 10457,
166 Self::InvalidTokenAmountError(_) => 10458,
167 Self::InvalidTokenNoteTooBigError(_) => 10459,
168 Self::TokenNoteOnlyAllowedWhenProposerError(_) => 10460,
169
170 Self::DuplicatedIdentityPublicKeyBasicError(_) => 10500,
172 Self::DuplicatedIdentityPublicKeyIdBasicError(_) => 10501,
173 Self::IdentityAssetLockProofLockedTransactionMismatchError(_) => 10502,
174 Self::IdentityAssetLockTransactionIsNotFoundError(_) => 10503,
175 Self::IdentityAssetLockTransactionOutPointAlreadyConsumedError(_) => 10504,
176 Self::IdentityAssetLockTransactionOutputNotFoundError(_) => 10505,
177 Self::InvalidAssetLockProofCoreChainHeightError(_) => 10506,
178 Self::InvalidAssetLockProofTransactionHeightError(_) => 10507,
179 Self::InvalidAssetLockTransactionOutputReturnSizeError(_) => 10508,
180 Self::InvalidIdentityAssetLockTransactionError(_) => 10509,
181 Self::InvalidIdentityAssetLockTransactionOutputError(_) => 10510,
182 Self::InvalidIdentityPublicKeyDataError(_) => 10511,
183 Self::InvalidInstantAssetLockProofError(_) => 10512,
184 Self::InvalidInstantAssetLockProofSignatureError(_) => 10513,
185 Self::InvalidIdentityAssetLockProofChainLockValidationError(_) => 10514,
186 Self::DataContractBoundsNotPresentError(_) => 10515,
187 Self::DisablingKeyIdAlsoBeingAddedInSameTransitionError(_) => 10516,
188 Self::MissingMasterPublicKeyError(_) => 10517,
189 Self::TooManyMasterPublicKeyError(_) => 10518,
190 Self::InvalidIdentityPublicKeySecurityLevelError(_) => 10519,
191 Self::InvalidIdentityKeySignatureError { .. } => 10520,
192 Self::InvalidCreditWithdrawalTransitionOutputScriptError(_) => 10521,
193 Self::InvalidCreditWithdrawalTransitionCoreFeeError(_) => 10522,
194 Self::NotImplementedCreditWithdrawalTransitionPoolingError(_) => 10523,
195 Self::InvalidIdentityCreditTransferAmountError(_) => 10524,
196 Self::InvalidIdentityCreditWithdrawalTransitionAmountError(_) => 10525,
197 Self::InvalidIdentityUpdateTransitionEmptyError(_) => 10526,
198 Self::InvalidIdentityUpdateTransitionDisableKeysError(_) => 10527,
199 Self::IdentityCreditTransferToSelfError(_) => 10528,
200 Self::MasterPublicKeyUpdateError(_) => 10529,
201 Self::IdentityAssetLockTransactionOutPointNotEnoughBalanceError(_) => 10530,
202 Self::IdentityAssetLockStateTransitionReplayError(_) => 10531,
203 Self::WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError(_) => 10532,
204 Self::InvalidKeyPurposeForContractBoundsError(_) => 10533,
205
206 Self::InvalidStateTransitionTypeError { .. } => 10600,
208 Self::MissingStateTransitionTypeError { .. } => 10601,
209 Self::StateTransitionMaxSizeExceededError { .. } => 10602,
210 Self::StateTransitionNotActiveError(_) => 10603,
211
212 Self::OverflowError(_) => 10700,
214
215 Self::TransitionOverMaxInputsError(_) => 10800,
217 Self::TransitionOverMaxOutputsError(_) => 10801,
218 Self::InputWitnessCountMismatchError(_) => 10802,
219 Self::TransitionNoInputsError(_) => 10803,
220 Self::TransitionNoOutputsError(_) => 10804,
221 Self::FeeStrategyEmptyError(_) => 10805,
222 Self::FeeStrategyDuplicateError(_) => 10806,
223 Self::FeeStrategyIndexOutOfBoundsError(_) => 10807,
224 Self::FeeStrategyTooManyStepsError(_) => 10808,
225 Self::InputBelowMinimumError(_) => 10809,
226 Self::OutputBelowMinimumError(_) => 10810,
227 Self::InputOutputBalanceMismatchError(_) => 10811,
228 Self::OutputsNotGreaterThanInputsError(_) => 10812,
229 Self::WithdrawalBalanceMismatchError(_) => 10813,
230 Self::InsufficientFundingAmountError(_) => 10814,
231 Self::InputsNotLessThanOutputsError(_) => 10815,
232 Self::OutputAddressAlsoInputError(_) => 10816,
233 Self::InvalidRemainderOutputCountError(_) => 10817,
234 Self::WithdrawalBelowMinAmountError(_) => 10818,
235 Self::ShieldedNoActionsError(_) => 10819,
237 Self::ShieldedEmptyProofError(_) => 10820,
238 Self::ShieldedZeroAnchorError(_) => 10821,
239 Self::ShieldedInvalidValueBalanceError(_) => 10822,
240 Self::ShieldedTooManyActionsError(_) => 10825,
241 }
242 }
243}
244
245impl ErrorWithCode for SignatureError {
246 fn code(&self) -> u32 {
247 match self {
248 Self::IdentityNotFoundError { .. } => 20000,
249 Self::InvalidIdentityPublicKeyTypeError { .. } => 20001,
250 Self::InvalidStateTransitionSignatureError { .. } => 20002,
251 Self::MissingPublicKeyError { .. } => 20003,
252 Self::InvalidSignaturePublicKeySecurityLevelError { .. } => 20004,
253 Self::WrongPublicKeyPurposeError { .. } => 20005,
254 Self::PublicKeyIsDisabledError { .. } => 20006,
255 Self::PublicKeySecurityLevelNotMetError { .. } => 20007,
256 Self::SignatureShouldNotBePresentError(_) => 20008,
257 Self::BasicECDSAError(_) => 20009,
258 Self::BasicBLSError(_) => 20010,
259 Self::InvalidSignaturePublicKeyPurposeError(_) => 20011,
260 Self::UncompressedPublicKeyNotAllowedError(_) => 20012,
261 }
262 }
263}
264
265impl ErrorWithCode for FeeError {
266 fn code(&self) -> u32 {
267 match self {
268 Self::BalanceIsNotEnoughError { .. } => 30000,
269 }
270 }
271}
272
273impl ErrorWithCode for StateError {
274 fn code(&self) -> u32 {
275 match self {
276 Self::DataContractAlreadyPresentError { .. } => 40000,
278 Self::DataContractIsReadonlyError { .. } => 40001,
279 Self::DataContractConfigUpdateError { .. } => 40002,
280 Self::DataContractUpdatePermissionError(_) => 40003,
281 Self::DataContractUpdateActionNotAllowedError(_) => 40004,
282 Self::PreProgrammedDistributionTimestampInPastError(_) => 40005,
283 Self::IdentityInTokenConfigurationNotFoundError(_) => 40006,
284 Self::IdentityMemberOfGroupNotFoundError(_) => 40007,
285 Self::DataContractNotFoundError(_) => 40008,
286 Self::InvalidTokenPositionStateError(_) => 40009,
287
288 Self::DocumentAlreadyPresentError { .. } => 40100,
290 Self::DocumentNotFoundError { .. } => 40101,
291 Self::DocumentOwnerIdMismatchError { .. } => 40102,
292 Self::DocumentTimestampsMismatchError { .. } => 40103,
293 Self::DocumentTimestampWindowViolationError { .. } => 40104,
294 Self::DuplicateUniqueIndexError { .. } => 40105,
295 Self::InvalidDocumentRevisionError { .. } => 40106,
296 Self::DocumentTimestampsAreEqualError(_) => 40107,
297 Self::DocumentNotForSaleError(_) => 40108,
298 Self::DocumentIncorrectPurchasePriceError(_) => 40109,
299 Self::DocumentContestCurrentlyLockedError(_) => 40110,
300 Self::DocumentContestNotJoinableError(_) => 40111,
301 Self::DocumentContestIdentityAlreadyContestantError(_) => 40112,
302 Self::DocumentContestDocumentWithSameIdAlreadyPresentError(_) => 40113,
303 Self::DocumentContestNotPaidForError(_) => 40114,
304 Self::RequiredTokenPaymentInfoNotSetError(_) => 40115,
305 Self::IdentityHasNotAgreedToPayRequiredTokenAmountError(_) => 40116,
306 Self::IdentityTryingToPayWithWrongTokenError(_) => 40117,
307
308 Self::IdentityAlreadyExistsError(_) => 40200,
310 Self::IdentityPublicKeyIsReadOnlyError { .. } => 40201,
311 Self::InvalidIdentityPublicKeyIdError { .. } => 40202,
312 Self::InvalidIdentityRevisionError { .. } => 40203,
313 Self::InvalidIdentityNonceError(_) => 40204,
314 Self::MaxIdentityPublicKeyLimitReachedError { .. } => 40205,
315 Self::DuplicatedIdentityPublicKeyStateError { .. } => 40206,
316 Self::DuplicatedIdentityPublicKeyIdStateError { .. } => 40207,
317 Self::IdentityPublicKeyIsDisabledError { .. } => 40208,
318 Self::MissingIdentityPublicKeyIdsError { .. } => 40209,
319 Self::IdentityInsufficientBalanceError(_) => 40210,
320 Self::IdentityPublicKeyAlreadyExistsForUniqueContractBoundsError(_) => 40211,
321 Self::DocumentTypeUpdateError(_) => 40212,
322 Self::MissingTransferKeyError(_) => 40214,
323 Self::NoTransferKeyForCoreWithdrawalAvailableError(_) => 40215,
324 Self::RecipientIdentityDoesNotExistError(_) => 40216,
325 Self::IdentityToFreezeDoesNotExistError(_) => 40217,
326
327 Self::MasternodeNotFoundError(_) => 40300,
329 Self::VotePollNotFoundError(_) => 40301,
330 Self::VotePollNotAvailableForVotingError(_) => 40302,
331 Self::MasternodeVotedTooManyTimesError(_) => 40303,
332 Self::MasternodeVoteAlreadyPresentError(_) => 40304,
333 Self::MasternodeIncorrectVotingAddressError(_) => 40305,
334 Self::MasternodeIncorrectVoterIdentityIdError(_) => 40306,
335
336 Self::PrefundedSpecializedBalanceInsufficientError(_) => 40400,
338 Self::PrefundedSpecializedBalanceNotFoundError(_) => 40401,
339
340 Self::DataTriggerError(ref e) => e.code(),
342
343 Self::AddressDoesNotExistError(_) => 40600,
345 Self::AddressNotEnoughFundsError(_) => 40601,
346 Self::AddressesNotEnoughFundsError(_) => 40602,
347 Self::AddressInvalidNonceError(_) => 40603,
348
349 Self::IdentityDoesNotHaveEnoughTokenBalanceError(_) => 40700,
351 Self::UnauthorizedTokenActionError(_) => 40701,
352 Self::IdentityTokenAccountFrozenError(_) => 40702,
353 Self::IdentityTokenAccountNotFrozenError(_) => 40703,
354 Self::TokenSettingMaxSupplyToLessThanCurrentSupplyError(_) => 40704,
355 Self::TokenMintPastMaxSupplyError(_) => 40705,
356 Self::NewTokensDestinationIdentityDoesNotExistError(_) => 40706,
357 Self::NewAuthorizedActionTakerIdentityDoesNotExistError(_) => 40707,
358 Self::NewAuthorizedActionTakerGroupDoesNotExistError(_) => 40708,
359 Self::NewAuthorizedActionTakerMainGroupNotSetError(_) => 40709,
360 Self::InvalidGroupPositionError(_) => 40710,
361 Self::TokenIsPausedError(_) => 40711,
362 Self::IdentityTokenAccountAlreadyFrozenError(_) => 40712,
363 Self::TokenAlreadyPausedError(_) => 40713,
364 Self::TokenNotPausedError(_) => 40714,
365 Self::InvalidTokenClaimPropertyMismatch(_) => 40715,
366 Self::InvalidTokenClaimNoCurrentRewards(_) => 40716,
367 Self::InvalidTokenClaimWrongClaimant(_) => 40717,
368 Self::TokenTransferRecipientIdentityNotExistError(_) => 40718,
369 Self::TokenDirectPurchaseUserPriceTooLow(_) => 40719,
370 Self::TokenAmountUnderMinimumSaleAmount(_) => 40720,
371 Self::TokenNotForDirectSale(_) => 40721,
372
373 Self::IdentityNotMemberOfGroupError(_) => 40800,
375 Self::GroupActionDoesNotExistError(_) => 40801,
376 Self::GroupActionAlreadyCompletedError(_) => 40802,
377 Self::GroupActionAlreadySignedByIdentityError(_) => 40803,
378 Self::ModificationOfGroupActionMainParametersNotPermittedError(_) => 40804,
379
380 Self::InvalidAnchorError(_) => 40900,
382 Self::NullifierAlreadySpentError(_) => 40901,
383 Self::InvalidShieldedProofError(_) => 40902,
384 Self::InsufficientPoolNotesError(_) => 40903,
385 Self::InsufficientShieldedFeeError(_) => 40904,
386 }
387 }
388}
389
390impl ErrorWithCode for DataTriggerError {
391 fn code(&self) -> u32 {
392 match self {
393 Self::DataTriggerConditionError { .. } => 40500,
394 Self::DataTriggerExecutionError { .. } => 40501,
395 Self::DataTriggerInvalidResultError { .. } => 40502,
396 }
397 }
398}