Skip to content

Commit

Permalink
feat(filler): Add prepare_call method (#2011)
Browse files Browse the repository at this point in the history
* feat(filler): Add a new method to allow users customize transaction requests for eth_call

* feat(filler): Add a new method to FillProvider to prepare txRequest which might be useful

* feat(filler): Implement default method for wallet to set address
  • Loading branch information
neithanmo authored Feb 10, 2025
1 parent 59a3e8e commit c804d24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/provider/src/fillers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ pub trait TxFiller<N: Network = Ethereum>: Clone + Send + Sync + std::fmt::Debug
self.fill(fillable, tx).await
}
}

/// Prepares transaction request with necessary fillers required for eth_call operations
fn prepare_call(
&self,
tx: &mut N::TransactionRequest,
) -> impl_future!(<Output = TransportResult<()>>) {
let _ = tx;
// This is a no-op by default
futures::future::ready(Ok(()))
}
}

/// A [`Provider`] that applies one or more [`TxFiller`]s.
Expand Down Expand Up @@ -268,6 +278,15 @@ where
pub async fn fill(&self, tx: N::TransactionRequest) -> TransportResult<SendableTx<N>> {
self.fill_inner(SendableTx::Builder(tx)).await
}

/// Prepares a transaction request for eth_call operations using the configured fillers
pub async fn prepare_call(
&self,
mut tx: N::TransactionRequest,
) -> TransportResult<N::TransactionRequest> {
self.filler.prepare_call(&mut tx).await?;
Ok(tx)
}
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
Expand Down
7 changes: 7 additions & 0 deletions crates/provider/src/fillers/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ where

Ok(SendableTx::Envelope(envelope))
}

async fn prepare_call(&self, tx: &mut N::TransactionRequest) -> TransportResult<()> {
if tx.from().is_none() {
tx.set_from(self.wallet.default_signer_address());
}
Ok(())
}
}

#[cfg(feature = "reqwest")]
Expand Down

0 comments on commit c804d24

Please sign in to comment.