dpp/errors/consensus/basic/decode/
version_error.rs

1use crate::consensus::basic::BasicError;
2use crate::errors::ProtocolError;
3use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
4use thiserror::Error;
5
6use crate::consensus::ConsensusError;
7use bincode::{Decode, Encode};
8
9#[derive(
10    Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
11)]
12#[error("Can't read protocol version from serialized object: {error}")]
13#[platform_serialize(unversioned)]
14pub struct VersionError {
15    /*
16
17    DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION
18
19    */
20    error: String,
21}
22
23impl VersionError {
24    pub fn new(error: String) -> Self {
25        Self { error }
26    }
27
28    pub fn error(&self) -> &str {
29        &self.error
30    }
31}
32
33impl From<VersionError> for ConsensusError {
34    fn from(err: VersionError) -> Self {
35        Self::BasicError(BasicError::VersionError(err))
36    }
37}
38
39impl From<VersionError> for u32 {
40    fn from(_val: VersionError) -> Self {
41        0
42    }
43}
44
45impl From<&str> for VersionError {
46    fn from(value: &str) -> Self {
47        VersionError::new(value.to_string())
48    }
49}
50
51impl From<String> for VersionError {
52    fn from(value: String) -> Self {
53        VersionError::new(value)
54    }
55}