Skip to content

Commit

Permalink
feat(evm): add nonce methods to TxEnv (paradigmxyz#14014)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Jan 27, 2025
1 parent 2d044a2 commit 6b1b9c4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6b1b9c4

Please sign in to comment.