snarkos_errors/network/
send.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    consensus::ConsensusError,
19    network::{message::MessageError, ConnectError},
20    objects::BlockError,
21};
22
23#[derive(Debug, Error)]
24pub enum SendError {
25    #[error("{}: {}", _0, _1)]
26    Crate(&'static str, String),
27
28    #[error("{}", _0)]
29    ConnectError(ConnectError),
30
31    #[error("{}", _0)]
32    ConsensusError(ConsensusError),
33
34    #[error("{}", _0)]
35    Message(String),
36
37    #[error("{}", _0)]
38    MessageError(MessageError),
39
40    #[error("{}", _0)]
41    BlockError(BlockError),
42}
43
44impl From<BlockError> for SendError {
45    fn from(error: BlockError) -> Self {
46        SendError::BlockError(error)
47    }
48}
49
50impl From<ConnectError> for SendError {
51    fn from(error: ConnectError) -> Self {
52        SendError::ConnectError(error)
53    }
54}
55
56impl From<ConsensusError> for SendError {
57    fn from(error: ConsensusError) -> Self {
58        SendError::ConsensusError(error)
59    }
60}
61
62impl From<MessageError> for SendError {
63    fn from(error: MessageError) -> Self {
64        SendError::MessageError(error)
65    }
66}