Skip to main content

signet_bundle/send/
error.rs

1#[cfg(doc)]
2use crate::SignetEthBundle;
3use alloy::eips::eip2718::Eip2718Error;
4use signet_types::{MarketError, SignedPermitError};
5use trevm::{
6    revm::{context::result::EVMError, Database},
7    BundleError,
8};
9
10/// Errors that can occur while recovering signatures from transactions in
11/// bundles.
12#[derive(Debug, thiserror::Error)]
13pub enum RecoverError {
14    /// Bundle is empty. Bundles must contain at least one RU transaction.
15    #[error("Bundle must contain at least one RU transaction")]
16    EmptyBundle,
17
18    /// Error occurred while decoding the transaction.
19    #[error(transparent)]
20    Decoding(#[from] Eip2718Error),
21
22    /// Error occurred while recovering the signature.
23    #[error(transparent)]
24    Recovering(#[from] alloy::consensus::crypto::RecoveryError),
25}
26
27/// Decoding error specifying the an error encountered while decoding
28/// transactions in a Signet bundle.
29#[derive(Debug, thiserror::Error)]
30#[error("Failed to decode transaction. Host: {host}, Index: {index}, Error: {inner}")]
31pub struct BundleRecoverError {
32    /// Error decoding a transaction.
33    #[source]
34    pub inner: RecoverError,
35    /// Whether the transaction was a host transaction.
36    pub host: bool,
37    /// Index of the transaction in the bundle.
38    pub index: usize,
39}
40
41impl BundleRecoverError {
42    /// Creates a new `BundleRecoverError`.
43    pub fn new(inner: impl Into<RecoverError>, host: bool, index: usize) -> Self {
44        Self { inner: inner.into(), host, index }
45    }
46}
47
48/// Errors while running a [`SignetEthBundle`] on the EVM.
49#[derive(thiserror::Error)]
50pub enum SignetEthBundleError<Db: Database> {
51    /// Bundle error.
52    #[error(transparent)]
53    Bundle(#[from] BundleError<Db>),
54
55    /// SignetPermit error.
56    #[error(transparent)]
57    SignetPermit(#[from] SignedPermitError),
58
59    /// Contract error.
60    #[error(transparent)]
61    Contract(#[from] alloy::contract::Error),
62
63    /// Market error.
64    #[error(transparent)]
65    Market(#[from] MarketError),
66
67    /// Host simulation error.
68    #[error("{0}")]
69    HostSimulation(&'static str),
70}
71
72impl<Db: Database> core::fmt::Debug for SignetEthBundleError<Db> {
73    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74        match self {
75            SignetEthBundleError::Bundle(inner) => {
76                f.debug_tuple("BundleError").field(inner).finish()
77            }
78            SignetEthBundleError::SignetPermit(inner) => {
79                f.debug_tuple("SignedPermitError").field(inner).finish()
80            }
81            SignetEthBundleError::Contract(inner) => {
82                f.debug_tuple("ContractError").field(inner).finish()
83            }
84            SignetEthBundleError::Market(inner) => {
85                f.debug_tuple("MarketError").field(inner).finish()
86            }
87            SignetEthBundleError::HostSimulation(msg) => {
88                f.debug_tuple("HostSimulationError").field(msg).finish()
89            }
90        }
91    }
92}
93
94impl<Db: Database> From<EVMError<Db::Error>> for SignetEthBundleError<Db> {
95    fn from(err: EVMError<Db::Error>) -> Self {
96        Self::Bundle(BundleError::from(err))
97    }
98}