zcash_hsmbuilder/
errors.rs1use std::error;
2use std::fmt;
3
4#[derive(Debug, PartialEq)]
5pub enum Error {
6 AnchorMismatch,
7 BindingSig,
8 ChangeIsNegative,
9 InvalidAddress,
10 InvalidAddressFormat,
11 InvalidAddressHash,
12 InvalidAmount,
13 NoChangeAddress,
14 SpendProof,
15 SpendSig,
16 TranspararentSig,
17 Finalization,
18 MinShieldedOuputs,
19 BuilderNoKeys,
20 ReadWriteError,
21 InvalidOVKHashSeed,
22}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 match self {
27 Error::AnchorMismatch => {
28 write!(f, "Anchor mismatch (anchors for all spends must be equal)")
29 }
30 Error::BindingSig => write!(f, "Failed to create bindingSig"),
31 Error::ChangeIsNegative => write!(f, "Change is negative"),
32 Error::InvalidAddress => write!(f, "Invalid address"),
33 Error::InvalidAmount => write!(f, "Invalid amount"),
34 Error::NoChangeAddress => {
35 write!(f, "No change address specified or discoverable")
36 }
37 Error::SpendProof => {
38 write!(f, "Failed to create Sapling spend proof")
39 }
40 Error::SpendSig => {
41 write!(f, "Failed to get Sapling spend signature")
42 }
43 Error::InvalidAddressFormat => {
44 write!(f, "Incorrect format of address")
45 }
46 Error::InvalidAddressHash => write!(f, "Incorrect hash of address"),
47 Error::TranspararentSig => {
48 write!(f, "Failed to sign transparent inputs")
49 }
50 Error::Finalization => {
51 write!(f, "Failed to build complete transaction")
52 }
53 Error::MinShieldedOuputs => {
54 write!(f, "Not enough shielded outputs for transaction")
55 }
56 Error::BuilderNoKeys => {
57 write!(f, "Builder does not have any keys set")
58 }
59 Error::ReadWriteError => {
60 write!(f, "Error writing/reading bytes to/from vector")
61 }
62 Error::InvalidOVKHashSeed => {
63 write!(f, "Error: either OVK or hashseed should be some")
64 }
65 }
66 }
67}
68
69impl error::Error for Error {}
70
71impl From<std::io::Error> for Error {
72 fn from(e: std::io::Error) -> Error {
73 Error::ReadWriteError
74 }
75}