eth_valkyoth_protocol/transaction/dynamic_fee/
error.rs1use core::fmt;
2
3use eth_valkyoth_codec::{DecodeError, DecodeErrorCategory};
4
5use super::DynamicFeeTransactionField;
6use crate::transaction::{TransactionEnvelopeError, TransactionEnvelopeErrorCategory};
7
8#[non_exhaustive]
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub enum DynamicFeeTransactionDecodeError {
12 Envelope(TransactionEnvelopeError),
14 WrongTransactionType {
16 type_byte: u8,
18 },
19 WrongFieldCount {
21 expected: usize,
23 found: usize,
25 },
26 FieldDecode {
28 field: DynamicFeeTransactionField,
30 source: DecodeError,
32 },
33 InvalidToLength {
35 found: usize,
37 },
38 InvalidYParity {
40 value: u64,
42 },
43 InvalidAccessListEntryFieldCount {
45 found: usize,
47 },
48 InvalidAccessListAddressLength {
50 found: usize,
52 },
53 InvalidStorageKeyLength {
55 found: usize,
57 },
58}
59
60impl DynamicFeeTransactionDecodeError {
61 #[must_use]
63 pub const fn code(self) -> &'static str {
64 match self {
65 Self::Envelope(error) => error.code(),
66 Self::WrongTransactionType { .. } => "ETH_DYNAMIC_FEE_TX_WRONG_TYPE",
67 Self::WrongFieldCount { .. } => "ETH_DYNAMIC_FEE_TX_WRONG_FIELD_COUNT",
68 Self::FieldDecode { source, .. } => source.code(),
69 Self::InvalidToLength { .. } => "ETH_DYNAMIC_FEE_TX_INVALID_TO_LENGTH",
70 Self::InvalidYParity { .. } => "ETH_DYNAMIC_FEE_TX_INVALID_Y_PARITY",
71 Self::InvalidAccessListEntryFieldCount { .. } => {
72 "ETH_DYNAMIC_FEE_TX_INVALID_ENTRY_FIELD_COUNT"
73 }
74 Self::InvalidAccessListAddressLength { .. } => {
75 "ETH_DYNAMIC_FEE_TX_INVALID_ADDRESS_LENGTH"
76 }
77 Self::InvalidStorageKeyLength { .. } => "ETH_DYNAMIC_FEE_TX_INVALID_STORAGE_KEY_LENGTH",
78 }
79 }
80
81 #[must_use]
83 pub const fn message(self) -> &'static str {
84 match self {
85 Self::Envelope(error) => error.message(),
86 Self::WrongTransactionType { .. } => {
87 "dynamic-fee transaction decoder received a different envelope type"
88 }
89 Self::WrongFieldCount { .. } => {
90 "dynamic-fee transaction must contain exactly twelve RLP fields"
91 }
92 Self::FieldDecode { .. } => "dynamic-fee transaction field failed bounded decoding",
93 Self::InvalidToLength { .. } => {
94 "dynamic-fee transaction to field must be empty or a 20-byte address"
95 }
96 Self::InvalidYParity { .. } => "dynamic-fee transaction y parity must be 0 or 1",
97 Self::InvalidAccessListEntryFieldCount { .. } => {
98 "dynamic-fee access-list entry must contain exactly address and storage-key list"
99 }
100 Self::InvalidAccessListAddressLength { .. } => {
101 "dynamic-fee access-list address must be a 20-byte scalar"
102 }
103 Self::InvalidStorageKeyLength { .. } => {
104 "dynamic-fee access-list storage key must be a 32-byte scalar"
105 }
106 }
107 }
108
109 #[must_use]
111 pub const fn category(self) -> DynamicFeeTransactionDecodeErrorCategory {
112 match self {
113 Self::Envelope(error) => match error.category() {
114 TransactionEnvelopeErrorCategory::ResourceExhaustion => {
115 DynamicFeeTransactionDecodeErrorCategory::ResourceExhaustion
116 }
117 TransactionEnvelopeErrorCategory::Unsupported => {
118 DynamicFeeTransactionDecodeErrorCategory::WrongType
119 }
120 _ => DynamicFeeTransactionDecodeErrorCategory::MalformedInput,
121 },
122 Self::WrongTransactionType { .. } => {
123 DynamicFeeTransactionDecodeErrorCategory::WrongType
124 }
125 Self::FieldDecode { source, .. } => match source.category() {
126 DecodeErrorCategory::ResourceExhaustion => {
127 DynamicFeeTransactionDecodeErrorCategory::ResourceExhaustion
128 }
129 _ => DynamicFeeTransactionDecodeErrorCategory::MalformedInput,
130 },
131 Self::WrongFieldCount { .. }
132 | Self::InvalidToLength { .. }
133 | Self::InvalidYParity { .. }
134 | Self::InvalidAccessListEntryFieldCount { .. }
135 | Self::InvalidAccessListAddressLength { .. }
136 | Self::InvalidStorageKeyLength { .. } => {
137 DynamicFeeTransactionDecodeErrorCategory::MalformedInput
138 }
139 }
140 }
141}
142
143impl fmt::Display for DynamicFeeTransactionDecodeError {
144 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
145 formatter.write_str(self.message())
146 }
147}
148
149#[cfg(feature = "std")]
150impl std::error::Error for DynamicFeeTransactionDecodeError {}
151
152#[non_exhaustive]
154#[derive(Clone, Copy, Debug, Eq, PartialEq)]
155pub enum DynamicFeeTransactionDecodeErrorCategory {
156 MalformedInput,
158 WrongType,
160 ResourceExhaustion,
162}