1use std::{io, sync::Arc};
4use thiserror::Error;
5use zcash_protocol::value::BalanceError;
6
7#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
11pub enum RandError {
12 #[error("failed to generate a secure stream of random bytes")]
14 FillBytes,
15}
16
17#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
19pub enum NoteError {
20 #[error("Randomness generation failure")]
22 InsufficientRandomness(#[from] RandError),
23 #[error("failed to generate an Orchard note's rho.")]
25 InvalidRho,
26}
27
28#[derive(Error, Copy, Clone, Debug, PartialEq, Eq)]
31pub enum AddressError {
32 #[error("Randomness generation failure")]
34 InsufficientRandomness(#[from] RandError),
35 #[error("Randomness did not hash into the Jubjub group for producing a new diversifier")]
37 DiversifierGenerationFailure,
38}
39
40#[derive(Clone, Error, Debug)]
42pub enum Error {
43 #[error("invalid consensus branch id")]
45 InvalidConsensusBranchId,
46
47 #[error(transparent)]
49 Io(#[from] Arc<io::Error>),
50
51 #[error("the transaction is missing a network upgrade")]
53 MissingNetworkUpgrade,
54
55 #[error(transparent)]
57 Amount(#[from] BalanceError),
58
59 #[error("Zakura's type could not be converted to its librustzcash equivalent: {0}")]
61 Conversion(String),
62}
63
64impl From<io::Error> for Error {
67 fn from(value: io::Error) -> Self {
68 Arc::new(value).into()
69 }
70}
71
72impl PartialEq for Error {
75 fn eq(&self, other: &Self) -> bool {
76 match self {
77 Error::InvalidConsensusBranchId => matches!(other, Error::InvalidConsensusBranchId),
78 Error::Io(e) => {
79 if let Error::Io(o) = other {
80 e.to_string() == o.to_string()
83 } else {
84 false
85 }
86 }
87 Error::MissingNetworkUpgrade => matches!(other, Error::MissingNetworkUpgrade),
88 Error::Amount(e) => matches!(other, Error::Amount(o) if e == o),
89 Error::Conversion(e) => matches!(other, Error::Conversion(o) if e == o),
90 }
91 }
92}
93
94impl Eq for Error {}