1use alloc::string::{String, ToString};
10use core::fmt;
11
12#[derive(Debug, Clone, PartialEq)]
14pub enum Error {
15 InsufficientBalance,
17 Replay,
19 PhoenixOwnership,
21 PhoenixCircuit(String),
23 PhoenixProver(String),
25 InvalidData,
27 BadLength(usize, usize),
29 InvalidChar(char, usize),
31 Rkyv(String),
33 Blob(String),
35 MemoTooLarge(usize),
40}
41
42impl fmt::Display for Error {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 write!(f, "Dusk-Core Error: {:?}", &self)
45 }
46}
47
48impl From<phoenix_core::Error> for Error {
49 fn from(core_error: phoenix_core::Error) -> Self {
50 #[allow(clippy::match_same_arms)]
51 match core_error {
52 phoenix_core::Error::InvalidNoteType(_) => Self::InvalidData,
53 phoenix_core::Error::MissingViewKey => Self::PhoenixOwnership,
54 phoenix_core::Error::InvalidEncryption => Self::PhoenixOwnership,
55 phoenix_core::Error::InvalidData => Self::InvalidData,
56 phoenix_core::Error::BadLength(found, expected) => {
57 Self::BadLength(found, expected)
58 }
59 phoenix_core::Error::InvalidChar(ch, index) => {
60 Self::InvalidChar(ch, index)
61 }
62 }
63 }
64}
65
66impl From<dusk_bytes::Error> for Error {
67 fn from(bytes_error: dusk_bytes::Error) -> Self {
68 match bytes_error {
69 dusk_bytes::Error::InvalidData => Self::InvalidData,
70 dusk_bytes::Error::BadLength { found, expected } => {
71 Self::BadLength(found, expected)
72 }
73 dusk_bytes::Error::InvalidChar { ch, index } => {
74 Self::InvalidChar(ch, index)
75 }
76 }
77 }
78}
79
80#[derive(Debug, Clone, PartialEq)]
85pub enum TxPreconditionError {
86 DeployLowPrice(u64),
88 DeployLowLimit(u64),
90 BlobLowLimit(u64),
92 BlobEmpty,
94 BlobTooMany(usize),
96}
97
98impl TxPreconditionError {
99 #[must_use]
104 pub fn legacy_to_string(&self) -> String {
105 match self {
106 TxPreconditionError::DeployLowPrice(_) => {
107 "gas price too low to deploy"
108 }
109 TxPreconditionError::DeployLowLimit(_) => {
110 "not enough gas to deploy"
111 }
112 TxPreconditionError::BlobLowLimit(_) => "not enough gas for blobs",
113 TxPreconditionError::BlobEmpty => {
114 "no blob attached to the transaction"
115 }
116 TxPreconditionError::BlobTooMany(_) => {
117 "too many blobs in the transaction"
118 }
119 }
120 .to_string()
121 }
122}