solana_block_decoder/errors/
decode_error.rs

1use {
2    solana_pubkey::ParsePubkeyError,
3    solana_signature::ParseSignatureError,
4    solana_hash::ParseHashError,
5    std::{
6        error::Error,
7        fmt,
8    },
9};
10
11#[derive(Debug, PartialEq)]
12pub enum DecodeError {
13    InvalidEncoding,
14    InvalidAccountKey,
15    InvalidBlockhash,
16    DecodeFailed,
17    DeserializeFailed,
18    ParseSignatureFailed(ParseSignatureError),
19    ParseHashFailed(ParseHashError),
20    ParsePubkeyFailed(ParsePubkeyError),
21    NotImplemented,
22    InvalidData,
23    UnsupportedEncoding,
24    UnsupportedVersion,
25}
26
27impl fmt::Display for DecodeError {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            DecodeError::InvalidEncoding => write!(f, "Invalid encoding"),
31            DecodeError::DecodeFailed => write!(f, "Decoding failed"),
32            DecodeError::DeserializeFailed => write!(f, "Deserialization failed"),
33            DecodeError::InvalidAccountKey => write!(f, "Invalid account key"),
34            DecodeError::InvalidBlockhash => write!(f, "Invalid blockhash"),
35            DecodeError::ParseSignatureFailed(err) => write!(f, "Failed to parse signature: {}", err),
36            DecodeError::ParseHashFailed(err) => write!(f, "Failed to parse hash: {}", err),
37            DecodeError::ParsePubkeyFailed(err) => write!(f, "Failed to parse pubkey: {}", err),
38            DecodeError::NotImplemented => write!(f, "Not implemented"),
39            DecodeError::InvalidData => write!(f, "Invalid data"),
40            DecodeError::UnsupportedEncoding => write!(f, "Encoding is not supported"),
41            DecodeError::UnsupportedVersion => write!(f, "Transaction version is not supported"),
42        }
43    }
44}
45
46impl Error for DecodeError {}
47
48impl From<ParsePubkeyError> for DecodeError {
49    fn from(err: ParsePubkeyError) -> Self {
50        DecodeError::ParsePubkeyFailed(err)
51    }
52}