ethers_middleware/transformer/
mod.rs

1pub mod ds_proxy;
2pub use ds_proxy::DsProxy;
3
4mod middleware;
5pub use middleware::TransformerMiddleware;
6
7use ethers_contract::AbiError;
8use ethers_core::{abi::ParseError, types::transaction::eip2718::TypedTransaction};
9use thiserror::Error;
10
11#[derive(Error, Debug)]
12/// Errors thrown from the types that implement the `Transformer` trait.
13pub enum TransformerError {
14    #[error("The field `{0}` is missing")]
15    MissingField(String),
16
17    #[error(transparent)]
18    AbiParseError(#[from] ParseError),
19
20    #[error(transparent)]
21    AbiError(#[from] AbiError),
22}
23
24/// `Transformer` is a trait to be implemented by a proxy wallet, eg. [`DsProxy`], that intends to
25/// intercept a transaction request and transform it into one that is instead sent via the proxy
26/// contract.
27pub trait Transformer: Send + Sync + std::fmt::Debug {
28    /// Transforms a [`transaction request`] into one that can be broadcasted and execute via the
29    /// proxy contract.
30    ///
31    /// [`transaction request`]: struct@ethers_core::types::TransactionRequest
32    fn transform(&self, tx: &mut TypedTransaction) -> Result<(), TransformerError>;
33}