feat(evm): add nonce methods to TxEnv (#14014)

This commit is contained in:
Dan Cline
2025-01-27 13:11:29 -05:00
committed by GitHub
parent 2d044a24c0
commit 6b1b9c41aa

View File

@ -241,6 +241,36 @@ pub trait TransactionEnv:
self
}
/// Returns the configured nonce.
///
/// This may return `None`, if the nonce has been intentionally unset in the environment. This
/// is useful in optimizations like transaction prewarming, where nonce checks should be
/// ignored.
fn nonce(&self) -> Option<u64>;
/// Sets the nonce.
fn set_nonce(&mut self, nonce: u64);
/// Sets the nonce.
fn with_nonce(mut self, nonce: u64) -> Self {
self.set_nonce(nonce);
self
}
/// Unsets the nonce. This should be used when nonce checks for the transaction should be
/// ignored.
///
/// See [`TransactionEnv::nonce`] for applications where this may be desired.
fn unset_nonce(&mut self);
/// Constructs a version of this [`TransactionEnv`] that has the nonce unset.
///
/// See [`TransactionEnv::nonce`] for applications where this may be desired.
fn without_nonce(mut self) -> Self {
self.unset_nonce();
self
}
/// Returns configured gas price.
fn gas_price(&self) -> U256;
@ -279,6 +309,18 @@ impl TransactionEnv for TxEnv {
self.gas_price.to()
}
fn nonce(&self) -> Option<u64> {
self.nonce
}
fn set_nonce(&mut self, nonce: u64) {
self.nonce = Some(nonce);
}
fn unset_nonce(&mut self) {
self.nonce = None;
}
fn value(&self) -> U256 {
self.value
}