snarkvm_errors/objects/
transaction.rs

1// Copyright (C) 2019-2021 Aleo Systems Inc.
2// This file is part of the snarkVM library.
3
4// The snarkVM 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 snarkVM 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 snarkVM library. If not, see <https://www.gnu.org/licenses/>.
16
17use std::fmt::Debug;
18
19#[derive(Debug, Error)]
20pub enum TransactionError {
21    #[error("UTXO has already been spent {:?} index: {:?}", _0, _1)]
22    AlreadySpent(Vec<u8>, u32),
23
24    #[error("there is a double spend occuring with this transaction {}", _0)]
25    DoubleSpend(String),
26
27    #[error("{}: {}", _0, _1)]
28    Crate(&'static str, String),
29
30    #[error("insufficient funds from input: {} to spend as output: {}", _0, _1)]
31    InsufficientFunds(u64, u64),
32
33    #[error("invalid coinbase transaction")]
34    InvalidCoinbaseTransaction,
35
36    #[error("invalid transaction id {:?}", _0)]
37    InvalidTransactionId(usize),
38
39    #[error("invalid variable size integer: {:?}", _0)]
40    InvalidVariableSizeInteger(usize),
41
42    #[error("{}", _0)]
43    Message(String),
44
45    #[error("missing outpoint script public key")]
46    MissingOutpointScriptPublicKey,
47
48    #[error("the block has multiple coinbase transactions: {:?}", _0)]
49    MultipleCoinbaseTransactions(u32),
50
51    #[error("Null Error {:?}", _0)]
52    NullError(()),
53}
54
55impl From<hex::FromHexError> for TransactionError {
56    fn from(error: hex::FromHexError) -> Self {
57        TransactionError::Crate("hex", format!("{:?}", error))
58    }
59}
60
61impl From<std::io::Error> for TransactionError {
62    fn from(error: std::io::Error) -> Self {
63        TransactionError::Crate("std::io", format!("{:?}", error))
64    }
65}
66
67impl From<std::num::ParseIntError> for TransactionError {
68    fn from(error: std::num::ParseIntError) -> Self {
69        TransactionError::Crate("std::num", format!("{:?}", error))
70    }
71}
72
73impl From<std::str::ParseBoolError> for TransactionError {
74    fn from(error: std::str::ParseBoolError) -> Self {
75        TransactionError::Crate("std::str", format!("{:?}", error))
76    }
77}
78
79impl From<()> for TransactionError {
80    fn from(_error: ()) -> Self {
81        TransactionError::NullError(())
82    }
83}
84
85impl From<&'static str> for TransactionError {
86    fn from(msg: &'static str) -> Self {
87        TransactionError::Message(msg.into())
88    }
89}