sol-chainsaw 0.0.2

Deserializing Solana accounts using their progam IDL
Documentation
use thiserror::Error;

pub type ChainsawResult<T> = Result<T, ChainsawError>;

#[derive(Error, Debug)]
pub enum ChainsawError {
    #[error("Format Error")]
    FormatError(#[from] std::fmt::Error),
    #[error("Borsh IO Error")]
    BorshIoError(#[from] borsh::maybestd::io::Error),

    #[error("Borsh failed to deserialize type '{1}' ({0}")]
    BorshDeserializeTypeError(String, borsh::maybestd::io::Error, Vec<u8>),

    #[error("Borsh failed to deserialize type '{0}' ({1})")]
    CompositeDeserializeError(String, Box<ChainsawError>),

    #[error("Borsh failed to deserialize type for field '{0}' ({1})")]
    FieldDeserializeError(String, Box<ChainsawError>),

    #[error("Borsh failed to deserialize type for enum variant '{0}' ({1})")]
    EnumVariantDeserializeError(String, Box<ChainsawError>),

    #[error("Borsh failed to deserialize type for struct '{0}' ({1})")]
    StructDeserializeError(String, Box<ChainsawError>),

    #[error("Borsh failed to deserialize type for enum '{0}' ({1})")]
    EnumDeserializeError(String, Box<ChainsawError>),

    #[error("Account {0} is requested to be deserialized but was not defined in the IDL")]
    UnknownAccount(String),

    #[error("Account with discriminator {0} is requested to be deserialized but was not defined in the IDL")]
    UnknownDiscriminatedAccount(String),

    #[error("Type {0} is referenced but was not defined in the IDL")]
    CannotFindDefinedType(String),

    #[error("Variant with discriminant {0} does not exist")]
    InvalidEnumVariantDiscriminator(u8),

    #[error("Unable to parse JSON")]
    ParseJsonError(#[from] serde_json::Error),

    #[cfg(feature = "bson")]
    #[error("Raw Bson Error")]
    RawBsonError(#[from] bson::raw::Error),

    #[error("No IDL was added for the program {0}.")]
    CannotFindAccountDeserializerForProgramId(String),

    #[error("Unable to derive pubkey for the IDL to fetch")]
    IdlPubkeyError(#[from] solana_program::pubkey::PubkeyError),

    #[cfg(feature = "network")]
    #[error("Solana client issue")]
    IdlClientError(#[from] solana_client::client_error::ClientError),

    #[cfg(feature = "network")]
    #[error("Unable to fetch valid IDL data (got less than 8 bytes)")]
    AnchorIdlDataNeedsToBeAtLeast8Bytes,

    #[cfg(feature = "network")]
    #[error(
        "Unable to deserialize the IDL container account for address {0} at derived address {1} ({2})"
    )]
    IdlContainerAccountDeserializationError(String, String, String),

    #[cfg(feature = "network")]
    #[error("Unable to inflage IDl data ({0})")]
    IdlContainerShouldContainZlibData(String),

    #[cfg(feature = "network")]
    #[error("The account '{0}' was not found on chain")]
    AccountNotFound(String),
}