dpp/errors/consensus/basic/decode/
decoding_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 crate::data_contract::errors::DataContractError;
8use bincode::{Decode, Encode};
9
10#[derive(
11    Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
12)]
13#[error("Decoding error: {error}")]
14#[platform_serialize(unversioned)]
15pub struct DecodingError {
16    /*
17
18    DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION
19
20    */
21    error: String,
22}
23
24impl DecodingError {
25    pub fn new(error: String) -> Self {
26        Self { error }
27    }
28
29    pub fn error(&self) -> &str {
30        &self.error
31    }
32}
33
34impl From<DecodingError> for ConsensusError {
35    fn from(err: DecodingError) -> Self {
36        Self::BasicError(BasicError::ContractError(
37            DataContractError::DecodingContractError(err),
38        ))
39    }
40}
41
42impl From<DecodingError> for DataContractError {
43    fn from(err: DecodingError) -> Self {
44        Self::DecodingContractError(err)
45    }
46}