-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathprotocol_error.rs
More file actions
357 lines (287 loc) · 10.7 KB
/
protocol_error.rs
File metadata and controls
357 lines (287 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
use thiserror::Error;
use crate::consensus::basic::state_transition::InvalidStateTransitionTypeError;
use crate::consensus::signature::{
InvalidSignaturePublicKeySecurityLevelError, PublicKeyIsDisabledError,
UncompressedPublicKeyNotAllowedError,
};
use crate::consensus::ConsensusError;
use crate::data_contract::errors::*;
use crate::document::errors::*;
#[cfg(any(
feature = "state-transition-validation",
feature = "state-transition-signing"
))]
use crate::state_transition::errors::InvalidIdentityPublicKeyTypeError;
#[cfg(all(feature = "state-transitions", feature = "validation"))]
use crate::state_transition::errors::StateTransitionError;
#[cfg(any(
all(feature = "state-transitions", feature = "validation"),
feature = "state-transition-validation",
feature = "state-transition-signing",
feature = "state-transition-validation"
))]
use crate::state_transition::errors::WrongPublicKeyPurposeError;
#[cfg(feature = "state-transition-validation")]
use crate::state_transition::errors::{
InvalidSignaturePublicKeyError, PublicKeyMismatchError, PublicKeySecurityLevelNotMetError,
StateTransitionIsNotSignedError,
};
use crate::{
CompatibleProtocolVersionIsNotDefinedError, DashPlatformProtocolInitError,
InvalidVectorSizeError, NonConsensusError, SerdeParsingError,
};
use dashcore::consensus::encode::Error as DashCoreError;
use crate::tokens::errors::TokenError;
use crate::version::FeatureVersion;
use platform_value::{Error as ValueError, Value};
use platform_version::error::PlatformVersionError;
#[allow(clippy::large_enum_variant)]
#[derive(Error, Debug)]
pub enum ProtocolError {
#[error("Identifier Error: {0}")]
IdentifierError(String),
#[error("String Decode Error {0}")]
StringDecodeError(String),
#[error("Public key data is not set")]
EmptyPublicKeyDataError,
#[error("Payload reached a {max_size_kbytes}KB limit")]
MaxEncodedBytesReachedError {
max_size_kbytes: usize,
size_hit: usize,
},
#[error("Encoding Error - {0}")]
EncodingError(String),
#[error("Decoding Error - {0}")]
DecodingError(String),
#[error("File not found Error - {0}")]
FileNotFound(String),
/// Platform expected some specific versions
#[error(
"dpp received not allowed version on {method}, allowed versions: {allowed_versions:?}, received: {received}"
)]
UnsupportedVersionMismatch {
/// method
method: String,
/// the allowed versions for this method
allowed_versions: Vec<FeatureVersion>,
/// requested core height
received: FeatureVersion,
},
/// Platform expected some specific versions
#[error(
"dpp unknown version on {method}, known versions: {known_versions:?}, received: {received}"
)]
UnknownVersionMismatch {
/// method
method: String,
/// the allowed versions for this method
known_versions: Vec<FeatureVersion>,
/// requested core height
received: FeatureVersion,
},
#[error("current platform version not initialized")]
CurrentProtocolVersionNotInitialized,
#[error("unknown version error {0}")]
UnknownVersionError(String),
#[error("unknown protocol version error {0}")]
UnknownProtocolVersionError(String),
#[error("Not included or invalid protocol version")]
NoProtocolVersionError,
#[error("Parsing error: {0}")]
ParsingError(String),
#[error(transparent)]
ParsingJsonError(#[from] serde_json::Error),
#[error(transparent)]
Error(#[from] anyhow::Error),
#[error("Invalid key contract bounds error {0}")]
InvalidKeyContractBoundsError(String),
#[error("unknown storage key requirements {0}")]
UnknownStorageKeyRequirements(String),
#[error("unknown contested index resolution {0}")]
UnknownContestedIndexResolution(String),
#[error(transparent)]
DataContractError(#[from] DataContractError),
#[cfg(all(feature = "state-transitions", feature = "validation"))]
#[error(transparent)]
StateTransitionError(#[from] StateTransitionError),
#[error("Invalid State Transition Type: {0}")]
InvalidStateTransitionType(String),
#[error(transparent)]
PlatformVersionError(#[from] PlatformVersionError),
#[error(transparent)]
ConsensusError(Box<ConsensusError>),
#[error(transparent)]
Document(Box<DocumentError>),
#[error(transparent)]
Token(Box<TokenError>),
#[error("Generic Error: {0}")]
Generic(String),
#[error("Address witness verification error: {0}")]
AddressWitnessError(String),
#[error("Shielded transaction build error: {0}")]
ShieldedBuildError(String),
#[error("Not supported Error: {0}")]
NotSupported(String),
#[cfg(feature = "message-signing")]
#[error("Invalid signing type error: {0}")]
InvalidSigningKeyTypeError(String),
// State Transition Errors
#[cfg(any(
feature = "state-transition-validation",
feature = "state-transition-signing"
))]
#[error(transparent)]
InvalidIdentityPublicKeyTypeError(InvalidIdentityPublicKeyTypeError),
#[cfg(feature = "state-transition-validation")]
#[error(transparent)]
StateTransitionIsNotSignedError(StateTransitionIsNotSignedError),
#[cfg(feature = "state-transition-validation")]
#[error(transparent)]
PublicKeySecurityLevelNotMetError(PublicKeySecurityLevelNotMetError),
#[cfg(any(
all(feature = "state-transitions", feature = "validation"),
feature = "state-transition-validation",
feature = "state-transition-signing",
feature = "state-transition-validation"
))]
#[error(transparent)]
WrongPublicKeyPurposeError(WrongPublicKeyPurposeError),
#[cfg(feature = "state-transition-validation")]
#[error(transparent)]
PublicKeyMismatchError(PublicKeyMismatchError),
#[cfg(feature = "state-transition-validation")]
#[error(transparent)]
InvalidSignaturePublicKeyError(InvalidSignaturePublicKeyError),
#[error(transparent)]
NonConsensusError(#[from] NonConsensusError),
#[error(transparent)]
CompatibleProtocolVersionIsNotDefinedError(#[from] CompatibleProtocolVersionIsNotDefinedError),
#[error(transparent)]
InvalidDocumentTypeError(InvalidDocumentTypeError),
#[error(transparent)]
DataContractNotPresentError(DataContractNotPresentError),
#[error(transparent)]
InvalidSignaturePublicKeySecurityLevelError(InvalidSignaturePublicKeySecurityLevelError),
#[error(transparent)]
InvalidStateTransitionTypeError(InvalidStateTransitionTypeError),
#[error(transparent)]
PublicKeyIsDisabledError(PublicKeyIsDisabledError),
#[error(transparent)]
UncompressedPublicKeyNotAllowedError(UncompressedPublicKeyNotAllowedError),
#[error(transparent)]
IdentityNotPresentError(IdentityNotPresentError),
/// Error
#[error("overflow error: {0}")]
Overflow(&'static str),
#[error("divide by zero error: {0}")]
DivideByZero(&'static str),
/// Error
#[error("missing key: {0}")]
DesiredKeyWithTypePurposeSecurityLevelMissing(String),
/// Value error
#[error("value error: {0}")]
ValueError(#[from] ValueError),
/// Value error
#[error("platform serialization error: {0}")]
PlatformSerializationError(String),
/// Value error
#[error("platform deserialization error: {0}")]
PlatformDeserializationError(String),
/// Dash core error
#[error("dash core error: {0}")]
DashCoreError(#[from] DashCoreError),
#[error("Invalid Identity: {errors:?}")]
InvalidIdentityError {
errors: Vec<ConsensusError>,
raw_identity: Value,
},
#[error("votes error {0}")]
VoteError(String),
#[error("Public key generation error {0}")]
PublicKeyGenerationError(String),
#[error("group member not found in contract: {0}")]
GroupMemberNotFound(String),
#[error("group not found in contract: {0}")]
GroupNotFound(String),
#[error("corrupted code execution: {0}")]
CorruptedCodeExecution(String),
#[error("corrupted serialization: {0}")]
CorruptedSerialization(String),
#[error("critical corrupted credits code execution: {0}")]
CriticalCorruptedCreditsCodeExecution(String),
#[error(transparent)]
InvalidVectorSizeError(InvalidVectorSizeError),
/// Invalid CBOR error
#[error("invalid cbor error: {0}")]
InvalidCBOR(String),
/// BLS signature error
#[cfg(feature = "bls-signatures")]
#[error(transparent)]
BlsError(#[from] dashcore::blsful::BlsError),
#[error("Private key wrong size: expected 32, got {got}")]
PrivateKeySizeError { got: u32 },
#[error("Private key invalid error: {0}")]
InvalidBLSPrivateKeyError(String),
#[error("Signature wrong size: expected 96, got {got}")]
BlsSignatureSizeError { got: u32 },
/// Error when trying to add two different types of `RewardDistributionMoment`.
#[error("Attempted to add incompatible types of RewardDistributionMoment: {0}")]
AddingDifferentTypes(String),
#[error("invalid distribution step error: {0}")]
InvalidDistributionStep(&'static str),
#[error("missing epoch info: {0}")]
MissingEpochInfo(String),
#[error("Invalid BatchedTransitionAction variant: expected {expected}, found {found}")]
InvalidBatchedTransitionActionVariant {
expected: &'static str,
found: &'static str,
},
#[error(
"Invalid verification wrong number of elements: needed {needed}, using {using}, {msg}"
)]
InvalidVerificationWrongNumberOfElements {
needed: u16,
using: u16,
msg: &'static str,
},
}
impl From<&str> for ProtocolError {
fn from(v: &str) -> ProtocolError {
ProtocolError::Generic(String::from(v))
}
}
impl From<String> for ProtocolError {
fn from(v: String) -> ProtocolError {
Self::from(v.as_str())
}
}
impl From<ConsensusError> for ProtocolError {
fn from(e: ConsensusError) -> Self {
ProtocolError::ConsensusError(Box::new(e))
}
}
impl From<DocumentError> for ProtocolError {
fn from(e: DocumentError) -> Self {
ProtocolError::Document(Box::new(e))
}
}
impl From<TokenError> for ProtocolError {
fn from(e: TokenError) -> Self {
ProtocolError::Token(Box::new(e))
}
}
impl From<SerdeParsingError> for ProtocolError {
fn from(e: SerdeParsingError) -> Self {
ProtocolError::ParsingError(e.to_string())
}
}
impl From<DashPlatformProtocolInitError> for ProtocolError {
fn from(e: DashPlatformProtocolInitError) -> Self {
ProtocolError::Generic(e.to_string())
}
}
impl From<InvalidVectorSizeError> for ProtocolError {
fn from(err: InvalidVectorSizeError) -> Self {
Self::InvalidVectorSizeError(err)
}
}