pub struct CallBuilder<T, S, E> {
pub tx: T,
/* private fields */
}
Expand description
Represents a prepared EVM contract call, ready for configuration and execution.
Instances are created via Contract::call_builder. The primary interaction
involves configuring the transaction parameters via the public CallBuilder::tx field,
followed by invoking an execution method like .call()
.
See the documentation on the Contract struct for a detailed explanation of the configuration workflow and examples.
Fields§
§tx: T
The transaction environment (EvmFactory::Tx
) containing call parameters.
Configuration: This field holds the transaction details (caller, value, gas, etc.). It must be configured directly by modifying its members before calling an execution method.
Example: builder.tx.caller = MY_ADDRESS; builder.tx.gas_limit = 100_000;
Implementations§
Source§impl<S, F, N, P, C> CallBuilder<F::Tx, S, &mut EvmEnv<ProofDb<ProviderDb<N, P>>, F, HostCommit<C>>>
impl<S, F, N, P, C> CallBuilder<F::Tx, S, &mut EvmEnv<ProofDb<ProviderDb<N, P>>, F, HostCommit<C>>>
Sourcepub async fn prefetch_access_list(self, access_list: AccessList) -> Result<Self>
Available on crate feature host
only.
pub async fn prefetch_access_list(self, access_list: AccessList) -> Result<Self>
host
only.Prefetches state for a given EIP-2930 AccessList
on the host.
Fetches EIP-1186 storage proofs for the items
in the access_list
. This can reduce the number of individual RPC calls
(eth_getStorageAt
) needed during subsequent execution simulation if the
accessed slots are known beforehand.
This method only fetches data; it does not set the access list field on the transaction itself (EIP-2930).
§Usage
Useful when an access list is already available. For automatic generation
and prefetching, see CallBuilder::call_with_prefetch
.
§Example
let mut contract = Contract::preflight(contract_address, &mut env);
let builder = contract.call_builder(&call).prefetch_access_list(access_list).await?;
let result = builder.call().await?;
Sourcepub async fn call(self) -> Result<S::Return>
Available on crate feature host
only.
pub async fn call(self) -> Result<S::Return>
host
only.Executes the configured call during host preflight.
This simulates the transaction execution using revm
within a blocking thread
(via [tokio::task::spawn_blocking
]) to avoid blocking the async runtime.
It uses the state fetched (and potentially prefetched) into the ProviderDb
.
Returns the decoded return value of the call or an error if execution fails.
Source§impl<S, P, C> CallBuilder<<EthEvmFactory as EvmFactory>::Tx, S, &mut EvmEnv<ProofDb<ProviderDb<Ethereum, P>>, EthEvmFactory, HostCommit<C>>>
impl<S, P, C> CallBuilder<<EthEvmFactory as EvmFactory>::Tx, S, &mut EvmEnv<ProofDb<ProviderDb<Ethereum, P>>, EthEvmFactory, HostCommit<C>>>
Sourcepub async fn call_with_prefetch(self) -> Result<S::Return>
Available on crate feature host
only.
pub async fn call_with_prefetch(self) -> Result<S::Return>
host
only.Automatically creates and prefetches an EIP-2930 access list, then executes the call.
This method aims to optimize host preflight time for calls involving numerous
storage reads (SLOAD
). It performs the following steps:
- Calls
eth_createAccessList
RPC to determine the storage slots and accounts the transaction is likely to access. - Calls CallBuilder::prefetch_access_list with the generated list to fetch the required state efficiently (often in a single batch RPC).
- Executes the call simulation using CallBuilder::call.
§Trade-offs
- Node Compatibility: Relies on the
eth_createAccessList
RPC, which might not be available or fully supported on all Ethereum node software or chains. - Gas Estimation Issues: Some node implementations might perform gas checks or
require sufficient balance in the
from
account foreth_createAccessList
, even for view calls. Setting a relevantfrom
address might be necessary.
§Example
let mut contract = Contract::preflight(contract_address, &mut env);
// Automatically generates access list, fetches state, and executes
let result = contract.call_builder(&call).call_with_prefetch().await?;
Source§impl<S, F> CallBuilder<F::Tx, S, &EvmEnv<StateDb, F, Commitment>>where
S: SolCall,
F: EvmFactory,
impl<S, F> CallBuilder<F::Tx, S, &EvmEnv<StateDb, F, Commitment>>where
S: SolCall,
F: EvmFactory,
Sourcepub fn try_call(self) -> Result<S::Return, String>
pub fn try_call(self) -> Result<S::Return, String>
Executes the call within the guest environment, returning a Result
.
Use this if you need to handle potential EVM execution errors explicitly
(e.g., reverts, halts) within the guest. The error type is String
for simplicity
in the guest context.
For straightforward calls where failure should halt guest execution, prefer CallBuilder::call.
Sourcepub fn call(self) -> S::Return
pub fn call(self) -> S::Return
Executes the call within the guest environment, panicking on failure.
This is a convenience wrapper around CallBuilder::try_call. It unwraps the result, causing the guest to panic if the EVM call reverts, halts, or encounters an error. Use this when a successful call is expected.
Trait Implementations§
Auto Trait Implementations§
impl<T, S, E> Freeze for CallBuilder<T, S, E>
impl<T, S, E> RefUnwindSafe for CallBuilder<T, S, E>
impl<T, S, E> Send for CallBuilder<T, S, E>
impl<T, S, E> Sync for CallBuilder<T, S, E>
impl<T, S, E> Unpin for CallBuilder<T, S, E>
impl<T, S, E> UnwindSafe for CallBuilder<T, S, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<TxEnv, T> FromRecoveredTx<&T> for TxEnvwhere
TxEnv: FromRecoveredTx<T>,
impl<TxEnv, T> FromRecoveredTx<&T> for TxEnvwhere
TxEnv: FromRecoveredTx<T>,
§fn from_recovered_tx(tx: &&T, sender: Address) -> TxEnv
fn from_recovered_tx(tx: &&T, sender: Address) -> TxEnv
TxEnv
] from a transaction and a sender address.§impl<TxEnv, T> FromTxWithEncoded<&T> for TxEnvwhere
TxEnv: FromTxWithEncoded<T>,
impl<TxEnv, T> FromTxWithEncoded<&T> for TxEnvwhere
TxEnv: FromTxWithEncoded<T>,
§fn from_encoded_tx(tx: &&T, sender: Address, encoded: Bytes) -> TxEnv
fn from_encoded_tx(tx: &&T, sender: Address, encoded: Bytes) -> TxEnv
TxEnv
] from a transaction, its sender, and encoded transaction bytes.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.