snarkos_errors/dpc/
dpc.rs

1// Copyright (C) 2019-2020 Aleo Systems Inc.
2// This file is part of the snarkOS library.
3
4// The snarkOS library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The snarkOS library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::{
18    algorithms::{
19        CRHError,
20        CommitmentError,
21        EncodingError,
22        EncryptionError,
23        MerkleError,
24        PRFError,
25        SNARKError,
26        SignatureError,
27    },
28    dpc::LedgerError,
29    objects::AccountError,
30    parameters::ParametersError,
31};
32
33#[derive(Debug, Error)]
34pub enum DPCError {
35    #[error("{}", _0)]
36    AccountError(AccountError),
37
38    #[error("{}", _0)]
39    CommitmentError(CommitmentError),
40
41    #[error("{}", _0)]
42    CRHError(CRHError),
43
44    #[error("{}: {}", _0, _1)]
45    Crate(&'static str, String),
46
47    #[error("{}", _0)]
48    EncodingError(EncodingError),
49
50    #[error("{}", _0)]
51    EncryptionError(EncryptionError),
52
53    #[error("{}", _0)]
54    LedgerError(LedgerError),
55
56    #[error("{}", _0)]
57    MerkleError(MerkleError),
58
59    #[error("{}", _0)]
60    Message(String),
61
62    #[error("missing inner snark proving parameters")]
63    MissingInnerSnarkProvingParameters,
64
65    #[error("missing outer snark proving parameters")]
66    MissingOuterSnarkProvingParameters,
67
68    #[error("{}", _0)]
69    ParametersError(ParametersError),
70
71    #[error("{}", _0)]
72    PRFError(PRFError),
73
74    #[error("{}", _0)]
75    SignatureError(SignatureError),
76
77    #[error("{}", _0)]
78    SNARKError(SNARKError),
79}
80
81impl From<AccountError> for DPCError {
82    fn from(error: AccountError) -> Self {
83        DPCError::AccountError(error)
84    }
85}
86
87impl From<CommitmentError> for DPCError {
88    fn from(error: CommitmentError) -> Self {
89        DPCError::CommitmentError(error)
90    }
91}
92
93impl From<CRHError> for DPCError {
94    fn from(error: CRHError) -> Self {
95        DPCError::CRHError(error)
96    }
97}
98
99impl From<EncodingError> for DPCError {
100    fn from(error: EncodingError) -> Self {
101        DPCError::EncodingError(error)
102    }
103}
104
105impl From<EncryptionError> for DPCError {
106    fn from(error: EncryptionError) -> Self {
107        DPCError::EncryptionError(error)
108    }
109}
110
111impl From<LedgerError> for DPCError {
112    fn from(error: LedgerError) -> Self {
113        DPCError::LedgerError(error)
114    }
115}
116
117impl From<MerkleError> for DPCError {
118    fn from(error: MerkleError) -> Self {
119        DPCError::MerkleError(error)
120    }
121}
122
123impl From<PRFError> for DPCError {
124    fn from(error: PRFError) -> Self {
125        DPCError::PRFError(error)
126    }
127}
128
129impl From<SignatureError> for DPCError {
130    fn from(error: SignatureError) -> Self {
131        DPCError::SignatureError(error)
132    }
133}
134
135impl From<ParametersError> for DPCError {
136    fn from(error: ParametersError) -> Self {
137        DPCError::ParametersError(error)
138    }
139}
140
141impl From<SNARKError> for DPCError {
142    fn from(error: SNARKError) -> Self {
143        DPCError::SNARKError(error)
144    }
145}
146
147impl From<std::io::Error> for DPCError {
148    fn from(error: std::io::Error) -> Self {
149        DPCError::Crate("std::io", format!("{:?}", error))
150    }
151}