1use core::fmt;
2
3use alloy::transports::{RpcError, TransportErrorKind};
4use eth_trie::TrieError;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum EthTrieError {
9 #[error("Trie error: {0}")]
10 Trie(TrieError),
11 #[error("EIP error: {0}")]
12 Eip(alloy::eips::eip2718::Eip2718Error),
13 #[error("RLP error: {0}")]
14 Rlp(alloy_rlp::Error),
15 #[error("RPC error: {0}")]
16 RPC(RpcError<TransportErrorKind>),
17 #[error("Transaction not found")]
18 TxNotFound,
19 #[error("Block not found")]
20 BlockNotFound,
21 #[error("Invalid transaction version")]
22 InvalidTxVersion,
23 #[error("Error converting field: {0}")]
24 ConversionError(Field),
25 #[error("Unexpected root")]
26 UnexpectedRoot,
27 #[error("Invalid mpt proof")]
28 InvalidMPTProof,
29 #[error("Invalid transaction trie")]
30 TrieNotFound,
31 #[error("Field not found")]
32 FieldNotFound,
33}
34
35#[derive(Debug)]
36pub enum Field {
37 ChainId,
38 Nonce,
39 GasPrice,
40 GasLimit,
41 Input,
42 AccessList,
43 MaxFeePerGas,
44 MaxPriorityFeePerGas,
45 MaxFeePerBlobGas,
46 Signature,
47}
48
49impl fmt::Display for Field {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 match self {
52 Field::ChainId => write!(f, "chain_id"),
53 Field::Nonce => write!(f, "nonce"),
54 Field::GasPrice => write!(f, "gas_price"),
55 Field::GasLimit => write!(f, "gas_limit"),
56 Field::Input => write!(f, "input"),
57 Field::AccessList => write!(f, "access_list"),
58 Field::MaxFeePerGas => write!(f, "max_fee_per_gas"),
59 Field::MaxPriorityFeePerGas => write!(f, "max_priority_fee_per_gas"),
60 Field::MaxFeePerBlobGas => write!(f, "max_fee_per_blob_gas"),
61 Field::Signature => write!(f, "signature"),
62 }
63 }
64}
65
66impl From<TrieError> for EthTrieError {
67 fn from(err: TrieError) -> Self {
68 EthTrieError::Trie(err)
69 }
70}