Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: fix custom middleware example
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Feb 13, 2023
1 parent 208ef53 commit 4ab2e09
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions examples/middleware/examples/create_custom_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ethers::{
utils::{parse_units, Anvil},
},
middleware::MiddlewareBuilder,
providers::{FromErr, Http, Middleware, PendingTransaction, Provider},
providers::{Http, Middleware, MiddlewareError, PendingTransaction, Provider},
signers::{LocalWallet, Signer},
};
use thiserror::Error;
Expand Down Expand Up @@ -98,7 +98,7 @@ where
println!("Raised transaction gas: {raised_gas:?} wei");

// Dispatch the call to the inner layer
self.inner().send_transaction(tx, block).await.map_err(FromErr::from)
self.inner().send_transaction(tx, block).await.map_err(MiddlewareError::from_err)
}
}

Expand All @@ -122,10 +122,19 @@ pub enum GasMiddlewareError<M: Middleware> {
NoGasSetForTransaction,
}

impl<M: Middleware> FromErr<M::Error> for GasMiddlewareError<M> {
fn from(src: M::Error) -> Self {
impl<M: Middleware> MiddlewareError for GasMiddlewareError<M> {
type Inner = M::Error;

fn from_err(src: M::Error) -> Self {
GasMiddlewareError::MiddlewareError(src)
}

fn as_inner(&self) -> Option<&Self::Inner> {
match self {
GasMiddlewareError::MiddlewareError(e) => Some(e),
_ => None,
}
}
}

#[tokio::main]
Expand Down

0 comments on commit 4ab2e09

Please sign in to comment.