#[cfg(doc)]
use crate::SignetEthBundle;
use alloy::eips::eip2718::Eip2718Error;
use signet_types::{MarketError, SignedPermitError};
use trevm::{
revm::{context::result::EVMError, Database},
BundleError,
};
#[derive(Debug, thiserror::Error)]
pub enum RecoverError {
#[error("Bundle must contain at least one RU transaction")]
EmptyBundle,
#[error(transparent)]
Decoding(#[from] Eip2718Error),
#[error(transparent)]
Recovering(#[from] alloy::consensus::crypto::RecoveryError),
}
#[derive(Debug, thiserror::Error)]
#[error("Failed to decode transaction. Host: {host}, Index: {index}, Error: {inner}")]
pub struct BundleRecoverError {
#[source]
pub inner: RecoverError,
pub host: bool,
pub index: usize,
}
impl BundleRecoverError {
pub fn new(inner: impl Into<RecoverError>, host: bool, index: usize) -> Self {
Self { inner: inner.into(), host, index }
}
}
#[derive(thiserror::Error)]
pub enum SignetEthBundleError<Db: Database> {
#[error(transparent)]
Bundle(#[from] BundleError<Db>),
#[error(transparent)]
SignetPermit(#[from] SignedPermitError),
#[error(transparent)]
Contract(#[from] alloy::contract::Error),
#[error(transparent)]
Market(#[from] MarketError),
#[error("{0}")]
HostSimulation(&'static str),
}
impl<Db: Database> core::fmt::Debug for SignetEthBundleError<Db> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SignetEthBundleError::Bundle(inner) => {
f.debug_tuple("BundleError").field(inner).finish()
}
SignetEthBundleError::SignetPermit(inner) => {
f.debug_tuple("SignedPermitError").field(inner).finish()
}
SignetEthBundleError::Contract(inner) => {
f.debug_tuple("ContractError").field(inner).finish()
}
SignetEthBundleError::Market(inner) => {
f.debug_tuple("MarketError").field(inner).finish()
}
SignetEthBundleError::HostSimulation(msg) => {
f.debug_tuple("HostSimulationError").field(msg).finish()
}
}
}
}
impl<Db: Database> From<EVMError<Db::Error>> for SignetEthBundleError<Db> {
fn from(err: EVMError<Db::Error>) -> Self {
Self::Bundle(BundleError::from(err))
}
}