Skip to main content

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