From f8cd8c56a297853403a6ad2e740e07677bf4abfc Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 4 May 2024 13:50:23 +0200 Subject: [PATCH] feat: add helper functions for batch executor (#8087) --- crates/evm/src/execute.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index 7b3e58646..e7ce09e79 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -34,6 +34,27 @@ pub trait BatchExecutor { /// Executes the next block in the batch and update the state internally. fn execute_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error>; + /// Executes multiple inputs in the batch and update the state internally. + fn execute_many<'a, I>(&mut self, inputs: I) -> Result<(), Self::Error> + where + I: IntoIterator>, + { + for input in inputs { + self.execute_one(input)?; + } + Ok(()) + } + + /// Executes the entire batch and return the final state. + fn execute_batch<'a, I>(mut self, batch: I) -> Result + where + I: IntoIterator>, + Self: Sized, + { + self.execute_many(batch)?; + Ok(self.finalize()) + } + /// Finishes the batch and return the final state. fn finalize(self) -> Self::Output;