hopr-types 1.8.0

Complete collection of Rust types used in Hoprnet and other related projects
Documentation
use crate::crypto::errors::CryptoError;
use crate::primitive::errors::GeneralError;
use multiaddr::Error as MultiaddrError;
use thiserror::Error;

/// Enumeration of all core type related errors.
#[derive(Error, Debug)]
pub enum CoreTypesError {
    #[error("{0}")]
    InvalidInputData(String),

    #[error("failed to parse/deserialize the data of {0}")]
    ParseError(String),

    #[error("arithmetic error: {0}")]
    ArithmeticError(String),

    #[error("invalid ticket signature or wrong ticket recipient")]
    InvalidTicketRecipient,

    #[error("packet acknowledgement could not be verified")]
    InvalidAcknowledgement,

    #[error("invalid winning probability value")]
    InvalidWinningProbability,

    #[error(
        "cannot acknowledge self-signed tickets. Ticket sender and recipient must be different"
    )]
    LoopbackTicket,

    #[error("ticket is not winning")]
    TicketNotWinning,

    #[error(transparent)]
    InvalidMultiaddr(#[from] MultiaddrError),

    #[error(transparent)]
    CryptoError(#[from] CryptoError),

    #[error(transparent)]
    GeneralError(#[from] GeneralError),
}

/// Path selection and construction errors.
#[derive(Error, Debug)]
pub enum PathError {
    #[error("path is not valid")]
    PathNotValid,

    #[error("path contains a missing peer id or address: {0}")]
    InvalidPeer(String),

    #[error("path contains a unknown peer that cannot be resolved: {0}")]
    UnknownPeer(String),

    #[error("missing channel between {0} and {1}")]
    MissingChannel(String, String),

    #[error("channel between {0} and {1} is not opened")]
    ChannelNotOpened(String, String),

    #[error("path contains loop on {0}")]
    LoopsNotAllowed(String),

    #[error("cannot find {0} hop path {1} -> {2} in the channel graph")]
    PathNotFound(usize, String, String),

    #[error(transparent)]
    OtherError(#[from] GeneralError),
}

/// Convenience type alias for `Result` with [`CoreTypesError`] as the error type.
pub type Result<T> = core::result::Result<T, CoreTypesError>;