Skip to main content

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

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