1//! Errors that can occur inside any `zebra-chain` submodule.
23use std::io;
4use thiserror::Error;
56// TODO: Move all these enums into a common enum at the bottom.
78/// Errors related to random bytes generation.
9#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
10pub enum RandError {
11/// Error of the `try_fill_bytes` function.
12#[error("failed to generate a secure stream of random bytes")]
13FillBytes,
14}
1516/// An error type pertaining to shielded notes.
17#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
18pub enum NoteError {
19/// Errors of type `RandError`.
20#[error("Randomness generation failure")]
21InsufficientRandomness(#[from] RandError),
22/// Error of `pallas::Point::from_bytes()` for new rho randomness.
23#[error("failed to generate an Orchard note's rho.")]
24InvalidRho,
25}
2627/// An error type pertaining to note commitments.
28#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
29pub enum NoteCommitmentError {
30/// Errors of type `RandError`.
31#[error("Randomness generation failure")]
32InsufficientRandomness(#[from] RandError),
33/// Error of `jubjub::AffinePoint::try_from`.
34#[error("failed to generate a sapling::NoteCommitment from a diversifier")]
35InvalidDiversifier,
36}
3738/// An error type pertaining to key generation, parsing, modification,
39/// randomization.
40#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
41pub enum KeyError {
42/// Errors of type `RandError`.
43#[error("Randomness generation failure")]
44InsufficientRandomness(#[from] RandError),
45}
4647/// An error type pertaining to payment address generation, parsing,
48/// modification, diversification.
49#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
50pub enum AddressError {
51/// Errors of type `RandError`.
52#[error("Randomness generation failure")]
53InsufficientRandomness(#[from] RandError),
54/// Errors pertaining to diversifier generation.
55#[error("Randomness did not hash into the Jubjub group for producing a new diversifier")]
56DiversifierGenerationFailure,
57}
5859/// `zebra-chain`'s errors
60#[derive(Error, Debug)]
61pub enum Error {
62/// Invalid consensus branch ID.
63#[error("invalid consensus branch id")]
64InvalidConsensusBranchId,
6566/// Zebra's type could not be converted to its librustzcash equivalent.
67#[error("Zebra's type could not be converted to its librustzcash equivalent: ")]
68Conversion(#[from] io::Error),
6970/// The transaction is missing a network upgrade.
71#[error("the transaction is missing a network upgrade")]
72MissingNetworkUpgrade,
73}